Skip to content

Commit

Permalink
docs(Banner): add story for dismissing banner (#4619)
Browse files Browse the repository at this point in the history
* docs(Banner): add story for dismissing banner

* chore: update types for examples

---------

Co-authored-by: Josh Black <joshblack@users.noreply.github.com>
  • Loading branch information
joshblack and joshblack authored May 24, 2024
1 parent e47445d commit 4c4e98a
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/react/src/Banner/Banner.examples.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,40 @@ export const Multiline = () => {
/>
)
}

export const DismissBanner = () => {
const ref = React.useRef<React.ElementRef<'h2'>>(null)
const [banner, setBanner] = React.useState<React.ComponentPropsWithoutRef<typeof Banner> | null>({
title: 'Info',
description: (
<>
GitHub users are{' '}
<Link inline underline href="#">
now required
</Link>{' '}
to enable two-factor authentication as an additional security measure.
</>
),
})

return (
<>
<main>
{banner ? (
<Banner
title={banner.title}
description={banner.description}
onDismiss={() => {
setBanner(null)
ref.current?.focus()
}}
/>
) : null}
<h2 ref={ref} tabIndex={-1}>
Example page title
</h2>
<p>Example page content</p>
</main>
</>
)
}

0 comments on commit 4c4e98a

Please sign in to comment.