All files / laravel-saas/resources/js/Components/ui Input.stories.tsx

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

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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
import type { Meta, StoryObj } from '@storybook/react';
import { Input } from './Input';
import { Label } from './Label';
 
const meta = {
  title: 'UI/Input',
  component: Input,
  parameters: {
    layout: 'centered',
  },
  tags: ['autodocs'],
  argTypes: {
    type: {
      control: 'select',
      options: ['text', 'email', 'password', 'number', 'tel', 'url', 'search'],
    },
    error: {
      control: 'boolean',
    },
    disabled: {
      control: 'boolean',
    },
    placeholder: {
      control: 'text',
    },
  },
} satisfies Meta<typeof Input>;
 
export default meta;
type Story = StoryObj<typeof meta>;
 
export const Default: Story = {
  args: {
    placeholder: 'Enter text...',
  },
};
 
export const WithValue: Story = {
  args: {
    value: 'Sample input value',
    placeholder: 'Enter text...',
  },
};
 
export const Email: Story = {
  args: {
    type: 'email',
    placeholder: 'Enter your email...',
  },
};
 
export const Password: Story = {
  args: {
    type: 'password',
    placeholder: 'Enter your password...',
  },
};
 
export const Number: Story = {
  args: {
    type: 'number',
    placeholder: 'Enter a number...',
  },
};
 
export const Search: Story = {
  args: {
    type: 'search',
    placeholder: 'Search...',
  },
};
 
export const Tel: Story = {
  args: {
    type: 'tel',
    placeholder: 'Enter phone number...',
  },
};
 
export const URL: Story = {
  args: {
    type: 'url',
    placeholder: 'https://example.com',
  },
};
 
export const WithError: Story = {
  args: {
    error: true,
    placeholder: 'Enter text...',
    value: 'Invalid input',
  },
};
 
export const Disabled: Story = {
  args: {
    disabled: true,
    placeholder: 'Disabled input',
    value: 'Cannot edit this',
  },
};
 
export const WithLabel: Story = {
  render: () => (
    <div className="grid w-full max-w-sm items-center gap-1.5">
      <Label htmlFor="email">Email</Label>
      <Input type="email" id="email" placeholder="Email" />
    </div>
  ),
};
 
export const WithLabelAndError: Story = {
  render: () => (
    <div className="grid w-full max-w-sm items-center gap-1.5">
      <Label htmlFor="email-error">Email</Label>
      <Input 
        type="email" 
        id="email-error" 
        placeholder="Email" 
        error={true}
        value="invalid-email"
      />
      <p className="text-sm text-destructive">Please enter a valid email address.</p>
    </div>
  ),
};
 
export const FileInput: Story = {
  render: () => (
    <div className="grid w-full max-w-sm items-center gap-1.5">
      <Label htmlFor="picture">Picture</Label>
      <Input id="picture" type="file" />
    </div>
  ),
};
 
export const FormExample: Story = {
  render: () => (
    <div className="w-full max-w-sm space-y-4">
      <div className="grid w-full items-center gap-1.5">
        <Label htmlFor="name">Name</Label>
        <Input type="text" id="name" placeholder="John Doe" />
      </div>
      
      <div className="grid w-full items-center gap-1.5">
        <Label htmlFor="email-form">Email</Label>
        <Input type="email" id="email-form" placeholder="john@example.com" />
      </div>
      
      <div className="grid w-full items-center gap-1.5">
        <Label htmlFor="password-form">Password</Label>
        <Input type="password" id="password-form" placeholder="Password" />
      </div>
      
      <div className="grid w-full items-center gap-1.5">
        <Label htmlFor="phone">Phone</Label>
        <Input type="tel" id="phone" placeholder="+1 (555) 000-0000" />
      </div>
      
      <div className="grid w-full items-center gap-1.5">
        <Label htmlFor="website">Website</Label>
        <Input type="url" id="website" placeholder="https://example.com" />
      </div>
    </div>
  ),
};
 
export const AllInputTypes: Story = {
  render: () => (
    <div className="w-full max-w-lg space-y-4">
      <div className="text-lg font-semibold">Input Types</div>
      <div className="grid gap-4">
        <div className="grid w-full items-center gap-1.5">
          <Label>Text Input</Label>
          <Input type="text" placeholder="Text input" />
        </div>
        
        <div className="grid w-full items-center gap-1.5">
          <Label>Email Input</Label>
          <Input type="email" placeholder="Email input" />
        </div>
        
        <div className="grid w-full items-center gap-1.5">
          <Label>Password Input</Label>
          <Input type="password" placeholder="Password input" />
        </div>
        
        <div className="grid w-full items-center gap-1.5">
          <Label>Number Input</Label>
          <Input type="number" placeholder="Number input" />
        </div>
        
        <div className="grid w-full items-center gap-1.5">
          <Label>Search Input</Label>
          <Input type="search" placeholder="Search input" />
        </div>
        
        <div className="grid w-full items-center gap-1.5">
          <Label>Tel Input</Label>
          <Input type="tel" placeholder="Tel input" />
        </div>
        
        <div className="grid w-full items-center gap-1.5">
          <Label>URL Input</Label>
          <Input type="url" placeholder="URL input" />
        </div>
        
        <div className="grid w-full items-center gap-1.5">
          <Label>File Input</Label>
          <Input type="file" />
        </div>
      </div>
    </div>
  ),
};
 
export const InputStates: Story = {
  render: () => (
    <div className="w-full max-w-sm space-y-4">
      <div className="text-lg font-semibold">Input States</div>
      <div className="grid gap-4">
        <div className="grid w-full items-center gap-1.5">
          <Label>Normal</Label>
          <Input placeholder="Normal input" />
        </div>
        
        <div className="grid w-full items-center gap-1.5">
          <Label>With Value</Label>
          <Input value="Input with value" />
        </div>
        
        <div className="grid w-full items-center gap-1.5">
          <Label>Error State</Label>
          <Input error={true} placeholder="Error input" />
        </div>
        
        <div className="grid w-full items-center gap-1.5">
          <Label>Disabled</Label>
          <Input disabled placeholder="Disabled input" />
        </div>
        
        <div className="grid w-full items-center gap-1.5">
          <Label>Disabled with Value</Label>
          <Input disabled value="Disabled with value" />
        </div>
      </div>
    </div>
  ),
};