diff --git a/.changeset/shiny-pans-film.md b/.changeset/shiny-pans-film.md new file mode 100644 index 0000000000..a5077a8941 --- /dev/null +++ b/.changeset/shiny-pans-film.md @@ -0,0 +1,6 @@ +--- +"@digdir/designsystemet-css": patch +"@digdir/designsystemet-react": patch +--- + +PopoverTrigger: New prop `inline` for use when inline elements (such as text) need a `Popover` diff --git a/packages/css/src/button.css b/packages/css/src/button.css index 6866850ca1..f0009e5af1 100644 --- a/packages/css/src/button.css +++ b/packages/css/src/button.css @@ -75,7 +75,7 @@ position: relative; /* Place focusring on top */ } - &:not([hidden]) { + &:where(:not([hidden])) { display: flex; } diff --git a/packages/css/src/popover.css b/packages/css/src/popover.css index c1d5b43820..46a2383b41 100644 --- a/packages/css/src/popover.css +++ b/packages/css/src/popover.css @@ -55,3 +55,14 @@ --dsc-popover-background: var(--ds-color-neutral-background-default); } } + +[data-popover='inline'] { + all: unset; + cursor: pointer; + display: inline; + text-decoration: underline dotted; + text-underline-offset: 0.27em; + font-size: inherit; + + @composes ds-focus from './base.css'; +} diff --git a/packages/react/src/components/Popover/Popover.stories.tsx b/packages/react/src/components/Popover/Popover.stories.tsx index 545b367a2e..5e855b90ec 100644 --- a/packages/react/src/components/Popover/Popover.stories.tsx +++ b/packages/react/src/components/Popover/Popover.stories.tsx @@ -185,3 +185,34 @@ WithoutContext.parameters = { padding: '8rem 6rem 1rem', }, }; + +export const DottedUnderline: StoryFn = () => { + return ( + <> + + + Vi bruker design tokens for + å sikre at vi har en konsistent design. + + + + + Design tokens + + Design tokens er en samling av variabler som definerer designet i et + designsystem. + + + + + ); +}; +DottedUnderline.parameters = { + customStyles: { + padding: '10rem 6rem 1rem', + }, +}; diff --git a/packages/react/src/components/Popover/PopoverTrigger.tsx b/packages/react/src/components/Popover/PopoverTrigger.tsx index 1b2fa4a45d..1fd7d816cc 100644 --- a/packages/react/src/components/Popover/PopoverTrigger.tsx +++ b/packages/react/src/components/Popover/PopoverTrigger.tsx @@ -1,16 +1,36 @@ import { Slot } from '@radix-ui/react-slot'; -import { forwardRef, useContext } from 'react'; +import { type HTMLAttributes, forwardRef, useContext } from 'react'; +import type { DefaultProps } from '../../types'; import { Button, type ButtonProps } from '../Button/Button'; import { Context } from './PopoverTriggerContext'; -export type PopoverTriggerProps = ButtonProps; +export type PopoverTriggerProps = + | ({ + inline?: true; + asChild?: boolean; + } & HTMLAttributes & + DefaultProps) + | ({ + inline?: false; + } & ButtonProps); export const PopoverTrigger = forwardRef< HTMLButtonElement, PopoverTriggerProps ->(function PopoverTrigger({ id, asChild, ...rest }, ref) { +>(function PopoverTrigger({ id, inline, asChild, ...rest }, ref) { const { popoverId } = useContext(Context); - const Component = asChild ? Slot : Button; + const Component = asChild ? Slot : inline ? 'button' : Button; - return ; + return ( + + ); });