diff --git a/.changeset/fair-beds-destroy.md b/.changeset/fair-beds-destroy.md new file mode 100644 index 0000000000..68c96596f7 --- /dev/null +++ b/.changeset/fair-beds-destroy.md @@ -0,0 +1,6 @@ +--- +"@digdir/designsystemet-css": patch +"@digdir/designsystemet-react": patch +--- + +CSS: base sizing on font-size so all components can have all sizes, and naturally inherits size from context diff --git a/packages/css/accordion.css b/packages/css/accordion.css index ea7e8e5fe1..cb0cb3a665 100644 --- a/packages/css/accordion.css +++ b/packages/css/accordion.css @@ -8,7 +8,8 @@ --dsc-accordion-heading-background--hover: var(--ds-color-neutral-surface-default); --dsc-accordion-heading-background--open: var(--ds-color-neutral-background-subtle); --dsc-accordion-heading-background: var(--ds-color-neutral-background-default); - --dsc-accordion-padding: var(--ds-spacing-4); + --dsc-accordion-padding: var(--ds-spacing-2) var(--ds-spacing-4); + --dsc-accordion-size: var(--ds-sizing-14); &[data-border] > * { border: var(--dsc-accordion-border); @@ -65,16 +66,18 @@ box-sizing: border-box; & > :is(summary, u-summary) { + align-items: center; background: var(--dsc-accordion-heading-background); box-sizing: border-box; cursor: pointer; + display: flex; list-style: none; + min-height: var(--dsc-accordion-size); + gap: var(--dsc-accordion-chevron-gap); outline: none; - padding-block: var(--dsc-accordion-padding); - padding-inline: calc(var(--dsc-accordion-padding) + var(--dsc-accordion-chevron-size) + var(--dsc-accordion-chevron-gap)) var(--dsc-accordion-padding); + padding: var(--dsc-accordion-padding); @composes ds-focus from './base/base.css'; - @composes ds-body-text--sm from './base/base.css'; &:focus-visible { position: relative; /* Ensure foucs outline renders on top */ @@ -84,11 +87,9 @@ background: currentcolor; border-radius: var(--ds-border-radius-md); content: ''; + flex-shrink: 0; height: var(--dsc-accordion-chevron-size); mask: 50% / contain no-repeat var(--dsc-accordion-chevron-url); - position: absolute; - margin-inline: calc((var(--dsc-accordion-chevron-size) + var(--dsc-accordion-chevron-gap)) * -1); /* Using margin instead of top/left to avoid position: relative and to support dir="rtl" */ - width: var(--dsc-accordion-chevron-size); } } diff --git a/packages/css/alert.css b/packages/css/alert.css index 4868a9d0c4..fe28d6aaae 100644 --- a/packages/css/alert.css +++ b/packages/css/alert.css @@ -18,8 +18,6 @@ padding-inline: calc(var(--dsc-alert-padding) + var(--dsc-alert-icon-size) + var(--dsc-alert-gap)) var(--dsc-alert-padding); position: relative; - @composes ds-body-text--md from './base/base.css'; - & > :is(h1, h2, h3, h4, h5, h6):first-child::before /* If Alert starts with Heading, align icon to this */, &:not(:has(> :is(h1, h2, h3, h4, h5, h6):first-child))::before /* If there is no Heading, align icon to Alert itself */ { background: var(--dsc-alert-icon-color); @@ -55,21 +53,4 @@ --dsc-alert-icon-color: var(--ds-color-danger-text-subtle); --dsc-alert-icon-url: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill-rule='evenodd' d='M7.74 2.47a.75.75 0 0 1 .53-.22h7.46a.75.75 0 0 1 .53.22l5.27 5.27c.14.14.22.33.22.53v7.46a.75.75 0 0 1-.22.53l-5.27 5.27a.75.75 0 0 1-.53.22H8.27a.75.75 0 0 1-.53-.22l-5.27-5.27a.75.75 0 0 1-.22-.53V8.27a.75.75 0 0 1 .22-.53zm1.29 5.5a.75.75 0 0 0-1.06 1.06L10.94 12l-2.97 2.97a.75.75 0 1 0 1.06 1.06L12 13.06l2.97 2.97a.75.75 0 1 0 1.06-1.06L13.06 12l2.97-2.97a.75.75 0 0 0-1.06-1.06L12 10.94z'/%3E%3C/svg%3E"); } - - /** - * Sizes - */ - &[data-size='sm'] { - --dsc-alert-icon-size: var(--ds-sizing-6); - --dsc-alert-padding: var(--ds-spacing-5); - - @composes ds-body-text--sm from './base/base.css'; - } - - &[data-size='lg'] { - --dsc-alert-icon-size: var(--ds-sizing-8); - --dsc-alert-padding: var(--ds-spacing-7); - - @composes ds-body-text--lg from './base/base.css'; - } } diff --git a/packages/css/avatar.css b/packages/css/avatar.css index 0f17adc12a..3e37c02b1a 100644 --- a/packages/css/avatar.css +++ b/packages/css/avatar.css @@ -12,6 +12,7 @@ box-sizing: border-box; color: var(--dsc-avatar-color); display: inline-flex; + font-weight: var(--ds-font-weight-medium); height: var(--dsc-avatar-size); justify-content: center; overflow: hidden; @@ -19,8 +20,6 @@ text-transform: uppercase; user-select: none; - @composes ds-body-text--xs from './base/base.css'; - &:not(:has(> img)) { padding: var(--dsc-avatar-padding); } @@ -79,31 +78,20 @@ --dsc-avatar-color: var(--ds-color-brand3-contrast-default); } + /* TODO: Sizes */ &[data-size='xs'] { - --dsc-avatar-size: var(--ds-sizing-7); - --dsc-avatar-padding: var(--ds-spacing-1); - - @composes ds-body-text--xs from './base/base.css'; + font-size: var(--ds-body-xs-font-size); } &[data-size='sm'] { - --dsc-avatar-size: var(--ds-sizing-9); - --dsc-avatar-padding: var(--ds-spacing-1); - @composes ds-heading-text--2xs from './base/base.css'; } &[data-size='md'] { - --dsc-avatar-size: var(--ds-sizing-12); - --dsc-avatar-padding: var(--ds-spacing-2); - @composes ds-heading-text--sm from './base/base.css'; } &[data-size='lg'] { - --dsc-avatar-size: var(--ds-sizing-15); - --dsc-avatar-padding: var(--ds-spacing-2); - @composes ds-heading-text--md from './base/base.css'; } } diff --git a/packages/css/badge.css b/packages/css/badge.css index 6d171b3bf8..704c304062 100644 --- a/packages/css/badge.css +++ b/packages/css/badge.css @@ -6,10 +6,9 @@ box-sizing: border-box; display: inline-flex; + line-height: var(--ds-line-height-sm); position: relative; - @composes ds-body-text--short-sm from './base/base.css'; - &::before { content: attr(data-count); background: var(--dsc-badge-background); @@ -23,26 +22,8 @@ place-items: center; } - &[data-size='sm'] { - --dsc-badge-size: var(--ds-sizing-3); - --dsc-badge-padding: 0 var(--ds-spacing-1); - - @composes ds-body-text--short-xs from './base/base.css'; - - &[data-count] { - --dsc-badge-size: var(--ds-sizing-5); - } - } - - &[data-size='lg'] { - --dsc-badge-size: var(--ds-sizing-4); - --dsc-badge-padding: 0 var(--ds-spacing-2); - - @composes ds-body-text--short-md from './base/base.css'; - - &[data-count] { - --dsc-badge-size: var(--ds-sizing-7); - } + &:not([data-size]) { + font-size: var(--ds-font-size-minus-1); /* Default to small when size is not defined */ } &[data-color='info'] { diff --git a/packages/css/base/base.css b/packages/css/base/base.css index 62863d5826..37ce955b0f 100644 --- a/packages/css/base/base.css +++ b/packages/css/base/base.css @@ -17,6 +17,14 @@ --dsc-focus-border-width: 3px; /* Default focus border width */ --dsc-focus-boxShadow: 0 0 0 var(--dsc-focus-border-width) var(--ds-color-focus-inner); --dsc-focus-outline: var(--ds-color-focus-outer) solid var(--dsc-focus-border-width); + --ds-font-size-minus-1: max(.9em, .875rem); /* Default to 90% of font-size, but minimum 14px */ + --ds-font-size-plus-1: 1.1em; /* Default to 110% */ + + /* font-size adjustments if supporting round() */ + @supports (width: round(down, .1em, 1px)) { + --ds-font-size-minus-1: round(down, max(.9em, .875rem), 0.0625rem); /* Default to 90% of font-size, but minimum 14px */ + --ds-font-size-plus-1: round(down, 1.1em, 0.0625rem); /* Default to 110% */ + } color: var(--ds-color-neutral-text-default); background-color: var(--ds-color-neutral-background-default); @@ -42,114 +50,44 @@ outline-offset: var(--dsc-focus-border-width); } -/** Body typography */ -.ds-body-text--xs { +[data-size='xs'] { font-weight: var(--ds-body-xs-font-weight); line-height: var(--ds-body-xs-line-height); font-size: var(--ds-body-xs-font-size); letter-spacing: var(--ds-body-xs-letter-spacing); } -.ds-body-text--sm { +[data-size='sm'] { font-weight: var(--ds-body-sm-font-weight); line-height: var(--ds-body-sm-line-height); font-size: var(--ds-body-sm-font-size); letter-spacing: var(--ds-body-sm-letter-spacing); } -.ds-body-text--md { +/* Setting default font on
*/ position: relative; - @composes ds-validation-message--md from './base/base.css'; - - &[data-size='xs'] { - --dsc-validation-message-icon-size: var(--ds-sizing-5); - --dsc-validation-message-gap: var(--ds-spacing-1); - - @composes ds-validation-message--xs from './base/base.css'; - } - - &[data-size='sm'] { - --dsc-validation-message-icon-size: var(--ds-sizing-6); - - @composes ds-validation-message--sm from './base/base.css'; - } - - &[data-size='lg'] { - --dsc-validation-message-icon-size: var(--ds-sizing-8); - - @composes ds-validation-message--lg from './base/base.css'; - } - /* Only render error icon if the ValidationMessage actually contains an error message */ &[data-error]:not(:empty) { color: var(--ds-color-danger-text-subtle); diff --git a/packages/react/src/components/Alert/Alert.stories.tsx b/packages/react/src/components/Alert/Alert.stories.tsx index 115e105244..5564cda053 100644 --- a/packages/react/src/components/Alert/Alert.stories.tsx +++ b/packages/react/src/components/Alert/Alert.stories.tsx @@ -20,7 +20,7 @@ export const Preview: Story = (args) => ; Preview.args = { color: 'info', - size: 'md', + size: undefined, children: 'En beskjed det er viktig at brukeren ser', }; diff --git a/packages/react/src/components/Alert/Alert.tsx b/packages/react/src/components/Alert/Alert.tsx index bbfe42ca25..7eea2dd392 100644 --- a/packages/react/src/components/Alert/Alert.tsx +++ b/packages/react/src/components/Alert/Alert.tsx @@ -1,6 +1,7 @@ import cl from 'clsx/lite'; import type { HTMLAttributes } from 'react'; import { forwardRef } from 'react'; +import type { Size } from '../../types'; export type AlertProps = { /** @@ -11,10 +12,8 @@ export type AlertProps = { /** * Sets the size of the alert. * Does not affect font size. - * - * @default md */ - size?: 'sm' | 'md' | 'lg'; + size?: Size; } & HTMLAttributes; /** @@ -23,7 +22,7 @@ export type AlertProps = { * Dette er en informasjonsmelding */ export const Alert = forwardRef(function Alert( - { color = 'info', size = 'md', className, ...rest }, + { color = 'info', size, className, ...rest }, ref, ) { return ( diff --git a/packages/react/src/components/Avatar/Avatar.test.tsx b/packages/react/src/components/Avatar/Avatar.test.tsx index ba265017f4..a3817ac01d 100644 --- a/packages/react/src/components/Avatar/Avatar.test.tsx +++ b/packages/react/src/components/Avatar/Avatar.test.tsx @@ -5,7 +5,6 @@ describe('Avatar', () => { it('should render correctly with default props', () => { render(); expect(screen.getByRole('img')).toBeInTheDocument(); - expect(screen.getByRole('img')).toHaveAttribute('data-size', 'md'); expect(screen.getByRole('img')).toHaveAttribute('data-variant', 'circle'); expect(screen.getByRole('img')).toHaveAttribute('data-color', 'accent'); }); diff --git a/packages/react/src/components/Avatar/Avatar.tsx b/packages/react/src/components/Avatar/Avatar.tsx index 6a4b0fe18d..f883f30f5f 100644 --- a/packages/react/src/components/Avatar/Avatar.tsx +++ b/packages/react/src/components/Avatar/Avatar.tsx @@ -2,6 +2,7 @@ import { Slot } from '@radix-ui/react-slot'; import cl from 'clsx/lite'; import { Fragment, forwardRef } from 'react'; import type { HTMLAttributes, ReactNode } from 'react'; +import type { Size } from '../../types'; export type AvatarProps = { /** @@ -16,8 +17,6 @@ export type AvatarProps = { color?: 'accent' | 'neutral' | 'brand1' | 'brand2' | 'brand3'; /** * The size of the avatar. - * - * @default 'md' */ size?: 'xs' | 'sm' | 'md' | 'lg'; /** @@ -54,7 +53,7 @@ export const Avatar = forwardRef(function Avatar( { 'aria-label': ariaLabel, color = 'accent', - size = 'md', + size, variant = 'circle', className, children, diff --git a/packages/react/src/components/Badge/Badge.tsx b/packages/react/src/components/Badge/Badge.tsx index 8bed93944a..2819b5dc9b 100644 --- a/packages/react/src/components/Badge/Badge.tsx +++ b/packages/react/src/components/Badge/Badge.tsx @@ -1,5 +1,6 @@ import cl from 'clsx/lite'; import { type HTMLAttributes, type ReactNode, forwardRef } from 'react'; +import type { Size } from '../../types'; export type BadgeProps = { /** @@ -10,10 +11,8 @@ export type BadgeProps = { color?: 'accent' | 'info' | 'success' | 'warning' | 'danger' | 'neutral'; /** * The size of the badge - * - * @default md */ - size?: 'sm' | 'md' | 'lg'; + size?: Size; /** * The number to display in the badge */ @@ -63,7 +62,7 @@ export const Badge = forwardRef(function Badge( maxCount, overlap = 'rectangle', placement = 'top-right', - size = 'md', + size, ...rest }, ref, diff --git a/packages/react/src/components/Breadcrumbs/Breadcrumbs.tsx b/packages/react/src/components/Breadcrumbs/Breadcrumbs.tsx index 304bce93d5..ff67724b16 100644 --- a/packages/react/src/components/Breadcrumbs/Breadcrumbs.tsx +++ b/packages/react/src/components/Breadcrumbs/Breadcrumbs.tsx @@ -1,5 +1,6 @@ import cl from 'clsx/lite'; import { type HTMLAttributes, forwardRef } from 'react'; +import type { Size } from '../../types'; export type BreadcrumbsProps = { /** @@ -9,9 +10,8 @@ export type BreadcrumbsProps = { 'aria-label'?: string; /** * Sets the size of the component - * @default md */ - size?: 'sm' | 'md' | 'lg'; + size?: Size; } & HTMLAttributes; export const Breadcrumbs = forwardRef( diff --git a/packages/react/src/components/Button/Button.mdx b/packages/react/src/components/Button/Button.mdx index affe2cdf48..2f05a1d675 100644 --- a/packages/react/src/components/Button/Button.mdx +++ b/packages/react/src/components/Button/Button.mdx @@ -109,23 +109,7 @@ Som regel er det **venstre** som er den beste plasseringen, men det finnes unnta ### Størrelse på ikon -Når du bruker ikon må du sette størrelsen på ikonet selv. Vi anbefaler å bruke disse størrelsene for [Aksel](https://aksel.nav.no/ikoner) sine ikoner: - -| Størrelse på knapp | Aksels ikon `fontSize` | -| :----------------- | :--------------------- | -| sm | 1rem | -| md | 1.5rem | -| lg | 2rem | - - - -For knapper med kun ikon anbefaler vi å bruke større ikon: - -| Størrelse på knapp | Aksels ikon `fontSize` | -| :----------------- | :--------------------- | -| sm | 1.5rem | -| md | 2rem | -| lg | 2.5rem | +Ikon skalerer automatisk basert på knappestørrelse, men du endre denne ved å sette font størrelsen. diff --git a/packages/react/src/components/Button/Button.stories.tsx b/packages/react/src/components/Button/Button.stories.tsx index 28417350bc..d56c7ac0dc 100644 --- a/packages/react/src/components/Button/Button.stories.tsx +++ b/packages/react/src/components/Button/Button.stories.tsx @@ -67,7 +67,7 @@ export const Secondary: StoryFn = () => ( export const Tertiary: StoryFn = () => ( <> - + Rediger > @@ -102,15 +102,15 @@ AccentPressed.parameters = { export const Neutral: StoryFn = () => ( <> - + Skriv ut - + Rediger - + Videresend > @@ -131,15 +131,15 @@ NeutralPressed.parameters = { export const Danger: StoryFn = () => ( <> - + Slett - + Slett - + Slett > @@ -175,7 +175,7 @@ export const AsLink: StoryFn = () => ( Gå til Designsystemet - + ); @@ -184,10 +184,10 @@ export const TextAndIcon: StoryFn = () => ( <> Start utfylling - + - + Angre > @@ -209,25 +209,25 @@ export const Loading: StoryFn = () => ( export const Icons: StoryFn = () => ( <> - - + + - + Small - - + + - + Medium - - + + - + Large > @@ -237,12 +237,12 @@ export const IconOnly: StoryFn = () => ( <> - + - + @@ -252,7 +252,7 @@ export const IconOnly: StoryFn = () => ( variant='tertiary' aria-label='Innstillinger' > - + > @@ -267,13 +267,13 @@ IconOnly.parameters = { export const IconsOnlyPrimary: StoryFn = () => ( <> - + - + - + > ); diff --git a/packages/react/src/components/Button/Button.tsx b/packages/react/src/components/Button/Button.tsx index c39c955474..a3cff1f39d 100644 --- a/packages/react/src/components/Button/Button.tsx +++ b/packages/react/src/components/Button/Button.tsx @@ -2,6 +2,7 @@ import { Slot, Slottable } from '@radix-ui/react-slot'; import cl from 'clsx/lite'; import { forwardRef } from 'react'; import type { ButtonHTMLAttributes } from 'react'; +import type { Size } from '../../types'; import { Spinner } from '../loaders/Spinner'; export type ButtonProps = { @@ -16,9 +17,8 @@ export type ButtonProps = { color?: 'accent' | 'neutral' | 'danger'; /** * Size - * @default md */ - size?: 'sm' | 'md' | 'lg'; + size?: Size; /** Toggle icon only styling, pass icon as children * @default false */ @@ -53,7 +53,7 @@ export const Button = forwardRef( color = 'accent', icon = false, loading = false, - size = 'md', + size, variant = 'primary', ...rest }, diff --git a/packages/react/src/components/Card/Card.stories.tsx b/packages/react/src/components/Card/Card.stories.tsx index 0eed2ccaff..7fad0635ef 100644 --- a/packages/react/src/components/Card/Card.stories.tsx +++ b/packages/react/src/components/Card/Card.stories.tsx @@ -6,13 +6,16 @@ import cat5 from '@assets/img/cats/Cat 5.jpg'; import { PlusIcon, TrashFillIcon } from '@navikt/aksel-icons'; import type { Meta, StoryFn } from '@storybook/react'; -import { Card } from '.'; -import { Button } from '../Button'; -import { Heading } from '../Heading'; -import { Label } from '../Label'; -import { Paragraph } from '../Paragraph'; -import { Select } from '../form/Select'; -import { Textfield } from '../form/Textfield'; +import { + Button, + Card, + Field, + Heading, + Label, + Paragraph, + Select, + Textfield, +} from '../../'; type Story = StoryFn; @@ -34,9 +37,7 @@ export default { export const Preview: Story = (args) => ( - - Card Neutral - + Card Neutral Most provide as with carried business are much better more the perfected designer. Writing slightly explain desk unable at supposedly about this @@ -56,9 +57,7 @@ export const Variants: StoryFn = () => ( - - Card Neutral - + Card Neutral Most provide as with carried business are much better more the perfected designer. Writing slightly explain desk unable at supposedly @@ -71,9 +70,7 @@ export const Variants: StoryFn = () => ( - - Card Subtle - + Card Subtle Most provide as with carried business are much better more the perfected designer. Writing slightly explain desk unable at supposedly @@ -86,9 +83,7 @@ export const Variants: StoryFn = () => ( - - Card First - + Card First Most provide as with carried business are much better more the perfected designer. Writing slightly explain desk unable at supposedly @@ -101,9 +96,7 @@ export const Variants: StoryFn = () => ( - - Card Second - + Card Second Most provide as with carried business are much better more the perfected designer. Writing slightly explain desk unable at supposedly @@ -116,9 +109,7 @@ export const Variants: StoryFn = () => ( - - Card Third - + Card Third Most provide as with carried business are much better more the perfected designer. Writing slightly explain desk unable at supposedly @@ -136,9 +127,7 @@ export const Media: Story = () => ( - - Card Neutral - + Card Neutral Most provide as with carried business are much better more the perfected designer. Writing slightly explain desk unable at supposedly @@ -148,9 +137,7 @@ export const Media: Story = () => ( - - Card Neutral - + Card Neutral Most provide as with carried business are much better more the perfected designer. Writing slightly explain desk unable at supposedly @@ -177,7 +164,7 @@ export const Video: Story = () => ( > - + ( alignItems: 'center', }} > - - Rolle 1 - + Rolle 1 Fjern @@ -229,14 +214,16 @@ export const Composed: Story = () => ( - Velg rolle - - {options.map(({ value, label }, index) => ( - - {label} - - ))} - + + Velg rolle + + {options.map(({ value, label }, index) => ( + + {label} + + ))} + + @@ -252,9 +239,7 @@ export const Composed: Story = () => ( - - Card Neutral - + Card Neutral Most provide as with carried business are much better more the perfected designer. Writing slightly explain desk unable at supposedly @@ -272,7 +257,7 @@ export const WithLink: Story = (args) => ( - + ( - + ( rel='noopener noreferrer' > - - Link Card with blocks - + Link Card with blocks @@ -341,9 +324,7 @@ export const AsLink: Story = (args) => ( target='_blank' rel='noopener noreferrer' > - - Link Card - + Link Card Most provide as with carried business are much better more the perfected designer. @@ -358,9 +339,7 @@ export const AsButton: Story = (args) => ( - - Button Card with blocks - + Button Card with blocks @@ -372,9 +351,7 @@ export const AsButton: Story = (args) => ( - - Link Card - + Link Card Most provide as with carried business are much better more the perfected designer. @@ -387,9 +364,7 @@ export const AsButton: Story = (args) => ( export const AsGrid: Story = (args) => ( - - Button Card with blocks - + Button Card with blocks diff --git a/packages/react/src/components/Chip/Chips.tsx b/packages/react/src/components/Chip/Chips.tsx index 8f633f852d..dcf14c562d 100644 --- a/packages/react/src/components/Chip/Chips.tsx +++ b/packages/react/src/components/Chip/Chips.tsx @@ -2,13 +2,13 @@ import { Slot, Slottable } from '@radix-ui/react-slot'; import cl from 'clsx/lite'; import { forwardRef } from 'react'; import type { ButtonHTMLAttributes, InputHTMLAttributes } from 'react'; +import type { Size } from '../../types'; type ChipBaseProps = { /** * Size - * @default md */ - size?: 'sm' | 'md' | 'lg'; + size?: Size; /** * Change the default rendered element for the one passed as a child, merging their props and behavior. * @default false diff --git a/packages/react/src/components/Dropdown/Dropdown.tsx b/packages/react/src/components/Dropdown/Dropdown.tsx index 1a07ca95f9..738a089a9c 100644 --- a/packages/react/src/components/Dropdown/Dropdown.tsx +++ b/packages/react/src/components/Dropdown/Dropdown.tsx @@ -1,6 +1,5 @@ import cl from 'clsx/lite'; -import { createContext, forwardRef, useEffect, useState } from 'react'; -import type { ReactNode } from 'react'; +import { forwardRef } from 'react'; import type { Placement } from '@floating-ui/react'; import { Popover } from '../Popover'; @@ -11,7 +10,6 @@ export type DropdownProps = { * @default bottom-end */ placement?: Placement; - children: ReactNode; } & Omit; export const Dropdown = forwardRef( @@ -19,36 +17,13 @@ export const Dropdown = forwardRef( { placement = 'bottom-end', className, ...rest }, ref, ) { - const [size, setSize] = useState>( - rest.size || 'md', - ); - - useEffect(() => { - setSize(rest.size || 'md'); - }, [rest.size]); - return ( - - - + ); }, ); - -type DropdownCtxType = { - size: NonNullable; -}; - -export const DropdownCtx = createContext({ - size: 'md', -}); diff --git a/packages/react/src/components/Dropdown/DropdownItem.tsx b/packages/react/src/components/Dropdown/DropdownItem.tsx index 22ca6d059d..1f594be09d 100644 --- a/packages/react/src/components/Dropdown/DropdownItem.tsx +++ b/packages/react/src/components/Dropdown/DropdownItem.tsx @@ -1,23 +1,18 @@ -import { forwardRef, useContext } from 'react'; +import { forwardRef } from 'react'; import type { ButtonProps } from '../Button'; import { Button } from '../Button/Button'; -import { DropdownCtx } from './Dropdown'; - export type DropdownItemProps = Omit; export const DropdownItem = forwardRef( function DropdownItem({ className, style, ...rest }, ref) { - const { size } = useContext(DropdownCtx); - return ( diff --git a/packages/react/src/components/ErrorSummary/ErrorSummary.tsx b/packages/react/src/components/ErrorSummary/ErrorSummary.tsx index 2df4ca7e4e..fbdc001310 100644 --- a/packages/react/src/components/ErrorSummary/ErrorSummary.tsx +++ b/packages/react/src/components/ErrorSummary/ErrorSummary.tsx @@ -1,30 +1,27 @@ import cl from 'clsx/lite'; import { createContext, forwardRef, useId, useState } from 'react'; import type { HTMLAttributes } from 'react'; - -import type { ListUnorderedProps } from '../List'; +import type { Size } from '../../types'; type ErrorSummaryContextType = { - size: ListUnorderedProps['size']; headingId?: string; setHeadingId: (id: string) => void; }; export const ErrorSummaryContext = createContext({ - size: 'md', headingId: 'heading', setHeadingId: () => {}, }); export type ErrorSummaryProps = { - size?: ListUnorderedProps['size']; + size?: Size; } & HTMLAttributes; export const ErrorSummary = forwardRef( function ErrorSummary( { className, - size = 'md', + size, role = 'alert', 'aria-live': ariaLive = 'polite', 'aria-relevant': ariaRelevant = 'all', @@ -36,7 +33,7 @@ export const ErrorSummary = forwardRef( const [headingId, setHeadingId] = useState(randomId); return ( - + ]: HeadingProps['size']; -} = { - sm: '2xs', - md: 'xs', - lg: 'sm', -} as const; - export const ErrorSummaryHeading = forwardRef< HTMLHeadingElement, ErrorSummaryHeadingProps @@ -19,18 +11,11 @@ export const ErrorSummaryHeading = forwardRef< { className, id, ...rest }: ErrorSummaryHeadingProps, ref, ) { - const { size, headingId, setHeadingId } = useContext(ErrorSummaryContext); + const { headingId, setHeadingId } = useContext(ErrorSummaryContext); useEffect(() => { if (id && headingId !== id) setHeadingId(id); }, [headingId, id, setHeadingId]); - return ( - - ); + return ; }); diff --git a/packages/react/src/components/ErrorSummary/ErrorSummaryList.tsx b/packages/react/src/components/ErrorSummary/ErrorSummaryList.tsx index 42ba5bd1e7..15835682c0 100644 --- a/packages/react/src/components/ErrorSummary/ErrorSummaryList.tsx +++ b/packages/react/src/components/ErrorSummary/ErrorSummaryList.tsx @@ -1,14 +1,11 @@ -import { forwardRef, useContext } from 'react'; +import { forwardRef } from 'react'; import { List, type ListUnorderedProps } from '../List'; -import { ErrorSummaryContext } from './ErrorSummary'; - export type ErrorSummaryListProps = ListUnorderedProps; export const ErrorSummaryList = forwardRef< HTMLOListElement, ErrorSummaryListProps >(function ErrorSummaryList({ ...rest }: ErrorSummaryListProps, ref) { - const { size } = useContext(ErrorSummaryContext); - return ; + return ; }); diff --git a/packages/react/src/components/Heading/Heading.tsx b/packages/react/src/components/Heading/Heading.tsx index ec42003cc3..dec96487ac 100644 --- a/packages/react/src/components/Heading/Heading.tsx +++ b/packages/react/src/components/Heading/Heading.tsx @@ -10,8 +10,6 @@ export type HeadingProps = { */ level?: 1 | 2 | 3 | 4 | 5 | 6; /** Changes text sizing - * @default 'xl' - * */ size?: '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'; /** @@ -28,10 +26,7 @@ export type HeadingProps = { * Heading */ export const Heading = forwardRef( - function Heading( - { size = 'xl', level = 2, className, asChild, ...rest }, - ref, - ) { + function Heading({ size, level = 2, className, asChild, ...rest }, ref) { const Component = asChild ? Slot : (`h${level}` as ElementType); return ( diff --git a/packages/react/src/components/HelpText/HelpText.tsx b/packages/react/src/components/HelpText/HelpText.tsx index fcd96cde35..2dc6a2e273 100644 --- a/packages/react/src/components/HelpText/HelpText.tsx +++ b/packages/react/src/components/HelpText/HelpText.tsx @@ -3,7 +3,8 @@ import cl from 'clsx/lite'; import { forwardRef } from 'react'; import type { ButtonHTMLAttributes } from 'react'; -import { Popover, type PopoverProps } from '../Popover'; +import type { Size } from '../../types'; +import { Popover } from '../Popover'; export type HelpTextProps = { /** @@ -12,19 +13,21 @@ export type HelpTextProps = { 'aria-label': string; /** * Size of the helptext - * @default md */ - size?: PopoverProps['size']; + size?: Size; /** * Placement of the Popover. * @default 'right' */ placement?: Placement; -} & Omit, 'color'>; +} & { 'data-size'?: string } & Omit< + ButtonHTMLAttributes, + 'color' + >; export const HelpText = forwardRef( function HelpText( - { placement = 'right', size = 'md', className, children, ...rest }, + { placement = 'right', size, className, children, ...rest }, ref, ) { return ( @@ -36,7 +39,11 @@ export const HelpText = forwardRef( variant='tertiary' {...rest} /> - + {children} diff --git a/packages/react/src/components/Label/Label.tsx b/packages/react/src/components/Label/Label.tsx index 0c41dd2f66..ef7562f81c 100644 --- a/packages/react/src/components/Label/Label.tsx +++ b/packages/react/src/components/Label/Label.tsx @@ -2,11 +2,11 @@ import { Slot } from '@radix-ui/react-slot'; import cl from 'clsx/lite'; import type { LabelHTMLAttributes } from 'react'; import { forwardRef } from 'react'; +import type { Size } from '../../types'; export type LabelProps = { /** * Changes text sizing - * @default md */ size?: 'xs' | 'sm' | 'md' | 'lg'; /** @@ -28,7 +28,7 @@ export type LabelProps = { * Label */ export const Label = forwardRef(function Label( - { className, size = 'md', weight = 'medium', asChild, ...rest }, + { className, size, weight = 'medium', asChild, ...rest }, ref, ) { const Component = asChild ? Slot : 'label'; diff --git a/packages/react/src/components/List/Lists.tsx b/packages/react/src/components/List/Lists.tsx index 83b76dc662..a8265a39c5 100644 --- a/packages/react/src/components/List/Lists.tsx +++ b/packages/react/src/components/List/Lists.tsx @@ -11,8 +11,6 @@ type ListBaseProps = { asChild?: boolean; /** * Changes text sizing - * @default md - * */ size?: 'sm' | 'md' | 'lg'; }; @@ -25,7 +23,7 @@ export type ListOrderedProps = ListBaseProps & const render = ( tagName: string, - { asChild, className, size = 'md', ...rest }: ListOrderedProps, + { asChild, className, size, ...rest }: ListOrderedProps, ref: ForwardedRef, ) => { const Component = asChild ? Slot : tagName; diff --git a/packages/react/src/components/Modal/Modal.stories.tsx b/packages/react/src/components/Modal/Modal.stories.tsx index c13e49ae93..429bd9eff1 100644 --- a/packages/react/src/components/Modal/Modal.stories.tsx +++ b/packages/react/src/components/Modal/Modal.stories.tsx @@ -54,7 +54,7 @@ export const Preview: StoryFn = (args) => ( Open Modal - + Modal header @@ -74,7 +74,7 @@ export const WithoutModalContext: StoryFn = (args) => { modalRef.current?.showModal()}>Open Modal Modal subtittel - + Modal header @@ -94,9 +94,7 @@ export const BackdropClose: StoryFn = () => { Open Modal - - Modal med backdropClose og en veldig lang tittel - + Modal med backdropClose og en veldig lang tittel Lorem ipsum dolor sit, amet consectetur adipisicing elit. Blanditiis doloremque obcaecati assumenda odio ducimus sunt et. @@ -113,7 +111,7 @@ export const WithHeaderAndFooter: StoryFn = () => ( Her er det også divider - Vi kan legge divider under header + Vi kan legge divider under header @@ -152,7 +150,7 @@ export const ModalWithForm: StoryFn = () => { Open Modal setInput('')} backdropClose> - + Modal med skjema = () => ( Open Modal - + Modal med en veldig lang bredde @@ -210,7 +208,7 @@ export const ModalWithCombobox: StoryFn = () => { Open Modal - Modal med combobox + Modal med combobox diff --git a/packages/react/src/components/Modal/Modal.tsx b/packages/react/src/components/Modal/Modal.tsx index cf7dfbeb97..686ff41a29 100644 --- a/packages/react/src/components/Modal/Modal.tsx +++ b/packages/react/src/components/Modal/Modal.tsx @@ -20,7 +20,6 @@ export type ModalProps = { backdropClose?: boolean; /** * Callback that is called when the modal is closed. - * @default undefined */ onClose?: () => void; asChild?: boolean; diff --git a/packages/react/src/components/Pagination/Pagination.stories.tsx b/packages/react/src/components/Pagination/Pagination.stories.tsx index f77596f8a8..399d3997f6 100644 --- a/packages/react/src/components/Pagination/Pagination.stories.tsx +++ b/packages/react/src/components/Pagination/Pagination.stories.tsx @@ -2,13 +2,16 @@ import { useArgs } from '@storybook/preview-api'; import type { Meta, StoryFn } from '@storybook/react'; import { Pagination, type UsePaginationProps, usePagination } from '.'; +import type { Size } from '../../types'; export default { title: 'Komponenter/Pagination', component: Pagination, } as Meta; -export const Preview: StoryFn = (args) => { +export const Preview: StoryFn = ( + args, +) => { const [, updateArgs] = useArgs(); const { pages, nextButtonProps, prevButtonProps } = usePagination({ ...args, @@ -16,7 +19,7 @@ export const Preview: StoryFn = (args) => { }); return ( - + @@ -41,6 +44,7 @@ export const Preview: StoryFn = (args) => { }; Preview.args = { + size: 'md', currentPage: 4, setCurrentPage: console.log, // Added to include in storybook args onChange: console.log, // Open console to see this event diff --git a/packages/react/src/components/Pagination/Pagination.tsx b/packages/react/src/components/Pagination/Pagination.tsx index 42ed4ecd78..b607abeb03 100644 --- a/packages/react/src/components/Pagination/Pagination.tsx +++ b/packages/react/src/components/Pagination/Pagination.tsx @@ -1,11 +1,8 @@ import { Slot } from '@radix-ui/react-slot'; import cl from 'clsx/lite'; -import { createContext, forwardRef } from 'react'; +import { forwardRef } from 'react'; import type { HTMLAttributes } from 'react'; - -export const PaginationContext = createContext({ - size: 'md' as NonNullable, -}); +import type { Size } from '../../types'; export type PaginationProps = { /** @@ -16,7 +13,7 @@ export type PaginationProps = { /** Sets the size of the component * @default md */ - size?: 'sm' | 'md' | 'lg'; + size?: Size; /** * Change the default rendered element for the one passed as a child, merging their props and behavior. * @default false @@ -30,7 +27,7 @@ export const Pagination = forwardRef( 'aria-label': ariaLabel = 'Sidenavigering', asChild, className, - size = 'md', + size, ...rest }, ref, @@ -38,14 +35,13 @@ export const Pagination = forwardRef( const Component = asChild ? Slot : 'nav'; return ( - - - + ); }, ); diff --git a/packages/react/src/components/Pagination/PaginationButton.tsx b/packages/react/src/components/Pagination/PaginationButton.tsx index aa579cb133..871adc9188 100644 --- a/packages/react/src/components/Pagination/PaginationButton.tsx +++ b/packages/react/src/components/Pagination/PaginationButton.tsx @@ -1,9 +1,7 @@ -import { type AriaAttributes, forwardRef, useContext } from 'react'; +import { type AriaAttributes, forwardRef } from 'react'; import { Button, type ButtonProps } from '../Button/Button'; -import { PaginationContext } from './Pagination'; - export type PaginationButtonProps = { /** * Toggle button as active @@ -16,7 +14,5 @@ export const PaginationButton = forwardRef< HTMLButtonElement, PaginationButtonProps >(function PaginationButton(rest, ref) { - const { size } = useContext(PaginationContext); - - return ; + return ; }); diff --git a/packages/react/src/components/Pagination/PaginationList.tsx b/packages/react/src/components/Pagination/PaginationList.tsx index 46ccf3a010..4cb627d9e9 100644 --- a/packages/react/src/components/Pagination/PaginationList.tsx +++ b/packages/react/src/components/Pagination/PaginationList.tsx @@ -1,5 +1,5 @@ import { Slot } from '@radix-ui/react-slot'; -import { forwardRef, useContext, useEffect, useRef } from 'react'; +import { forwardRef } from 'react'; import type { HTMLAttributes } from 'react'; export type PaginationListProps = { diff --git a/packages/react/src/components/Paragraph/Paragraph.tsx b/packages/react/src/components/Paragraph/Paragraph.tsx index 87f6114d1f..3d6803a492 100644 --- a/packages/react/src/components/Paragraph/Paragraph.tsx +++ b/packages/react/src/components/Paragraph/Paragraph.tsx @@ -6,9 +6,6 @@ import { forwardRef } from 'react'; export type ParagraphProps = { /** * Changes text sizing - * - * @default 'md' - * */ size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'; /** @@ -30,7 +27,7 @@ export type ParagraphProps = { */ export const Paragraph = forwardRef( function Paragraph( - { className, size = 'md', asChild, variant = 'default', ...rest }, + { className, size, asChild, variant = 'default', ...rest }, ref, ) { const Component = asChild ? Slot : 'p'; diff --git a/packages/react/src/components/Popover/Popover.tsx b/packages/react/src/components/Popover/Popover.tsx index 3aa0b72360..301540bb41 100644 --- a/packages/react/src/components/Popover/Popover.tsx +++ b/packages/react/src/components/Popover/Popover.tsx @@ -12,6 +12,7 @@ import cl from 'clsx/lite'; import { forwardRef, useContext, useRef, useState } from 'react'; import type { HTMLAttributes } from 'react'; import { useEffect } from 'react'; +import type { Size } from '../../types'; import { Context } from './PopoverContext'; // Make React support popovertarget attribute @@ -51,9 +52,8 @@ export type PopoverProps = { open?: boolean; /** * Size of the popover - * @default md */ - size?: 'sm' | 'md' | 'lg'; + size?: Size; /** * Callback when the popover wants to open. */ @@ -80,7 +80,7 @@ export const Popover = forwardRef( onOpen, open, placement = 'top', - size = 'md', + size, variant = 'default', autoPlacement = true, asChild = false, diff --git a/packages/react/src/components/Table/Table.stories.tsx b/packages/react/src/components/Table/Table.stories.tsx index 036ff0f955..f0489317a7 100644 --- a/packages/react/src/components/Table/Table.stories.tsx +++ b/packages/react/src/components/Table/Table.stories.tsx @@ -2,20 +2,9 @@ import type { Meta, StoryFn } from '@storybook/react'; import type { ChangeEvent } from 'react'; import { useEffect, useState } from 'react'; -import { Checkbox } from '../form/Checkbox'; -import { Textfield } from '../form/Textfield'; - import type { TableHeaderCellProps } from './TableHeaderCell'; -import { - Table, - TableBody, - TableCell, - TableHead, - TableHeaderCell, - TableRow, -} from '.'; -import { Label } from '../Label'; +import { Checkbox, Label, Table, Textfield } from '../..'; type Story = StoryFn; @@ -27,25 +16,25 @@ export default { export const Preview: Story = (args) => { return ( - - - Header 1 - Header 2 - Header 3 - - - - - Cell 1 - Cell 2 - Cell 3 - - - Cell 4 - Cell 5 - Cell 6 - - + + + Header 1 + Header 2 + Header 3 + + + + + Cell 1 + Cell 2 + Cell 3 + + + Cell 4 + Cell 5 + Cell 6 + + ); }; @@ -117,32 +106,32 @@ export const Sortable: Story = (args) => { return ( - - - + + handleSort('navn')} > Navn - - Epost - + Epost + handleSort('telefon')} > Telefon - - - - + + + + {sortedData.map((row) => ( - - {row.navn} - {row.epost} - {row.telefon} - + + {row.navn} + {row.epost} + {row.telefon} + ))} - + ); }; @@ -151,22 +140,22 @@ export const StickyHeader: Story = (args) => { const rows = Array.from({ length: 50 }, (_, i) => i + 1); return ( - - - Header 1 - Header 2 - Header 3 - - - + + + Header 1 + Header 2 + Header 3 + + + {rows.map((row) => ( - - {`Cell ${row}1`} - {`Cell ${row}2`} - {`Cell ${row}3`} - + + {`Cell ${row}1`} + {`Cell ${row}2`} + {`Cell ${row}3`} + ))} - + ); }; @@ -221,9 +210,9 @@ export const WithFormElements: Story = (args) => { return ( - - - + + + { /> Selection - - Header 1 - Header 2 - Header 3 - - - + + Header 1 + Header 2 + Header 3 + + + {rows.map((row) => ( - - + + { onChange={(event) => handleCheckboxChange(event, row)} size='sm' /> - - 1 - 2 - + + 1 + 2 + - - + + ))} - + ); }; @@ -273,22 +262,22 @@ export const FixedTable: Story = (args) => { tableLayout: 'fixed', }} > - - - Header 1 - Header 2 - Header 3 - - - + + + Header 1 + Header 2 + Header 3 + + + {rows.map((row) => ( - - {`Cell ${row}1`} - {`Cell ${row}2`} - {`Cell ${row}3`} - + + {`Cell ${row}1`} + {`Cell ${row}2`} + {`Cell ${row}3`} + ))} - + ); }; @@ -297,26 +286,26 @@ export const MultipleHeaderRows: Story = (args) => { const rows = Array.from({ length: 50 }, (_, i) => i + 1); return ( - - - Header 1 - Header 2 - - - Header 3 - Header 4 - Header 5 - - - + + + Header 1 + Header 2 + + + Header 3 + Header 4 + Header 5 + + + {rows.map((row) => ( - - {`Cell ${row}1`} - {`Cell ${row}2`} - {`Cell ${row}3`} - + + {`Cell ${row}1`} + {`Cell ${row}2`} + {`Cell ${row}3`} + ))} - + ); }; diff --git a/packages/react/src/components/Table/Table.tsx b/packages/react/src/components/Table/Table.tsx index 7e590a39a5..36cbcd346a 100644 --- a/packages/react/src/components/Table/Table.tsx +++ b/packages/react/src/components/Table/Table.tsx @@ -1,13 +1,13 @@ import cl from 'clsx/lite'; import { forwardRef } from 'react'; import type { TableHTMLAttributes } from 'react'; +import type { Size } from '../../types'; export type TableProps = { /** * The size of the table - * @default md */ - size?: 'sm' | 'md' | 'lg'; + size?: Size; /** * If true, the table will have zebra striping * @default false @@ -36,7 +36,7 @@ export const Table = forwardRef(function Table( stickyHeader = false, border = false, hover = false, - size = 'md', + size, className, children, ...rest diff --git a/packages/react/src/components/Tabs/Tabs.tsx b/packages/react/src/components/Tabs/Tabs.tsx index 129dfbf441..4615c3bcac 100644 --- a/packages/react/src/components/Tabs/Tabs.tsx +++ b/packages/react/src/components/Tabs/Tabs.tsx @@ -1,6 +1,7 @@ import cl from 'clsx/lite'; import type { HTMLAttributes } from 'react'; import { createContext, forwardRef, useState } from 'react'; +import type { Size } from '../../types'; export type TabsProps = { /** Controlled state for `Tabs` component. */ @@ -11,16 +12,14 @@ export type TabsProps = { onChange?: (value: string) => void; /** * Changes items size and paddings - * @default md */ - size?: 'sm' | 'md' | 'lg'; + size?: Size; } & Omit, 'onChange' | 'value'>; export type ContextProps = { value?: string; defaultValue?: string; onChange?: (value: string) => void; - size?: TabsProps['size']; }; export const Context = createContext({}); @@ -42,7 +41,7 @@ export const Context = createContext({}); * ``` */ export const Tabs = forwardRef(function Tabs( - { size = 'md', value, defaultValue, className, onChange, ...rest }, + { size, value, defaultValue, className, onChange, ...rest }, ref, ) { const isControlled = value !== undefined; @@ -64,7 +63,6 @@ export const Tabs = forwardRef(function Tabs( value, defaultValue, onChange: onValueChange, - size, }} > ( function TabsPanel({ children, value, className, ...rest }, ref) { - const { value: tabsValue, size } = useContext(Context); + const { value: tabsValue } = useContext(Context); const active = value === tabsValue; return ( diff --git a/packages/react/src/components/Tag/Tag.tsx b/packages/react/src/components/Tag/Tag.tsx index 8dc290aa72..9d301ac9e8 100644 --- a/packages/react/src/components/Tag/Tag.tsx +++ b/packages/react/src/components/Tag/Tag.tsx @@ -1,6 +1,7 @@ import cl from 'clsx/lite'; import type { HTMLAttributes } from 'react'; import { forwardRef } from 'react'; +import type { Size } from '../../types'; export type TagProps = { /** @@ -18,9 +19,8 @@ export type TagProps = { | 'brand3'; /** * Size of the tag - * @default md */ - size?: 'sm' | 'md' | 'lg'; + size?: Size; } & HTMLAttributes; /** @@ -29,7 +29,7 @@ export type TagProps = { * Success */ export const Tag = forwardRef(function Tag( - { size = 'md', color = 'neutral', className, ...rest }, + { size, color = 'neutral', className, ...rest }, ref, ) { return ( diff --git a/packages/react/src/components/ToggleGroup/ToggleGroup.tsx b/packages/react/src/components/ToggleGroup/ToggleGroup.tsx index 7258c98e9c..033baac9e4 100644 --- a/packages/react/src/components/ToggleGroup/ToggleGroup.tsx +++ b/packages/react/src/components/ToggleGroup/ToggleGroup.tsx @@ -2,15 +2,14 @@ import cl from 'clsx/lite'; import type { HTMLAttributes } from 'react'; import { createContext, forwardRef, useId, useState } from 'react'; +import type { Size } from '../../types'; import { RovingFocusRoot } from '../../utilities/RovingFocus'; -import type { ButtonProps } from '../Button'; export type ToggleGroupContextProps = { value?: string; defaultValue?: string; onChange?: (value: string) => void; name?: string; - size?: ButtonProps['size']; }; export const ToggleGroupContext = createContext({}); @@ -25,10 +24,9 @@ export type ToggleGroupProps = { /** Form element name */ name?: string; /** - * Changes items size and paddings - * @default md + * Size */ - size?: ToggleGroupContextProps['size']; + size?: Size; } & Omit, 'value' | 'onChange'>; /** @@ -42,16 +40,7 @@ export type ToggleGroupProps = { */ export const ToggleGroup = forwardRef( function ToggleGroup( - { - size = 'md', - children, - value, - defaultValue, - onChange, - name, - className, - ...rest - }, + { size, children, value, defaultValue, onChange, name, className, ...rest }, ref, ) { const nameId = useId(); @@ -76,12 +65,12 @@ export const ToggleGroup = forwardRef( defaultValue, name: name ?? `togglegroup-name-${nameId}`, onChange: onValueChange, - size, }} > (function ToggleGroupItem(rest, ref) { - const { active, size = 'md', buttonProps, value } = useToggleGroupItem(rest); + const { active, buttonProps, value } = useToggleGroupItem(rest); return ( { active: boolean; - size?: ToggleGroupContextProps['size']; value: string; buttonProps?: Pick< ButtonProps, @@ -30,7 +28,6 @@ export const useToggleGroupItem: UseToggleGroupItem = ( return { ...rest, active: active, - size: toggleGroup?.size, value, buttonProps: { id: buttonId, diff --git a/packages/react/src/components/Tooltip/Tooltip.stories.tsx b/packages/react/src/components/Tooltip/Tooltip.stories.tsx index 35d098ac95..88c9a44846 100644 --- a/packages/react/src/components/Tooltip/Tooltip.stories.tsx +++ b/packages/react/src/components/Tooltip/Tooltip.stories.tsx @@ -16,12 +16,15 @@ export default { }, } satisfies Meta; -export const Preview: Story = { - args: { - content: 'Tooltip text', - children: defaultChildren, - placement: 'top', - }, +export const Preview: StoryFn = (args) => ( + + My trigger + +); + +Preview.args = { + content: 'Tooltip text', + placement: 'top', }; export const Placement: Story = { diff --git a/packages/react/src/components/Tooltip/Tooltip.tsx b/packages/react/src/components/Tooltip/Tooltip.tsx index f7c1757632..fa25841e54 100644 --- a/packages/react/src/components/Tooltip/Tooltip.tsx +++ b/packages/react/src/components/Tooltip/Tooltip.tsx @@ -23,7 +23,7 @@ import type { } from 'react'; import { Fragment, cloneElement, forwardRef, useRef, useState } from 'react'; -import type { PortalProps } from '../../types/Portal'; +import type { PortalProps } from '../../types'; export type TooltipProps = { /** diff --git a/packages/react/src/components/ValidationMessage/ValidationMessage.tsx b/packages/react/src/components/ValidationMessage/ValidationMessage.tsx index f6c1871c9f..2b72268979 100644 --- a/packages/react/src/components/ValidationMessage/ValidationMessage.tsx +++ b/packages/react/src/components/ValidationMessage/ValidationMessage.tsx @@ -2,11 +2,11 @@ import { Slot } from '@radix-ui/react-slot'; import cl from 'clsx/lite'; import type { HTMLAttributes } from 'react'; import { forwardRef } from 'react'; +import type { Size } from '../../types'; export type ValidationMessageProps = { /** * Changes text sizing - * @default md */ size?: 'xs' | 'sm' | 'md' | 'lg'; /** Toggle error color */ @@ -23,7 +23,7 @@ export const ValidationMessage = forwardRef< HTMLParagraphElement, ValidationMessageProps >(function ValidationMessage( - { size = 'md', className, asChild, error = true, ...rest }, + { size, className, asChild, error = true, ...rest }, ref, ) { const Component = asChild ? Slot : 'div'; diff --git a/packages/react/src/components/form/Combobox/Combobox.tsx b/packages/react/src/components/form/Combobox/Combobox.tsx index c790cec1d6..f43a41c8ff 100644 --- a/packages/react/src/components/form/Combobox/Combobox.tsx +++ b/packages/react/src/components/form/Combobox/Combobox.tsx @@ -4,7 +4,7 @@ import cl from 'clsx/lite'; import { forwardRef, useEffect, useRef, useState } from 'react'; import type { InputHTMLAttributes, ReactNode } from 'react'; -import type { PortalProps } from '../../../types/Portal'; +import type { PortalProps } from '../../../types'; import { omit, useDebounceCallback } from '../../../utilities'; import { Spinner } from '../../loaders/Spinner'; import type { FormFieldProps } from '../useFormField'; diff --git a/packages/react/src/components/form/Input/Input.tsx b/packages/react/src/components/form/Input/Input.tsx index f1aea063a0..579a3f9456 100644 --- a/packages/react/src/components/form/Input/Input.tsx +++ b/packages/react/src/components/form/Input/Input.tsx @@ -1,14 +1,14 @@ import cl from 'clsx/lite'; import type { InputHTMLAttributes } from 'react'; import { forwardRef } from 'react'; +import type { Size } from '../../../types'; type InputAttr = InputHTMLAttributes; export type InputProps = { /** * Changes field size and paddings - * @default md */ - size?: 'sm' | 'md' | 'lg'; + size?: Size; /** Supported `input` types */ type?: InputAttr['type']; /** Exposes the HTML `size` attribute. @@ -33,7 +33,7 @@ export type InputProps = { * ``` */ export const Input = forwardRef(function Input( - { type = 'text', size = 'md', htmlSize, className, onClick, ...rest }, + { type = 'text', size, htmlSize, className, onClick, ...rest }, ref, ) { return ( diff --git a/packages/react/src/components/form/Search/Search.tsx b/packages/react/src/components/form/Search/Search.tsx index 9a8eb92b1f..e5e77d2c12 100644 --- a/packages/react/src/components/form/Search/Search.tsx +++ b/packages/react/src/components/form/Search/Search.tsx @@ -4,6 +4,7 @@ import cl from 'clsx/lite'; import type { ChangeEvent, InputHTMLAttributes, ReactNode } from 'react'; import { forwardRef, useCallback, useRef, useState } from 'react'; +import type { Size } from '../../../types'; import { omit } from '../../../utilities'; import { Button } from '../../Button/Button'; import { Label } from '../../Label'; @@ -23,7 +24,7 @@ export type SearchProps = { * Changes field size and paddings * @default md */ - size?: 'sm' | 'md' | 'lg'; + size?: Size; /** Variant * @default 'simple' */ diff --git a/packages/react/src/components/form/Select/Select.tsx b/packages/react/src/components/form/Select/Select.tsx index 39f44dc070..fdcc88a69a 100644 --- a/packages/react/src/components/form/Select/Select.tsx +++ b/packages/react/src/components/form/Select/Select.tsx @@ -1,13 +1,14 @@ import cl from 'clsx/lite'; import { forwardRef } from 'react'; import type { SelectHTMLAttributes } from 'react'; +import type { Size } from '../../../types'; export type SelectProps = { /** * Defines the size of the select. * @default md **/ - size?: 'sm' | 'md' | 'lg'; + size?: Size; /** Defines if the select is readOnly * @default false */ diff --git a/packages/react/src/components/form/Textarea/Textarea.stories.tsx b/packages/react/src/components/form/Textarea/Textarea.stories.tsx index 9472b2dfbf..c56d59d4d3 100644 --- a/packages/react/src/components/form/Textarea/Textarea.stories.tsx +++ b/packages/react/src/components/form/Textarea/Textarea.stories.tsx @@ -62,7 +62,6 @@ export const Preview: Story = { export const FullWidth: Story = { args: { - rows: 10, cols: 40, id: 'my-textarea', }, diff --git a/packages/react/src/components/form/Textarea/Textarea.tsx b/packages/react/src/components/form/Textarea/Textarea.tsx index 979ae5c6fe..5887fc26e1 100644 --- a/packages/react/src/components/form/Textarea/Textarea.tsx +++ b/packages/react/src/components/form/Textarea/Textarea.tsx @@ -1,13 +1,14 @@ import cl from 'clsx/lite'; import type { TextareaHTMLAttributes } from 'react'; import { forwardRef } from 'react'; +import type { Size } from '../../../types'; export type TextareaProps = { /** * Defines the size of the select. * @default md **/ - size?: 'sm' | 'md' | 'lg'; + size?: Size; } & TextareaHTMLAttributes; /** Textarea field diff --git a/packages/react/src/components/form/Textfield/Textfield.tsx b/packages/react/src/components/form/Textfield/Textfield.tsx index 11336bad66..69702b6538 100644 --- a/packages/react/src/components/form/Textfield/Textfield.tsx +++ b/packages/react/src/components/form/Textfield/Textfield.tsx @@ -3,6 +3,7 @@ import cl from 'clsx/lite'; import type { InputHTMLAttributes, ReactNode } from 'react'; import { forwardRef, useId, useState } from 'react'; +import type { Size } from '../../../types'; import { omit } from '../../../utilities'; import { Label } from '../../Label'; import { Paragraph } from '../../Paragraph'; @@ -22,7 +23,7 @@ export type TextfieldProps = { * Changes field size and paddings * @default md */ - size?: 'sm' | 'md' | 'lg'; + size?: Size; /** Prefix for field. */ prefix?: string; /** Suffix for field. */ diff --git a/packages/react/src/components/form/useFormField.ts b/packages/react/src/components/form/useFormField.ts index e866b08233..7c4ab727c1 100644 --- a/packages/react/src/components/form/useFormField.ts +++ b/packages/react/src/components/form/useFormField.ts @@ -2,6 +2,7 @@ import cl from 'clsx/lite'; import { useContext, useId } from 'react'; import type { HTMLAttributes, InputHTMLAttributes, ReactNode } from 'react'; +import type { Size } from '../../types'; import { FieldsetContext } from './Fieldset/FieldsetContext'; export type FormFieldProps = { @@ -23,7 +24,7 @@ export type FormFieldProps = { * Changes field size and paddings * @default md */ - size?: 'sm' | 'md' | 'lg'; + size?: Size; } & Pick, 'aria-describedby'>; export type FormField = { diff --git a/packages/react/src/components/loaders/Spinner/Spinner.test.tsx b/packages/react/src/components/loaders/Spinner/Spinner.test.tsx index ac7c6cc49e..2c21afe4d3 100644 --- a/packages/react/src/components/loaders/Spinner/Spinner.test.tsx +++ b/packages/react/src/components/loaders/Spinner/Spinner.test.tsx @@ -7,14 +7,6 @@ beforeAll(() => { }); describe('spinner', (): void => { - it('should render with default medium size', (): void => { - render(); - expect(screen.getByTitle('Loading').parentElement).toHaveAttribute( - 'data-size', - 'md', - ); - }); - it('should render with title "loading', (): void => { render(); expect(screen.getByTitle('Loading')).toBeInTheDocument(); diff --git a/packages/react/src/components/loaders/Spinner/Spinner.tsx b/packages/react/src/components/loaders/Spinner/Spinner.tsx index 93ea490ae6..f2d8a7fe41 100644 --- a/packages/react/src/components/loaders/Spinner/Spinner.tsx +++ b/packages/react/src/components/loaders/Spinner/Spinner.tsx @@ -8,8 +8,6 @@ export type SpinnerProps = { title: string; /** * Spinner size - * - * @default md */ size?: '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl'; /** @@ -23,7 +21,7 @@ export type SpinnerProps = { export const Spinner = ({ title, color = 'neutral', - size = 'md', + size, className, ...rest }: SpinnerProps): JSX.Element => { diff --git a/packages/react/src/types/Portal.ts b/packages/react/src/types.ts similarity index 84% rename from packages/react/src/types/Portal.ts rename to packages/react/src/types.ts index 09ba9044b0..a70d2ef8e1 100644 --- a/packages/react/src/types/Portal.ts +++ b/packages/react/src/types.ts @@ -1,3 +1,5 @@ +export type Size = 'sm' | 'md' | 'lg'; + export type PortalProps = { /** * Portals the floating element outside of the app root and into the body. diff --git a/packages/react/stories/testing.stories.tsx b/packages/react/stories/testing.stories.tsx index 4c96b74d79..373546a5da 100644 --- a/packages/react/stories/testing.stories.tsx +++ b/packages/react/stories/testing.stories.tsx @@ -1,16 +1,44 @@ +import { PrinterSmallIcon } from '@navikt/aksel-icons'; import type { Meta, StoryFn } from '@storybook/react'; +import { useState } from 'react'; import { + Accordion, + Alert, + Avatar, + Badge, + Breadcrumbs, Button, + Card, Checkbox, Chip, Combobox, + Dropdown, + ErrorSummary, + Field, + Heading, + HelpText, + Input, + Label, + Link, + List, + Modal, + Pagination, + Paragraph, + Popover, Radio, Select, + Spinner, Switch, + Table, + Tabs, Tag, Textfield, -} from '../src/components'; + ToggleGroup, + Tooltip, + ValidationMessage, + usePagination, +} from '../src'; export default { title: 'Testing', @@ -127,3 +155,884 @@ LargeCol.args = { size: 'lg', direction: 'column', }; + +export const Sizes: StoryFn = () => { + const [currentPage, setCurrentPage] = useState(4); + const { pages, nextButtonProps, prevButtonProps } = usePagination({ + currentPage, + onChange: console.log, // Open console to see this event + totalPages: 10, + showPages: 7, + setCurrentPage, + }); + + return ( + + 14px + 16px + 18px + 24px + + + + Hvem kan registrere seg i Frivillighetsregisteret? + + + For å kunne bli registrert i Frivillighetsregisteret, må + organisasjonen drive frivillig virksomhet. Det er bare foreninger, + stiftelser og aksjeselskap som kan registreres. Virksomheten kan + ikke dele ut midler til fysiske personer. Virksomheten må ha et + styre. + + + + + + + Hvem kan registrere seg i Frivillighetsregisteret? + + + For å kunne bli registrert i Frivillighetsregisteret, må + organisasjonen drive frivillig virksomhet. Det er bare foreninger, + stiftelser og aksjeselskap som kan registreres. Virksomheten kan + ikke dele ut midler til fysiske personer. Virksomheten må ha et + styre. + + + + + + + Hvem kan registrere seg i Frivillighetsregisteret? + + + For å kunne bli registrert i Frivillighetsregisteret, må + organisasjonen drive frivillig virksomhet. Det er bare foreninger, + stiftelser og aksjeselskap som kan registreres. Virksomheten kan + ikke dele ut midler til fysiske personer. Virksomheten må ha et + styre. + + + + + + + Hvem kan registrere seg i Frivillighetsregisteret? + + + For å kunne bli registrert i Frivillighetsregisteret, må + organisasjonen drive frivillig virksomhet. Det er bare foreninger, + stiftelser og aksjeselskap som kan registreres. Virksomheten kan + ikke dele ut midler til fysiske personer. Virksomheten må ha et + styre. + + + + Dette er en alert + Dette er en alert + Dette er en alert + Dette er en alert + + + JD + + + + + JD + + + + + JD + + + + + JD + + + + + + + + + + Nivå 1 + + + Nivå 2 + + + Nivå 3 + + + + + + + Nivå 1 + + + Nivå 2 + + + Nivå 3 + + + + + + + Nivå 1 + + + Nivå 2 + + + Nivå 3 + + + + + + + Nivå 1 + + + Nivå 2 + + + Nivå 3 + + + + + + + Klikk her + + + + + + Klikk her + + + + + Klikk her + + + + + Klikk her + + + + Card Neutral + + Most provide as with carried business are much better more the + perfected designer. Writing slightly explain desk unable at supposedly + about this + + + + Card Neutral + + Most provide as with carried business are much better more the + perfected designer. Writing slightly explain desk unable at supposedly + about this + + + + Card Neutral + + Most provide as with carried business are much better more the + perfected designer. Writing slightly explain desk unable at supposedly + about this + + + + Card Neutral + + Most provide as with carried business are much better more the + perfected designer. Writing slightly explain desk unable at supposedly + about this + + + + Radio + Check + Knapp + + + Radio + Check + Knapp + + + Radio + Check + Knapp + + + Radio + Check + Knapp + + + + Dropdown + + Heading 1 + + Button 1.1 + Button 1.2 + + + + + + + Dropdown + + Heading 1 + + Button 1.1 + Button 1.2 + + + + + + + Dropdown + + Heading 1 + + Button 1.1 + Button 1.2 + + + + + + + Dropdown + + Heading 1 + + Button 1.1 + Button 1.2 + + + + + + + For å gå videre må du rette opp følgende feil: + + + + Fødselsdato kan ikke være etter år 2005 + + E-post må være gyldig + + + + + For å gå videre må du rette opp følgende feil: + + + + Fødselsdato kan ikke være etter år 2005 + + E-post må være gyldig + + + + + For å gå videre må du rette opp følgende feil: + + + + Fødselsdato kan ikke være etter år 2005 + + E-post må være gyldig + + + + + For å gå videre må du rette opp følgende feil: + + + + Fødselsdato kan ikke være etter år 2005 + + E-post må være gyldig + + + + + Text + + En feil + + + Text + + En feil + + + Text + + En feil + + + Text + + En feil + + + + Text + + + + Text + + + + Text + + + + Text + + + + Text + + + + Text + + + + Text + + + + Text + + + + Text + + + + Text + + + + Text + + + + Text + + + Mer tekst + + + Mer tekst + + + Mer tekst + + + Mer tekst + + + Lenke + + + Lenke + + + Lenke + + + Lenke + + + List Item 1 + List Item 2 + List Item 3 + + + List Item 1 + List Item 2 + List Item 3 + + + List Item 1 + List Item 2 + List Item 3 + + + List Item 1 + List Item 2 + List Item 3 + + + + + + + + Open Modal + + + Modal header + + + Lorem ipsum dolor sit, amet consectetur adipisicing elit. + Blanditiis doloremque obcaecati assumenda odio ducimus sunt et. + + + + + + + Open Modal + + + Modal header + + + Lorem ipsum dolor sit, amet consectetur adipisicing elit. + Blanditiis doloremque obcaecati assumenda odio ducimus sunt et. + + + + + + + Open Modal + + + Modal header + + + Lorem ipsum dolor sit, amet consectetur adipisicing elit. + Blanditiis doloremque obcaecati assumenda odio ducimus sunt et. + + + + + + + Open Modal + + + Modal header + + + Lorem ipsum dolor sit, amet consectetur adipisicing elit. + Blanditiis doloremque obcaecati assumenda odio ducimus sunt et. + + + + + + + + + Forrige + + + {pages.map(({ page, itemKey, buttonProps }) => ( + + + {page} + + + ))} + + + Neste + + + + + + + + + Forrige + + + {pages.map(({ page, itemKey, buttonProps }) => ( + + + {page} + + + ))} + + + Neste + + + + + + + + + Forrige + + + {pages.map(({ page, itemKey, buttonProps }) => ( + + + {page} + + + ))} + + + Neste + + + + + + + + + Forrige + + + {pages.map(({ page, itemKey, buttonProps }) => ( + + + {page} + + + ))} + + + Neste + + + + + + + My popup + popover content + + + + + My popup + popover content + + + + + My popup + popover content + + + + + My popup + popover content + + + + + + Header 1 + Header 2 + Header 3 + + + + + Cell 1 + Cell 2 + Cell 3 + + + Cell 4 + Cell 5 + Cell 6 + + + + + + + Header 1 + Header 2 + Header 3 + + + + + Cell 1 + Cell 2 + Cell 3 + + + Cell 4 + Cell 5 + Cell 6 + + + + + + + Header 1 + Header 2 + Header 3 + + + + + Cell 1 + Cell 2 + Cell 3 + + + Cell 4 + Cell 5 + Cell 6 + + + + + + + Header 1 + Header 2 + Header 3 + + + + + Cell 1 + Cell 2 + Cell 3 + + + Cell 4 + Cell 5 + Cell 6 + + + + + + Tab 1 + Tab 2 + Tab 3 + + content 1 + content 2 + content 3 + + + + Tab 1 + Tab 2 + Tab 3 + + content 1 + content 2 + content 3 + + + + Tab 1 + Tab 2 + Tab 3 + + content 1 + content 2 + content 3 + + + + Tab 1 + Tab 2 + Tab 3 + + content 1 + content 2 + content 3 + + Tag + Tag + Tag + Tag + + Innboks + Utkast + Arkiv + + + Innboks + Utkast + Arkiv + + + Innboks + Utkast + Arkiv + + + Innboks + Utkast + Arkiv + + + + My tooltip + + + + + My tooltip + + + + + My tooltip + + + + + My tooltip + + + + ); +};