import { PintGlassIcon, WindIcon } from "@phosphor-icons/react"; import type { Meta, StoryObj } from "@storybook/react-vite"; import { useRef, useState } from "react"; import type { DSSuggestionElement } from "../"; import type { FieldSuggestionSelected } from "../react"; import { Field, Flex, Input } from "../react"; import styles from "../styles.module.css"; const meta = { title: "Designsystem/Field", argTypes: { as: { description: "Element type", table: { defaultValue: { summary: "input" }, type: { summary: "input | textarea | select" }, }, }, type: { description: "Input type", table: { type: { summary: "text | checkbox | radio | ..." }, }, }, label: { description: "Label text", table: { type: { summary: "React.ReactNode" }, }, }, description: { description: "Description text", table: { type: { summary: "React.ReactNode" }, }, }, value: { description: "Value", table: { type: { summary: "string" }, }, }, checked: { description: 'If `type="checkbox"` or `type="radio"`', table: { type: { summary: "boolean" }, }, }, validation: { description: "Validation message", table: { type: { summary: "React.ReactNode" }, }, }, count: { description: "Character count", table: { type: { summary: "number" }, }, }, options: { description: 'If `as="select"` or `as={Field.Suggestion}`', table: { type: { summary: "string[] | { label: string; value: string; children?: React.ReactNode }[]", }, }, }, prefix: { description: "Prefix", table: { type: { summary: "string" }, }, }, suffix: { description: "Suffix", table: { type: { summary: "string" }, }, }, helpText: { description: "What to display in HelpText", table: { type: { summary: "React.ReactNode" }, }, }, helpTextLabel: { description: "Label of HelpText button", table: { type: { summary: "string" }, }, }, "data-nofilter": { description: "If `as={Field.Suggestion}`", table: { type: { summary: "boolean" }, }, }, selected: { description: "If `as={Field.Suggestion}`", table: { type: { summary: "{ label: string; value: string; children?: React.ReactNode }[]", }, }, }, onSelectedChange: { description: "If `as={Field.Suggestion}`", table: { type: { summary: "(selected) => void" }, }, }, }, decorators: [ (Story) => (
), ], } satisfies Meta; export default meta; type Story = StoryObj; export const Default: Story = { render: () => (

Beskrivelse

), }; export const React: Story = { render: () => ( <>

Field uten as attributt lar deg bygge opp av bestanddeler:

Ledetekst Beskrivelse

Field med as="input" gir deg en komplett field med
label + description + input +{" "} error + prefix + suffix:


Field med as="input" og type="checkbox":


Field med as="textarea" og{" "} count={15}:


Field med as="select":

), }; export const Required: Story = { parameters: { showInOverview: true }, render: () => (

Beskrivelse

), }; export const Indeterminate: Story = { render: function Render() { const [checked, setChecked] = useState(["1", "2"]); const all = ["1", "2", "3"]; const isAll = checked.length === all.length; const onChange = ({ target }: React.ChangeEvent) => setChecked( checked.includes(target.value) ? checked.filter((v) => v !== target.value) : [...checked, target.value], ); return (
Velg alternativer setChecked(isAll ? [] : all)} type="checkbox" />
{all.map((value) => ( ))}
); }, }; export const Toggles: Story = { render: () => ( <>

Beskrivelse

), }; export const WithValidation: Story = { parameters: { showInOverview: true }, render: () => (

Beskrivelse

Validation
), }; export const WithValidationForm: Story = { parameters: { layout: "padded" }, name: "With Validation Form", render: () => { const [selected, setSelected] = useState([]); return (

Beskrivelse

Må inneholde en gyldig e-postadresse

Beskrivelse

Må fylles ut
Sogndal Oslo Brønnøysund Stavanger Trondheim Bergen Lillestrøm
Må fylles ut
); }, }; export const WithAffixes: Story = { parameters: { showInOverview: true, }, render: () => (
NOK pr. mnd.
), }; export const WithCharacterCount: Story = { parameters: { layout: "padded", showInOverview: true, }, render: () => (

Beskrivelse