@bykhd/lab-ds 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,54 @@
1
1
  {
2
2
  "name": "@bykhd/lab-ds",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Daidai design system: React components on Base UI + Tailwind CSS v4.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": [
8
+ "**/*.css"
9
+ ],
10
+ "files": [
11
+ "dist",
12
+ "src/components/*/*.md",
13
+ "README.md"
14
+ ],
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ },
23
+ "./styles.css": "./dist/styles.css"
24
+ },
25
+ "module": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "scripts": {
28
+ "build": "tsup",
29
+ "typecheck": "tsc --noEmit"
30
+ },
31
+ "peerDependencies": {
32
+ "react": "^19.0.0",
33
+ "react-dom": "^19.0.0"
34
+ },
35
+ "dependencies": {
36
+ "@base-ui/react": "^1.9.0",
37
+ "@tabler/icons-react": "^3.50.0",
38
+ "cn": "^0.5.2",
39
+ "input-otp": "^1.5.0",
40
+ "tw-animate-css": "^1.4.0"
41
+ },
42
+ "devDependencies": {
43
+ "@tailwindcss/postcss": "^4",
44
+ "@types/react": "^19",
45
+ "@types/react-dom": "^19",
46
+ "postcss": "^8",
47
+ "react": "19.3.1",
48
+ "react-dom": "19.3.1",
49
+ "shadcn": "^4.23.0",
50
+ "tailwindcss": "^4",
51
+ "tsup": "^8",
52
+ "typescript": "^5"
53
+ }
54
+ }
@@ -0,0 +1,82 @@
1
+ # Alert
2
+
3
+ Shows a short, important message inline on the page, such as a status, a warning, or an error.
4
+
5
+ ## When to use
6
+
7
+ - To tell the user something about the current page or section that they should notice right away: a failed save, a problem with their account, a requirement before they can continue.
8
+ - To show an error that affects a whole form or section rather than one field.
9
+ - When the message should stay visible until the situation changes, not disappear on its own.
10
+
11
+ ## When not to use
12
+
13
+ - For an error on a single input. Show it next to that field instead (see `Field`).
14
+ - For a message that needs a decision before the user can go on. Use `Dialog`.
15
+ - For a short label or status on an item, like "New" or "Paid". Use `Badge`.
16
+ - For routine information that isn't urgent. Alert is announced to screen readers as soon as it appears, so too many of them become noise.
17
+ - TODO: confirm whether lab-ds will have a toast for brief, temporary confirmations ("Saved"). There isn't one yet.
18
+
19
+ ## Parts
20
+
21
+ An Alert is built from these parts. Only the container is required.
22
+
23
+ | Part | What it is |
24
+ | --- | --- |
25
+ | `Alert` | The container. Holds everything else. |
26
+ | `AlertTitle` | One short line saying what happened. Medium weight. |
27
+ | `AlertDescription` | Supporting text: detail, cause, or what to do next. Can hold more than one paragraph. Links inside it are underlined. |
28
+ | `AlertAction` | A spot in the top-right corner for an action, such as a `Button`. The text moves over to make room for it. |
29
+ | Icon (optional) | Place an icon as the first item inside `Alert`. It sits in its own column on the left, at 16px, in the same color as the text. |
30
+
31
+ ## Props and variants
32
+
33
+ `Alert` has one prop of its own:
34
+
35
+ | Prop | Values | Default |
36
+ | --- | --- | --- |
37
+ | `variant` | `default`, `destructive` | `default` |
38
+
39
+ | `variant` | Look | Use for |
40
+ | --- | --- | --- |
41
+ | `default` | Card-colored background, regular text | Neutral or informational messages |
42
+ | `destructive` | Light red background, red border, red text | Errors and anything that went wrong or can cause loss |
43
+
44
+ There are no `success`, `warning`, or `info` variants, and no sizes. TODO: decide whether warning/success variants are needed; tokens for them would come from `theme.css`.
45
+
46
+ Every part also accepts the normal props of a `<div>`, such as `id` and `className`.
47
+
48
+ ## Tokens used
49
+
50
+ | Token | Where |
51
+ | --- | --- |
52
+ | `--color-base-foreground-card` | `default` background |
53
+ | `--color-on-base-content-high` | `default` text and title; link hover color |
54
+ | `--color-on-base-content-medium` | Description text in the `default` variant |
55
+ | `--color-danger-foreground-subtle` | `destructive` background |
56
+ | `--color-danger-border-default` | `destructive` border |
57
+ | `--color-danger-content-default` | `destructive` text, title, and description |
58
+ | `--radius-lg` (0.75rem) | Corner radius |
59
+
60
+ All color tokens have dark-mode values in `theme.css` and switch automatically.
61
+
62
+ The `default` variant's border is the global default border color, `--color-on-base-border-default`.
63
+
64
+ ## Example
65
+
66
+ From the `WithAction` story: an icon, a title, a description, and a small outline `Button` in the action spot.
67
+
68
+ ```tsx
69
+ import { IconInfoCircle } from "@tabler/icons-react"
70
+ import { Alert, AlertAction, AlertDescription, AlertTitle, Button } from "@bykhd/lab-ds"
71
+
72
+ <Alert>
73
+ <IconInfoCircle />
74
+ <AlertTitle>A new version is available</AlertTitle>
75
+ <AlertDescription>Reload to get the latest changes.</AlertDescription>
76
+ <AlertAction>
77
+ <Button size="sm" variant="outline">Reload</Button>
78
+ </AlertAction>
79
+ </Alert>
80
+ ```
81
+
82
+ The stories also show `Default`, `Destructive`, `WithIcon`, and `TitleOnly`.
@@ -0,0 +1,77 @@
1
+ # Badge
2
+
3
+ A small, non-interactive label that shows the status or category of an item, such as "Paid", "Draft", or "New".
4
+
5
+ ## When to use
6
+
7
+ - To show a status or category next to an item in a list, table, card, or heading.
8
+ - To mark something as new, beta, or changed.
9
+ - When the label is one or two words.
10
+
11
+ ## When not to use
12
+
13
+ - For a message about the page or a section. Use `Alert`.
14
+ - For an action. Use `Button`. A Badge looks like a label, so people won't expect to click it.
15
+ - For long text or full sentences. The Badge never wraps.
16
+ - As the only way to show a status. Color alone isn't enough; the word inside the Badge must say it.
17
+ - TODO: confirm whether badges for counts (e.g. "3" unread) are wanted. There is no count or dot style.
18
+
19
+ ## Props and variants
20
+
21
+ | Prop | Values | Default |
22
+ | --- | --- | --- |
23
+ | `variant` | `default`, `secondary`, `destructive`, `outline`, `ghost`, `link` | `default` |
24
+
25
+ | `variant` | Look | Use for |
26
+ | --- | --- | --- |
27
+ | `default` | Solid dark fill, white text | The most important status on the screen |
28
+ | `secondary` | Light orange fill, orange text | Highlighted or positive statuses ("Paid", "New") |
29
+ | `destructive` | Light red fill, red text | Errors and problems ("Overdue", "Failed") |
30
+ | `outline` | Border only, regular text | Neutral statuses ("Draft") |
31
+ | `ghost` | No fill or border until hovered | Low-emphasis labels in dense UI |
32
+ | `link` | Orange text, underline on hover | A label that is also a link |
33
+
34
+ TODO: there is no `success` or `warning` variant; confirm which variant to use for those statuses.
35
+
36
+ There is one size: 20px tall, extra-small medium-weight text, fully rounded.
37
+
38
+ An icon can sit before or after the text. It is shown at 12px.
39
+
40
+ ## Tokens used
41
+
42
+ | Token | Where |
43
+ | --- | --- |
44
+ | `--color-primary-foreground-default` / `-hover` | `default` fill (hover only when it's a link) |
45
+ | `--color-on-primary-content-high` | `default` text |
46
+ | `--color-secondary-foreground-subtle` / `-subtle-hover` | `secondary` fill |
47
+ | `--color-secondary-content-default` | `secondary` text |
48
+ | `--color-danger-foreground-subtle` / `-subtle-hover` | `destructive` fill |
49
+ | `--color-danger-content-default` | `destructive` text |
50
+ | `--color-on-base-border-default` | `outline` border |
51
+ | `--color-on-base-content-high` | `outline` and `ghost` text |
52
+ | `--color-base-foreground-action-hover` | `outline` hover fill (links only) |
53
+ | `--color-base-foreground-inset` | `ghost` hover fill |
54
+ | `--color-on-cta-content-tertiary-default` | `link` text |
55
+ | `--color-primary-border-strong` | Focus ring |
56
+ | `--color-danger-border-strong` | Invalid border and ring |
57
+ | `--radius-rounded` | Pill shape |
58
+
59
+ All color tokens have dark-mode values and switch automatically.
60
+
61
+ ## Example
62
+
63
+ From the `WithIcon` story:
64
+
65
+ ```tsx
66
+ import { IconCheck } from "@tabler/icons-react"
67
+ import { Badge } from "@bykhd/lab-ds"
68
+
69
+ <Badge variant="secondary">
70
+ <IconCheck data-icon="inline-start" />
71
+ Paid
72
+ </Badge>
73
+ <Badge variant="destructive">Overdue</Badge>
74
+ <Badge variant="outline">Draft</Badge>
75
+ ```
76
+
77
+ The stories also show `Default` and `Variants`.
@@ -0,0 +1,126 @@
1
+ # Button
2
+
3
+ Triggers an action, such as submitting a form, opening a dialog, saving, or deleting.
4
+
5
+ ## When to use
6
+
7
+ - For any action on the current page: "Save changes", "Create project", "Delete project…".
8
+ - To submit a form or confirm a dialog.
9
+ - To open a dialog or menu.
10
+
11
+ ## When not to use
12
+
13
+ - To go to another page. Use a link, styled as a button if it needs to look like one.
14
+ - For a status or label that does nothing when clicked. Use `Badge`.
15
+ - For an on/off choice. Use `Checkbox`.
16
+ - Inside running text when the action should read like a link. Use the `link` variant, or a real link if it navigates.
17
+
18
+ ## Rules
19
+
20
+ 1. **One `default` (primary) Button per view or section.** Everything else is `secondary`, `outline`, or `ghost`.
21
+ 2. **Pick the variant by importance, not by color.** See the variant table below.
22
+ 3. **Destructive actions:** `danger` for the main action that confirms something irreversible, `variant="destructive"` for a less prominent destructive action.
23
+ 4. **`danger` only works with `variant="default"`.** It has no effect on any other variant.
24
+ 5. **Use `sm`, `default`, or `lg`.** `xs` exists for dense UI but is outside the Figma scale.
25
+ 6. **Icon-only Buttons need an `aria-label`** that says what they do.
26
+ 7. **Labels are verbs** that say what happens: "Save changes", "Delete project", not "OK" or "Yes".
27
+ 8. **Use the same verb in the trigger and the confirm Button:** "Delete project…" opens a dialog whose confirm Button says "Delete project".
28
+ 9. **Sentence case, 1–3 words, no trailing punctuation.** Use "…" only when the Button opens a step that asks for more input or confirmation. Labels never wrap.
29
+ 10. **Primary action last** (on the right) in dialogs and forms: Cancel, then Save.
30
+ 11. **Buttons in the same row share a size**, and match the size of inputs beside them.
31
+ 12. **Don't change colors, heights, or corners per Button.** If no variant fits, change the tokens or ask for a new variant.
32
+
33
+ ## Props and variants
34
+
35
+ | Prop | Values | Default |
36
+ | --- | --- | --- |
37
+ | `variant` | `default`, `secondary`, `outline`, `ghost`, `destructive`, `link` | `default` |
38
+ | `size` | `xs`, `sm`, `default`, `lg`, `icon-xs`, `icon-sm`, `icon`, `icon-lg` | `default` |
39
+ | `danger` | `true`, `false` | `false` |
40
+ | `disabled` | `true`, `false` | `false` |
41
+
42
+ ### Variants
43
+
44
+ | `variant` | Emphasis | Use for | Example | Figma name |
45
+ | --- | --- | --- | --- | --- |
46
+ | `default` | Highest | The main action of a view, form, or dialog. One per section. | "Save changes" | Primary |
47
+ | `secondary` | High | An important action next to the primary, or the main action where a solid primary would be too loud. | "Save draft" | Secondary |
48
+ | `outline` | Medium | Neutral actions; Cancel or Back next to a primary. | "Cancel", "Export" | Default |
49
+ | `ghost` | Low | Toolbars, table rows, repeated actions, icon buttons where a border adds noise. | Row "Edit" icon | Ghost |
50
+ | `destructive` | Medium | A destructive action that isn't the main focus, or that starts a destructive flow. | "Delete project…" in settings | Secondary Danger |
51
+ | `link` | Lowest | An inline action that should read like a link. | "Resend code" | Tertiary |
52
+ | `default` + `danger` | Highest | The confirm Button that commits an irreversible change, usually in a dialog. | "Delete project" | Primary Danger |
53
+
54
+ Don't:
55
+
56
+ - Put `danger` on any variant except `default`. It does nothing there.
57
+ - Use `danger` for actions that can be undone (archive, hide). Use `outline` or `secondary`.
58
+ - Put two red Buttons side by side.
59
+
60
+ ### Sizes
61
+
62
+ | `size` | Height | Figma | Use for |
63
+ | --- | --- | --- | --- |
64
+ | `lg` | 48px | Large | Hero actions, marketing pages, main actions on mobile |
65
+ | `default` | 40px | Medium | Most forms, dialogs, and pages |
66
+ | `sm` | 32px | Small | Compact layouts, cards, next to small inputs |
67
+ | `xs` | 24px | not in Figma | Dense UI only (toolbars, table cells). Prefer `sm`. |
68
+
69
+ Icon-only sizes are square and match the text sizes: `icon-lg` (48px), `icon` (40px), `icon-sm` (32px), `icon-xs` (24px).
70
+
71
+ TODO: `xs` and `icon-xs` don't use design tokens for height, corners, or icon size, so they won't follow token changes.
72
+
73
+ ### Icons
74
+
75
+ - An icon can sit before the label (to reinforce the action, like a plus for "New") or after it (to show direction, like an arrow for "Continue").
76
+ - At most one icon per Button with a label.
77
+ - Icons are sized to match the Button.
78
+
79
+ ### States
80
+
81
+ The Button shows these on its own:
82
+
83
+ | State | When | Notes |
84
+ | --- | --- | --- |
85
+ | Hover / pressed | Pointer | Pressed nudges the Button down 1px. |
86
+ | Focus | Keyboard | A visible focus ring. Never hide it. |
87
+ | Disabled | `disabled` | Can't be clicked or reached with Tab. Prefer explaining why an action is unavailable over silently disabling it. |
88
+ | Invalid | `aria-invalid` | Red border and ring, for a Button that acts as a form control (e.g. a picker). |
89
+ | Expanded | While a menu it opens is shown | Keeps the hover color (`outline`, `secondary`, `ghost`). |
90
+
91
+ There is no loading state. While an action runs, disable the Button and change its label ("Saving…").
92
+
93
+ ## Tokens used
94
+
95
+ | Token group | Where |
96
+ | --- | --- |
97
+ | `--color-cta-foreground-primary-*`, `--color-cta-border-primary-*`, `--color-on-cta-content-primary-*` | `default` fill, border, and text (default, hover, pressed, disabled) |
98
+ | `--color-danger-foreground-*`, `--color-on-danger-content-high` | `default` + `danger` fill and text |
99
+ | `--color-cta-foreground-secondary-*`, `--color-cta-border-secondary-*`, `--color-on-cta-content-secondary-*` | `secondary` |
100
+ | `--color-base-foreground-action-*`, `--color-on-base-border-*`, `--color-on-base-content-high` | `outline`, and `ghost` hover |
101
+ | `--color-base-foreground-disable`, `--color-on-base-content-disable` | Disabled `outline`, `ghost`, `link` |
102
+ | `--color-danger-foreground-subtle-*`, `--color-danger-border-*`, `--color-danger-content-*` | `destructive` |
103
+ | `--color-on-cta-content-tertiary-default` | `link` text |
104
+ | `--color-primary-border-strong` | Focus ring |
105
+ | `--color-danger-border-strong` | Invalid border and ring |
106
+ | `--radius-comp-cta` (0.5rem) | Corners |
107
+ | `--shadow-comp-cta` | Shadow on `default` |
108
+ | `--spacing-comp-*`, `--spacing-pad-*`, `--spacing-inner-md` | Heights, minimum widths, padding, icon gap |
109
+ | `--text-cta-s`, `--text-cta-m`, `--text-cta-l`, `--font-weight-cta-normal`, `--tracking-cta`, `--font-cta` | Label text for `sm`, `default`, `lg` |
110
+
111
+ All color tokens have dark-mode values and switch automatically.
112
+
113
+ ## Example
114
+
115
+ From the `Sizes` story: an icon-only Button, named with `aria-label`.
116
+
117
+ ```tsx
118
+ import { IconPlus } from "@tabler/icons-react"
119
+ import { Button } from "@bykhd/lab-ds"
120
+
121
+ <Button size="icon" aria-label="Add">
122
+ <IconPlus />
123
+ </Button>
124
+ ```
125
+
126
+ The stories also show `Default`, `Variants`, `WithIcon`, `Danger`, `Disabled`, `Invalid`, and `Focused`. For a `danger` Button in a confirmation dialog, see the `DestructiveConfirmation` story under Dialog.
@@ -0,0 +1,82 @@
1
+ # Card
2
+
3
+ A bordered container that groups content and actions about one subject.
4
+
5
+ ## When to use
6
+
7
+ - To group information about one thing, such as a plan, a project, or a setting, so it reads as a unit.
8
+ - To lay out several similar items in a grid that people scan and compare.
9
+ - When the group has its own title and, optionally, its own actions.
10
+
11
+ ## When not to use
12
+
13
+ - Just to add a border or padding around content. Use layout spacing instead.
14
+ - For a message the user must notice. Use `Alert`.
15
+ - For a task that needs the user's full attention. Use `Dialog`.
16
+ - For a product in a shop listing. Use `ProductCard`.
17
+ - Inside another Card. Nested borders make the hierarchy hard to read.
18
+ - TODO: confirm whether a whole Card can be clickable (a link). There is no clickable style.
19
+
20
+ ## Parts
21
+
22
+ | Part | What it is |
23
+ | --- | --- |
24
+ | `Card` | The container: card-colored background, thin border, large rounded corners. |
25
+ | `CardHeader` | Top area for the title, description, and action. |
26
+ | `CardTitle` | The card's heading. Medium weight. |
27
+ | `CardDescription` | One line of supporting text under the title, in a muted color. |
28
+ | `CardAction` | A spot in the header's top-right corner for a small `Button`. |
29
+ | `CardContent` | The main body. |
30
+ | `CardFooter` | A tinted strip along the bottom with a top border, for actions. |
31
+
32
+ An image placed as the first item of a Card runs edge to edge with rounded top corners.
33
+
34
+ TODO: `CardTitle` is not a heading element. Confirm how card titles should fit into the page's heading structure.
35
+
36
+ ## Props and variants
37
+
38
+ | Prop | Values | Default |
39
+ | --- | --- | --- |
40
+ | `size` | `default`, `sm` | `default` |
41
+
42
+ | `size` | Spacing | Title text |
43
+ | --- | --- | --- |
44
+ | `default` | 16px inside and between parts | Base size |
45
+ | `sm` | 12px inside and between parts | Small size |
46
+
47
+ There are no visual variants.
48
+
49
+ ## Tokens used
50
+
51
+ | Token | Where |
52
+ | --- | --- |
53
+ | `--color-base-foreground-card` | Card background |
54
+ | `--color-on-base-content-high` | Text and title |
55
+ | `--color-on-base-content-medium` | Description |
56
+ | `--color-on-base-border-default` | Card border and footer top border |
57
+ | `--color-base-foreground-surface-subtle` | Footer background |
58
+ | `--radius-xl` (1rem) | Corners |
59
+ | `--font-heading` | Title font |
60
+
61
+ All color tokens have dark-mode values and switch automatically.
62
+
63
+ ## Example
64
+
65
+ From the `Default` story:
66
+
67
+ ```tsx
68
+ import { Button, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@bykhd/lab-ds"
69
+
70
+ <Card>
71
+ <CardHeader>
72
+ <CardTitle>Team plan</CardTitle>
73
+ <CardDescription>Up to 10 members and unlimited projects.</CardDescription>
74
+ </CardHeader>
75
+ <CardContent>Your next invoice is on 1 December.</CardContent>
76
+ <CardFooter>
77
+ <Button variant="outline" size="sm">Manage plan</Button>
78
+ </CardFooter>
79
+ </Card>
80
+ ```
81
+
82
+ The stories also show `WithAction` and `Small`.
@@ -0,0 +1,65 @@
1
+ # Checkbox
2
+
3
+ Lets the user turn one option on or off, or pick any number of options from a list.
4
+
5
+ ## When to use
6
+
7
+ - To pick zero, one, or several options from a list ("Email", "Text message").
8
+ - For a single yes/no choice that is submitted with a form, such as "Accept terms and conditions".
9
+
10
+ ## When not to use
11
+
12
+ - To pick exactly one option from a list. TODO: lab-ds has no radio group yet.
13
+ - For a setting that takes effect right away. TODO: lab-ds has no switch yet.
14
+ - Without a visible label. Every Checkbox needs text that says what it turns on.
15
+
16
+ ## Rules
17
+
18
+ - Always pair it with a label (use `Field` with `orientation="horizontal"`). Clicking the label toggles the box.
19
+ - Group related checkboxes under one `FieldSet` and `FieldLegend`, and phrase the legend as the question being asked.
20
+ - Don't pre-check options for the user unless the default is clearly what most people want.
21
+ - Write labels as positive statements: "Send me updates", not "Don't send me updates".
22
+
23
+ ## Props and variants
24
+
25
+ There are no visual variants and one size (16px square).
26
+
27
+ | Prop | Values | Default | What it does |
28
+ | --- | --- | --- | --- |
29
+ | `checked` / `onCheckedChange` | boolean / function | not set | Control the checked state yourself. |
30
+ | `defaultChecked` | `true`, `false` | `false` | Start checked without controlling it. |
31
+ | `disabled` | `true`, `false` | `false` | Can't be changed; shown at half opacity. |
32
+ | `aria-invalid` | `true`, `false` | not set | Shows the red error border and ring. |
33
+
34
+ TODO: Base UI also supports an indeterminate ("mixed") state for a parent checkbox, but this Checkbox always shows a check mark. Confirm before using it.
35
+
36
+ ## Tokens used
37
+
38
+ | Token | Where |
39
+ | --- | --- |
40
+ | `--color-base-foreground-action` | Unchecked fill |
41
+ | `--color-on-base-border-default` / `-hover` | Unchecked border, and on hover |
42
+ | `--color-primary-foreground-default` / `-hover` | Checked fill and border |
43
+ | `--color-on-primary-content-high` | Check mark |
44
+ | `--color-primary-border-strong` | Focus border and ring |
45
+ | `--color-danger-border-strong` | Invalid border and ring |
46
+
47
+ The corner radius is a fixed 4px, not a token. All color tokens have dark-mode values and switch automatically.
48
+
49
+ ## Example
50
+
51
+ From the `WithDescription` story:
52
+
53
+ ```tsx
54
+ import { Checkbox, Field, FieldContent, FieldDescription, FieldLabel } from "@bykhd/lab-ds"
55
+
56
+ <Field orientation="horizontal">
57
+ <Checkbox id="updates" defaultChecked />
58
+ <FieldContent>
59
+ <FieldLabel htmlFor="updates">Product updates</FieldLabel>
60
+ <FieldDescription>One email a month about new features.</FieldDescription>
61
+ </FieldContent>
62
+ </Field>
63
+ ```
64
+
65
+ The stories also show `Default`, `Disabled`, and `Invalid`. `Field` shows a group of checkboxes in `FieldSetWithLegend`.
@@ -0,0 +1,154 @@
1
+ # Dialog
2
+
3
+ A modal window over the page that asks the user to complete one focused task or make a decision before they go back to the page.
4
+
5
+ ## When to use
6
+
7
+ - To confirm an action that is destructive or hard to undo ("Delete project?").
8
+ - For a short, self-contained task that shouldn't take the user away from where they are: rename an item, invite a member, a 2–3 field form.
9
+ - When the user must deal with something before they can continue, and the page behind should be blocked while they do.
10
+ - When the user opened it themselves (by pressing a Button), not as a surprise.
11
+
12
+ ## When not to use
13
+
14
+ - For status messages, warnings, or errors that don't need a decision. Use `Alert` inline on the page.
15
+ - For brief confirmations like "Saved". TODO: lab-ds has no toast yet.
16
+ - For long or multi-step content, large forms, or anything the user may want to bookmark or share. Use a full page.
17
+ - For content the user needs to see alongside the page (filters, details panel). TODO: lab-ds has no sheet/drawer or popover yet.
18
+ - For small hints or extra info next to a control. TODO: lab-ds has no tooltip or popover yet.
19
+ - To open on page load, for marketing or promotions. Unrequested dialogs interrupt the user.
20
+ - Inside another dialog. Avoid dialogs that open dialogs. The one accepted exception is a confirmation to discard unsaved changes.
21
+ - TODO: lab-ds has no alert dialog. That is a separate pattern for confirmations the user must answer, and screen readers announce it as an alert. Until lab-ds has one, use the `DestructiveConfirmation` recipe below: `disablePointerDismissal` plus initial focus on Cancel. It works the same way, but screen readers still announce it as an ordinary dialog.
22
+
23
+ ## Parts
24
+
25
+ A Dialog is built from these parts. `Dialog`, `DialogContent`, and `DialogTitle` are always needed.
26
+
27
+ | Part | What it is |
28
+ | --- | --- |
29
+ | `Dialog` | Holds the open/closed state. Renders nothing itself. |
30
+ | `DialogTrigger` | The control that opens the dialog, usually a `Button`. |
31
+ | `DialogContent` | The dialog window: a centered card above a dimmed, slightly blurred backdrop. Shows a close (×) button in the top-right corner by default. |
32
+ | `DialogHeader` | Stacks the title and description. |
33
+ | `DialogTitle` | Required. One short line saying what the dialog is for. Screen readers announce it as the dialog's name. |
34
+ | `DialogDescription` | Supporting text below the title. Add it to confirmations and short messages. A form can go without it. Muted color; links inside it are underlined. Read out by screen readers with the title. |
35
+ | `DialogFooter` | The action bar at the bottom: a tinted strip with a top border. Buttons sit right-aligned in a row; on small screens they stack full width with the last Button on top. |
36
+ | `DialogClose` | Wraps any control that should close the dialog, such as a "Cancel" `Button`. |
37
+
38
+ ## Props and variants
39
+
40
+ Dialog has **no visual variants and no sizes**. Width is fixed: 384px (24rem) on screens 640px and wider, otherwise the screen width minus 16px on each side. That width suits a confirmation or a form of 2–3 fields; bigger content belongs on a page. TODO: decide whether wider sizes are needed (Carbon, for example, has four).
41
+
42
+ Props added by lab-ds:
43
+
44
+ | Part | Prop | Values | Default | What it does |
45
+ | --- | --- | --- | --- | --- |
46
+ | `DialogContent` | `showCloseButton` | `true`, `false` | `true` | Shows the × close button in the top-right corner. |
47
+ | `DialogFooter` | `showCloseButton` | `true`, `false` | `false` | Adds an outline "Close" Button at the end of the footer. |
48
+
49
+ Behaviour props on `Dialog` (from Base UI):
50
+
51
+ | Prop | Values | Default | What it does |
52
+ | --- | --- | --- | --- |
53
+ | `open` / `onOpenChange` | boolean / function | not set | Control the open state yourself, e.g. to close after a save succeeds. |
54
+ | `defaultOpen` | `true`, `false` | `false` | Open on first render without controlling it. |
55
+ | `modal` | `true`, `false`, `'trap-focus'` | `true` | `true`: focus stays in the dialog, the page can't scroll or be clicked. `'trap-focus'`: focus is kept in, but the page can still scroll and be clicked. `false`: no restrictions. Keep `true` unless there's a clear reason. With `false` or `'trap-focus'` the page stays usable, so it is no longer a true modal. |
56
+ | `disablePointerDismissal` | `true`, `false` | `false` | Stops a click on the backdrop from closing the dialog. Use it when closing by accident would lose input or skip a required decision. Escape still closes. |
57
+
58
+ `DialogContent` also accepts Base UI's `initialFocus` and `finalFocus`, to choose which element gets focus when the dialog opens and closes. The defaults are usually right; see Accessibility.
59
+
60
+ ## Behaviour and accessibility
61
+
62
+ These come built in. Don't remove them.
63
+
64
+ - Focus moves into the dialog when it opens and stays inside it while it's open (with the default `modal`).
65
+ - When it closes, focus goes back to the control that opened it. If that control is gone (for example, the row was deleted), use `finalFocus` to choose where focus goes.
66
+ - When opened by touch, focus goes to the dialog itself, not its first field, so the on-screen keyboard doesn't pop up.
67
+ - Escape closes it. Clicking the backdrop closes it unless `disablePointerDismissal` is set.
68
+ - The page behind can't be scrolled or clicked while it's open.
69
+ - Opens and closes with a short fade and scale.
70
+
71
+ Your job:
72
+
73
+ - Always include a `DialogTitle`, even if it's short. Without it the dialog has no name for screen readers.
74
+ - Keep a visible way to close inside the dialog: the × button, a "Cancel" Button, or both. People using a screen reader on a touch screen can't press Escape. Don't hide the × (`showCloseButton={false}`) unless the footer has a Cancel or Close Button.
75
+ - In a destructive confirmation, initial focus always goes to the safer action (e.g. "Cancel"), set with `initialFocus`. The WAI-ARIA guide only suggests this; lab-ds makes it a rule.
76
+ - If the dialog opens with long text before any control, move initial focus to the title so screen-reader users start at the top. The title can't take focus by default, so add `tabIndex={-1}` to it and pass its ref to `initialFocus`.
77
+ - Use `disablePointerDismissal` for dialogs with a form or a required decision, so a stray click on the backdrop can't throw away input. Leave it off for dialogs that only show information.
78
+
79
+ ## Content
80
+
81
+ - **Title:** always visible. Says what is being decided or done, in sentence case. Prefer a specific question or action, ideally reusing the trigger's label: "Invite member…" opens "Invite a member". Avoid "Are you sure?" and "Warning".
82
+ - **Description:** add it when the title alone doesn't say what's at stake. One or two sentences, including consequences ("This deletes all 12 pages. You can't undo this.").
83
+ - **Actions:** one primary Button, plus Cancel. Labels are verbs that repeat the action: "Delete project", not "OK" or "Yes". "OK" is acceptable only for a dialog that just asks the user to acknowledge something. Follow the `Button` guideline:
84
+ - Primary is last (right side). Cancel uses `variant="outline"`.
85
+ - For a confirm that destroys data, use `<Button danger>` as the primary.
86
+ - Use `default` size Buttons in the footer.
87
+ - **Length:** keep it short enough to read without scrolling. If it needs to scroll, it probably belongs on a page. Never scroll sideways. TODO: lab-ds doesn't handle tall content yet. The dialog has no maximum height and no scrolling area, so keep dialogs short. Other systems (e.g. Carbon) scroll only the body and keep the title and footer fixed.
88
+
89
+ ## Tokens used
90
+
91
+ | Token | Where |
92
+ | --- | --- |
93
+ | `--color-base-foreground-blanket` | Backdrop behind the dialog (black at 50%) |
94
+ | `--color-base-foreground-card` | Dialog background |
95
+ | `--color-on-base-content-high` | Body text and title |
96
+ | `--color-on-base-content-medium` | Description text |
97
+ | `--color-base-foreground-surface-subtle` | Footer background |
98
+ | `--color-on-base-border-default` | Footer top border (the global default border color) |
99
+ | `--radius-xl` (1rem) | Dialog corner radius; also the footer's bottom corners |
100
+ | `--font-heading` | Title font (currently the same as `--font-sans`) |
101
+
102
+ All color tokens have dark-mode values in `theme.css` and switch automatically. The backdrop is black at 50% in both modes.
103
+
104
+ The close button and footer Buttons use the `Button` tokens (`ghost` and `outline` variants).
105
+
106
+ TODO: the dialog's shadow is Tailwind's stock `shadow-lg`, not a lab-ds token. The only elevation token is `--shadow-comp-cta`. Decide whether to add a modal elevation token.
107
+
108
+ ## Example
109
+
110
+ From the `DestructiveConfirmation` story: a `variant="destructive"` Button opens the dialog. Focus starts on Cancel, a click on the backdrop doesn't close the dialog, and a `danger` Button confirms.
111
+
112
+ ```tsx
113
+ import * as React from "react"
114
+ import {
115
+ Button,
116
+ Dialog,
117
+ DialogClose,
118
+ DialogContent,
119
+ DialogDescription,
120
+ DialogFooter,
121
+ DialogHeader,
122
+ DialogTitle,
123
+ DialogTrigger,
124
+ } from "@bykhd/lab-ds"
125
+
126
+ function DeleteProjectDialog() {
127
+ const cancelRef = React.useRef<HTMLButtonElement>(null)
128
+ return (
129
+ <Dialog disablePointerDismissal>
130
+ <DialogTrigger render={<Button variant="destructive" />}>Delete project…</DialogTrigger>
131
+ <DialogContent initialFocus={cancelRef}>
132
+ <DialogHeader>
133
+ <DialogTitle>Delete project?</DialogTitle>
134
+ <DialogDescription>
135
+ This deletes "Website redesign" and all 12 pages. You can't undo this.
136
+ </DialogDescription>
137
+ </DialogHeader>
138
+ <DialogFooter>
139
+ <DialogClose ref={cancelRef} render={<Button variant="outline" />}>Cancel</DialogClose>
140
+ <Button danger>Delete project</Button>
141
+ </DialogFooter>
142
+ </DialogContent>
143
+ </Dialog>
144
+ )
145
+ }
146
+ ```
147
+
148
+ The stories also show `Default` (a short rename form), `FooterCloseButton` (information only, with a single Close button), and `Open`. `Open` starts open only so reviewers can see the dialog in Storybook; don't open dialogs on page load in a product.
149
+
150
+ ## References
151
+
152
+ Guidance above follows the [WAI-ARIA APG modal dialog](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/) and [alert dialog](https://www.w3.org/WAI/ARIA/apg/patterns/alertdialog/) patterns, [Base UI Dialog](https://base-ui.com/react/components/dialog), [IBM Carbon modal](https://carbondesignsystem.com/components/modal/usage/), and [Atlassian modal dialog](https://atlassian.design/components/modal-dialog/usage). For initial focus in destructive dialogs, APG suggests the least destructive action and Atlassian focuses the close button; lab-ds follows APG and makes it a rule.
153
+
154
+ TODO: these points are common practice but weren't checked against a primary source: stacking footer Buttons on small screens with the primary on top, avoiding "Are you sure?" titles, and only opening a dialog when the user asks for it.