1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/components/component-library/banner-alert
Garrett Bear 79b2deb194
update text component color to use box color (#18246)
snapshot updates

fix snapshots

add background colors

fix snapshots
2023-03-23 13:00:37 -07:00
..
__snapshots__ update text component color to use box color (#18246) 2023-03-23 13:00:37 -07:00
banner-alert.constants.js Update BannerAlert component (#17586) 2023-02-07 09:32:35 -08:00
banner-alert.js fix broken stories and readme from TS update (#17703) 2023-02-14 11:33:04 -06:00
banner-alert.scss Update BannerAlert component (#17586) 2023-02-07 09:32:35 -08:00
banner-alert.stories.js update to add end icon support (#17776) 2023-02-22 09:42:06 -08:00
banner-alert.test.js Update BannerAlert component (#17586) 2023-02-07 09:32:35 -08:00
index.js Update BannerAlert component (#17586) 2023-02-07 09:32:35 -08:00
README.mdx update to add end icon support (#17776) 2023-02-22 09:42:06 -08:00

import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import { BannerAlert } from './banner-alert';
import { BannerBase } from '..';

# BannerAlert

`BannerAlert` is an inline notification that notifies users of important information & sometimes time-sensitive changes.

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

## Props

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

<ArgsTable of={BannerAlert} />

The `BannerAlert` accepts all `BannerBase` component props below

<ArgsTable of={BannerBase} />

### Severity

Use the `severity` prop and the `SEVERITIES` object from `./ui/helpers/constants/design-system.js` to change the context of `BannerAlert`.

Optional: `BANNER_ALERT_SEVERITIES` from `./banner` object can be used instead of `SEVERITIES`.

Possible options:

- `SEVERITIES.INFO` Default
- `SEVERITIES.WARNING`
- `SEVERITIES.DANGER`
- `SEVERITIES.SUCCESS`

<Canvas>
  <Story id="components-componentlibrary-banneralert--severity" />
</Canvas>

```jsx
import { BannerAlert } from '../../component-library';
import { SEVERITIES } from '../../../helpers/constants/design-system';

<BannerAlert title="Info">
  This is a demo of severity Info.
</BannerAlert>
<BannerAlert severity={SEVERITIES.WARNING} title="Warning">
  This is a demo of severity Warning.
</BannerAlert>
<BannerAlert severity={SEVERITIES.DANGER} title="Danger">
  This is a demo of severity Danger.
</BannerAlert>
<BannerAlert severity={SEVERITIES.SUCCESS} title="Success">
  This is a demo of severity Success.
</BannerAlert>
```

### Title

Use the `title` prop to pass a string that is sentence case no period. Use the `titleProps` prop to pass additional props to the `Text` component.

<Canvas>
  <Story id="components-componentlibrary-banneralert--title" />
</Canvas>

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

<BannerAlert title="Title is sentence case no period">
  Pass only a string through the title prop
</BannerAlert>;
```

### Description

The `description` is the content area of the `BannerAlert` that must be a string. Description shouldn't repeat title and only 1-3 lines.

If content requires more than a string, see `children` prop below.

<Canvas>
  <Story id="components-componentlibrary-banneralert--description" />
</Canvas>

```jsx
import { BannerAlert } from '../../component-library';
<BannerAlert
  title="Description vs children"
  description="Pass only a string through the description prop or you can use children if the contents require more"
/>;
```

### Children

The `children` prop is an alternative to `description` for `BannerAlert` when more than a string is needed. Children content shouldn't repeat title and only 1-3 lines.

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

```jsx
import { Size } from '../../../helpers/constants/design-system';
import { BannerAlert } from '../../component-library';

<BannerAlert>
  {`Description shouldn't repeat title. 1-3 lines. Can contain a `}
  <ButtonLink size={Size.auto} href="https://metamask.io/" target="_blank">
    hyperlink.
  </ButtonLink>
</BannerAlert>;
```

### Action Button Label, onClick, & Props

Use the `actionButtonLabel` prop to pass text, `actionButtonOnClick` prop to pass an onClick handler, and `actionButtonProps` prop to pass an object of [ButtonLink props](/docs/components-componentlibrary-buttonlink--default-story) for the action

<Canvas>
  <Story id="components-componentlibrary-banneralert--action-button" />
</Canvas>

```jsx
import { BannerAlert, ICON_NAMES } from '../../component-library';

<BannerAlert
  title="Action prop demo"
  actionButtonLabel="Action"
  actionButtonProps={{
    endIconName: ICON_NAMES.ARROW_2_RIGHT,
  }}
  actionButtonOnClick={() => console.log('ButtonLink actionButtonOnClick demo')}
>
  Use actionButtonLabel for action text, actionButtonOnClick for the onClick
  handler, and actionButtonProps to pass any ButtonLink prop types such as
  iconName
</BannerAlert>;
```

### On Close

Use the `onClose` prop to pass a function to the close button. The close button will appear when this prop is used.

Additional props can be passed to the close button with `closeButtonProps`

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

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

<BannerAlert
  title="onClose demo"
  onClose={() => console.log('close button clicked')}
>
  Click the close button icon to hide this notifcation
</BannerAlert>;
```