|
| 1 | +import { StoryObj, Meta } from "@storybook/react"; |
| 2 | +import { Input } from "../../lib/main"; |
| 3 | +import { useState } from "react"; |
| 4 | + |
| 5 | +const meta = { |
| 6 | + title: "Components/Input", |
| 7 | + component: Input, |
| 8 | + parameters: { layout: "centered" }, |
| 9 | + tags: ["autodocs"], |
| 10 | + args: { |
| 11 | + label: "Enter Password", |
| 12 | + value: "", |
| 13 | + variant: "general", |
| 14 | + message: "This is a helper message", |
| 15 | + error: false, |
| 16 | + disabled: false, |
| 17 | + }, |
| 18 | + argTypes: { |
| 19 | + leftPlaceholder: { |
| 20 | + control: { |
| 21 | + disable: true, |
| 22 | + }, |
| 23 | + }, |
| 24 | + rightPlaceholder: { |
| 25 | + control: { |
| 26 | + disable: true, |
| 27 | + }, |
| 28 | + }, |
| 29 | + value: { |
| 30 | + control: { |
| 31 | + disable: true, |
| 32 | + }, |
| 33 | + }, |
| 34 | + variant: { |
| 35 | + options: ["general", "success", "warning", "error"], |
| 36 | + control: { |
| 37 | + type: "select", |
| 38 | + }, |
| 39 | + }, |
| 40 | + message: { |
| 41 | + control: { |
| 42 | + type: "text", |
| 43 | + }, |
| 44 | + }, |
| 45 | + error: { |
| 46 | + control: { |
| 47 | + type: "boolean", |
| 48 | + }, |
| 49 | + }, |
| 50 | + }, |
| 51 | +} satisfies Meta<typeof Input>; |
| 52 | + |
| 53 | +export default meta; |
| 54 | +type Story = StoryObj<typeof meta>; |
| 55 | + |
| 56 | +export const Default: Story = { |
| 57 | + name: "Default Input", |
| 58 | + args: { |
| 59 | + label: "Enter name", |
| 60 | + value: "", |
| 61 | + message: "This is a helper message", |
| 62 | + }, |
| 63 | + render: (args) => { |
| 64 | + const [value, setValue] = useState(""); |
| 65 | + |
| 66 | + return ( |
| 67 | + <Input |
| 68 | + {...args} |
| 69 | + value={value} |
| 70 | + onChange={(e) => setValue(e.target.value)} |
| 71 | + /> |
| 72 | + ); |
| 73 | + }, |
| 74 | +}; |
| 75 | + |
| 76 | +export const Disabled: Story = { |
| 77 | + name: "Disabled Input", |
| 78 | + args: { |
| 79 | + label: "Enter name", |
| 80 | + value: "", |
| 81 | + message: "This is a helper message", |
| 82 | + disabled: true, |
| 83 | + }, |
| 84 | + render: (args) => { |
| 85 | + const [value, setValue] = useState(""); |
| 86 | + |
| 87 | + return ( |
| 88 | + <Input |
| 89 | + {...args} |
| 90 | + value={value} |
| 91 | + onChange={(e) => setValue(e.target.value)} |
| 92 | + /> |
| 93 | + ); |
| 94 | + }, |
| 95 | +}; |
| 96 | + |
| 97 | +export const Success: Story = { |
| 98 | + name: "Success Input", |
| 99 | + args: { |
| 100 | + label: "Enter name", |
| 101 | + value: "", |
| 102 | + message: "This is a helper message", |
| 103 | + variant: "success", |
| 104 | + }, |
| 105 | + render: (args) => { |
| 106 | + const [value, setValue] = useState(""); |
| 107 | + |
| 108 | + return ( |
| 109 | + <Input |
| 110 | + {...args} |
| 111 | + value={value} |
| 112 | + onChange={(e) => setValue(e.target.value)} |
| 113 | + /> |
| 114 | + ); |
| 115 | + }, |
| 116 | +}; |
| 117 | + |
| 118 | +export const Error: Story = { |
| 119 | + name: "Error Input", |
| 120 | + args: { |
| 121 | + label: "Enter name", |
| 122 | + value: "", |
| 123 | + message: "This is a helper message", |
| 124 | + variant: "error", |
| 125 | + }, |
| 126 | + render: (args) => { |
| 127 | + const [value, setValue] = useState(""); |
| 128 | + |
| 129 | + return ( |
| 130 | + <Input |
| 131 | + {...args} |
| 132 | + value={value} |
| 133 | + onChange={(e) => setValue(e.target.value)} |
| 134 | + /> |
| 135 | + ); |
| 136 | + }, |
| 137 | +}; |
| 138 | + |
| 139 | +export const Warning: Story = { |
| 140 | + name: "Error Input", |
| 141 | + args: { |
| 142 | + label: "Enter name", |
| 143 | + value: "", |
| 144 | + message: "This is a helper message", |
| 145 | + variant: "warning", |
| 146 | + }, |
| 147 | + render: (args) => { |
| 148 | + const [value, setValue] = useState(""); |
| 149 | + |
| 150 | + return ( |
| 151 | + <Input |
| 152 | + {...args} |
| 153 | + value={value} |
| 154 | + onChange={(e) => setValue(e.target.value)} |
| 155 | + /> |
| 156 | + ); |
| 157 | + }, |
| 158 | +}; |
| 159 | + |
| 160 | +export const RightPlaceholder: Story = { |
| 161 | + name: "Input with Right Placeholder", |
| 162 | + args: { |
| 163 | + label: "Enter name", |
| 164 | + value: "", |
| 165 | + message: "This is a helper message", |
| 166 | + rightPlaceholder: "USD", |
| 167 | + }, |
| 168 | + render: (args) => { |
| 169 | + const [value, setValue] = useState(""); |
| 170 | + |
| 171 | + return ( |
| 172 | + <Input |
| 173 | + {...args} |
| 174 | + value={value} |
| 175 | + onChange={(e) => setValue(e.target.value)} |
| 176 | + /> |
| 177 | + ); |
| 178 | + }, |
| 179 | +}; |
0 commit comments