2023-01-25 19:39:49 +01:00
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';
2023-02-07 18:32:35 +01:00
import { BannerAlert } from './banner-alert';
2023-01-25 19:39:49 +01:00
import { BannerBase } from '..';
2023-02-07 18:32:35 +01:00
# BannerAlert
2023-01-25 19:39:49 +01:00
2023-02-07 18:32:35 +01:00
`BannerAlert` is an inline notification that notifies users of important information & sometimes time-sensitive changes.
2023-01-25 19:39:49 +01:00
<Canvas>
2023-02-07 18:32:35 +01:00
<Story id="components-componentlibrary-banneralert--default-story" />
2023-01-25 19:39:49 +01:00
</Canvas>
## Props
2023-02-07 18:32:35 +01:00
The `BannerAlert` accepts all props below as well as all [Box](/docs/components-ui-box--default-story#props) component props
2023-01-25 19:39:49 +01:00
2023-02-14 18:33:04 +01:00
<ArgsTable of={BannerAlert} />
2023-01-25 19:39:49 +01:00
2023-02-07 18:32:35 +01:00
The `BannerAlert` accepts all `BannerBase` component props below
2023-01-25 19:39:49 +01:00
<ArgsTable of={BannerBase} />
### Severity
2023-08-01 23:41:30 +02:00
Use the `severity` prop and the `Severity` enum from `./ui/helpers/constants/design-system.js` to change the context of `BannerAlert`.
2023-01-25 19:39:49 +01:00
2023-08-01 23:41:30 +02:00
Optional: `BANNER_ALERT_SEVERITIES` from `./banner` object can be used instead of `Severity`.
2023-01-25 19:39:49 +01:00
Possible options:
2023-08-01 23:41:30 +02:00
- `Severity.Info` Default
- `Severity.Warning`
- `Severity.Danger`
- `Severity.Success`
2023-01-25 19:39:49 +01:00
<Canvas>
2023-08-01 23:41:30 +02:00
<Story id="components-componentlibrary-banneralert--severity-story" />
2023-01-25 19:39:49 +01:00
</Canvas>
```jsx
2023-02-07 18:32:35 +01:00
import { BannerAlert } from '../../component-library';
2023-08-01 23:41:30 +02:00
import { Severity } from '../../../helpers/constants/design-system';
2023-01-25 19:39:49 +01:00
2023-02-07 18:32:35 +01:00
<BannerAlert title="Info">
2023-01-25 19:39:49 +01:00
This is a demo of severity Info.
2023-02-07 18:32:35 +01:00
</BannerAlert>
2023-08-01 23:41:30 +02:00
<BannerAlert severity={Severity.Warning} title="Warning">
2023-01-25 19:39:49 +01:00
This is a demo of severity Warning.
2023-02-07 18:32:35 +01:00
</BannerAlert>
2023-08-01 23:41:30 +02:00
<BannerAlert severity={Severity.Danger} title="Danger">
2023-01-25 19:39:49 +01:00
This is a demo of severity Danger.
2023-02-07 18:32:35 +01:00
</BannerAlert>
2023-08-01 23:41:30 +02:00
<BannerAlert severity={Severity.Success} title="Success">
2023-01-25 19:39:49 +01:00
This is a demo of severity Success.
2023-02-07 18:32:35 +01:00
</BannerAlert>
2023-01-25 19:39:49 +01:00
```
### 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>
2023-02-07 18:32:35 +01:00
<Story id="components-componentlibrary-banneralert--title" />
2023-01-25 19:39:49 +01:00
</Canvas>
```jsx
2023-02-07 18:32:35 +01:00
import { BannerAlert } from '../../component-library';
2023-01-25 19:39:49 +01:00
2023-02-07 18:32:35 +01:00
<BannerAlert title="Title is sentence case no period">
2023-01-25 19:39:49 +01:00
Pass only a string through the title prop
2023-02-07 18:32:35 +01:00
</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"
/>;
2023-01-25 19:39:49 +01:00
```
### Children
2023-02-07 18:32:35 +01:00
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.
2023-01-25 19:39:49 +01:00
<Canvas>
2023-02-07 18:32:35 +01:00
<Story id="components-componentlibrary-banneralert--children" />
2023-01-25 19:39:49 +01:00
</Canvas>
```jsx
2023-02-02 21:15:26 +01:00
import { Size } from '../../../helpers/constants/design-system';
2023-02-07 18:32:35 +01:00
import { BannerAlert } from '../../component-library';
2023-01-25 19:39:49 +01:00
2023-02-07 18:32:35 +01:00
<BannerAlert>
2023-01-25 19:39:49 +01:00
{`Description shouldn't repeat title. 1-3 lines. Can contain a `}
2023-02-02 21:15:26 +01:00
<ButtonLink size={Size.auto} href="https://metamask.io/" target="_blank">
2023-01-25 19:39:49 +01:00
hyperlink.
</ButtonLink>
2023-02-07 18:32:35 +01:00
</BannerAlert>;
2023-01-25 19:39:49 +01:00
```
### 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>
2023-02-07 18:32:35 +01:00
<Story id="components-componentlibrary-banneralert--action-button" />
2023-01-25 19:39:49 +01:00
</Canvas>
```jsx
2023-04-05 18:11:10 +02:00
import { BannerAlert, IconName } from '../../component-library';
2023-01-25 19:39:49 +01:00
2023-02-07 18:32:35 +01:00
<BannerAlert
2023-01-25 19:39:49 +01:00
title="Action prop demo"
actionButtonLabel="Action"
actionButtonProps={{
2023-04-05 18:11:10 +02:00
endIconName: IconName.Arrow2Right,
2023-01-25 19:39:49 +01:00
}}
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
2023-02-07 18:32:35 +01:00
</BannerAlert>;
2023-01-25 19:39:49 +01:00
```
### 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>
2023-02-07 18:32:35 +01:00
<Story id="components-componentlibrary-banneralert--on-close" />
2023-01-25 19:39:49 +01:00
</Canvas>
```jsx
2023-02-07 18:32:35 +01:00
import { BannerAlert } from '../../component-library';
2023-01-25 19:39:49 +01:00
2023-02-07 18:32:35 +01:00
<BannerAlert
2023-01-25 19:39:49 +01:00
title="onClose demo"
onClose={() => console.log('close button clicked')}
>
Click the close button icon to hide this notifcation
2023-02-07 18:32:35 +01:00
</BannerAlert>;
2023-01-25 19:39:49 +01:00
```