Skip to content

Commit 731d7c7

Browse files
author
Zack Jones
committed
WECH-23: Added Banner story
1 parent 0476687 commit 731d7c7

File tree

2 files changed

+142
-0
lines changed

2 files changed

+142
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import React from 'react';
2+
import styled from 'styled-components';
3+
import { ComponentStory, ComponentMeta } from '@storybook/react';
4+
import { Banner as BannerWave, Button } from '../..';
5+
6+
const Banner = styled(BannerWave)`
7+
position: initial;
8+
transition: none;
9+
`;
10+
11+
const description = `
12+
Banner is a strong visual pattern that is used to display an important information or state which remains until the cause is resolved or the banner is dismissed by the user.
13+
14+
- Banner can include any kind of content, i.e. icons, links, copy
15+
- Banner should be dismissible
16+
- Banner **info** and **success** appear at the bottom of the screen (sticky)
17+
- Banner **error** appears at the top of the screen (sticky)
18+
- Banner appears and disappears via slide in/out animation combined with soft fade and smooth easing
19+
20+
To properly hide the banner with the correct animation, it is recommended to call the dismiss function that can be used when providing a function as the child. This will also unmount the component once the animation is completed.
21+
22+
If you need the banner to be placed top or bottom without depending on the variant make sure to align with the design team and bear in mind that you can use the **position** prop for it.
23+
`;
24+
25+
export default {
26+
title: 'Components/Banner',
27+
component: Banner,
28+
parameters: {
29+
docs: {
30+
description: {
31+
component: description
32+
}
33+
}
34+
},
35+
argTypes: {
36+
onClose: { table: { disable: true } },
37+
children: {
38+
description: 'Children elements can be a ReactNode or a render prop that provides a dismiss method',
39+
control: { type: 'none' }
40+
}
41+
}
42+
} as ComponentMeta<typeof Banner>;
43+
44+
const Template: ComponentStory<typeof Banner> = args => <Banner {...args} />;
45+
46+
export const Info = Template.bind({});
47+
Info.args = {
48+
variant: 'info',
49+
children: (
50+
<>
51+
In order to continuously improve our websites, and show offers and advertisements that are suited to you, we
52+
use cookies, tracking and (re-)targeting technologies. Please see our Cookie policy for more information.
53+
Tracking and (re-)targeting technologies will only be used if you click on Agree.
54+
</>
55+
)
56+
};
57+
58+
export const Success = Template.bind({});
59+
Success.args = {
60+
variant: 'success',
61+
children: 'Booking radius updated'
62+
};
63+
64+
export const Danger = Template.bind({});
65+
Danger.args = {
66+
variant: 'danger',
67+
children: 'Something went wrong :('
68+
};
69+
70+
export const Dismiss = Template.bind({});
71+
const code = `
72+
<Banner>
73+
{dismiss => <Button onClick={dismiss}>Close</Button>}
74+
</Banner>
75+
`;
76+
Dismiss.args = {
77+
variant: 'info',
78+
children: dismiss => <Button onClick={dismiss}>Close</Button>
79+
};
80+
Dismiss.parameters = {
81+
docs: {
82+
source: { code, language: 'javascript', type: 'auto' }
83+
}
84+
};
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import React from 'react';
2+
import styled from 'styled-components';
3+
import { ComponentStory, ComponentMeta } from '@storybook/react';
4+
import { Button, Banner as BannerWave, useBannerDismiss } from '../..';
5+
6+
const Banner = styled(BannerWave)`
7+
position: initial;
8+
transition: none;
9+
`;
10+
11+
const InsideBanner = () => {
12+
const dismiss = useBannerDismiss();
13+
return <Button onClick={dismiss}>Close</Button>;
14+
};
15+
16+
const Example = () => (
17+
<Banner>
18+
<InsideBanner />
19+
</Banner>
20+
);
21+
22+
const code = `
23+
const InsideBanner = () => {
24+
const dismiss = useBannerDismiss()
25+
return <Button onClick={dismiss}>Close</Button>
26+
}
27+
28+
const Wrapper = () => (
29+
<Banner>
30+
<InsideBanner />
31+
</Banner>
32+
)
33+
`;
34+
35+
const description =
36+
'Renders a `button` tag. This module exposes two types of buttons `<TextButton />` and `<Button />`. Take a look to the [MDN web docs - Button](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button) to know more about some of the default props supported by a button along with some accessibility concerns. \n\n The purpose of the buttons is to trigger an interaction like order, confirmation or submit. For navigation targets consider a link. Use the primary button only once per screen and avoid putting two primary buttons next to each other. Use the secondary button for less important actions and in multi button scenarios.';
37+
38+
export default {
39+
title: 'Hooks/useBannerDismiss',
40+
component: Example,
41+
parameters: {
42+
docs: {
43+
description: {
44+
component: description
45+
}
46+
}
47+
}
48+
} as ComponentMeta<typeof Example>;
49+
50+
const Template: ComponentStory<typeof Example> = () => <Example />;
51+
52+
export const Default = Template.bind({});
53+
Default.storyName = 'useBannerDismiss';
54+
Default.parameters = {
55+
docs: {
56+
source: { code, language: 'javascript', type: 'auto' }
57+
}
58+
};

0 commit comments

Comments
 (0)