Skip to content

Commit 6f53c42

Browse files
committed
feat(Banner): add banner component
1 parent 32b0cf7 commit 6f53c42

File tree

82 files changed

+630
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+630
-3
lines changed

e2e/components/Banner.test.ts

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import {test, expect} from '@playwright/test'
2+
import {visit} from '../test-helpers/storybook'
3+
import {themes} from '../test-helpers/themes'
4+
5+
const stories = [
6+
// {
7+
// title: 'Default',
8+
// id: 'drafts-components-banner--default',
9+
// },
10+
{
11+
title: 'Critical',
12+
id: 'drafts-components-banner-features--critical',
13+
},
14+
{
15+
title: 'Info',
16+
id: 'drafts-components-banner-features--info',
17+
},
18+
{
19+
title: 'Success',
20+
id: 'drafts-components-banner-features--success',
21+
},
22+
{
23+
title: 'Upsell',
24+
id: 'drafts-components-banner-features--upsell',
25+
},
26+
{
27+
title: 'Warning',
28+
id: 'drafts-components-banner-features--warning',
29+
},
30+
{
31+
title: 'Dismiss',
32+
id: 'drafts-components-banner-features--dismiss',
33+
},
34+
{
35+
title: 'TitleOnly',
36+
id: 'drafts-components-banner-features--title-only',
37+
},
38+
{
39+
title: 'WithTitle',
40+
id: 'drafts-components-banner-features--with-title',
41+
},
42+
{
43+
title: 'WithActions',
44+
id: 'drafts-components-banner-features--with-actions',
45+
},
46+
]
47+
48+
test.describe('Banner', () => {
49+
for (const story of stories) {
50+
test.describe(story.title, () => {
51+
for (const theme of themes) {
52+
test.describe(theme, () => {
53+
test('default @vrt', async ({page}) => {
54+
await visit(page, {
55+
id: story.id,
56+
globals: {
57+
colorScheme: theme,
58+
},
59+
})
60+
61+
// Default state
62+
expect(await page.screenshot()).toMatchSnapshot(`Banner.${story.title}.${theme}.png`)
63+
})
64+
65+
test('axe @aat', async ({page}) => {
66+
await visit(page, {
67+
id: story.id,
68+
globals: {
69+
colorScheme: theme,
70+
},
71+
})
72+
await expect(page).toHaveNoViolations()
73+
})
74+
})
75+
}
76+
})
77+
}
78+
79+
// Responsive
80+
test('Responsive behavior', async ({page}) => {
81+
await visit(page, {
82+
id: 'drafts-components-banner--default',
83+
})
84+
85+
// Small
86+
// await page.setViewportSize({width: 375, height: 667})
87+
// expect(await page.screenshot()).toMatchSnapshot('Banner.Responsive.Small.png')
88+
89+
// Medium
90+
// await page.setViewportSize({width: 1024, height: 768})
91+
// expect(await page.screenshot()).toMatchSnapshot('Banner.Responsive.Medium.png')
92+
93+
// Large
94+
// await page.setViewportSize({width: 1024, height: 768})
95+
// expect(await page.screenshot()).toMatchSnapshot('Banner.Responsive.Large.png')
96+
})
97+
})

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"id": "banner",
3+
"name": "Banner",
4+
"status": "draft",
5+
"a11yReviewed": false,
6+
"stories": [],
7+
"props": [
8+
{
9+
"name": "onDismiss",
10+
"type": "() => void",
11+
"description": ""
12+
},
13+
{
14+
"name": "icon",
15+
"type": "",
16+
"description": ""
17+
},
18+
{
19+
"name": "title",
20+
"type": "",
21+
"description": ""
22+
},
23+
{
24+
"name": "variant",
25+
"type": "",
26+
"description": ""
27+
}
28+
],
29+
"subcomponents": [
30+
{
31+
"name": "Banner.Description",
32+
"props": []
33+
},
34+
{
35+
"name": "Banner.Actions",
36+
"props": []
37+
},
38+
{
39+
"name": "Banner.PrimaryAction",
40+
"props": []
41+
},
42+
{
43+
"name": "Banner.SecondaryAction",
44+
"props": []
45+
}
46+
]
47+
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import {Banner} from '../Banner'
2+
import {action} from '@storybook/addon-actions'
3+
import Link from '../Link'
4+
import type {Meta} from '@storybook/react'
5+
6+
const meta = {
7+
title: 'Drafts/Components/Banner/Features',
8+
component: Banner,
9+
} satisfies Meta<typeof Banner>
10+
11+
export default meta
12+
13+
export const Critical = () => {
14+
return (
15+
<Banner variant="critical">
16+
<Banner.Description>
17+
GitHub users are{' '}
18+
<Link inline underline href="#">
19+
now required
20+
</Link>{' '}
21+
to enable two-factor authentication as an additional security measure.
22+
</Banner.Description>
23+
</Banner>
24+
)
25+
}
26+
27+
export const Info = () => {
28+
return (
29+
<Banner onDismiss={action('onDismiss')} variant="info">
30+
<Banner.Description>
31+
GitHub users are{' '}
32+
<Link inline underline href="#">
33+
now required
34+
</Link>{' '}
35+
to enable two-factor authentication as an additional security measure.
36+
</Banner.Description>
37+
</Banner>
38+
)
39+
}
40+
41+
export const Success = () => {
42+
return (
43+
<Banner onDismiss={action('onDismiss')} variant="success">
44+
<Banner.Description>
45+
GitHub users are{' '}
46+
<Link inline underline href="#">
47+
now required
48+
</Link>{' '}
49+
to enable two-factor authentication as an additional security measure.
50+
</Banner.Description>
51+
</Banner>
52+
)
53+
}
54+
55+
export const Upsell = () => {
56+
return (
57+
<Banner onDismiss={action('onDismiss')} variant="upsell">
58+
<Banner.Description>
59+
GitHub users are{' '}
60+
<Link inline underline href="#">
61+
now required
62+
</Link>{' '}
63+
to enable two-factor authentication as an additional security measure.
64+
</Banner.Description>
65+
</Banner>
66+
)
67+
}
68+
69+
export const Warning = () => {
70+
return (
71+
<Banner onDismiss={action('onDismiss')} variant="warning">
72+
<Banner.Description>
73+
GitHub users are{' '}
74+
<Link inline underline href="#">
75+
now required
76+
</Link>{' '}
77+
to enable two-factor authentication as an additional security measure.
78+
</Banner.Description>
79+
</Banner>
80+
)
81+
}
82+
83+
export const Dismiss = () => {
84+
return (
85+
<Banner onDismiss={action('onDismiss')}>
86+
<Banner.Description>
87+
GitHub users are{' '}
88+
<Link inline underline href="#">
89+
now required
90+
</Link>{' '}
91+
to enable two-factor authentication as an additional security measure.
92+
</Banner.Description>
93+
</Banner>
94+
)
95+
}
96+
97+
export const TitleOnly = () => {
98+
return (
99+
<Banner
100+
title={
101+
<>
102+
GitHub users are{' '}
103+
<Link inline underline href="#">
104+
now required
105+
</Link>{' '}
106+
to enable two-factor authentication as an additional security measure.
107+
</>
108+
}
109+
variant="warning"
110+
/>
111+
)
112+
}
113+
114+
export const WithTitle = () => {
115+
return (
116+
<Banner title="This is a title" variant="warning">
117+
<Banner.Description>
118+
GitHub users are{' '}
119+
<Link inline underline href="#">
120+
now required
121+
</Link>{' '}
122+
to enable two-factor authentication as an additional security measure.
123+
</Banner.Description>
124+
</Banner>
125+
)
126+
}
127+
128+
export const WithActions = () => {
129+
return (
130+
<Banner title="This is a title" variant="warning">
131+
<Banner.Description>
132+
GitHub users are{' '}
133+
<Link inline underline href="#">
134+
now required
135+
</Link>{' '}
136+
to enable two-factor authentication as an additional security measure.
137+
</Banner.Description>
138+
<Banner.Actions>
139+
<Banner.PrimaryAction>Button</Banner.PrimaryAction>
140+
<Banner.SecondaryAction>Button</Banner.SecondaryAction>
141+
</Banner.Actions>
142+
</Banner>
143+
)
144+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import type {Meta, StoryObj} from '@storybook/react'
2+
import React from 'react'
3+
import {Button} from '../Button'
4+
import Link from '../Link'
5+
import {Banner} from '../Banner'
6+
import {action} from '@storybook/addon-actions'
7+
8+
const meta = {
9+
title: 'Drafts/Components/Banner',
10+
component: Banner,
11+
} satisfies Meta<typeof Banner>
12+
13+
export default meta
14+
15+
export const Default = () => {
16+
return (
17+
<Banner title="This is a title" onDismiss={action('onDismiss')}>
18+
<Banner.Description>
19+
GitHub users are{' '}
20+
<Link inline href="#">
21+
now required
22+
</Link>{' '}
23+
to enable two-factor authentication as an additional security measure.
24+
</Banner.Description>
25+
<Banner.Actions>
26+
<Button>Button</Button>
27+
<Button variant="invisible">Button</Button>
28+
</Banner.Actions>
29+
</Banner>
30+
)
31+
}
32+
33+
export const Playground: StoryObj<typeof Banner> = {
34+
render: ({onDismiss, variant, ...rest}) => {
35+
return (
36+
<Banner
37+
{...rest}
38+
title="This is the title"
39+
onDismiss={onDismiss ? action('onDismiss') : undefined}
40+
variant={variant}
41+
>
42+
<Banner.Description>
43+
GitHub users are{' '}
44+
<Link inline underline href="#">
45+
now required
46+
</Link>{' '}
47+
to enable two-factor authentication as an additional security measure.
48+
</Banner.Description>
49+
</Banner>
50+
)
51+
},
52+
argTypes: {
53+
onDismiss: {
54+
controls: {
55+
type: 'boolean',
56+
},
57+
defaultValue: false,
58+
},
59+
variant: {
60+
controls: {
61+
type: 'radio',
62+
},
63+
options: ['critical', 'info', 'success', 'upsell', 'warning'],
64+
},
65+
},
66+
}

0 commit comments

Comments
 (0)