1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-29 23:58:06 +01:00
metamask-extension/ui/components/component-library/header-base/header-base.tsx
David Walsh ab4843f06b
UX: Multichain: Implement Account Details Popover (#18811)
* UX: Multichain: Implement Account Details Popover

* Styling account details popover

* using ButtonSecondary with variant, removing Text

* adding account-details jest test

* Close popover when outside area clicked

* Move all export functionality into the popover

* Improve jest tests

* Implement new design for export key screens

* Hide warning when popover is closed

* Vertically align the copy button

* Move AccountDetailsDisplay to its own file

* Move authentication to its own file

* Move private key to its own component

* Fix misalignment of avatar on display screen

* Move private key to its own component

* Update ui/components/multichain/account-details/account-details-authenticate.js

Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>

* Update ui/components/multichain/account-details/account-details.test.js

Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>

* Prevent account name overflow, update text size

* Use FormTextField

* Add analytics

* Move location of accountDetailsAddress

* Ensure passsword input is used

---------

Co-authored-by: Victor Thomas <10986371+vthomas13@users.noreply.github.com>
Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>
2023-05-03 12:09:13 -05:00

115 lines
3.0 KiB
TypeScript

import React, { useRef, useEffect, useMemo, useState } from 'react';
import classnames from 'classnames';
import {
BLOCK_SIZES,
DISPLAY,
JustifyContent,
} from '../../../helpers/constants/design-system';
import Box from '../../ui/box';
import { HeaderBaseProps } from './header-base.types';
export const HeaderBase: React.FC<HeaderBaseProps> = ({
startAccessory,
endAccessory,
className = '',
children,
childrenWrapperProps,
startAccessoryWrapperProps,
endAccessoryWrapperProps,
...props
}) => {
const startAccessoryRef = useRef<HTMLDivElement>(null);
const endAccessoryRef = useRef<HTMLDivElement>(null);
const [accessoryMinWidth, setAccessoryMinWidth] = useState<number>();
useEffect(() => {
function handleResize() {
if (startAccessoryRef.current && endAccessoryRef.current) {
const accMinWidth = Math.max(
startAccessoryRef.current.scrollWidth,
endAccessoryRef.current.scrollWidth,
);
setAccessoryMinWidth(accMinWidth);
} else if (startAccessoryRef.current && !endAccessoryRef.current) {
setAccessoryMinWidth(startAccessoryRef.current.scrollWidth);
} else if (!startAccessoryRef.current && endAccessoryRef.current) {
setAccessoryMinWidth(endAccessoryRef.current.scrollWidth);
} else {
setAccessoryMinWidth(0);
}
}
handleResize();
window.addEventListener('resize', handleResize);
return () => {
window.removeEventListener('resize', handleResize);
};
}, [startAccessoryRef, endAccessoryRef, children]);
const getTitleStyles = useMemo(() => {
if (startAccessory && !endAccessory) {
return {
marginRight: `${accessoryMinWidth}px`,
};
} else if (!startAccessory && endAccessory) {
return {
marginLeft: `${accessoryMinWidth}px`,
};
}
return {};
}, [accessoryMinWidth, startAccessory, endAccessory]);
return (
<Box
className={classnames('mm-header-base', className)}
display={DISPLAY.FLEX}
justifyContent={JustifyContent.spaceBetween}
{...props}
>
{startAccessory && (
<Box
ref={startAccessoryRef}
style={
children
? {
minWidth: `${accessoryMinWidth}px`,
}
: undefined
}
{...startAccessoryWrapperProps}
>
{startAccessory}
</Box>
)}
{children && (
<Box
width={BLOCK_SIZES.FULL}
style={getTitleStyles}
{...childrenWrapperProps}
>
{children}
</Box>
)}
{endAccessory && (
<Box
display={DISPLAY.FLEX}
justifyContent={JustifyContent.flexEnd}
ref={endAccessoryRef}
style={
children
? {
minWidth: `${accessoryMinWidth}px`,
}
: undefined
}
{...endAccessoryWrapperProps}
>
{endAccessory}
</Box>
)}
</Box>
);
};