1
1
import type { Meta , StoryObj } from "@storybook/react" ;
2
+ import { fn } from "@storybook/test" ;
3
+ import { useState } from "react" ;
2
4
3
5
import { SearchInput as SearchInputComponent , SIZES } from "./index.jsx" ;
6
+ import styles from "./index.stories.module.scss" ;
4
7
5
8
const meta = {
6
9
component : SearchInputComponent ,
@@ -35,7 +38,32 @@ const meta = {
35
38
category : "State" ,
36
39
} ,
37
40
} ,
41
+ placeholder : {
42
+ control : "text" ,
43
+ table : {
44
+ category : "Content" ,
45
+ } ,
46
+ } ,
47
+ defaultValue : {
48
+ control : "text" ,
49
+ table : {
50
+ category : "Content" ,
51
+ } ,
52
+ } ,
53
+ onSubmit : {
54
+ action : "submitted" ,
55
+ table : {
56
+ category : "Events" ,
57
+ } ,
58
+ } ,
59
+ onChange : {
60
+ action : "changed" ,
61
+ table : {
62
+ category : "Events" ,
63
+ } ,
64
+ } ,
38
65
} ,
66
+ tags : [ "autodocs" ] ,
39
67
} satisfies Meta < typeof SearchInputComponent > ;
40
68
export default meta ;
41
69
@@ -47,3 +75,126 @@ export const SearchInput = {
47
75
isDisabled : false ,
48
76
} ,
49
77
} satisfies StoryObj < typeof SearchInputComponent > ;
78
+
79
+ type Story = StoryObj < typeof SearchInputComponent > ;
80
+
81
+ // Size variations
82
+ export const ExtraSmall : Story = {
83
+ args : {
84
+ size : "xs" ,
85
+ placeholder : "Search..." ,
86
+ } ,
87
+ } ;
88
+
89
+ export const Small : Story = {
90
+ args : {
91
+ size : "sm" ,
92
+ placeholder : "Search..." ,
93
+ } ,
94
+ } ;
95
+
96
+ export const Medium : Story = {
97
+ args : {
98
+ size : "md" ,
99
+ placeholder : "Search..." ,
100
+ } ,
101
+ } ;
102
+
103
+ export const Large : Story = {
104
+ args : {
105
+ size : "lg" ,
106
+ placeholder : "Search..." ,
107
+ } ,
108
+ } ;
109
+
110
+ // State variations
111
+ export const WithValue : Story = {
112
+ args : {
113
+ size : "md" ,
114
+ defaultValue : "pyth network" ,
115
+ } ,
116
+ } ;
117
+
118
+ export const Pending : Story = {
119
+ args : {
120
+ size : "md" ,
121
+ isPending : true ,
122
+ defaultValue : "searching..." ,
123
+ } ,
124
+ } ;
125
+
126
+ export const Disabled : Story = {
127
+ args : {
128
+ size : "md" ,
129
+ isDisabled : true ,
130
+ placeholder : "Search disabled" ,
131
+ } ,
132
+ } ;
133
+
134
+ // Width variations
135
+ export const FixedWidth : Story = {
136
+ args : {
137
+ size : "md" ,
138
+ width : 100 ,
139
+ placeholder : "Fixed width" ,
140
+ } ,
141
+ } ;
142
+
143
+ export const FluidWidth : Story = {
144
+ args : {
145
+ size : "md" ,
146
+ placeholder : "Fluid width (default)" ,
147
+ } ,
148
+ } ;
149
+
150
+ // Functional examples
151
+ export const WithSubmitHandler : Story = {
152
+ args : {
153
+ size : "md" ,
154
+ placeholder : "Press Enter to search" ,
155
+ onSubmit : fn ( ) ,
156
+ } ,
157
+ } ;
158
+
159
+ export const ControlledInput : Story = {
160
+ render : ( ) => {
161
+ const [ value , setValue ] = useState ( "" ) ;
162
+
163
+ return (
164
+ < div className = { styles . controlledContainer } >
165
+ < SearchInputComponent
166
+ value = { value }
167
+ onChange = { setValue }
168
+ onSubmit = { ( ) => alert ( `Searching for: ${ value } ` ) }
169
+ placeholder = "Controlled search input"
170
+ />
171
+ < p > Current value: { value } </ p >
172
+ </ div >
173
+ ) ;
174
+ } ,
175
+ } ;
176
+
177
+ export const AllSizes : Story = {
178
+ render : ( ) => (
179
+ < div className = { styles . sizesContainer } >
180
+ { SIZES . map ( ( size ) => (
181
+ < SearchInputComponent
182
+ key = { size }
183
+ size = { size }
184
+ placeholder = { `Size: ${ size } ` }
185
+ />
186
+ ) ) }
187
+ </ div >
188
+ ) ,
189
+ } ;
190
+
191
+ export const AllStates : Story = {
192
+ render : ( ) => (
193
+ < div className = { styles . statesContainer } >
194
+ < SearchInputComponent placeholder = "Default state" />
195
+ < SearchInputComponent defaultValue = "With value" />
196
+ < SearchInputComponent isPending defaultValue = "Loading results..." />
197
+ < SearchInputComponent isDisabled placeholder = "Disabled" />
198
+ </ div >
199
+ ) ,
200
+ } ;
0 commit comments