-
Notifications
You must be signed in to change notification settings - Fork 43
[New component] GlobalAlert #4188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d9a9cf6
:truck: Extracted GlobalAlert from #4085
KenAJoh 90fb57e
:memo: Changeset
KenAJoh 9abdb18
:label: Rename root
KenAJoh 08e30ba
:loud_sound: GlobalAlert now always an alert
KenAJoh 0927f1f
Apply suggestion from @HalvorHaugan
KenAJoh 6b24c76
:memo: Add button css to global alert mappings
KenAJoh 7e326a3
Apply suggestion from @HalvorHaugan
KenAJoh 625fa6d
:memo: Docs
KenAJoh 5b20c5d
Apply suggestion from @HalvorHaugan
KenAJoh 1fea18d
Apply suggestion from @Copilot
KenAJoh 35365e2
Apply suggestion from @HalvorHaugan
KenAJoh cd2efaf
:recycle: Remove prop-destructuring
KenAJoh c6c099f
Merge branch 'base-alert' into global-alert
KenAJoh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@navikt/ds-react": minor | ||
| "@navikt/ds-css": minor | ||
| --- | ||
|
|
||
| GlobalAlert: :tada: New component replacing `<Alert fullWidth>`, now with built-in centering of content. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
212 changes: 212 additions & 0 deletions
212
@navikt/core/react/src/alert/global-alert/GlobalAlert.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,212 @@ | ||
| import type { Meta, StoryObj } from "@storybook/react-vite"; | ||
| import React from "react"; | ||
| import { Button } from "../../button"; | ||
| import { VStack } from "../../layout/stack"; | ||
| import { Link } from "../../link"; | ||
| import { renderStoriesForChromatic } from "../../util/renderStoriesForChromatic"; | ||
| import { | ||
| GlobalAlert, | ||
| GlobalAlertClose, | ||
| GlobalAlertContent, | ||
| GlobalAlertHeader, | ||
| GlobalAlertTitle, | ||
| } from "./index"; | ||
|
|
||
| const meta: Meta<typeof GlobalAlert> = { | ||
| title: "ds-react/Alert/GlobalAlert", | ||
| component: GlobalAlert, | ||
| parameters: { | ||
| chromatic: { disable: true }, | ||
| layout: "padded", | ||
| }, | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj<typeof GlobalAlert>; | ||
|
|
||
| export const Default: Story = { | ||
| render: (props) => { | ||
| return ( | ||
| <GlobalAlert variant={props.variant ?? "announcement"} size={props.size}> | ||
| <GlobalAlertHeader> | ||
| <GlobalAlertTitle> | ||
| {props.title ?? "GlobalAlert title"} | ||
| </GlobalAlertTitle> | ||
| <GlobalAlertClose onClick={() => alert("Lukket!")} /> | ||
| </GlobalAlertHeader> | ||
| <GlobalAlertContent> | ||
| {props.children ?? "GlobalAlert content"} | ||
| </GlobalAlertContent> | ||
| </GlobalAlert> | ||
| ); | ||
| }, | ||
|
|
||
| args: { | ||
| children: "Id elit esse enim reprehenderit enim nisi veniam nostrud.", | ||
| title: "GlobalAlert Title", | ||
| size: "medium", | ||
| variant: "announcement", | ||
| }, | ||
| argTypes: { | ||
| size: { | ||
| control: { type: "radio" }, | ||
| options: ["medium", "small"], | ||
| }, | ||
| variant: { | ||
| control: { type: "select" }, | ||
| options: ["error", "warning", "announcement", "success"], | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export const SizeSmall: Story = { | ||
| render: () => { | ||
| return ( | ||
| <GlobalAlert variant="announcement" size="small"> | ||
| <GlobalAlertHeader> | ||
| <GlobalAlertTitle>GlobalAlert Title</GlobalAlertTitle> | ||
| <GlobalAlertClose onClick={() => alert("Lukket!")} /> | ||
| </GlobalAlertHeader> | ||
| <DemoContent /> | ||
| </GlobalAlert> | ||
| ); | ||
| }, | ||
| }; | ||
|
|
||
| export const OnlyHeader: Story = { | ||
| render: () => { | ||
| return ( | ||
| <VStack gap="space-16"> | ||
| <GlobalAlert variant="announcement"> | ||
| <GlobalAlertHeader> | ||
| <GlobalAlertTitle>GlobalAlert Title</GlobalAlertTitle> | ||
| </GlobalAlertHeader> | ||
| </GlobalAlert> | ||
| <GlobalAlert variant="announcement"> | ||
| <GlobalAlertHeader> | ||
| <GlobalAlertTitle>GlobalAlert Title</GlobalAlertTitle> | ||
| <GlobalAlertClose onClick={() => alert("Lukket!")} /> | ||
| </GlobalAlertHeader> | ||
| </GlobalAlert> | ||
| <GlobalAlert variant="announcement" size="small"> | ||
| <GlobalAlertHeader> | ||
| <GlobalAlertTitle>GlobalAlert Title</GlobalAlertTitle> | ||
| </GlobalAlertHeader> | ||
| </GlobalAlert> | ||
| <GlobalAlert variant="announcement" size="small"> | ||
| <GlobalAlertHeader> | ||
| <GlobalAlertTitle>GlobalAlert Title</GlobalAlertTitle> | ||
| <GlobalAlertClose onClick={() => alert("Lukket!")} /> | ||
| </GlobalAlertHeader> | ||
| </GlobalAlert> | ||
| </VStack> | ||
| ); | ||
| }, | ||
| }; | ||
|
|
||
| const variants = ["announcement", "warning", "error", "success"] as const; | ||
|
|
||
| export const Compositions: Story = { | ||
| render: () => { | ||
| return ( | ||
| <VStack gap="space-16"> | ||
| {variants.map((variant) => ( | ||
| <GlobalAlert variant={variant} key={variant}> | ||
| <GlobalAlertHeader> | ||
| <GlobalAlertTitle>{variant} GlobalAlert title</GlobalAlertTitle> | ||
| <GlobalAlertClose onClick={() => alert("Lukket!")} /> | ||
| </GlobalAlertHeader> | ||
| <DemoContent /> | ||
| </GlobalAlert> | ||
| ))} | ||
| </VStack> | ||
| ); | ||
| }, | ||
| }; | ||
|
|
||
| export const CloseButton: Story = { | ||
| render: () => { | ||
| return ( | ||
| <VStack gap="space-16"> | ||
| <GlobalAlert variant="announcement"> | ||
| <GlobalAlertHeader> | ||
| <GlobalAlertTitle>Info: GlobalAlert title</GlobalAlertTitle> | ||
| <GlobalAlertClose onClick={() => alert("Lukket!")} /> | ||
| </GlobalAlertHeader> | ||
| <DemoContent /> | ||
| </GlobalAlert> | ||
| <GlobalAlert variant="announcement" size="small"> | ||
| <GlobalAlertHeader> | ||
| <GlobalAlertTitle>Info: GlobalAlert title</GlobalAlertTitle> | ||
| <GlobalAlertClose onClick={() => alert("Lukket!")} /> | ||
| </GlobalAlertHeader> | ||
| <DemoContent /> | ||
| </GlobalAlert> | ||
| </VStack> | ||
| ); | ||
| }, | ||
| parameters: { | ||
| layout: "padded", | ||
| }, | ||
| }; | ||
|
|
||
| export const WrappingTitle: Story = { | ||
| render: () => { | ||
| return ( | ||
| <GlobalAlert variant="announcement"> | ||
| <GlobalAlertHeader> | ||
| <GlobalAlertTitle> | ||
| Lorem ipsum dolor sit, amet consectetur adipisicing elit. Non fugiat | ||
| tempore corrupti asperiores praesentium? Asperiores, doloribus? | ||
| Molestias, laudantium saepe. Nihil in alias praesentium maxime iure | ||
| ipsam? Accusantium libero quia quis! | ||
| </GlobalAlertTitle> | ||
| <GlobalAlertClose onClick={() => alert("Lukket!")} /> | ||
| </GlobalAlertHeader> | ||
| <DemoContent /> | ||
| </GlobalAlert> | ||
| ); | ||
| }, | ||
| }; | ||
|
|
||
| export const Chromatic = renderStoriesForChromatic({ | ||
| Default, | ||
| SizeSmall, | ||
| OnlyHeader, | ||
| Compositions, | ||
| CloseButton, | ||
| WrappingTitle, | ||
| }); | ||
|
|
||
| export const ChromaticLight = renderStoriesForChromatic({ | ||
| Default, | ||
| SizeSmall, | ||
| OnlyHeader, | ||
| Compositions, | ||
| CloseButton, | ||
| WrappingTitle, | ||
| }); | ||
| ChromaticLight.globals = { theme: "light", mode: "darkside" }; | ||
|
|
||
| export const ChromaticDark = renderStoriesForChromatic({ | ||
| Default, | ||
| SizeSmall, | ||
| OnlyHeader, | ||
| Compositions, | ||
| CloseButton, | ||
| WrappingTitle, | ||
| }); | ||
| ChromaticDark.globals = { theme: "dark", mode: "darkside" }; | ||
|
|
||
| function DemoContent() { | ||
| return ( | ||
| <GlobalAlertContent> | ||
| Lorem ipsum dolor, sit amet consectetur adipisicing elit. Iure unde, | ||
| repudiandae, deleniti exercitationem quod aut veniam sint officiis | ||
| necessitatibus nulla nostrum voluptatem <Link href="#">Test</Link> | ||
| facilis! Commodi, nobis tempora quibusdam temporibus nulla quam.{" "} | ||
| <Button size="small">test</Button> | ||
| </GlobalAlertContent> | ||
| ); | ||
| } |
20 changes: 20 additions & 0 deletions
20
@navikt/core/react/src/alert/global-alert/close/GlobalAlertClose.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { BaseAlert } from "../../base-alert"; | ||
|
|
||
| type GlobalAlertCloseProps = BaseAlert.CloseProps; | ||
|
|
||
| /** | ||
| * @see 🏷️ {@link GlobalAlertCloseProps} | ||
| * @example | ||
| * ```jsx | ||
| * <GlobalAlert> | ||
| * <GlobalAlert.Header> | ||
| * <GlobalAlert.Title>Info tittel</GlobalAlert.Title> | ||
| * <GlobalAlert.Close onClick={() => alert("Lukket!")} /> | ||
| * </GlobalAlert.Header> | ||
| * </GlobalAlert> | ||
| * ``` | ||
| */ | ||
| const GlobalAlertClose = BaseAlert.Close; | ||
|
|
||
| export { GlobalAlertClose }; | ||
| export type { GlobalAlertCloseProps }; |
21 changes: 21 additions & 0 deletions
21
@navikt/core/react/src/alert/global-alert/content/GlobalAlertContent.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { BaseAlert } from "../../base-alert"; | ||
|
|
||
| type GlobalAlertContentProps = BaseAlert.ContentProps; | ||
|
|
||
| /** | ||
| * @see 🏷️ {@link GlobalAlertContentProps} | ||
| * @example | ||
| * ```jsx | ||
| * <GlobalAlert> | ||
| * <GlobalAlert.Header> | ||
| * <GlobalAlert.Title>Info tittel</GlobalAlert.Title> | ||
| * </GlobalAlert.Header> | ||
| * | ||
| * <GlobalAlert.Content>Innhold</GlobalAlert.Content> | ||
| * </GlobalAlert> | ||
| * ``` | ||
| */ | ||
| const GlobalAlertContent = BaseAlert.Content; | ||
|
|
||
| export { GlobalAlertContent }; | ||
| export type { GlobalAlertContentProps }; |
24 changes: 24 additions & 0 deletions
24
@navikt/core/react/src/alert/global-alert/header/GlobalAlertHeader.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import React, { forwardRef } from "react"; | ||
| import { BaseAlert } from "../../base-alert"; | ||
|
|
||
| type GlobalAlertHeaderProps = Omit<BaseAlert.HeaderProps, "icon">; | ||
|
|
||
| /** | ||
| * @see 🏷️ {@link GlobalAlertHeaderProps} | ||
| * @example | ||
| * ```jsx | ||
| * <GlobalAlert variant="info"> | ||
| * <GlobalAlert.Header> | ||
| * <GlobalAlert.Title>Info tittel</GlobalAlert.Title> | ||
| * </GlobalAlert.Header> | ||
| * </GlobalAlert> | ||
| * ``` | ||
| */ | ||
| const GlobalAlertHeader = forwardRef<HTMLDivElement, GlobalAlertHeaderProps>( | ||
| (props, forwardedRef) => { | ||
| return <BaseAlert.Header ref={forwardedRef} {...props} />; | ||
| }, | ||
| ); | ||
|
|
||
| export { GlobalAlertHeader }; | ||
| export type { GlobalAlertHeaderProps }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| "use client"; | ||
| export { | ||
| GlobalAlert, | ||
| GlobalAlertHeader, | ||
| GlobalAlertTitle, | ||
| GlobalAlertContent, | ||
| GlobalAlertClose, | ||
| } from "./root/GlobalAlertRoot"; | ||
|
|
||
| export type { | ||
| GlobalAlertProps, | ||
| GlobalAlertHeaderProps, | ||
| GlobalAlertTitleProps, | ||
| GlobalAlertContentProps, | ||
| GlobalAlertCloseProps, | ||
| } from "./root/GlobalAlertRoot"; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.