import type { Meta, StoryObj } from '@storybook/react'; import { expect, userEvent, within } from 'storybook/test'; import { Input } from './input'; import { Search, Mail, Lock } from 'lucide-react'; import React from 'react'; import { Label } from '../label'; const meta: Meta = { title: 'UI/Input', component: Input, render: args => , argTypes: { type: { control: 'select', options: ['text', 'email', 'password', 'number', 'search', 'tel', 'url'], }, size: { control: 'select', options: ['sm', 'md', 'lg'], description: 'Size variant — matches the form sizing scale.', }, disabled: { control: 'boolean', }, }, }; export default meta; type Story = StoryObj; export const Default: Story = { args: { placeholder: 'Standard Input', }, }; export const Email: Story = { args: { type: 'email', placeholder: 'you@example.com', }, }; export const Password: Story = { args: { type: 'password', placeholder: '••••••••', }, }; export const Disabled: Story = { args: { disabled: true, placeholder: 'Disabled Input', value: 'Content is fixed', }, }; export const WithLabel: Story = { render: args => (
), }; export const WithHelperText: Story = { render: args => (

We'll never share your email with anyone.

), }; export const WithSearchIcon: Story = { render: args => { const iconSizeClasses = { sm: 'left-2.5 top-2 size-3.5', md: 'left-2.5 top-3 size-4', lg: 'left-3 top-4 size-5', }; const paddingClasses = { sm: 'pl-8', md: 'pl-9', lg: 'pl-11', }; return (
); }, }; /** * Size comparison: sm, md (default), lg. */ export const Sizes: Story = { render: () => (
), }; export const Typing: Story = { args: { placeholder: 'Type here...' }, play: async ({ canvasElement }) => { const canvas = within(canvasElement); const input = canvas.getByRole('textbox'); await userEvent.click(input); await expect(input).toHaveFocus(); await userEvent.type(input, 'Hello Xertica'); await expect(input).toHaveValue('Hello Xertica'); await userEvent.clear(input); await expect(input).toHaveValue(''); }, }; export const DisabledInteraction: Story = { args: { disabled: true, placeholder: 'Cannot type here' }, play: async ({ canvasElement }) => { const canvas = within(canvasElement); const input = canvas.getByRole('textbox'); await expect(input).toBeDisabled(); }, };