|
| 1 | +import type { Meta, StoryObj } from "@storybook/react"; |
| 2 | +import type { ComponentProps } from "react"; |
| 3 | +import { useState } from "react"; |
| 4 | +import { PhoneInput, type PhoneInputProps } from "./phone-input"; |
| 5 | + |
| 6 | +const meta: Meta<typeof PhoneInput> = { |
| 7 | + title: "General/PhoneInput", |
| 8 | + component: PhoneInput, |
| 9 | + tags: ["autodocs"], |
| 10 | + parameters: { |
| 11 | + layout: "centered", |
| 12 | + }, |
| 13 | + decorators: [ |
| 14 | + (Story: React.ComponentType) => ( |
| 15 | + <div className="w-[350px]"> |
| 16 | + <Story /> |
| 17 | + </div> |
| 18 | + ), |
| 19 | + ], |
| 20 | +}; |
| 21 | + |
| 22 | +export default meta; |
| 23 | + |
| 24 | +type Story = StoryObj<typeof PhoneInput>; |
| 25 | + |
| 26 | +// Interactive wrapper component |
| 27 | +function PhoneInputDemo(props: ComponentProps<typeof PhoneInput>): React.JSX.Element { |
| 28 | + const [value, setValue] = useState(props.value ?? ""); |
| 29 | + |
| 30 | + return ( |
| 31 | + <div className="space-y-4"> |
| 32 | + <PhoneInput {...props} value={value} onChange={setValue} /> |
| 33 | + <div className="text-muted-foreground text-sm"> |
| 34 | + <strong>Value:</strong> {value || "(empty)"} |
| 35 | + </div> |
| 36 | + </div> |
| 37 | + ); |
| 38 | +} |
| 39 | + |
| 40 | +export const Default: Story = { |
| 41 | + render: (args: PhoneInputProps) => <PhoneInputDemo {...args} />, |
| 42 | + args: { |
| 43 | + placeholder: "Enter phone number", |
| 44 | + }, |
| 45 | +}; |
| 46 | + |
| 47 | +export const WithValue: Story = { |
| 48 | + render: (args: PhoneInputProps) => <PhoneInputDemo {...args} />, |
| 49 | + args: { |
| 50 | + value: "+34 612 345 678", |
| 51 | + placeholder: "Enter phone number", |
| 52 | + }, |
| 53 | +}; |
| 54 | + |
| 55 | +export const WithUSNumber: Story = { |
| 56 | + render: (args: PhoneInputProps) => <PhoneInputDemo {...args} />, |
| 57 | + args: { |
| 58 | + value: "+1 555 123 4567", |
| 59 | + placeholder: "Enter phone number", |
| 60 | + }, |
| 61 | +}; |
| 62 | + |
| 63 | +export const Required: Story = { |
| 64 | + render: (args: PhoneInputProps) => <PhoneInputDemo {...args} />, |
| 65 | + args: { |
| 66 | + placeholder: "Enter phone number", |
| 67 | + required: true, |
| 68 | + }, |
| 69 | +}; |
| 70 | + |
| 71 | +export const Disabled: Story = { |
| 72 | + render: (args: PhoneInputProps) => <PhoneInputDemo {...args} />, |
| 73 | + args: { |
| 74 | + value: "+44 20 7123 4567", |
| 75 | + placeholder: "Enter phone number", |
| 76 | + disabled: true, |
| 77 | + }, |
| 78 | +}; |
| 79 | + |
| 80 | +export const WithError: Story = { |
| 81 | + render: (args: PhoneInputProps) => <PhoneInputDemo {...args} />, |
| 82 | + args: { |
| 83 | + value: "+1 555", |
| 84 | + placeholder: "Enter phone number", |
| 85 | + errorMessage: "Please enter a valid phone number", |
| 86 | + }, |
| 87 | +}; |
| 88 | + |
| 89 | +export const RTLDirection: Story = { |
| 90 | + render: (args: PhoneInputProps) => <PhoneInputDemo {...args} />, |
| 91 | + args: { |
| 92 | + value: "+966 50 123 4567", |
| 93 | + placeholder: "أدخل رقم الهاتف", |
| 94 | + dir: "rtl", |
| 95 | + }, |
| 96 | +}; |
0 commit comments