|
| 1 | +import type { Meta, StoryObj } from "@storybook/react-vite"; |
| 2 | +import { useState } from "react"; |
| 3 | + |
| 4 | +import { Checkbox, type CheckboxProps } from "./checkbox"; |
| 5 | + |
| 6 | +const meta: Meta<CheckboxProps> = { |
| 7 | + title: "Components/Checkbox", |
| 8 | + component: Checkbox, |
| 9 | + parameters: { |
| 10 | + layout: "centered", |
| 11 | + docs: { |
| 12 | + description: { |
| 13 | + component: ` |
| 14 | +# Checkbox Component |
| 15 | +
|
| 16 | +A simple checkbox component built with @ark-ui/react and styled with PandaCSS. |
| 17 | +No refraction effects - just clean, accessible checkboxes. |
| 18 | +
|
| 19 | +## States |
| 20 | +
|
| 21 | +- **Unchecked**: Default empty state |
| 22 | +- **Checked**: Selected state with checkmark |
| 23 | +- **Indeterminate**: Partial selection state with minus icon |
| 24 | +- **Disabled**: Non-interactive state |
| 25 | +
|
| 26 | +## Interactions |
| 27 | +
|
| 28 | +- **Hover**: Slightly darker border and background |
| 29 | +- **Focus**: Blue outline ring |
| 30 | +- **Disabled**: Reduced opacity and muted colors |
| 31 | + `, |
| 32 | + }, |
| 33 | + }, |
| 34 | + }, |
| 35 | + argTypes: { |
| 36 | + disabled: { |
| 37 | + control: "boolean", |
| 38 | + description: "Whether the checkbox is disabled", |
| 39 | + }, |
| 40 | + label: { |
| 41 | + control: "text", |
| 42 | + description: "Label text for the checkbox", |
| 43 | + }, |
| 44 | + }, |
| 45 | + args: { |
| 46 | + disabled: false, |
| 47 | + label: "Label", |
| 48 | + }, |
| 49 | +}; |
| 50 | + |
| 51 | +export default meta; |
| 52 | + |
| 53 | +type Story = StoryObj<typeof meta>; |
| 54 | + |
| 55 | +/** |
| 56 | + * Default checkbox in unchecked state |
| 57 | + */ |
| 58 | +export const Default: Story = { |
| 59 | + args: { |
| 60 | + checked: false, |
| 61 | + }, |
| 62 | +}; |
| 63 | + |
| 64 | +/** |
| 65 | + * Checkbox in checked state |
| 66 | + */ |
| 67 | +export const Checked: Story = { |
| 68 | + args: { |
| 69 | + checked: true, |
| 70 | + }, |
| 71 | +}; |
| 72 | + |
| 73 | +/** |
| 74 | + * Checkbox in indeterminate state (partial selection) |
| 75 | + */ |
| 76 | +export const Indeterminate: Story = { |
| 77 | + args: { |
| 78 | + checked: "indeterminate", |
| 79 | + }, |
| 80 | +}; |
| 81 | + |
| 82 | +/** |
| 83 | + * Disabled checkbox states |
| 84 | + */ |
| 85 | +export const Disabled: Story = { |
| 86 | + render: () => ( |
| 87 | + <div style={{ display: "flex", flexDirection: "column", gap: "16px" }}> |
| 88 | + <Checkbox label="Unchecked Disabled" disabled defaultChecked={false} /> |
| 89 | + <Checkbox label="Checked Disabled" disabled defaultChecked /> |
| 90 | + <Checkbox |
| 91 | + label="Indeterminate Disabled" |
| 92 | + disabled |
| 93 | + defaultChecked="indeterminate" |
| 94 | + /> |
| 95 | + </div> |
| 96 | + ), |
| 97 | +}; |
| 98 | + |
| 99 | +/** |
| 100 | + * Interactive checkbox with controlled state |
| 101 | + */ |
| 102 | +export const Interactive: Story = { |
| 103 | + render: () => { |
| 104 | + const [checked, setChecked] = useState<boolean | "indeterminate">(false); |
| 105 | + |
| 106 | + return ( |
| 107 | + <div style={{ display: "flex", flexDirection: "column", gap: "16px" }}> |
| 108 | + <Checkbox |
| 109 | + label="Interactive Checkbox" |
| 110 | + checked={checked} |
| 111 | + onCheckedChange={setChecked} |
| 112 | + /> |
| 113 | + <div style={{ fontSize: "14px", color: "#666" }}> |
| 114 | + Current state:{" "} |
| 115 | + <strong> |
| 116 | + {checked === "indeterminate" |
| 117 | + ? "Indeterminate" |
| 118 | + : checked |
| 119 | + ? "Checked" |
| 120 | + : "Unchecked"} |
| 121 | + </strong> |
| 122 | + </div> |
| 123 | + <div style={{ display: "flex", gap: "8px" }}> |
| 124 | + <button |
| 125 | + type="button" |
| 126 | + onClick={() => setChecked(false)} |
| 127 | + style={{ |
| 128 | + padding: "4px 12px", |
| 129 | + borderRadius: "4px", |
| 130 | + border: "1px solid #ccc", |
| 131 | + background: "white", |
| 132 | + cursor: "pointer", |
| 133 | + }} |
| 134 | + > |
| 135 | + Uncheck |
| 136 | + </button> |
| 137 | + <button |
| 138 | + type="button" |
| 139 | + onClick={() => setChecked(true)} |
| 140 | + style={{ |
| 141 | + padding: "4px 12px", |
| 142 | + borderRadius: "4px", |
| 143 | + border: "1px solid #ccc", |
| 144 | + background: "white", |
| 145 | + cursor: "pointer", |
| 146 | + }} |
| 147 | + > |
| 148 | + Check |
| 149 | + </button> |
| 150 | + <button |
| 151 | + type="button" |
| 152 | + onClick={() => setChecked("indeterminate")} |
| 153 | + style={{ |
| 154 | + padding: "4px 12px", |
| 155 | + borderRadius: "4px", |
| 156 | + border: "1px solid #ccc", |
| 157 | + background: "white", |
| 158 | + cursor: "pointer", |
| 159 | + }} |
| 160 | + > |
| 161 | + Set Indeterminate |
| 162 | + </button> |
| 163 | + </div> |
| 164 | + </div> |
| 165 | + ); |
| 166 | + }, |
| 167 | +}; |
0 commit comments