Skip to content

Commit d52f029

Browse files
committed
docs: add stories to SearchInput component
1 parent 20ff158 commit d52f029

File tree

2 files changed

+165
-0
lines changed

2 files changed

+165
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@use "../theme";
2+
3+
.controlledContainer {
4+
> p {
5+
margin-top: theme.spacing(4);
6+
}
7+
}
8+
9+
.sizesContainer,
10+
.statesContainer {
11+
display: flex;
12+
flex-direction: column;
13+
gap: theme.spacing(4);
14+
}

packages/component-library/src/SearchInput/index.stories.tsx

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { Meta, StoryObj } from "@storybook/react";
2+
import { fn } from "@storybook/test";
3+
import { useState } from "react";
24

35
import { SearchInput as SearchInputComponent, SIZES } from "./index.jsx";
6+
import styles from "./index.stories.module.scss";
47

58
const meta = {
69
component: SearchInputComponent,
@@ -35,7 +38,32 @@ const meta = {
3538
category: "State",
3639
},
3740
},
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+
},
3865
},
66+
tags: ["autodocs"],
3967
} satisfies Meta<typeof SearchInputComponent>;
4068
export default meta;
4169

@@ -47,3 +75,126 @@ export const SearchInput = {
4775
isDisabled: false,
4876
},
4977
} 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

Comments
 (0)