Skip to content

Commit 5889c10

Browse files
author
Nikolai Lopin
committed
docs: moves Banner stories to the banner folder
1 parent c746efb commit 5889c10

File tree

3 files changed

+151
-1
lines changed

3 files changed

+151
-1
lines changed

src/components/Banner/Banner.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ type DismissFunc = () => void;
7575

7676
interface BannerProps {
7777
/**
78-
* Overrides the banner position.
78+
* Set banner position
7979
*/
8080
position?: 'top' | 'bottom';
8181
/**
8282
* Set the appropriate background color, screen position, and animation.
83+
* @default info
8384
*/
8485
variant?: 'info' | 'success' | 'danger';
8586
/**
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import React from 'react';
2+
import { Meta, StoryObj } from '@storybook/react';
3+
import { Banner } from '../Banner';
4+
import { Text } from '../../Text/Text';
5+
import { Button } from '../../Button/Button';
6+
7+
const meta: Meta = {
8+
title: 'Components/Banner',
9+
component: Banner,
10+
argTypes: {
11+
children: {
12+
description:
13+
'Content of the banner. Can be `ReactNode` or a render function that receives a dismiss method',
14+
control: { type: 'none' }
15+
},
16+
position: {
17+
table: {
18+
defaultValue: {
19+
summary: 'Depends on the variant prop value',
20+
detail: `
21+
info → top\nsuccess → top\ndanger → bottom
22+
`
23+
}
24+
}
25+
}
26+
},
27+
args: {
28+
children: (
29+
<Text inverted>
30+
In order to continuously improve our websites, and show offers and advertisements that are suited to
31+
you, we use cookies, tracking and (re-) targeting technologies. Please see our Cookie policy for more
32+
information. Tracking and (re-) targeting technologies will only be used if you click on Agree.
33+
</Text>
34+
)
35+
},
36+
decorators: [
37+
Story => (
38+
<div
39+
style={{
40+
willChange: 'transform',
41+
height: '250px',
42+
border: '1px dashed gray',
43+
display: 'flex',
44+
alignItems: 'center',
45+
justifyContent: 'center'
46+
}}
47+
>
48+
<Text secondary fontSize={3}>
49+
Page
50+
</Text>
51+
<Story />
52+
</div>
53+
)
54+
]
55+
};
56+
57+
export default meta;
58+
59+
type Story = StoryObj<typeof Banner>;
60+
61+
export const Default: Story = {
62+
args: {
63+
children: <Text inverted>Hello</Text>
64+
}
65+
};
66+
67+
export const Success: Story = {
68+
args: {
69+
variant: 'success'
70+
}
71+
};
72+
73+
export const Danger: Story = {
74+
args: {
75+
variant: 'danger',
76+
children: <Text inverted>Oops! Something went wrong</Text>
77+
}
78+
};
79+
80+
export const PositionTop: Story = {
81+
args: {
82+
position: 'top'
83+
}
84+
};
85+
86+
export const WithDismissedFn: Story = {
87+
args: {
88+
children: dismiss => (
89+
<>
90+
<Text inverted>If you are tired of this banner, hit the button 👉 </Text>
91+
<Button onClick={dismiss}>Close</Button>
92+
</>
93+
)
94+
}
95+
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { Meta, ArgTypes, Primary, Story, Stories, Source } from '@storybook/blocks';
2+
import * as BannerStories from './Banner.stories';
3+
import { Advice } from '../../../docs/Advice';
4+
5+
<Meta of={BannerStories} />
6+
7+
# Banner
8+
9+
Banner is a strong visual pattern that is used to display important information or state which remains until the
10+
cause is resolved or the banner is dismissed by the user.
11+
12+
- Banner can include any kind of content, i.e. icons, links, copy
13+
- Banner should be dismissible
14+
- Banner **info** and **success** appear at the bottom of the screen (sticky)
15+
- Banner **error** appears at the top of the screen (sticky)
16+
- Banner appears and disappears via slide in/out animation combined with soft fade and smooth easing
17+
18+
To properly hide the banner with the correct animation, it is recommended to call the dismiss function that can be used
19+
when providing a function as the child. This will also unmount the component once the animation is completed.
20+
21+
If you need the banner to be placed top or bottom without depending on the variant make sure to align with the design team
22+
and bear in mind that you can use the **position** prop for it.
23+
24+
<Primary />
25+
26+
## Properties
27+
28+
<ArgTypes of={BannerStories.Default} />
29+
30+
<Advice>
31+
The `Banner` uses `position:sticky` for positioning. It means it will always be rendered on top/bottom of the
32+
viewport ([MDN](http://developer.mozilla.org/en-US/docs/Web/CSS/position)).
33+
</Advice>
34+
35+
## Visibility management (dismiss function)
36+
37+
Banner provides a function to dismiss the component with an animation.
38+
The dismiss function is available either through render props or a hook.
39+
After the animation has finished the onClose callback will be called.
40+
41+
<Story of={BannerStories.WithDismissedFn} />
42+
43+
```tsx
44+
<Banner>
45+
{dismiss => (
46+
<>
47+
<Text inverted>If you are tired of this banner, hit the button 👉 </Text>
48+
<Button onClick={dismiss}>Close</Button>
49+
</>
50+
)}
51+
</Banner>
52+
```
53+
54+
<Stories includePrimary={false} />

0 commit comments

Comments
 (0)