Skip to content

Commit

Permalink
Add subcomponent controls
Browse files Browse the repository at this point in the history
  • Loading branch information
alimpens committed Dec 6, 2023
1 parent 577bc2f commit afdfbfb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Canvas, Markdown, Meta, Primary } from "@storybook/blocks";
import { Canvas, Controls, Markdown, Meta, Primary } from "@storybook/blocks";
import * as SearchFieldStories from "./SearchField.stories.tsx";
import README from "../../../../packages/css/src/components/search-field/README.md?raw";

Expand All @@ -8,6 +8,8 @@ import README from "../../../../packages/css/src/components/search-field/README.

<Primary />

<Controls />

### Met placeholder

Een zoekveld kan een placeholder hebben.
Expand Down
36 changes: 26 additions & 10 deletions storybook/storybook-react/src/SearchField/SearchField.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,46 @@
* Copyright (c) 2023 Gemeente Amsterdam
*/

import { SearchField } from '@amsterdam/design-system-react'
import { SearchField, SearchFieldProps } from '@amsterdam/design-system-react'
import { useArgs } from '@storybook/preview-api'
import { Meta, StoryObj } from '@storybook/react'

type InputProps = { label?: string; placeholder?: string }
type StoryProps = SearchFieldProps & InputProps

const meta = {
title: 'Forms/Search Field',
component: SearchField,
args: {
children: [<SearchField.Input key={1} />, <SearchField.Button key={2} />],
onSubmit: (e) => {
e.preventDefault()
},
},
argTypes: {
// TODO: add label and placeholder controls once we figure out an approach for subcomponent controls
children: {
table: {
disable: true,
},
},
label: {
control: 'text',
},
onSubmit: {
table: {
disable: true,
},
},
placeholder: {
control: 'text',
},
},
} satisfies Meta<typeof SearchField>
render: ({ label, placeholder, ...args }) => (
<SearchField {...args}>
<SearchField.Input label={label} placeholder={placeholder} />
<SearchField.Button />
</SearchField>
),
} satisfies Meta<StoryProps>

export default meta

Expand All @@ -39,18 +52,15 @@ export const Default: Story = {}

export const WithPlaceholder: Story = {
args: {
children: [
<SearchField.Input key={1} placeholder="Wat kunnen we voor u vinden?" />,
<SearchField.Button key={2} />,
],
placeholder: 'Wat kunnen we voor u vinden?',
},
}

export const Controlled: any = {
args: {
value: '',
},
render: function Component() {
render: function Component({ label, placeholder }: InputProps) {
const [args, setArgs] = useArgs()

const onValueChange = (event: any) => {
Expand All @@ -70,7 +80,13 @@ export const Controlled: any = {
}
}}
>
<SearchField.Input name="search-box" value={args['value']} onChange={onValueChange} />
<SearchField.Input
name="search-box"
value={args['value']}
label={label}
onChange={onValueChange}
placeholder={placeholder}
/>
<SearchField.Button />
</SearchField>
)
Expand Down

0 comments on commit afdfbfb

Please sign in to comment.