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/modal-header
rohit kerkar 80de5ceed4
Part of #18714: Replacing deprecated constants in Modal-Header folder (#19339)
* replacing deprecated

* replacing deprecated

---------

Co-authored-by: Brad Decker <bhdecker84@gmail.com>
2023-05-31 10:12:21 -07:00
..
__snapshots__ Some style, accessibility and sematic html updates to modal sub components (#19034) 2023-05-09 14:09:10 -07:00
index.ts Adding ModalHeader component and updating PopoverHeader stories (#18311) 2023-04-25 14:27:54 -07:00
modal-header.stories.tsx Part of #18714: Replacing deprecated constants in Modal-Header folder (#19339) 2023-05-31 10:12:21 -07:00
modal-header.test.tsx Adding ModalHeader component and updating PopoverHeader stories (#18311) 2023-04-25 14:27:54 -07:00
modal-header.tsx Some style, accessibility and sematic html updates to modal sub components (#19034) 2023-05-09 14:09:10 -07:00
modal-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 { ModalHeader } from './modal-header';

# ModalHeader

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

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

## Props

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

<ArgsTable of={ModalHeader} />

### Children

The title of the `ModalHeader` 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-modalheader--children" />
</Canvas>

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

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

<ModalHeader {...args} marginBottom={4}>
  Children as string
</ModalHeader>
<ModalHeader
  {...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>
</ModalHeader>
```

### 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-modalheader--on-back" />
</Canvas>

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

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

### 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-modalheader--on-close" />
</Canvas>

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

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

### 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-modalheader--start-accessory" />
</Canvas>

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

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

### 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-modalheader--end-accessory" />
</Canvas>

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

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