Skip to content

Commit

Permalink
feat(Banner): add banner component
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblack committed Mar 1, 2024
1 parent 32b0cf7 commit 6f53c42
Show file tree
Hide file tree
Showing 82 changed files with 630 additions and 3 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
97 changes: 97 additions & 0 deletions e2e/components/Banner.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import {test, expect} from '@playwright/test'
import {visit} from '../test-helpers/storybook'
import {themes} from '../test-helpers/themes'

const stories = [
// {
// title: 'Default',
// id: 'drafts-components-banner--default',
// },
{
title: 'Critical',
id: 'drafts-components-banner-features--critical',
},
{
title: 'Info',
id: 'drafts-components-banner-features--info',
},
{
title: 'Success',
id: 'drafts-components-banner-features--success',
},
{
title: 'Upsell',
id: 'drafts-components-banner-features--upsell',
},
{
title: 'Warning',
id: 'drafts-components-banner-features--warning',
},
{
title: 'Dismiss',
id: 'drafts-components-banner-features--dismiss',
},
{
title: 'TitleOnly',
id: 'drafts-components-banner-features--title-only',
},
{
title: 'WithTitle',
id: 'drafts-components-banner-features--with-title',
},
{
title: 'WithActions',
id: 'drafts-components-banner-features--with-actions',
},
]

test.describe('Banner', () => {
for (const story of stories) {
test.describe(story.title, () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: story.id,
globals: {
colorScheme: theme,
},
})

// Default state
expect(await page.screenshot()).toMatchSnapshot(`Banner.${story.title}.${theme}.png`)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: story.id,
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})
}

// Responsive
test('Responsive behavior', async ({page}) => {
await visit(page, {
id: 'drafts-components-banner--default',
})

// Small
// await page.setViewportSize({width: 375, height: 667})
// expect(await page.screenshot()).toMatchSnapshot('Banner.Responsive.Small.png')

// Medium
// await page.setViewportSize({width: 1024, height: 768})
// expect(await page.screenshot()).toMatchSnapshot('Banner.Responsive.Medium.png')

// Large
// await page.setViewportSize({width: 1024, height: 768})
// expect(await page.screenshot()).toMatchSnapshot('Banner.Responsive.Large.png')
})
})
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions packages/react/src/Banner/Banner.docs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"id": "banner",
"name": "Banner",
"status": "draft",
"a11yReviewed": false,
"stories": [],
"props": [
{
"name": "onDismiss",
"type": "() => void",
"description": ""
},
{
"name": "icon",
"type": "",
"description": ""
},
{
"name": "title",
"type": "",
"description": ""
},
{
"name": "variant",
"type": "",
"description": ""
}
],
"subcomponents": [
{
"name": "Banner.Description",
"props": []
},
{
"name": "Banner.Actions",
"props": []
},
{
"name": "Banner.PrimaryAction",
"props": []
},
{
"name": "Banner.SecondaryAction",
"props": []
}
]
}
144 changes: 144 additions & 0 deletions packages/react/src/Banner/Banner.features.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import {Banner} from '../Banner'
import {action} from '@storybook/addon-actions'
import Link from '../Link'
import type {Meta} from '@storybook/react'

const meta = {
title: 'Drafts/Components/Banner/Features',
component: Banner,
} satisfies Meta<typeof Banner>

export default meta

export const Critical = () => {
return (
<Banner variant="critical">

Check failure on line 15 in packages/react/src/Banner/Banner.features.stories.tsx

View workflow job for this annotation

GitHub Actions / lint

'React' must be in scope when using JSX
<Banner.Description>

Check failure on line 16 in packages/react/src/Banner/Banner.features.stories.tsx

View workflow job for this annotation

GitHub Actions / lint

'React' must be in scope when using JSX
GitHub users are{' '}
<Link inline underline href="#">

Check failure on line 18 in packages/react/src/Banner/Banner.features.stories.tsx

View workflow job for this annotation

GitHub Actions / lint

'React' must be in scope when using JSX
now required
</Link>{' '}
to enable two-factor authentication as an additional security measure.
</Banner.Description>
</Banner>
)
}

export const Info = () => {
return (
<Banner onDismiss={action('onDismiss')} variant="info">

Check failure on line 29 in packages/react/src/Banner/Banner.features.stories.tsx

View workflow job for this annotation

GitHub Actions / lint

'React' must be in scope when using JSX
<Banner.Description>

Check failure on line 30 in packages/react/src/Banner/Banner.features.stories.tsx

View workflow job for this annotation

GitHub Actions / lint

'React' must be in scope when using JSX
GitHub users are{' '}
<Link inline underline href="#">

Check failure on line 32 in packages/react/src/Banner/Banner.features.stories.tsx

View workflow job for this annotation

GitHub Actions / lint

'React' must be in scope when using JSX
now required
</Link>{' '}
to enable two-factor authentication as an additional security measure.
</Banner.Description>
</Banner>
)
}

