Skip to content

Commit 42793ce

Browse files
committed
Add button comp form story
1 parent 281a7fe commit 42793ce

File tree

1 file changed

+65
-3
lines changed

1 file changed

+65
-3
lines changed

packages/components/src/components/Button/Button.stories.tsx

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { css } from '@devup-ui/react'
2-
import { Meta } from '@storybook/react-vite'
2+
import { Meta, StoryObj } from '@storybook/react-vite'
3+
import { useState } from 'react'
34

45
import { Button } from './index'
56

7+
type Story = StoryObj<typeof meta>
8+
69
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
710
const meta: Meta<typeof Button> = {
811
title: 'Devfive/Button',
@@ -16,15 +19,16 @@ const meta: Meta<typeof Button> = {
1619
],
1720
}
1821

19-
export const Default = {
22+
export const Default: Story = {
2023
args: {
2124
children: 'Button Text',
2225
},
2326
}
2427

25-
export const WithIcon = {
28+
export const WithIcon: Story = {
2629
args: {
2730
children: 'Button text',
31+
disabled: true,
2832
icon: (
2933
<svg
3034
className={css({ color: '$text' })}
@@ -45,4 +49,62 @@ export const WithIcon = {
4549
},
4650
}
4751

52+
export const WithForm: Story = {
53+
args: {
54+
children: 'Button text',
55+
type: 'submit',
56+
},
57+
decorators: [
58+
(Story, { args }: { args: Story['args'] }) => {
59+
const [submitted, setSubmitted] = useState<{ text?: string }>({})
60+
const [value, setValue] = useState('')
61+
const [error, setError] = useState('')
62+
63+
return (
64+
<>
65+
<div>{submitted.text}</div>
66+
<form
67+
onSubmit={(e) => {
68+
e.preventDefault()
69+
const formData = new FormData(e.target as HTMLFormElement)
70+
const data = Object.fromEntries(formData)
71+
72+
setSubmitted({
73+
text: data.text as string,
74+
})
75+
}}
76+
>
77+
<input
78+
className={css({
79+
display: 'block',
80+
mb: '10px',
81+
})}
82+
minLength={3}
83+
name="text"
84+
onChange={(e) => {
85+
setValue(e.target.value)
86+
setError(
87+
!/[0-9]/.test(e.target.value) && e.target.value.length >= 3
88+
? 'Include one or more numbers.'
89+
: '',
90+
)
91+
}}
92+
placeholder="Include one or more numbers."
93+
required
94+
type="text"
95+
/>
96+
<Story
97+
args={{
98+
...args,
99+
disabled: value.length < 3,
100+
isError: !!error,
101+
}}
102+
/>
103+
</form>
104+
</>
105+
)
106+
},
107+
],
108+
}
109+
48110
export default meta

0 commit comments

Comments
 (0)