All files / react-base/src/components/ui input.stories.tsx

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

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                                                                                                                                                                                                                                                                 
import type { Meta, StoryObj } from "@storybook/react";
import { Input } from "./input";
import { Label } from "./label";
 
const meta = {
  title: "Design System/Input",
  component: Input,
  tags: ["autodocs"],
  parameters: {
    docs: {
      description: {
        component: "Text field primitive for forms and filters.",
      },
    },
  },
  argTypes: {
    type: {
      control: "select",
      options: ["text", "email", "password", "search", "number"],
    },
    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…",
  },
  parameters: {
    docs: {
      source: {
        code: `<Input placeholder="Enter text…" />`,
      },
    },
  },
};
 
export const Email: Story = {
  args: {
    type: "email",
    placeholder: "admin@company.com",
  },
  parameters: {
    docs: {
      source: {
        code: `<Input type="email" placeholder="admin@company.com" />`,
      },
    },
  },
};
 
export const Password: Story = {
  args: {
    type: "password",
    placeholder: "••••••••",
  },
  parameters: {
    docs: {
      source: {
        code: `<Input type="password" placeholder="••••••••" />`,
      },
    },
  },
};
 
export const Disabled: Story = {
  args: {
    placeholder: "Disabled input",
    disabled: true,
  },
  parameters: {
    docs: {
      source: {
        code: `<Input placeholder="Disabled input" disabled />`,
      },
    },
  },
};
 
export const WithLabel: Story = {
  parameters: {
    docs: {
      source: {
        code: `import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
 
<div className="grid w-80 gap-2">
  <Label htmlFor="name">Full name</Label>
  <Input id="name" placeholder="Jane Admin" />
</div>`,
      },
    },
  },
  render: () => (
    <div className="grid w-80 gap-2">
      <Label htmlFor="story-input-name">Full name</Label>
      <Input id="story-input-name" placeholder="Jane Admin" />
    </div>
  ),
};
 
export const Invalid: Story = {
  parameters: {
    docs: {
      source: {
        code: `import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
 
<div className="grid w-80 gap-2">
  <Label htmlFor="email">Email</Label>
  <Input id="email" type="email" placeholder="admin@company.com" aria-invalid />
  <p className="text-sm text-destructive">Enter a valid email address.</p>
</div>`,
      },
    },
  },
  render: () => (
    <div className="grid w-80 gap-2">
      <Label htmlFor="story-input-email">Email</Label>
      <Input id="story-input-email" type="email" placeholder="admin@company.com" aria-invalid />
      <p className="text-sm text-destructive">Enter a valid email address.</p>
    </div>
  ),
};