All files / laravel-saas/resources/js/Components/molecules FormField.stories.tsx

0% Statements 0/220
100% Branches 1/1
100% Functions 1/1
0% Lines 0/220

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
import type { Meta, StoryObj } from '@storybook/react';
import { FormField } from './FormField';
import { Input } from '../ui/Input';
import { Button } from '../ui/Button';
 
const meta = {
  title: 'Molecules/FormField',
  component: FormField,
  parameters: {
    layout: 'centered',
  },
  tags: ['autodocs'],
  argTypes: {
    label: {
      control: 'text',
    },
    error: {
      control: 'text',
    },
    required: {
      control: 'boolean',
    },
  },
} satisfies Meta<typeof FormField>;
 
export default meta;
type Story = StoryObj<typeof meta>;
 
export const Default: Story = {
  args: {
    label: 'Email',
    children: <Input type="email" placeholder="Enter your email" />,
  },
};
 
export const Required: Story = {
  args: {
    label: 'Email',
    required: true,
    children: <Input type="email" placeholder="Enter your email" />,
  },
};
 
export const WithError: Story = {
  args: {
    label: 'Email',
    error: 'Please enter a valid email address',
    children: <Input type="email" placeholder="Enter your email" value="invalid-email" />,
  },
};
 
export const RequiredWithError: Story = {
  args: {
    label: 'Password',
    required: true,
    error: 'Password must be at least 8 characters long',
    children: <Input type="password" placeholder="Enter your password" value="123" />,
  },
};
 
export const TextArea: Story = {
  args: {
    label: 'Message',
    children: (
      <textarea 
        placeholder="Enter your message..." 
        className="flex min-h-[60px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
      />
    ),
  },
};
 
export const SelectField: Story = {
  args: {
    label: 'Country',
    required: true,
    children: (
      <select className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50">
        <option value="">Select a country</option>
        <option value="us">United States</option>
        <option value="ca">Canada</option>
        <option value="uk">United Kingdom</option>
        <option value="de">Germany</option>
        <option value="fr">France</option>
      </select>
    ),
  },
};
 
export const FileUpload: Story = {
  args: {
    label: 'Profile Picture',
    children: <Input type="file" accept="image/*" />,
  },
};
 
export const LoginForm: Story = {
  render: () => (
    <div className="w-full max-w-sm space-y-4">
      <div className="text-2xl font-bold text-center">Login</div>
      
      <FormField
        label="Email"
        required
      >
        <Input type="email" placeholder="Enter your email" />
      </FormField>
      
      <FormField
        label="Password"
        required
      >
        <Input type="password" placeholder="Enter your password" />
      </FormField>
      
      <Button className="w-full">Sign In</Button>
    </div>
  ),
};
 
export const SignupForm: Story = {
  render: () => (
    <div className="w-full max-w-sm space-y-4">
      <div className="text-2xl font-bold text-center">Sign Up</div>
      
      <FormField
        label="Full Name"
        required
      >
        <Input type="text" placeholder="Enter your full name" />
      </FormField>
      
      <FormField
        label="Email"
        required
      >
        <Input type="email" placeholder="Enter your email" />
      </FormField>
      
      <FormField
        label="Password"
        required
      >
        <Input type="password" placeholder="Choose a password" />
      </FormField>
      
      <FormField
        label="Confirm Password"
        required
      >
        <Input type="password" placeholder="Confirm your password" />
      </FormField>
      
      <FormField
        label="Phone Number"
      >
        <Input type="tel" placeholder="+1 (555) 000-0000" />
      </FormField>
      
      <Button className="w-full">Create Account</Button>
    </div>
  ),
};
 
export const ContactForm: Story = {
  render: () => (
    <div className="w-full max-w-md space-y-4">
      <div className="text-2xl font-bold text-center">Contact Us</div>
      
      <FormField
        label="Name"
        required
      >
        <Input type="text" placeholder="Your name" />
      </FormField>
      
      <FormField
        label="Email"
        required
      >
        <Input type="email" placeholder="Your email" />
      </FormField>
      
      <FormField
        label="Subject"
        required
      >
        <Input type="text" placeholder="Subject" />
      </FormField>
      
      <FormField
        label="Message"
        required
      >
        <textarea 
          placeholder="Your message..." 
          className="flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
        />
      </FormField>
      
      <Button className="w-full">Send Message</Button>
    </div>
  ),
};
 
export const FormWithErrors: Story = {
  render: () => (
    <div className="w-full max-w-sm space-y-4">
      <div className="text-2xl font-bold text-center">Form with Errors</div>
      
      <FormField
        label="Email"
        required
        error="Please enter a valid email address"
      >
        <Input type="email" placeholder="Enter your email" value="invalid-email" />
      </FormField>
      
      <FormField
        label="Password"
        required
        error="Password must be at least 8 characters long"
      >
        <Input type="password" placeholder="Enter your password" value="123" />
      </FormField>
      
      <FormField
        label="Confirm Password"
        required
        error="Passwords do not match"
      >
        <Input type="password" placeholder="Confirm your password" value="456" />
      </FormField>
      
      <FormField
        label="Phone Number"
        error="Please enter a valid phone number"
      >
        <Input type="tel" placeholder="+1 (555) 000-0000" value="123" />
      </FormField>
      
      <Button className="w-full">Submit</Button>
    </div>
  ),
};
 
export const FormFieldStates: Story = {
  render: () => (
    <div className="w-full max-w-sm space-y-4">
      <div className="text-lg font-semibold">Form Field States</div>
      
      <FormField
        label="Normal Field"
      >
        <Input type="text" placeholder="Normal input" />
      </FormField>
      
      <FormField
        label="Required Field"
        required
      >
        <Input type="text" placeholder="Required input" />
      </FormField>
      
      <FormField
        label="Field with Error"
        error="This field has an error"
      >
        <Input type="text" placeholder="Error input" />
      </FormField>
      
      <FormField
        label="Required Field with Error"
        required
        error="This required field has an error"
      >
        <Input type="text" placeholder="Required error input" />
      </FormField>
      
      <FormField
        label="Disabled Field"
      >
        <Input type="text" placeholder="Disabled input" disabled />
      </FormField>
    </div>
  ),
};