-
Notifications
You must be signed in to change notification settings - Fork 43
[New component] InlineMessage #4185
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 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
28ade93
:truck: Move InlineMessage PR out of #4085
KenAJoh 290014b
:memo: Changeset
KenAJoh fa8d432
Update @navikt/core/react/src/inline-message/root/InlineMessage.tsx
KenAJoh 7b5cfcb
:memo: Jsdoc update
KenAJoh 58c2dc9
Update @navikt/core/react/src/inline-message/root/InlineMessage.tsx
KenAJoh b8bc0a9
:fire: Removed flex-start alignment
KenAJoh 0a473c3
Update @navikt/core/react/src/inline-message/root/InlineMessage.tsx
KenAJoh 3dc46bc
Update @navikt/core/react/src/inline-message/root/InlineMessage.tsx
KenAJoh a7b06b9
Update @navikt/core/react/src/inline-message/root/InlineMessage.tsx
KenAJoh 087490e
Update @navikt/core/react/src/inline-message/root/InlineMessage.tsx
KenAJoh 32d3e89
:recycle: Inline color-definitions
KenAJoh 3dc9893
:recycle: Clean up css use
KenAJoh b900c26
Update @navikt/core/react/src/inline-message/icon/InlineMessageIcon.tsx
KenAJoh d6d63a0
:fire: Remove redundant display-flex
KenAJoh 1634cb0
Merge branch 'base-alert' into inline-message-component
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
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 | ||
| --- | ||
|
|
||
| InlineMessage: :tada: New component! Replaces `<Alert inline />` variant as a standalone component. |
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
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,17 @@ | ||
| .aksel-inline-message { | ||
| display: flex; | ||
| align-items: flex-start; | ||
| gap: var(--ax-space-4); | ||
| color: var(--ax-text-default); | ||
| } | ||
|
|
||
| .aksel-inline-message__icon { | ||
| color: var(--ax-text-subtle); | ||
| font-size: 1.5rem; | ||
| display: flex; | ||
HalvorHaugan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| flex: 0 0 auto; | ||
|
|
||
| .aksel-inline-message[data-size="small"] & { | ||
| font-size: 1.25rem; | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| .navds-inline-message { | ||
| display: flex; | ||
| align-items: flex-start; | ||
| gap: var(--a-spacing-1); | ||
| } | ||
|
|
||
| .navds-inline-message[data-color="info"] { | ||
| color: var(--a-lightblue-900); | ||
|
|
||
| & .navds-inline-message__icon { | ||
| color: var(--a-icon-info); | ||
| } | ||
| } | ||
|
|
||
| .navds-inline-message[data-color="success"] { | ||
| color: var(--a-green-900); | ||
|
|
||
| & .navds-inline-message__icon { | ||
| color: var(--a-icon-success); | ||
| } | ||
| } | ||
|
|
||
| .navds-inline-message[data-color="danger"] { | ||
| color: var(--a-red-900); | ||
|
|
||
| & .navds-inline-message__icon { | ||
| color: var(--a-icon-danger); | ||
| } | ||
| } | ||
|
|
||
| .navds-inline-message[data-color="warning"] { | ||
| color: var(--a-orange-900); | ||
|
|
||
| & .navds-inline-message__icon { | ||
| color: var(--a-icon-warning); | ||
| } | ||
| } | ||
|
|
||
| .navds-inline-message__icon { | ||
| font-size: 1.5rem; | ||
| display: flex; | ||
| flex: 0 0 auto; | ||
|
|
||
| .navds-inline-message[data-size="small"] & { | ||
| font-size: 1.25rem; | ||
| } | ||
| } |
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
119 changes: 119 additions & 0 deletions
119
@navikt/core/react/src/inline-message/InlineMessage.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,119 @@ | ||
| import type { Meta, StoryObj } from "@storybook/react-vite"; | ||
| import React from "react"; | ||
| import { VStack } from "../layout/stack"; | ||
| import { Link } from "../link"; | ||
| import { renderStoriesForChromatic } from "../util/renderStoriesForChromatic"; | ||
| import { InlineMessage } from "./index"; | ||
|
|
||
| const meta: Meta<typeof InlineMessage> = { | ||
| title: "ds-react/InlineMessage", | ||
| component: InlineMessage, | ||
| parameters: { | ||
| chromatic: { disable: true }, | ||
| }, | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj<typeof InlineMessage>; | ||
|
|
||
| const variants = ["info", "success", "warning", "error"] as const; | ||
|
|
||
| export const Default: Story = { | ||
| render: (props) => { | ||
| return ( | ||
| <InlineMessage variant={props.variant ?? "warning"}> | ||
| {props.children ?? "InlineMessage content"} | ||
| </InlineMessage> | ||
| ); | ||
| }, | ||
|
|
||
| args: { | ||
| children: "Id elit esse enim reprehenderit enim nisi veniam nostrud.", | ||
| variant: "warning", | ||
| }, | ||
| argTypes: { | ||
| variant: { | ||
| control: { type: "select" }, | ||
| options: variants, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export const SizeSmall: Story = { | ||
| render: () => { | ||
| return ( | ||
| <InlineMessage variant="warning" size="small"> | ||
| <DemoContent /> | ||
| </InlineMessage> | ||
| ); | ||
| }, | ||
| }; | ||
|
|
||
| export const Compositions: Story = { | ||
| render: () => { | ||
| return ( | ||
| <VStack gap="space-16"> | ||
| {variants.map((variant) => ( | ||
| <InlineMessage variant={variant} key={variant}> | ||
| <DemoContent /> | ||
| </InlineMessage> | ||
| ))} | ||
| </VStack> | ||
| ); | ||
| }, | ||
| }; | ||
|
|
||
| export const WrappingTitle: Story = { | ||
| render: () => { | ||
| return ( | ||
| <InlineMessage variant="warning"> | ||
| <DemoContent /> | ||
| </InlineMessage> | ||
| ); | ||
| }, | ||
| }; | ||
|
|
||
| export const AsLink: Story = { | ||
| render: () => { | ||
| return ( | ||
| <InlineMessage variant="warning" as={Link} href="#"> | ||
| This is a link inside the InlineMessage | ||
| </InlineMessage> | ||
| ); | ||
| }, | ||
| }; | ||
|
|
||
| export const Chromatic = renderStoriesForChromatic({ | ||
| Default, | ||
| Compositions, | ||
| WrappingTitle, | ||
| SizeSmall, | ||
| }); | ||
|
|
||
| export const ChromaticLight = renderStoriesForChromatic({ | ||
| Default, | ||
| Compositions, | ||
| WrappingTitle, | ||
| SizeSmall, | ||
| }); | ||
| ChromaticLight.globals = { theme: "light", mode: "darkside" }; | ||
|
|
||
| export const ChromaticDark = renderStoriesForChromatic({ | ||
| Default, | ||
| Compositions, | ||
| WrappingTitle, | ||
| SizeSmall, | ||
| }); | ||
| ChromaticDark.globals = { theme: "dark", mode: "darkside" }; | ||
|
|
||
| function DemoContent() { | ||
| return ( | ||
| <span> | ||
| 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. | ||
| </span> | ||
| ); | ||
| } |
39 changes: 39 additions & 0 deletions
39
@navikt/core/react/src/inline-message/icon/InlineMessageIcon.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,39 @@ | ||
| import React from "react"; | ||
| import { | ||
| CheckmarkCircleFillIcon, | ||
| ExclamationmarkTriangleFillIcon, | ||
| InformationSquareFillIcon, | ||
| XMarkOctagonFillIcon, | ||
| } from "@navikt/aksel-icons"; | ||
| import { useRenameCSS } from "../../theme/Theme"; | ||
| import { useI18n } from "../../util/i18n/i18n.hooks"; | ||
|
|
||
| const VARIANT_ICONS = { | ||
| info: InformationSquareFillIcon, | ||
| success: CheckmarkCircleFillIcon, | ||
| warning: ExclamationmarkTriangleFillIcon, | ||
| error: XMarkOctagonFillIcon, | ||
| } as const; | ||
|
|
||
| function InlineMessageIcon({ | ||
| variant, | ||
| }: { | ||
| variant: "info" | "success" | "warning" | "error"; | ||
| }) { | ||
| const translate = useI18n("Alert"); | ||
| const { cn } = useRenameCSS(); | ||
|
|
||
| if (!variant) { | ||
| return null; | ||
| } | ||
KenAJoh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const Icon = VARIANT_ICONS[variant]; | ||
|
|
||
| return ( | ||
| <span className={cn("navds-inline-message__icon")}> | ||
| <Icon title={translate(variant)} /> | ||
| </span> | ||
KenAJoh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
| } | ||
|
|
||
| export { InlineMessageIcon }; | ||
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,3 @@ | ||
| "use client"; | ||
| export { InlineMessage } from "./root/InlineMessage"; | ||
| export type { InlineMessageProps } from "./root/InlineMessage"; |
86 changes: 86 additions & 0 deletions
86
@navikt/core/react/src/inline-message/root/InlineMessage.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,86 @@ | ||
| import React, { forwardRef } from "react"; | ||
| import { useRenameCSS, useThemeInternal } from "../../theme/Theme"; | ||
| import type { AkselColor } from "../../types"; | ||
| import { BodyShort } from "../../typography"; | ||
| import type { OverridableComponent } from "../../util"; | ||
| import { InlineMessageIcon } from "../icon/InlineMessageIcon"; | ||
|
|
||
| interface InlineMessageProps extends React.HTMLAttributes<HTMLDivElement> { | ||
| /** | ||
| * InlineMessage variant. | ||
| */ | ||
| variant: "info" | "success" | "warning" | "error"; | ||
| /** | ||
| * InlineMessage size. | ||
| * @default "medium" | ||
| */ | ||
| size?: "medium" | "small"; | ||
| } | ||
|
|
||
| /** | ||
| * Inline message are used to display important messages with other content. | ||
KenAJoh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @see [📝 Documentation](https://aksel.nav.no/komponenter/core/inline-message) | ||
| * @see 🏷️ {@link InlineMessageProps} | ||
| * @see [🤖 OverridableComponent](https://aksel.nav.no/grunnleggende/kode/overridablecomponent) support | ||
| * @example | ||
| * ```jsx | ||
| * <InlineMessage variant="error"> | ||
| * Inline Errormessage | ||
| * </InlineMessage> | ||
| * ``` | ||
| * | ||
| * * @example As a link | ||
KenAJoh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * ```jsx | ||
| * <InlineMessage variant="error" as={Link} href="#"> | ||
| * Inline Errormessage | ||
| * </InlineMessage> | ||
| * ``` | ||
| */ | ||
| const InlineMessage: OverridableComponent< | ||
| InlineMessageProps, | ||
| HTMLAnchorElement | ||
KenAJoh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| > = forwardRef( | ||
| ( | ||
| { | ||
| as: Component = "div", | ||
| children, | ||
| className, | ||
| variant, | ||
| size = "medium", | ||
| ...restProps | ||
| }: InlineMessageProps & { as?: React.ElementType }, | ||
| forwardedRef, | ||
| ) => { | ||
| const { cn } = useRenameCSS(); | ||
| const themeContext = useThemeInternal(false); | ||
|
|
||
| return ( | ||
| <BodyShort | ||
| ref={forwardedRef} | ||
| className={cn("navds-inline-message", className)} | ||
| data-color={variantToDataColor(variant)} | ||
KenAJoh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| {...restProps} | ||
| size={size} | ||
| as={Component} | ||
| data-variant={variant} | ||
| data-size={size} | ||
| > | ||
| <InlineMessageIcon variant={variant} /> | ||
| <span data-color={themeContext?.color}>{children}</span> | ||
KenAJoh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </BodyShort> | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| function variantToDataColor( | ||
| variant: InlineMessageProps["variant"], | ||
| ): AkselColor | undefined { | ||
| if (variant === "error") { | ||
| return "danger"; | ||
| } | ||
|
|
||
| return variant; | ||
| } | ||
|
|
||
| export { InlineMessage }; | ||
| export type { InlineMessageProps }; | ||
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.