@thekestongroup/ui 0.2.1 → 0.3.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/README.md +90 -32
- package/dist/components/Age/Age.vue.d.ts +19 -0
- package/dist/components/AppShell/AppShell.vue.d.ts +108 -0
- package/dist/components/Avatar/Avatar.vue.d.ts +34 -0
- package/dist/components/AvatarGroup/AvatarGroup.vue.d.ts +25 -0
- package/dist/components/Badge/Badge.vue.d.ts +41 -0
- package/dist/components/Breadcrumb/Breadcrumb.vue.d.ts +39 -0
- package/dist/components/Button/Button.vue.d.ts +69 -0
- package/dist/components/Calendar/Calendar.vue.d.ts +34 -0
- package/dist/components/Card/Card.vue.d.ts +56 -0
- package/dist/components/Checkbox/Checkbox.vue.d.ts +40 -0
- package/dist/components/Checklist/Checklist.vue.d.ts +18 -0
- package/dist/components/Chip/Chip.vue.d.ts +44 -0
- package/dist/components/Divider/Divider.vue.d.ts +36 -0
- package/dist/components/{ToastItem.vue.d.ts → FormField/FieldMessage.vue.d.ts} +10 -2
- package/dist/components/FormField/FormField.vue.d.ts +61 -0
- package/dist/components/Header/Header.vue.d.ts +104 -0
- package/dist/components/InfoTip/InfoTip.vue.d.ts +20 -0
- package/dist/components/Input/Input.vue.d.ts +56 -0
- package/dist/components/InputCode/InputCode.vue.d.ts +53 -0
- package/dist/components/InputDate/InputDate.vue.d.ts +49 -0
- package/dist/components/InputNumber/InputNumber.vue.d.ts +44 -0
- package/dist/components/InputPassword/InputPassword.vue.d.ts +51 -0
- package/dist/components/InputRichText/InputRichText.vue.d.ts +44 -0
- package/dist/components/Link/Link.vue.d.ts +39 -0
- package/dist/components/Notification/Notification.vue.d.ts +62 -0
- package/dist/components/Notification/NotificationPane.vue.d.ts +38 -0
- package/dist/components/Notification/Toaster.vue.d.ts +51 -0
- package/dist/components/Notification/notification.samples.d.ts +3 -0
- package/dist/components/Notification/notifications.d.ts +115 -0
- package/dist/components/PageHeader/PageHeader.vue.d.ts +43 -0
- package/dist/components/Popover/Popover.vue.d.ts +83 -0
- package/dist/components/Popover/popover.d.ts +16 -0
- package/dist/components/Progress/Progress.vue.d.ts +26 -0
- package/dist/components/RadioGroup/RadioGroup.vue.d.ts +45 -0
- package/dist/components/RelativeTime/RelativeTime.vue.d.ts +22 -0
- package/dist/components/Select/Select.vue.d.ts +110 -0
- package/dist/components/Sidebar/Sidebar.vue.d.ts +106 -0
- package/dist/components/Sidebar/sidebar.d.ts +10 -0
- package/dist/components/Slideover/Slideover.vue.d.ts +125 -0
- package/dist/components/Spinner/Spinner.vue.d.ts +30 -0
- package/dist/components/StatTile/StatTile.vue.d.ts +46 -0
- package/dist/components/SummaryList/SummaryList.vue.d.ts +62 -0
- package/dist/components/Switch/Switch.vue.d.ts +39 -0
- package/dist/components/Table/Table.vue.d.ts +82 -0
- package/dist/components/Table/table.d.ts +36 -0
- package/dist/components/Tooltip/Tooltip.vue.d.ts +46 -0
- package/dist/index.d.ts +89 -25
- package/dist/keston-ui.js +4963 -14785
- package/dist/lib/cn.d.ts +4 -0
- package/dist/lib/dates.d.ts +27 -0
- package/dist/lib/initials.d.ts +2 -0
- package/dist/lib/parseDate.d.ts +44 -0
- package/dist/lib/useNow.d.ts +3 -0
- package/package.json +53 -24
- package/src/components/.gitkeep +0 -0
- package/src/components/Age/Age.stories.ts +24 -0
- package/src/components/Age/Age.vue +56 -0
- package/src/components/AppShell/AppShell.stories.ts +124 -0
- package/src/components/AppShell/AppShell.vue +212 -0
- package/src/components/Avatar/Avatar.stories.ts +56 -0
- package/src/components/Avatar/Avatar.vue +118 -0
- package/src/components/AvatarGroup/AvatarGroup.stories.ts +47 -0
- package/src/components/AvatarGroup/AvatarGroup.vue +97 -0
- package/src/components/Badge/Badge.stories.ts +92 -0
- package/src/components/Badge/Badge.vue +67 -0
- package/src/components/Breadcrumb/Breadcrumb.stories.ts +58 -0
- package/src/components/Breadcrumb/Breadcrumb.vue +109 -0
- package/src/components/Button/Button.mdx +79 -0
- package/src/components/Button/Button.stories.ts +207 -0
- package/src/components/Button/Button.vue +266 -0
- package/src/components/Calendar/Calendar.stories.ts +51 -0
- package/src/components/Calendar/Calendar.vue +364 -0
- package/src/components/Card/Card.stories.ts +109 -0
- package/src/components/Card/Card.vue +115 -0
- package/src/components/Checkbox/Checkbox.stories.ts +102 -0
- package/src/components/Checkbox/Checkbox.vue +102 -0
- package/src/components/Checklist/Checklist.stories.ts +67 -0
- package/src/components/Checklist/Checklist.vue +38 -0
- package/src/components/Chip/Chip.stories.ts +71 -0
- package/src/components/Chip/Chip.vue +86 -0
- package/src/components/Divider/Divider.stories.ts +57 -0
- package/src/components/Divider/Divider.vue +58 -0
- package/src/components/FormField/FieldMessage.vue +81 -0
- package/src/components/FormField/FormField.stories.ts +55 -0
- package/src/components/FormField/FormField.vue +160 -0
- package/src/components/Header/Header.stories.ts +168 -0
- package/src/components/Header/Header.vue +232 -0
- package/src/components/InfoTip/InfoTip.stories.ts +63 -0
- package/src/components/InfoTip/InfoTip.vue +50 -0
- package/src/components/Input/Input.stories.ts +206 -0
- package/src/components/Input/Input.vue +90 -0
- package/src/components/InputCode/InputCode.stories.ts +85 -0
- package/src/components/InputCode/InputCode.vue +145 -0
- package/src/components/InputDate/InputDate.stories.ts +58 -0
- package/src/components/InputDate/InputDate.vue +258 -0
- package/src/components/InputNumber/InputNumber.stories.ts +63 -0
- package/src/components/InputNumber/InputNumber.vue +109 -0
- package/src/components/InputPassword/InputPassword.stories.ts +105 -0
- package/src/components/InputPassword/InputPassword.vue +132 -0
- package/src/components/InputRichText/InputRichText.stories.ts +100 -0
- package/src/components/InputRichText/InputRichText.vue +194 -0
- package/src/components/Link/Link.stories.ts +73 -0
- package/src/components/Link/Link.vue +56 -0
- package/src/components/Notification/Notification.stories.ts +196 -0
- package/src/components/Notification/Notification.vue +136 -0
- package/src/components/Notification/NotificationPane.vue +187 -0
- package/src/components/Notification/Toaster.vue +446 -0
- package/src/components/Notification/notification.samples.ts +45 -0
- package/src/components/Notification/notifications.test.ts +99 -0
- package/src/components/Notification/notifications.ts +172 -0
- package/src/components/PageHeader/PageHeader.stories.ts +79 -0
- package/src/components/PageHeader/PageHeader.vue +66 -0
- package/src/components/Popover/Popover.stories.ts +135 -0
- package/src/components/Popover/Popover.vue +192 -0
- package/src/components/Popover/popover.ts +20 -0
- package/src/components/Progress/Progress.stories.ts +74 -0
- package/src/components/Progress/Progress.vue +75 -0
- package/src/components/RadioGroup/RadioGroup.stories.ts +90 -0
- package/src/components/RadioGroup/RadioGroup.vue +132 -0
- package/src/components/RelativeTime/RelativeTime.stories.ts +74 -0
- package/src/components/RelativeTime/RelativeTime.vue +51 -0
- package/src/components/Select/Select.mdx +202 -0
- package/src/components/Select/Select.stories.ts +223 -0
- package/src/components/Select/Select.vue +630 -0
- package/src/components/Sidebar/Sidebar.stories.ts +192 -0
- package/src/components/Sidebar/Sidebar.vue +382 -0
- package/src/components/Sidebar/sidebar.ts +20 -0
- package/src/components/Slideover/Slideover.stories.ts +225 -0
- package/src/components/Slideover/Slideover.vue +365 -0
- package/src/components/Spinner/Spinner.stories.ts +79 -0
- package/src/components/Spinner/Spinner.vue +97 -0
- package/src/components/StatTile/StatTile.stories.ts +75 -0
- package/src/components/StatTile/StatTile.vue +89 -0
- package/src/components/SummaryList/SummaryList.stories.ts +103 -0
- package/src/components/SummaryList/SummaryList.vue +127 -0
- package/src/components/Switch/Switch.stories.ts +100 -0
- package/src/components/Switch/Switch.vue +96 -0
- package/src/components/Table/Table.stories.ts +206 -0
- package/src/components/Table/Table.vue +220 -0
- package/src/components/Table/table.test.ts +65 -0
- package/src/components/Table/table.ts +70 -0
- package/src/components/Tooltip/Tooltip.stories.ts +57 -0
- package/src/components/Tooltip/Tooltip.vue +86 -0
- package/src/examples/AppPages.stories.ts +500 -0
- package/src/examples/FormLayout.stories.ts +185 -0
- package/src/examples/KestonIdPages.stories.ts +415 -0
- package/src/examples/SchoolPages.stories.ts +665 -0
- package/src/index.ts +114 -36
- package/src/lib/cn.ts +4 -0
- package/src/lib/dates.test.ts +68 -0
- package/src/lib/dates.ts +86 -0
- package/src/lib/initials.ts +8 -0
- package/src/lib/parseDate.test.ts +331 -0
- package/src/lib/parseDate.ts +561 -0
- package/src/lib/useNow.ts +20 -0
- package/src/styles/theme.css +101 -0
- package/dist/components/AppLauncher.vue.d.ts +0 -10
- package/dist/components/Avatar.vue.d.ts +0 -16
- package/dist/components/Button.vue.d.ts +0 -27
- package/dist/components/Checkbox.vue.d.ts +0 -18
- package/dist/components/CloseButton.vue.d.ts +0 -6
- package/dist/components/Dialog.vue.d.ts +0 -23
- package/dist/components/Drawer.vue.d.ts +0 -34
- package/dist/components/DropdownMenu.vue.d.ts +0 -21
- package/dist/components/DropdownMenuItem.vue.d.ts +0 -19
- package/dist/components/DropdownMenuSeparator.vue.d.ts +0 -6
- package/dist/components/Input.vue.d.ts +0 -14
- package/dist/components/Label.vue.d.ts +0 -16
- package/dist/components/NotificationsMenu.vue.d.ts +0 -3
- package/dist/components/Popover.vue.d.ts +0 -23
- package/dist/components/ProfileSwitcher.vue.d.ts +0 -24
- package/dist/components/Select.vue.d.ts +0 -28
- package/dist/components/Separator.vue.d.ts +0 -11
- package/dist/components/ToastRenderer.vue.d.ts +0 -3
- package/dist/components/Toaster.vue.d.ts +0 -3
- package/dist/components/Tooltip.vue.d.ts +0 -23
- package/dist/components/TopBar.vue.d.ts +0 -34
- package/dist/favicon-old.svg +0 -1
- package/dist/favicon.svg +0 -1
- package/dist/keston-ui.cjs +0 -15
- package/dist/lib/toast.d.ts +0 -29
- package/dist/lib/types.d.ts +0 -5
- package/src/components/AppLauncher.vue +0 -63
- package/src/components/Avatar.vue +0 -51
- package/src/components/Button.vue +0 -54
- package/src/components/Checkbox.vue +0 -47
- package/src/components/CloseButton.vue +0 -24
- package/src/components/Dialog.vue +0 -65
- package/src/components/Drawer.vue +0 -202
- package/src/components/DropdownMenu.vue +0 -41
- package/src/components/DropdownMenuItem.vue +0 -28
- package/src/components/DropdownMenuSeparator.vue +0 -12
- package/src/components/Input.vue +0 -21
- package/src/components/Label.vue +0 -15
- package/src/components/NotificationsMenu.vue +0 -115
- package/src/components/Popover.vue +0 -46
- package/src/components/ProfileSwitcher.vue +0 -113
- package/src/components/Select.vue +0 -97
- package/src/components/Separator.vue +0 -30
- package/src/components/ToastItem.vue +0 -158
- package/src/components/ToastRenderer.vue +0 -113
- package/src/components/Toaster.vue +0 -11
- package/src/components/Tooltip.vue +0 -48
- package/src/components/TopBar.vue +0 -52
- package/src/lib/toast.ts +0 -95
- package/src/lib/types.ts +0 -5
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { Canvas, Controls, Meta, Primary } from '@storybook/addon-docs/blocks'
|
|
2
|
+
import * as SelectStories from './Select.stories'
|
|
3
|
+
|
|
4
|
+
<Meta of={SelectStories} />
|
|
5
|
+
|
|
6
|
+
# Select
|
|
7
|
+
|
|
8
|
+
Choose one or more options from a list that opens below the field. It looks like Input: same label, helper, status message and 38px field. The full platform-neutral spec is in `specs/select.md`; the values here are measured from the rendered component.
|
|
9
|
+
|
|
10
|
+
<Primary />
|
|
11
|
+
|
|
12
|
+
<Controls />
|
|
13
|
+
|
|
14
|
+
## Modes
|
|
15
|
+
|
|
16
|
+
Combine these freely: e.g. `searchable` + `multiple` + nested `children`.
|
|
17
|
+
|
|
18
|
+
| Mode | Prop | The field is | Built on | Use for |
|
|
19
|
+
|---|---|---|---|---|
|
|
20
|
+
| Single | — | A button showing the chosen option | Reka UI Select | 4–30 known options |
|
|
21
|
+
| Searchable | `searchable` | A text box that filters the list | Reka UI Combobox | About 10 or more options |
|
|
22
|
+
| Multiple | `multiple` | Chips for the chosen options | Either of the above | Choosing several |
|
|
23
|
+
| Nested | `children` on options | (as above) | Either of the above | Trees, e.g. Classes › Year 8 › 11Y/En2 › student |
|
|
24
|
+
|
|
25
|
+
## When to use
|
|
26
|
+
|
|
27
|
+
| Use Select for | Use instead |
|
|
28
|
+
|---|---|
|
|
29
|
+
| One of about 4–30 known options | 2–3 options that should all be visible: radio buttons |
|
|
30
|
+
| Longer lists (`searchable`) | Lists too long to load, or searched on the server: a server-backed search |
|
|
31
|
+
| Several options from a list (`multiple`) | Several from 2–6 visible options: checkboxes |
|
|
32
|
+
| Trees of options (`children`) | Navigating or running actions: a menu |
|
|
33
|
+
|
|
34
|
+
## Options
|
|
35
|
+
|
|
36
|
+
Every option needs a `label`. Everything else is optional, in any combination. Plain strings are also accepted: `'Year 7'` is the same as `{ label: 'Year 7', value: 'Year 7' }`.
|
|
37
|
+
|
|
38
|
+
| Field | Type | Default | Description |
|
|
39
|
+
|---|---|---|---|
|
|
40
|
+
| `label` | string | — | **Required.** Shown in the list and, once chosen, in the field. |
|
|
41
|
+
| `value` | string \| number | the label | What v-model is set to. The same option in several places must share a value (see Shared options). |
|
|
42
|
+
| `description` | string | — | Smaller grey text under the label, in the list only. Searched too. |
|
|
43
|
+
| `icon` | Component | — | Before the label, in the list and the field. Give every option in a list an icon, or none. |
|
|
44
|
+
| `disabled` | boolean | false | Shown at 40% opacity; can't be chosen. |
|
|
45
|
+
| `children` | options[] | — | Makes it a parent: choosing it opens these, with a back row. Parents don't need a value. |
|
|
46
|
+
|
|
47
|
+
Groups (`groups` prop) take `{ label?, icon?, options }`.
|
|
48
|
+
|
|
49
|
+
<Canvas of={SelectStories.WithDescriptions} />
|
|
50
|
+
|
|
51
|
+
<Canvas of={SelectStories.GroupsWithIcons} />
|
|
52
|
+
|
|
53
|
+
## Sizes
|
|
54
|
+
|
|
55
|
+
One size, matching Input and a `md` Button. Measured in the browser.
|
|
56
|
+
|
|
57
|
+
| Part | Height | Padding (y / x) | Gap | Icon | Corner radius |
|
|
58
|
+
|---|---|---|---|---|---|
|
|
59
|
+
| Field | **38px** (+24px per extra line of chips) | 8px / 12px | 8px | 16px, 70% opacity | 4px |
|
|
60
|
+
| Label to field | — | — | 6px | — | — |
|
|
61
|
+
| List panel | Up to the space available, then scrolls | 4px | 2px between rows | — | 4px |
|
|
62
|
+
| Option (label only) | **32px** | 6px / 8px | 8px | 16px, level with the label | 4px |
|
|
63
|
+
| Option (with description) | Grows: 48px with one line of description, +16px per line | 6px / 8px | 8px | 16px, level with the label | 4px |
|
|
64
|
+
| Group heading | 24px | 0 / 8px | 6px | 14px | — |
|
|
65
|
+
| Group divider | 1px | 2px above and below | — | — | — |
|
|
66
|
+
| Chip (multiple) | 20px | 0 / 6px | 4px between chips | 12px; × 16px | 4px |
|
|
67
|
+
|
|
68
|
+
| Panel width | Value |
|
|
69
|
+
|---|---|
|
|
70
|
+
| Minimum | The field's width |
|
|
71
|
+
| Maximum | 320px, or the field's width if wider; longer text wraps |
|
|
72
|
+
| Position | 5px below the field (above it if there's no room below) |
|
|
73
|
+
|
|
74
|
+
## Typography
|
|
75
|
+
|
|
76
|
+
**Lato**, sentence case, no letter spacing.
|
|
77
|
+
|
|
78
|
+
| Text | Size / line height | Weight | Colour | Tailwind |
|
|
79
|
+
|---|---|---|---|---|
|
|
80
|
+
| Label | **14px** / 20px | 400 | black `#050505` | `text-sm` |
|
|
81
|
+
| Chosen option in the field | **14px** / 20px | 400 | black | `text-sm` |
|
|
82
|
+
| Placeholder | **14px** / 20px | 400 | black 55% | `text-sm text-black/55` |
|
|
83
|
+
| Option label | **14px** / 20px | 400 (700 when chosen) | black | `text-sm` |
|
|
84
|
+
| Option description / search path | **12px** / 16px | 400 | black 65% | `text-xs text-black/65` |
|
|
85
|
+
| Group heading | **12px** / 16px | 700, uppercase | black 65% | `text-xs font-bold uppercase` |
|
|
86
|
+
| Back row | **14px** / 20px | 700 | black | `text-sm font-bold` |
|
|
87
|
+
| Chip | **12px** / 16px | 400 | black | `text-xs` |
|
|
88
|
+
| Helper / status message | **12px** / 16px | 400 | black 65% / red / green | `text-xs` |
|
|
89
|
+
|
|
90
|
+
## Colours and states
|
|
91
|
+
|
|
92
|
+
| State | Appearance |
|
|
93
|
+
|---|---|
|
|
94
|
+
| Enabled | White `#FAFAFA` field, black 15% border, 4px corners |
|
|
95
|
+
| Focused | 2px outline in focus `#007FC9`, 1px outside the border |
|
|
96
|
+
| Open | Chevron turns over (150ms); list fades in |
|
|
97
|
+
| Option highlighted | Black 10% fill (hover or arrow keys) |
|
|
98
|
+
| Option chosen | Bold label, ✓ at the right |
|
|
99
|
+
| Option disabled | 40% opacity |
|
|
100
|
+
| Parent option | › at the right instead of ✓ |
|
|
101
|
+
| Chip | Black 5% fill, black 15% border; × darkens to black 10% on hover |
|
|
102
|
+
| Error / success | Red `#D2042D` / green `#007A16` border and message |
|
|
103
|
+
| Disabled | 40% opacity, not-allowed cursor |
|
|
104
|
+
|
|
105
|
+
<Canvas of={SelectStories.Error} />
|
|
106
|
+
|
|
107
|
+
## Searchable
|
|
108
|
+
|
|
109
|
+
<Canvas of={SelectStories.Searchable} />
|
|
110
|
+
|
|
111
|
+
| Action | Result |
|
|
112
|
+
|---|---|
|
|
113
|
+
| Type | Opens the list and keeps options whose label or description contains the text (ignoring case and accents) |
|
|
114
|
+
| Groups with no matches | Hidden, with their divider |
|
|
115
|
+
| Nothing matches | "No matches" (`emptyText`) |
|
|
116
|
+
| Press or focus the field | Selects its text, so typing replaces it |
|
|
117
|
+
| Leave the field | Shows the chosen option's label again, or clears if nothing is chosen |
|
|
118
|
+
|
|
119
|
+
## Multiple
|
|
120
|
+
|
|
121
|
+
<Canvas of={SelectStories.MultipleSearchable} />
|
|
122
|
+
|
|
123
|
+
| Action | Result |
|
|
124
|
+
|---|---|
|
|
125
|
+
| Choose an option | Ticks or unticks it; the list stays open |
|
|
126
|
+
| Escape, Tab or press outside | Closes the list |
|
|
127
|
+
| × on a chip (searchable) | Removes it |
|
|
128
|
+
| Backspace in the empty search box | Removes the last chip |
|
|
129
|
+
| After each tick (searchable) | The search clears, ready for the next |
|
|
130
|
+
| v-model | An array, in the order chosen; `[]` when none |
|
|
131
|
+
|
|
132
|
+
Without `searchable`, the field is a button, so its chips have no ×: untick in the list instead.
|
|
133
|
+
|
|
134
|
+
## Nested
|
|
135
|
+
|
|
136
|
+
<Canvas of={SelectStories.Nested} />
|
|
137
|
+
|
|
138
|
+
| Action | Result |
|
|
139
|
+
|---|---|
|
|
140
|
+
| Choose a parent (›), or → | Shows its children, with a back row (‹ and the level's name) at the top |
|
|
141
|
+
| Choose the back row, or ← | Goes up one level |
|
|
142
|
+
| After opening a level | Highlight on its first option |
|
|
143
|
+
| After going back | Highlight on the option just left |
|
|
144
|
+
| Reopen (single) | Starts at the chosen option's level |
|
|
145
|
+
| Reopen (multiple) | Starts at the top |
|
|
146
|
+
| Search (searchable) | Searches every level; each match shows its path, e.g. "Classes › Year 8 › 11Y/En2". The path is searched too, so "Year 8" finds everyone in it |
|
|
147
|
+
| Field | Shows only the chosen label, e.g. "Ben Blissett", not its path |
|
|
148
|
+
|
|
149
|
+
## Shared options
|
|
150
|
+
|
|
151
|
+
The same option can appear in several places, e.g. a student in two classes. Give it the **same `value`** everywhere.
|
|
152
|
+
|
|
153
|
+
<Canvas of={SelectStories.MultipleNested} />
|
|
154
|
+
|
|
155
|
+
| Where | Result |
|
|
156
|
+
|---|---|
|
|
157
|
+
| Chosen in one place | Ticked everywhere it appears |
|
|
158
|
+
| Field (multiple) | One chip |
|
|
159
|
+
| Chosen again anywhere | Unticks it, so it can't be added twice |
|
|
160
|
+
| Search | One row, listing every place: "Classes › Year 8 › 11Y/En2 · Classes › Year 8 › 8X/Ma1" |
|
|
161
|
+
|
|
162
|
+
If each place has a different value (e.g. a row ID per class membership), they're treated as different options: map them to one ID first.
|
|
163
|
+
|
|
164
|
+
## Keyboard
|
|
165
|
+
|
|
166
|
+
| Key | Closed | Open |
|
|
167
|
+
|---|---|---|
|
|
168
|
+
| Enter / Space | Opens | Chooses (Space: not when searchable) |
|
|
169
|
+
| ↓ / ↑ | Opens | Moves |
|
|
170
|
+
| Home / End | — | First / last option |
|
|
171
|
+
| Letters | Chooses the next option starting with them, without opening; searchable: opens and filters | Highlights the next option starting with them; searchable: filters |
|
|
172
|
+
| → | — | Opens the highlighted parent (searchable: only while nothing is typed) |
|
|
173
|
+
| ← | — | Back one level (searchable: only while nothing is typed) |
|
|
174
|
+
| Backspace | — | Searchable multiple, empty box: removes the last chip |
|
|
175
|
+
| Escape / Tab | — | Closes |
|
|
176
|
+
|
|
177
|
+
## Accessibility
|
|
178
|
+
|
|
179
|
+
| Part | Announced as |
|
|
180
|
+
|---|---|
|
|
181
|
+
| Field | `combobox` named by its label; a button, or a text input with `aria-autocomplete="list"` when searchable |
|
|
182
|
+
| Helper / status | Linked with `aria-describedby`; errors set `aria-invalid` |
|
|
183
|
+
| List | `listbox` of `option`s; groups named by their heading |
|
|
184
|
+
| Parent option | `"{label}, more options"` |
|
|
185
|
+
| Back row | `"Back from {level}"` |
|
|
186
|
+
| Chip × | `"Remove {label}"` |
|
|
187
|
+
|
|
188
|
+
| Contrast | Ratio |
|
|
189
|
+
|---|---|
|
|
190
|
+
| Text on white | 19.5:1 |
|
|
191
|
+
| Placeholder (black 55%) on white | about 4.5:1 |
|
|
192
|
+
| Focus ring on white | 4.1:1 (minimum 3:1) |
|
|
193
|
+
|
|
194
|
+
## Do and don't
|
|
195
|
+
|
|
196
|
+
| Do | Don't |
|
|
197
|
+
|---|---|
|
|
198
|
+
| Give every option in a list an icon, or none | Mix options with and without icons: labels won't line up |
|
|
199
|
+
| Use the same `value` for the same thing in several places | Give each copy its own value |
|
|
200
|
+
| Say what is being chosen: "Year group" | "Select year group" |
|
|
201
|
+
| Keep lists short, searchable or nested | Use a select for 2 options (use radios) |
|
|
202
|
+
| Use a prompt as the placeholder ("Choose…") | Put actions ("Add new…") among the options |
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
|
2
|
+
import { AtSign, Bell, BellOff, BookOpen, Calculator, CalendarDays, FlaskConical, Globe, GraduationCap, Mail, Music, Palette, School, Users } from "@lucide/vue";
|
|
3
|
+
import { ref } from "vue";
|
|
4
|
+
import Select, { type SelectValueType } from "./Select.vue";
|
|
5
|
+
|
|
6
|
+
const yearGroups = ["Year 7", "Year 8", "Year 9", "Year 10", "Year 11", "Year 12", "Year 13"];
|
|
7
|
+
|
|
8
|
+
const meta = {
|
|
9
|
+
title: "Components/Form/Select",
|
|
10
|
+
component: Select,
|
|
11
|
+
// The docs page is Select.mdx (sizes, typography, behaviour), not autodocs.
|
|
12
|
+
argTypes: {
|
|
13
|
+
helperPlacement: { options: ["below", "icon"], control: { type: "inline-radio" } },
|
|
14
|
+
status: { options: [undefined, "error", "success"], control: { type: "inline-radio" } },
|
|
15
|
+
},
|
|
16
|
+
args: {
|
|
17
|
+
label: "Year group",
|
|
18
|
+
options: yearGroups,
|
|
19
|
+
searchable: false,
|
|
20
|
+
multiple: false,
|
|
21
|
+
helper: "",
|
|
22
|
+
helperPlacement: "below",
|
|
23
|
+
disabled: false,
|
|
24
|
+
},
|
|
25
|
+
decorators: [() => ({ template: '<div class="max-w-80"><story /></div>' })],
|
|
26
|
+
render: (args) => ({
|
|
27
|
+
components: { Select },
|
|
28
|
+
setup() {
|
|
29
|
+
const value = ref<SelectValueType | SelectValueType[]>();
|
|
30
|
+
return { args, value };
|
|
31
|
+
},
|
|
32
|
+
template: `
|
|
33
|
+
<Select v-bind="args" v-model="value" />
|
|
34
|
+
<p class="mt-4 text-xs text-black/65">Value: {{ value === undefined ? "undefined" : JSON.stringify(value) }}</p>`,
|
|
35
|
+
}),
|
|
36
|
+
} satisfies Meta<typeof Select>;
|
|
37
|
+
|
|
38
|
+
export default meta;
|
|
39
|
+
type Story = StoryObj<typeof meta>;
|
|
40
|
+
|
|
41
|
+
/** Playground: use the controls below. Options can be plain strings. */
|
|
42
|
+
export const Default: Story = {};
|
|
43
|
+
|
|
44
|
+
export const WithHelper: Story = {
|
|
45
|
+
args: { helper: "The year group the student is joining in September." },
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** Options as objects, with icons and a disabled option. The chosen option's icon shows in the field. */
|
|
49
|
+
export const WithIcons: Story = {
|
|
50
|
+
args: {
|
|
51
|
+
label: "Subject",
|
|
52
|
+
options: [
|
|
53
|
+
{ label: "English", value: "english", icon: BookOpen },
|
|
54
|
+
{ label: "Maths", value: "maths", icon: Calculator },
|
|
55
|
+
{ label: "Science", value: "science", icon: FlaskConical },
|
|
56
|
+
{ label: "Geography", value: "geography", icon: Globe },
|
|
57
|
+
{ label: "Art", value: "art", icon: Palette },
|
|
58
|
+
{ label: "Music", value: "music", icon: Music, disabled: true },
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Every option needs a label; a description and an icon are optional.
|
|
65
|
+
* Descriptions can vary per option, but give every option an icon or none,
|
|
66
|
+
* so the labels line up. Only the label (and icon) show in the field once chosen.
|
|
67
|
+
*/
|
|
68
|
+
export const WithDescriptions: Story = {
|
|
69
|
+
args: {
|
|
70
|
+
label: "Notifications",
|
|
71
|
+
options: [
|
|
72
|
+
{ label: "Everything", value: "all", description: "Messages, mentions and every update to your classes.", icon: Bell },
|
|
73
|
+
{ label: "Mentions only", value: "mentions", description: "When someone mentions you or replies to you.", icon: AtSign },
|
|
74
|
+
{ label: "Daily summary", value: "daily", description: "One email each morning.", icon: Mail },
|
|
75
|
+
{ label: "Weekly summary", value: "weekly", icon: CalendarDays },
|
|
76
|
+
{ label: "Off", value: "off", icon: BellOff },
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/** Label and description, no icons. */
|
|
82
|
+
export const WithDescriptionsNoIcons: Story = {
|
|
83
|
+
args: {
|
|
84
|
+
label: "Term",
|
|
85
|
+
options: [
|
|
86
|
+
{ label: "Autumn", value: "autumn", description: "September to December" },
|
|
87
|
+
{ label: "Spring", value: "spring", description: "January to April" },
|
|
88
|
+
{ label: "Summer", value: "summer", description: "April to July" },
|
|
89
|
+
{ label: "Whole year", value: "year" },
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/** Options grouped under headings. */
|
|
95
|
+
export const Groups: Story = {
|
|
96
|
+
args: {
|
|
97
|
+
label: "Year group",
|
|
98
|
+
options: [],
|
|
99
|
+
groups: [
|
|
100
|
+
{ label: "Key Stage 3", options: ["Year 7", "Year 8", "Year 9"] },
|
|
101
|
+
{ label: "Key Stage 4", options: ["Year 10", "Year 11"] },
|
|
102
|
+
{ label: "Sixth form", options: ["Year 12", "Year 13"] },
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/** A long list scrolls inside the panel, which never runs off the screen. */
|
|
108
|
+
export const LongList: Story = {
|
|
109
|
+
args: {
|
|
110
|
+
label: "Country",
|
|
111
|
+
options: [
|
|
112
|
+
"Australia", "Austria", "Belgium", "Brazil", "Canada", "China", "Denmark", "Egypt",
|
|
113
|
+
"Finland", "France", "Germany", "Greece", "India", "Ireland", "Italy", "Japan",
|
|
114
|
+
"Kenya", "Mexico", "Netherlands", "New Zealand", "Nigeria", "Norway", "Poland",
|
|
115
|
+
"Portugal", "Singapore", "South Africa", "Spain", "Sweden", "Switzerland",
|
|
116
|
+
"United Kingdom", "United States",
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/** Type to filter: matches anywhere in the label, ignoring case and accents. */
|
|
122
|
+
export const Searchable: Story = {
|
|
123
|
+
args: { ...LongList.args, searchable: true },
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/** Group headings can have an icon too. */
|
|
127
|
+
export const GroupsWithIcons: Story = {
|
|
128
|
+
args: {
|
|
129
|
+
label: "Subject",
|
|
130
|
+
options: [],
|
|
131
|
+
groups: [
|
|
132
|
+
{ label: "Core", icon: BookOpen, options: ["English", "Maths", "Science"] },
|
|
133
|
+
{ label: "Humanities", icon: Globe, options: ["Geography", "History", "Religious studies"] },
|
|
134
|
+
{ label: "Creative", icon: Palette, options: ["Art", "Drama", "Music"] },
|
|
135
|
+
],
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/** Searching grouped options: groups with no matches are hidden. */
|
|
140
|
+
export const SearchableGroups: Story = {
|
|
141
|
+
args: { ...Groups.args, searchable: true },
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// Classes › year › class › student, plus a top-level option and a second branch.
|
|
145
|
+
const student = (name: string) => ({ label: name, value: name.toLowerCase().replace(/ /g, "-") });
|
|
146
|
+
const classTree = [
|
|
147
|
+
{ label: "Whole school", value: "school", icon: School, description: "Every student" },
|
|
148
|
+
{
|
|
149
|
+
label: "Classes",
|
|
150
|
+
icon: Users,
|
|
151
|
+
description: "Choose a year, then a class",
|
|
152
|
+
children: [
|
|
153
|
+
{
|
|
154
|
+
label: "Year 7",
|
|
155
|
+
children: [
|
|
156
|
+
{ label: "7X/En1", children: ["Ava Patel", "Leo Wright", "Mia Chen"].map(student) },
|
|
157
|
+
{ label: "7Y/En2", children: ["Noah Evans", "Isla Ahmed"].map(student) },
|
|
158
|
+
],
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
label: "Year 8",
|
|
162
|
+
children: [
|
|
163
|
+
{ label: "11Y/En2", children: ["Ben Blissett", "Zara Khan", "Oscar Hughes"].map(student) },
|
|
164
|
+
// Ben is in two classes: the same value, so ticking him in one ticks him in both.
|
|
165
|
+
{ label: "8X/Ma1", children: ["Ben Blissett", "Freya Lewis", "Ethan Price"].map(student) },
|
|
166
|
+
],
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
label: "Tutor groups",
|
|
172
|
+
icon: GraduationCap,
|
|
173
|
+
children: [
|
|
174
|
+
{ label: "Tutor 7A", children: ["Ava Patel", "Noah Evans"].map(student) },
|
|
175
|
+
],
|
|
176
|
+
},
|
|
177
|
+
];
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Options with `children` open a level instead of being chosen, with a back
|
|
181
|
+
* row (‹ Year 8) at the top. → opens, ← goes back. The field shows only the
|
|
182
|
+
* chosen option; reopening starts at its level.
|
|
183
|
+
*/
|
|
184
|
+
export const Nested: Story = {
|
|
185
|
+
args: { label: "Recipient", options: classTree },
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
/** Searching a nested list looks through every level and shows each match's path. */
|
|
189
|
+
export const NestedSearchable: Story = {
|
|
190
|
+
args: { label: "Recipient", options: classTree, searchable: true },
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Choose several: the list stays open while ticking, and the chosen options
|
|
195
|
+
* show as chips, wrapping onto more lines. Untick an option to remove it.
|
|
196
|
+
*/
|
|
197
|
+
export const Multiple: Story = {
|
|
198
|
+
args: { ...WithIcons.args, label: "Subjects", multiple: true },
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Searchable and multiple: type to filter, Enter ticks and clears the search.
|
|
203
|
+
* × on a chip removes it; Backspace in the empty box removes the last one.
|
|
204
|
+
*/
|
|
205
|
+
export const MultipleSearchable: Story = {
|
|
206
|
+
args: { ...LongList.args, label: "Countries", multiple: true, searchable: true },
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Several people from anywhere in a nested list. The same person can be in
|
|
211
|
+
* several places (Ben is in 11Y/En2 and 8X/Ma1, Ava and Noah in a class and a
|
|
212
|
+
* tutor group): they share a value, so they're chosen once, ticked everywhere
|
|
213
|
+
* they appear, and shown as one chip.
|
|
214
|
+
*/
|
|
215
|
+
export const MultipleNested: Story = {
|
|
216
|
+
args: { label: "Recipients", options: classTree, multiple: true, searchable: true },
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
export const Error: Story = {
|
|
220
|
+
args: { errorText: "Choose a year group" },
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export const Disabled: Story = { args: { disabled: true } };
|