1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 02:10:12 +01:00
metamask-extension/ui/components/component-library/popover-header
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
..
__snapshots__ Add DS Popover component (#18805) 2023-05-19 11:49:53 -07:00
index.ts Feat/18308/ds popover header component (#18489) 2023-04-19 10:36:01 -07:00
popover-header.stories.tsx Adding ModalHeader component and updating PopoverHeader stories (#18311) 2023-04-25 14:27:54 -07:00
popover-header.test.tsx Adding ModalHeader component and updating PopoverHeader stories (#18311) 2023-04-25 14:27:54 -07:00
popover-header.tsx Add DS Popover component (#18805) 2023-05-19 11:49:53 -07:00
popover-header.types.ts Adding ModalHeader component and updating PopoverHeader stories (#18311) 2023-04-25 14:27:54 -07:00
README.mdx Adding ModalHeader component and updating PopoverHeader stories (#18311) 2023-04-25 14:27:54 -07:00

import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import { PopoverHeader } from './popover-header';

# PopoverHeader

`PopoverHeader` handles the title, close button and back button for all `Popover` components. It is built on top of the [HeaderBase](/docs/components-componentlibrary-headerbase--default-story) component

<Canvas>
  <Story id="components-componentlibrary-popoverheader--default-story" />
</Canvas>

## Props

The `PopoverHeader` accepts all props below as well as all [Box](/docs/ui-components-ui-box-box-stories-js--default-story#props) component props

<ArgsTable of={PopoverHeader} />

### Children

The title of the `PopoverHeader` component. Passing a `string` will render the content inside of a `Text` component. Passing any other type will render the content as is.

<Canvas>
  <Story id="components-componentlibrary-popoverheader--children" />
</Canvas>

```jsx
import {
  TextVariant,
  TextAlign,
  DISPLAY,
  FLEX_DIRECTION,
  AlignItems,
  JustifyContent,
} from '../../../helpers/constants/design-system';

import { PopoverHeader,  AvatarAccount, Text } from '../../component-library';

<PopoverHeader {...args} marginBottom={4}>
  Children as string
</PopoverHeader>
<PopoverHeader
  {...args}
  childrenWrapperProps={{
    display: DISPLAY.FLEX,
    flexDirection: FLEX_DIRECTION.COLUMN,
    alignItems: AlignItems.center,
    justifyContent: JustifyContent.center,
  }}
>
  <AvatarAccount address="0x1234" />
  <Text variant={TextVariant.headingSm} textAlign={TextAlign.Center}>
    Custom header using multiple components
  </Text>
</PopoverHeader>
```

### onBack

Use the onClick handler `onBack` prop to render the `ButtonIcon` back button in the startAccessory position.

Use the `backButtonProps` prop to pass additional props to the `ButtonIcon` back button.

<Canvas>
  <Story id="components-componentlibrary-popoverheader--on-back" />
</Canvas>

```jsx
import { PopoverHeader } from '../../component-library';

<PopoverHeader onBack={() => console.log('Back button click')}>
  OnBack Demo
</PopoverHeader>;
```

### onClose

Use the onClick handler `onClose` prop to render the `ButtonIcon` back button in the endAccessory position.

Use the `backButtonProps` prop to pass additional props to the `ButtonIcon` back button.

<Canvas>
  <Story id="components-componentlibrary-popoverheader--on-close" />
</Canvas>

```jsx
import { PopoverHeader } from '../../component-library';

<PopoverHeader onClose={() => console.log('Back button click')}>
  OnClose Demo
</PopoverHeader>;
```

### startAccessory

Use the `startAccessory` prop to render a component in the startAccessory position. This will override the default back `ButtonIcon`.

<Canvas>
  <Story id="components-componentlibrary-popoverheader--start-accessory" />
</Canvas>

```jsx
import { PopoverHeader, Button, BUTTON_SIZES } from '../../component-library';

<PopoverHeader startAccessory={<Button size={BUTTON_SIZES.SM}>Demo</Button>}>
  StartAccessory
</PopoverHeader>;
```

### endAccessory

Use the `endAccessory` prop to render a component in the endAccessory position. This will override the default close `ButtonIcon`.

<Canvas>
  <Story id="components-componentlibrary-popoverheader--end-accessory" />
</Canvas>

```jsx
import { PopoverHeader, Button, BUTTON_SIZES } from '../../component-library';

<PopoverHeader endAccessory={<Button size={BUTTON_SIZES.SM}>Demo</Button>}>
  EndAccessory
</PopoverHeader>;
```