export const Success = () => {
return (
<Banner onDismiss={action('onDismiss')} variant="success">

Check failure on line 43 in packages/react/src/Banner/Banner.features.stories.tsx

View workflow job for this annotation

GitHub Actions / lint

'React' must be in scope when using JSX
<Banner.Description>

Check failure on line 44 in packages/react/src/Banner/Banner.features.stories.tsx

View workflow job for this annotation

GitHub Actions / lint

'React' must be in scope when using JSX
GitHub users are{' '}
<Link inline underline href="#">

Check failure on line 46 in packages/react/src/Banner/Banner.features.stories.tsx

View workflow job for this annotation

GitHub Actions / lint

'React' must be in scope when using JSX
now required
</Link>{' '}
to enable two-factor authentication as an additional security measure.
</Banner.Description>
</Banner>
)
}

export const Upsell = () => {
return (
<Banner onDismiss={action('onDismiss')} variant="upsell">

Check failure on line 57 in packages/react/src/Banner/Banner.features.stories.tsx

View workflow job for this annotation

GitHub Actions / lint

'React' must be in scope when using JSX
<Banner.Description>
GitHub users are{' '}
<Link inline underline href="#">
now required
</Link>{' '}
to enable two-factor authentication as an additional security measure.
</Banner.Description>
</Banner>
)
}

export const Warning = () => {
return (
<Banner onDismiss={action('onDismiss')} variant="warning">
<Banner.Description>
GitHub users are{' '}
<Link inline underline href="#">
now required
</Link>{' '}
to enable two-factor authentication as an additional security measure.
</Banner.Description>
</Banner>
)
}

export const Dismiss = () => {
return (
<Banner onDismiss={action('onDismiss')}>
<Banner.Description>
GitHub users are{' '}
<Link inline underline href="#">
now required
</Link>{' '}
to enable two-factor authentication as an additional security measure.
</Banner.Description>
</Banner>
)
}

export const TitleOnly = () => {
return (
<Banner
title={
<>
GitHub users are{' '}
<Link inline underline href="#">
now required
</Link>{' '}
to enable two-factor authentication as an additional security measure.
</>
}
variant="warning"
/>
)
}

export const WithTitle = () => {
return (
<Banner title="This is a title" variant="warning">
<Banner.Description>
GitHub users are{' '}
<Link inline underline href="#">
now required
</Link>{' '}
to enable two-factor authentication as an additional security measure.
</Banner.Description>
</Banner>
)
}

export const WithActions = () => {
return (
<Banner title="This is a title" variant="warning">
<Banner.Description>
GitHub users are{' '}
<Link inline underline href="#">
now required
</Link>{' '}
to enable two-factor authentication as an additional security measure.
</Banner.Description>
<Banner.Actions>
<Banner.PrimaryAction>Button</Banner.PrimaryAction>
<Banner.SecondaryAction>Button</Banner.SecondaryAction>
</Banner.Actions>
</Banner>
)
}
66 changes: 66 additions & 0 deletions packages/react/src/Banner/Banner.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import type {Meta, StoryObj} from '@storybook/react'
import React from 'react'
import {Button} from '../Button'
import Link from '../Link'
import {Banner} from '../Banner'
import {action} from '@storybook/addon-actions'

const meta = {
title: 'Drafts/Components/Banner',
component: Banner,
} satisfies Meta<typeof Banner>

export default meta

export const Default = () => {
return (
<Banner title="This is a title" onDismiss={action('onDismiss')}>
<Banner.Description>
GitHub users are{' '}
<Link inline href="#">
now required
</Link>{' '}
to enable two-factor authentication as an additional security measure.
</Banner.Description>
<Banner.Actions>
<Button>Button</Button>
<Button variant="invisible">Button</Button>
</Banner.Actions>
</Banner>
)
}

export const Playground: StoryObj<typeof Banner> = {
render: ({onDismiss, variant, ...rest}) => {
return (
<Banner
{...rest}
title="This is the title"
onDismiss={onDismiss ? action('onDismiss') : undefined}
variant={variant}
>
<Banner.Description>
GitHub users are{' '}
<Link inline underline href="#">
now required
</Link>{' '}
to enable two-factor authentication as an additional security measure.
</Banner.Description>
</Banner>
)
},
argTypes: {
onDismiss: {
controls: {
type: 'boolean',
},
defaultValue: false,
},
variant: {
controls: {
type: 'radio',
},
options: ['critical', 'info', 'success', 'upsell', 'warning'],
},
},
}
Loading

0 comments on commit 6f53c42

Please sign in to comment.