1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00
metamask-extension/ui/components/component-library/popover-header/popover-header.tsx
Garrett Bear 2326195324
Add DS Popover component (#18805)
* Add DS Popover component

* Update to Popover story

* make role a prop with PopoverRole enum

* update to Hiro design changes

* fix snapshot

* Update ui/components/component-library/popover/README.mdx

Co-authored-by: George Marshall <george.marshall@consensys.net>

* Update ui/components/component-library/popover/README.mdx

Co-authored-by: George Marshall <george.marshall@consensys.net>

* small story changes and removal of unused forwardRef

* add more test coverage

* add more story demos

* add more popover demos

* if escKeyClose is passed then it will add event listener

* isPortal story

* add if statement

* replace Text with Box for now

* add esc test coverage

* add README docs

* fix readme and onEscKeyClose

* onEscKeyClose to onPressEscKey

* Update ui/components/component-library/popover/README.mdx

Co-authored-by: George Marshall <george.marshall@consensys.net>

* change conditional on useEffect

---------

Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
Co-authored-by: George Marshall <george.marshall@consensys.net>
2023-05-19 11:49:53 -07:00

70 lines
1.6 KiB
TypeScript

import React from 'react';
import classnames from 'classnames';
import { HeaderBase, Text, ButtonIcon, ButtonIconSize, IconName } from '..';
import {
IconColor,
TextVariant,
TextAlign,
Color,
} from '../../../helpers/constants/design-system';
import { useI18nContext } from '../../../hooks/useI18nContext';
import { PopoverHeaderProps } from '.';
export const PopoverHeader: React.FC<PopoverHeaderProps> = ({
children,
className = '',
startAccessory,
endAccessory,
onClose,
closeButtonProps,
onBack,
backButtonProps,
...props
}) => {
const t = useI18nContext();
return (
<HeaderBase
className={classnames('mm-popover-header', className)}
startAccessory={
startAccessory ||
(onBack && (
<ButtonIcon
iconName={IconName.ArrowLeft}
color={IconColor.inherit}
ariaLabel={t('back')}
size={ButtonIconSize.Sm}
onClick={onBack}
{...backButtonProps}
/>
))
}
endAccessory={
endAccessory ||
(onClose && (
<ButtonIcon
iconName={IconName.Close}
color={IconColor.inherit}
ariaLabel={t('close')}
size={ButtonIconSize.Sm}
onClick={onClose}
{...closeButtonProps}
/>
))
}
{...props}
>
{typeof children === 'string' ? (
<Text
variant={TextVariant.headingSm}
textAlign={TextAlign.Center}
color={Color.inherit}
>
{children}
</Text>
) : (
children
)}
</HeaderBase>
);
};