@thekestongroup/ui 0.4.0 → 0.6.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.
Files changed (38) hide show
  1. package/dist/components/AppShell/AppShell.vue.d.ts +4 -2
  2. package/dist/components/FormField/FormField.vue.d.ts +5 -0
  3. package/dist/components/Header/Header.vue.d.ts +9 -1
  4. package/dist/components/Input/Input.vue.d.ts +2 -0
  5. package/dist/components/InputDate/InputDate.vue.d.ts +2 -0
  6. package/dist/components/InputNumber/InputNumber.vue.d.ts +2 -0
  7. package/dist/components/InputPassword/InputPassword.vue.d.ts +2 -0
  8. package/dist/components/InputRichText/InputRichText.vue.d.ts +2 -0
  9. package/dist/components/Menu/Menu.vue.d.ts +38 -0
  10. package/dist/components/PageHeader/PageHeader.vue.d.ts +23 -1
  11. package/dist/components/Select/Select.vue.d.ts +2 -0
  12. package/dist/components/Sidebar/Sidebar.vue.d.ts +1 -1
  13. package/dist/components/Table/Table.vue.d.ts +14 -1
  14. package/dist/components/Tabs/Tabs.vue.d.ts +42 -0
  15. package/dist/index.d.ts +5 -1
  16. package/dist/keston-ui.js +817 -589
  17. package/package.json +1 -1
  18. package/src/components/AppShell/AppShell.stories.ts +5 -0
  19. package/src/components/AppShell/AppShell.vue +6 -2
  20. package/src/components/FormField/FormField.vue +7 -2
  21. package/src/components/Header/Header.stories.ts +9 -0
  22. package/src/components/Header/Header.vue +27 -4
  23. package/src/components/Input/Input.stories.ts +21 -0
  24. package/src/components/Input/Input.vue +3 -0
  25. package/src/components/InputDate/InputDate.vue +3 -0
  26. package/src/components/InputNumber/InputNumber.vue +3 -0
  27. package/src/components/InputPassword/InputPassword.vue +3 -0
  28. package/src/components/InputRichText/InputRichText.vue +3 -0
  29. package/src/components/Menu/Menu.stories.ts +40 -0
  30. package/src/components/Menu/Menu.vue +104 -0
  31. package/src/components/PageHeader/PageHeader.stories.ts +33 -1
  32. package/src/components/PageHeader/PageHeader.vue +52 -1
  33. package/src/components/Select/Select.vue +3 -0
  34. package/src/components/Table/Table.stories.ts +59 -1
  35. package/src/components/Table/Table.vue +57 -4
  36. package/src/components/Tabs/Tabs.stories.ts +47 -0
  37. package/src/components/Tabs/Tabs.vue +69 -0
  38. package/src/index.ts +5 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thekestongroup/ui",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Keston UI — Vue 3 + Reka UI + Tailwind CSS component library",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {
@@ -60,6 +60,11 @@ type Story = StoryObj<typeof meta>;
60
60
  */
61
61
  export const Default: Story = {};
62
62
 
63
+ /** titleTo: the app's name in the header links to its dashboard (`to` for `linkComponent`, or an href). */
64
+ export const TitleLink: Story = {
65
+ args: { titleTo: "#dashboard" },
66
+ };
67
+
63
68
  /** Starts with the sidebar collapsed to icons. */
64
69
  export const Collapsed: Story = {
65
70
  args: { collapsed: true },
@@ -35,6 +35,8 @@ import Slideover from '../Slideover/Slideover.vue'
35
35
  export interface AppShellProps {
36
36
  /** Name of the app, shown in the header and as the mobile menu's title. */
37
37
  title?: string
38
+ /** Make the header's title a link, e.g. to the app's dashboard (`to` for `linkComponent`, or an href). */
39
+ titleTo?: unknown
38
40
  /** The signed-in user, for the account menu. Without it, Sign in is shown. */
39
41
  user?: HeaderUser
40
42
  /** Which actions the account menu offers. Default all three. */
@@ -47,10 +49,10 @@ export interface AppShellProps {
47
49
  sections?: SidebarProps['sections']
48
50
  /** Wide screens: show the header's menu button, which collapses the sidebar to icons. */
49
51
  collapsible?: boolean
50
- /** Component used for sidebar items with `to`, e.g. RouterLink. */
52
+ /** Component used for sidebar items with `to`, and the title link, e.g. RouterLink. */
51
53
  linkComponent?: SidebarProps['linkComponent']
52
54
  /** Other Header props, e.g. `{ ui: { title: '…' } }`. */
53
- header?: Omit<HeaderProps, 'title' | 'menu' | 'menuOpen' | 'sticky' | 'user' | 'userActions' | 'signIn'>
55
+ header?: Omit<HeaderProps, 'title' | 'titleTo' | 'linkComponent' | 'menu' | 'menuOpen' | 'sticky' | 'user' | 'userActions' | 'signIn'>
54
56
  /** Other Sidebar props, e.g. `{ label: 'Admissions' }`. */
55
57
  sidebar?: Omit<SidebarProps, 'items' | 'sections' | 'collapsible' | 'linkComponent'>
56
58
  class?: HTMLAttributes['class']
@@ -126,6 +128,8 @@ const sidebarId = `${uid}-sidebar`
126
128
  <Header
127
129
  v-bind="header"
128
130
  :title="title"
131
+ :title-to="titleTo"
132
+ :link-component="linkComponent"
129
133
  menu
130
134
  sticky
131
135
  :menu-open="menuOpen"
@@ -22,6 +22,11 @@ export interface FormFieldProps {
22
22
  helper?: string
23
23
  /** Show helper text under the label, or behind a `?` icon next to it. */
24
24
  helperPlacement?: 'below' | 'icon'
25
+ /**
26
+ * Keep the label (and helper) for screen readers only, e.g. in a table of
27
+ * fields where the column headings say what each one is.
28
+ */
29
+ hideLabel?: boolean
25
30
  /**
26
31
  * Error message, e.g. from a Zod / VeeValidate schema. When set (and not
27
32
  * empty) the field shows as an error with this text; leave it undefined
@@ -120,8 +125,8 @@ const statusBorder: Record<FormFieldStatus, string> = {
120
125
  <div :class="cn('flex flex-col gap-1.5 text-black', props.class)">
121
126
  <!-- Label row and box in a grid, so label-trailing can come after the
122
127
  box in the page (and the Tab order) but show at the end of the label row. -->
123
- <div :class="cn('grid grid-cols-[minmax(0,1fr)_auto] gap-y-1.5', $slots['label-trailing'] && 'gap-x-3')">
124
- <div class="col-start-1 row-start-1 flex flex-col gap-0.5">
128
+ <div :class="cn('grid grid-cols-[minmax(0,1fr)_auto]', !hideLabel && 'gap-y-1.5', $slots['label-trailing'] && 'gap-x-3')">
129
+ <div :class="cn('col-start-1 row-start-1 flex flex-col gap-0.5', hideLabel && 'sr-only')">
125
130
  <div class="flex items-center gap-1">
126
131
  <label :id="labelId" :for="controlId" class="text-sm" @click="focusUnlabelable">{{ label }}</label>
127
132
 
@@ -106,6 +106,15 @@ export const CustomUser: Story = {
106
106
  }),
107
107
  };
108
108
 
109
+ /**
110
+ * titleTo: the app's name links to its dashboard. It looks the same, with a
111
+ * ghost button's hover background and the focus ring. Pass your router's
112
+ * link as `linkComponent` (it gets `to`); without one it's a plain `<a href>`.
113
+ */
114
+ export const TitleLink: Story = {
115
+ args: { titleTo: "#dashboard" },
116
+ };
117
+
109
118
  /** Just the title: no menu button, actions or account menu. */
110
119
  export const TitleOnly: Story = {
111
120
  args: { menu: false, user: undefined, signIn: false },
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { computed, type HTMLAttributes } from 'vue'
2
+ import { computed, type Component, type HTMLAttributes } from 'vue'
3
3
  import { ArrowLeftRight, LogOut, Menu, Settings } from '@lucide/vue'
4
4
  import { cn } from '../../lib/cn'
5
5
  import Avatar from '../Avatar/Avatar.vue'
@@ -34,6 +34,13 @@ export type HeaderUserAction = 'account-settings' | 'switch-account' | 'log-out'
34
34
  export interface HeaderProps {
35
35
  /** Name of the app or area, shown next to the menu button. */
36
36
  title?: string
37
+ /**
38
+ * Make the title a link, e.g. to the app's dashboard: passed as `to` to
39
+ * `linkComponent` (e.g. a route), or as `href` without one.
40
+ */
41
+ titleTo?: unknown
42
+ /** Component for the title link, e.g. RouterLink. It receives `to`. Default a plain `<a href>`. */
43
+ linkComponent?: string | Component
37
44
  /**
38
45
  * Show the menu button, which emits `menu` when pressed. Hide it on wide
39
46
  * screens with `ui.menu`, e.g. `{ menu: 'lg:hidden' }`.
@@ -79,6 +86,7 @@ const props = withDefaults(defineProps<HeaderProps>(), {
79
86
  menu: false,
80
87
  menuOpen: undefined,
81
88
  menuLabel: 'Menu',
89
+ linkComponent: 'a',
82
90
  userActions: () => ['account-settings', 'switch-account', 'log-out'],
83
91
  signIn: true,
84
92
  sticky: true
@@ -113,6 +121,19 @@ const accountLabel = computed(() => {
113
121
  return `${initials.value}, account: ${props.user.name}`
114
122
  })
115
123
 
124
+ const titleLink = computed(() => {
125
+ const target = props.titleTo
126
+ if (target === undefined || target === null || target === '') return undefined
127
+ return props.linkComponent === 'a' ? { href: target as string } : { to: target }
128
+ })
129
+
130
+ // As a link the title looks the same, with a ghost button's hover and press
131
+ // backgrounds round it; the negative margin keeps the text where it was.
132
+ const titleLinkClass = [
133
+ '-mx-2 rounded px-2 py-1 transition-colors hover:bg-black/10 active:bg-black/15',
134
+ 'outline-2 outline-offset-1 outline-transparent focus-visible:outline-focus forced-colors:not-focus-visible:outline-0'
135
+ ]
136
+
116
137
  function runAction(action: HeaderUserAction, close: () => void) {
117
138
  close()
118
139
  // Vue can't emit a name held in a variable with full typing, so switch.
@@ -148,12 +169,14 @@ function runAction(action: HeaderUserAction, close: () => void) {
148
169
 
149
170
  <slot name="leading" />
150
171
 
151
- <span
172
+ <component
173
+ :is="titleLink ? linkComponent : 'span'"
152
174
  v-if="title || $slots.title"
153
- :class="cn('min-w-0 truncate text-base font-bold', ui?.title)"
175
+ v-bind="titleLink"
176
+ :class="cn('min-w-0 truncate text-base font-bold', titleLink && titleLinkClass, ui?.title)"
154
177
  >
155
178
  <slot name="title">{{ title }}</slot>
156
- </span>
179
+ </component>
157
180
 
158
181
  <div :class="cn('flex min-w-0 flex-1 items-center', ui?.middle)">
159
182
  <slot />
@@ -204,3 +204,24 @@ export const NextToButton: Story = {
204
204
  </div>`,
205
205
  }),
206
206
  };
207
+
208
+ /**
209
+ * A table of fields: the column headings say what each is, so each field's
210
+ * label is hidden (`hide-label`) but still read by screen readers, e.g.
211
+ * "First name, user 2".
212
+ */
213
+ export const InATable: Story = {
214
+ render: () => ({
215
+ components: { Input },
216
+ setup: () => ({ rows: ref([{ first: "Jo", last: "Bloggs" }, { first: "Sam", last: "Lee" }]) }),
217
+ template: `
218
+ <div class="grid max-w-120 grid-cols-2 gap-x-3 gap-y-2">
219
+ <p class="text-sm" aria-hidden="true">First name</p>
220
+ <p class="text-sm" aria-hidden="true">Last name</p>
221
+ <template v-for="(r, i) in rows" :key="i">
222
+ <Input v-model="r.first" :label="'First name, user ' + (i + 1)" hide-label />
223
+ <Input v-model="r.last" :label="'Last name, user ' + (i + 1)" hide-label />
224
+ </template>
225
+ </div>`,
226
+ }),
227
+ };
@@ -15,6 +15,8 @@ export interface InputProps {
15
15
  helper?: string
16
16
  /** Show helper text under the label, or behind a `?` icon next to it. */
17
17
  helperPlacement?: 'below' | 'icon'
18
+ /** Keep the label for screen readers only, e.g. in a table of fields with column headings. */
19
+ hideLabel?: boolean
18
20
  /**
19
21
  * Error message, e.g. from a Zod / VeeValidate schema. When set (and not
20
22
  * empty) the field shows as an error with this text; leave it undefined
@@ -66,6 +68,7 @@ const statusText = computed(() => props.statusText ?? lengthError.value)
66
68
  :label="label"
67
69
  :helper="helper"
68
70
  :helper-placement="helperPlacement"
71
+ :hide-label="hideLabel"
69
72
  :error-text="errorText"
70
73
  :status="status"
71
74
  :status-text="statusText"
@@ -18,6 +18,8 @@ export interface InputDateProps {
18
18
  helper?: string
19
19
  /** Show helper text under the label, or behind a `?` icon next to it. */
20
20
  helperPlacement?: 'below' | 'icon'
21
+ /** Keep the label for screen readers only, e.g. in a table of fields with column headings. */
22
+ hideLabel?: boolean
21
23
  /** Error message, e.g. from a Zod schema. Overrides `status` / `statusText`. */
22
24
  errorText?: string
23
25
  /** Colours the field and the status text. */
@@ -211,6 +213,7 @@ const trigger = [
211
213
  :label="label"
212
214
  :helper="helper"
213
215
  :helper-placement="helperPlacement"
216
+ :hide-label="hideLabel"
214
217
  :error-text="errorText"
215
218
  :status="status"
216
219
  :status-text="statusText"
@@ -14,6 +14,8 @@ export interface InputNumberProps {
14
14
  helper?: string
15
15
  /** Show helper text under the label, or behind a `?` icon next to it. */
16
16
  helperPlacement?: 'below' | 'icon'
17
+ /** Keep the label for screen readers only, e.g. in a table of fields with column headings. */
18
+ hideLabel?: boolean
17
19
  /** Error message, e.g. from a Zod schema. Overrides `status` / `statusText`. */
18
20
  errorText?: string
19
21
  /** Colours the field and the status text. */
@@ -71,6 +73,7 @@ const increment = '-mr-3 rounded-r border-l border-black/15'
71
73
  :label="label"
72
74
  :helper="helper"
73
75
  :helper-placement="helperPlacement"
76
+ :hide-label="hideLabel"
74
77
  :error-text="errorText"
75
78
  :status="status"
76
79
  :status-text="statusText"
@@ -22,6 +22,8 @@ export interface InputPasswordProps {
22
22
  helper?: string
23
23
  /** Show helper text under the label, or behind a `?` icon next to it. */
24
24
  helperPlacement?: 'below' | 'icon'
25
+ /** Keep the label for screen readers only, e.g. in a table of fields with column headings. */
26
+ hideLabel?: boolean
25
27
  /**
26
28
  * Error message, e.g. from a Zod / VeeValidate schema or "Incorrect
27
29
  * password". When set (and not empty) the field shows as an error with this
@@ -86,6 +88,7 @@ const toggle = [
86
88
  :label="label"
87
89
  :helper="helper"
88
90
  :helper-placement="helperPlacement"
91
+ :hide-label="hideLabel"
89
92
  :error-text="errorText"
90
93
  :status="status"
91
94
  :status-text="statusText"
@@ -32,6 +32,8 @@ export interface InputRichTextProps {
32
32
  helper?: string
33
33
  /** Show helper text under the label, or behind a `?` icon next to it. */
34
34
  helperPlacement?: 'below' | 'icon'
35
+ /** Keep the label for screen readers only, e.g. in a table of fields with column headings. */
36
+ hideLabel?: boolean
35
37
  /** Error message, e.g. from a Zod schema. Overrides `status` / `statusText`. */
36
38
  errorText?: string
37
39
  /** Colours the field and the status text, e.g. 'loading' while it saves. */
@@ -152,6 +154,7 @@ const editable = [
152
154
  :label="label"
153
155
  :helper="helper"
154
156
  :helper-placement="helperPlacement"
157
+ :hide-label="hideLabel"
155
158
  :error-text="errorText"
156
159
  :status="status"
157
160
  :status-text="statusText"
@@ -0,0 +1,40 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import { Ban, KeyRound, SquareArrowOutUpRight, Trash2, UsersRound } from "@lucide/vue";
3
+ import Menu from "./Menu.vue";
4
+
5
+ const meta = {
6
+ title: "Components/Overlay/Menu",
7
+ component: Menu,
8
+ tags: ["autodocs"],
9
+ parameters: { layout: "centered" },
10
+ args: {
11
+ label: "Actions for Jo Bloggs",
12
+ items: [
13
+ { label: "Open profile", icon: SquareArrowOutUpRight, href: "#" },
14
+ { label: "Reset password", icon: KeyRound, onSelect: () => {} },
15
+ { label: "Block sign-in", icon: Ban, onSelect: () => {} },
16
+ { label: "Manage group memberships", icon: UsersRound, onSelect: () => {} },
17
+ { label: "Delete user", icon: Trash2, onSelect: () => {} },
18
+ ],
19
+ },
20
+ } satisfies Meta<typeof Menu>;
21
+
22
+ export default meta;
23
+ type Story = StoryObj<typeof meta>;
24
+
25
+ /** A row's actions. Open it with the button, or focus it and press Enter; arrow keys move between items. */
26
+ export const Default: Story = {};
27
+
28
+ /** Compact, for table rows. */
29
+ export const Small: Story = { args: { size: "sm" } };
30
+
31
+ /** Items can be turned off when they don't apply. */
32
+ export const WithDisabledItem: Story = {
33
+ args: {
34
+ items: [
35
+ { label: "Open profile", icon: SquareArrowOutUpRight, href: "#" },
36
+ { label: "Reset password", icon: KeyRound, onSelect: () => {} },
37
+ { label: "Delete user", icon: Trash2, disabled: true },
38
+ ],
39
+ },
40
+ };
@@ -0,0 +1,104 @@
1
+ <script setup lang="ts">
2
+ import type { Component, HTMLAttributes } from 'vue'
3
+ import { Ellipsis } from '@lucide/vue'
4
+ import {
5
+ DropdownMenuContent,
6
+ DropdownMenuItem,
7
+ DropdownMenuPortal,
8
+ DropdownMenuRoot,
9
+ DropdownMenuTrigger
10
+ } from 'reka-ui'
11
+ import { cn } from '../../lib/cn'
12
+ import Button from '../Button/Button.vue'
13
+ import { popoverContent } from '../Popover/popover'
14
+
15
+ export interface MenuItem {
16
+ label: string
17
+ /** A Lucide (or any) icon component, shown before the label. */
18
+ icon?: Component
19
+ /** Called when it's chosen (click, Enter or Space). */
20
+ onSelect?: () => void
21
+ /** Link with a plain <a href>. */
22
+ href?: string
23
+ /** Link through `linkComponent` (e.g. RouterLink), which receives `to`. */
24
+ to?: unknown
25
+ disabled?: boolean
26
+ }
27
+
28
+ /**
29
+ * More actions behind a "⋯" button, e.g. on each row of a table: Open,
30
+ * Reset password, Delete… Built on Reka UI's DropdownMenu, so it's a proper
31
+ * menu: arrow keys move between items, typing jumps to one, Escape closes
32
+ * it and focus goes back to the button.
33
+ *
34
+ * Items run `onSelect`, or are links (`href`, or `to` through
35
+ * `linkComponent`).
36
+ */
37
+ export interface MenuProps {
38
+ items: MenuItem[]
39
+ /** The button's accessible name, e.g. "Actions for Jo Bloggs". It has no visible text. */
40
+ label: string
41
+ /** The button's size; `sm` in compact tables. */
42
+ size?: 'sm' | 'md'
43
+ /** Component used for items with `to`, e.g. RouterLink or NuxtLink. */
44
+ linkComponent?: string | Component
45
+ class?: HTMLAttributes['class']
46
+ }
47
+
48
+ const props = withDefaults(defineProps<MenuProps>(), {
49
+ size: 'md',
50
+ linkComponent: 'a'
51
+ })
52
+
53
+ function tagFor(item: MenuItem) {
54
+ if (item.to !== undefined) return props.linkComponent
55
+ if (item.href !== undefined) return 'a'
56
+ return 'div'
57
+ }
58
+
59
+ function attrsFor(item: MenuItem) {
60
+ if (item.to !== undefined) return { to: item.to }
61
+ if (item.href !== undefined) return { href: item.href }
62
+ return {}
63
+ }
64
+
65
+ // Like Select's options: 32px rows, 8px either side, tinted like a ghost
66
+ // Button when highlighted.
67
+ const item = [
68
+ 'flex min-h-8 cursor-pointer items-center gap-2 rounded px-2 py-1.5 text-sm text-black no-underline outline-none select-none',
69
+ '[&_svg]:size-4 [&_svg]:shrink-0',
70
+ 'data-highlighted:bg-black/10',
71
+ 'data-disabled:cursor-not-allowed data-disabled:opacity-40'
72
+ ]
73
+ </script>
74
+
75
+ <template>
76
+ <DropdownMenuRoot :modal="false">
77
+ <DropdownMenuTrigger as-child>
78
+ <Button variant="ghost" square :size="size" :aria-label="label" :class="props.class">
79
+ <Ellipsis />
80
+ </Button>
81
+ </DropdownMenuTrigger>
82
+ <DropdownMenuPortal>
83
+ <DropdownMenuContent
84
+ align="end"
85
+ :side-offset="4"
86
+ :collision-padding="8"
87
+ :class="cn(popoverContent, 'min-w-48 p-1')"
88
+ >
89
+ <DropdownMenuItem
90
+ v-for="i in items"
91
+ :key="i.label"
92
+ :as="tagFor(i)"
93
+ v-bind="attrsFor(i)"
94
+ :disabled="i.disabled"
95
+ :class="item"
96
+ @select="i.onSelect?.()"
97
+ >
98
+ <component :is="i.icon" v-if="i.icon" aria-hidden="true" />
99
+ {{ i.label }}
100
+ </DropdownMenuItem>
101
+ </DropdownMenuContent>
102
+ </DropdownMenuPortal>
103
+ </DropdownMenuRoot>
104
+ </template>
@@ -1,5 +1,5 @@
1
1
  import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
- import { Building2, CalendarCog, Layers, UserPlus } from "@lucide/vue";
2
+ import { Building2, CalendarCog, KeyRound, Layers, LockOpen, LogOut, Pencil, Trash2, UserPlus, Users } from "@lucide/vue";
3
3
  import AvatarGroup from "../AvatarGroup/AvatarGroup.vue";
4
4
  import Badge from "../Badge/Badge.vue";
5
5
  import Button from "../Button/Button.vue";
@@ -77,3 +77,35 @@ export const WithPeople: Story = {
77
77
  </PageHeader>`,
78
78
  }),
79
79
  };
80
+
81
+ /**
82
+ * A record's everyday actions in the toolbar under the title, with the main
83
+ * action on the right. Narrow the preview to see the toolbar wrap.
84
+ */
85
+ export const WithToolbar: Story = {
86
+ args: {
87
+ title: "Jo Bloggs",
88
+ description: "jo.bloggs@keston.school",
89
+ breadcrumb: [
90
+ { label: "Users", icon: Users, href: "#" },
91
+ { label: "Jo Bloggs" },
92
+ ],
93
+ toolbar: [
94
+ { label: "Reset password", icon: KeyRound, onSelect: () => {} },
95
+ { label: "Unblock sign-in", icon: LockOpen, onSelect: () => {} },
96
+ { label: "Sign out everywhere", icon: LogOut, onSelect: () => {} },
97
+ { label: "Delete user", icon: Trash2, onSelect: () => {} },
98
+ ],
99
+ },
100
+ render: (args) => ({
101
+ components: { PageHeader, Badge, Button, Pencil },
102
+ setup: () => ({ args }),
103
+ template: `
104
+ <PageHeader v-bind="args">
105
+ <template #badge><Badge>Disabled</Badge></template>
106
+ <template #actions>
107
+ <Button variant="primary"><template #leading><Pencil /></template>Edit user</Button>
108
+ </template>
109
+ </PageHeader>`,
110
+ }),
111
+ };
@@ -2,12 +2,31 @@
2
2
  import type { Component, HTMLAttributes } from 'vue'
3
3
  import { cn } from '../../lib/cn'
4
4
  import Breadcrumb, { type BreadcrumbItem } from '../Breadcrumb/Breadcrumb.vue'
5
+ import Button from '../Button/Button.vue'
6
+
7
+ /** One of the page's everyday actions, in the toolbar under the title. */
8
+ export interface PageHeaderAction {
9
+ label: string
10
+ icon?: Component
11
+ /** Runs on click, e.g. opens a Slideover. */
12
+ onSelect?: () => void
13
+ /** Link with a plain <a href>. */
14
+ href?: string
15
+ /** Link through `linkComponent` (e.g. RouterLink), which receives `to`. */
16
+ to?: unknown
17
+ disabled?: boolean
18
+ }
5
19
 
6
20
  /**
7
21
  * The top of a page: where it is (breadcrumb), what it is (the h1 title, with
8
22
  * an optional status badge and description), and its main actions on the
9
23
  * right. Actions wrap under the title on narrow screens.
10
24
  *
25
+ * `toolbar`: the everyday things people do to what the page is about (e.g.
26
+ * on a user: Reset password, Unblock sign-in, Delete user), as a row of quiet
27
+ * buttons under the title. Keep the one main action (Save, Add…) in the
28
+ * actions slot on the right; the toolbar is for the rest.
29
+ *
11
30
  * Slots: badge (after the title, e.g. a Badge), description (instead of the
12
31
  * prop, for links or formatting), actions (e.g. Buttons), default (anything
13
32
  * under, e.g. an alert or tabs).
@@ -21,16 +40,26 @@ export interface PageHeaderProps {
21
40
  breadcrumb?: BreadcrumbItem[]
22
41
  /** Component used for breadcrumb steps with `to`, e.g. RouterLink. */
23
42
  linkComponent?: string | Component
43
+ /** Everyday actions, in a row under the title. */
44
+ toolbar?: PageHeaderAction[]
24
45
  class?: HTMLAttributes['class']
25
46
  /** Extra classes for the parts. */
26
47
  ui?: {
27
48
  title?: HTMLAttributes['class']
28
49
  description?: HTMLAttributes['class']
29
50
  actions?: HTMLAttributes['class']
51
+ toolbar?: HTMLAttributes['class']
30
52
  }
31
53
  }
32
54
 
33
- const props = defineProps<PageHeaderProps>()
55
+ const props = withDefaults(defineProps<PageHeaderProps>(), { linkComponent: 'a' })
56
+
57
+ // Links render as links, the rest as buttons.
58
+ function as(item: PageHeaderAction) {
59
+ if (item.to !== undefined) return props.linkComponent
60
+ if (item.href !== undefined) return 'a'
61
+ return 'button'
62
+ }
34
63
 
35
64
  defineSlots<{
36
65
  badge?(): unknown
@@ -61,6 +90,28 @@ defineSlots<{
61
90
  </div>
62
91
  </div>
63
92
 
93
+ <!-- Ghost buttons in a white bar, like a Card. -->
94
+ <div
95
+ v-if="toolbar?.length"
96
+ role="group"
97
+ :aria-label="`${title} actions`"
98
+ :class="cn('flex flex-wrap items-center gap-1 rounded-lg border border-black/15 bg-white p-1', ui?.toolbar)"
99
+ >
100
+ <Button
101
+ v-for="item in toolbar"
102
+ :key="item.label"
103
+ :as="as(item)"
104
+ :to="item.to"
105
+ :href="item.href"
106
+ variant="ghost"
107
+ :disabled="item.disabled"
108
+ @click="item.onSelect?.()"
109
+ >
110
+ <template v-if="item.icon" #leading><component :is="item.icon" aria-hidden="true" /></template>
111
+ {{ item.label }}
112
+ </Button>
113
+ </div>
114
+
64
115
  <slot />
65
116
  </header>
66
117
  </template>
@@ -103,6 +103,8 @@ export interface SelectProps {
103
103
  helper?: string
104
104
  /** Show helper text under the label, or behind a `?` icon next to it. */
105
105
  helperPlacement?: 'below' | 'icon'
106
+ /** Keep the label for screen readers only, e.g. in a table of fields with column headings. */
107
+ hideLabel?: boolean
106
108
  /** Error message, e.g. from a Zod schema. Overrides `status` / `statusText`. */
107
109
  errorText?: string
108
110
  /** Colours the field and the status text. */
@@ -430,6 +432,7 @@ const chevron = 'transition-transform duration-150 in-data-[state=open]:rotate-1
430
432
  :label="label"
431
433
  :helper="helper"
432
434
  :helper-placement="helperPlacement"
435
+ :hide-label="hideLabel"
433
436
  :error-text="errorText"
434
437
  :status="status"
435
438
  :status-text="statusText"
@@ -1,5 +1,5 @@
1
1
  import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
- import { ref } from "vue";
2
+ import { defineComponent, h, ref } from "vue";
3
3
  import { Ellipsis, Inbox } from "@lucide/vue";
4
4
  import Badge from "../Badge/Badge.vue";
5
5
  import Button from "../Button/Button.vue";
@@ -37,6 +37,17 @@ const columns: TableColumn<Applicant>[] = [
37
37
  { key: "actions", label: "Actions", hideLabel: true, align: "end" },
38
38
  ];
39
39
 
40
+ // Stands in for RouterLink: renders an <a> for `to` and reports the click
41
+ // instead of navigating, so the stories show where a row would go.
42
+ const opened = ref("");
43
+ const FakeRouterLink = defineComponent({
44
+ props: { to: { type: String, required: true } },
45
+ setup(props, { slots }) {
46
+ return () =>
47
+ h("a", { href: props.to, onClick: (e: MouseEvent) => (e.preventDefault(), (opened.value = props.to)) }, slots.default?.());
48
+ },
49
+ });
50
+
40
51
  const date = (d: Date) => d.toLocaleDateString("en-GB", { day: "numeric", month: "short", year: "numeric" });
41
52
 
42
53
  const meta = {
@@ -210,3 +221,50 @@ export const ManualSort: Story = {
210
221
  </div>`,
211
222
  }),
212
223
  };
224
+
225
+ /**
226
+ * rowLink: each row goes to the applicant's page. The name is a real link,
227
+ * stretched over the row, so the row highlights on hover and a click anywhere
228
+ * on it opens the page; Tab reaches the link (the ring goes round the row).
229
+ * The ⋯ button in the actions column still works on its own. Pass your
230
+ * router's link as `linkComponent` (here a stand-in that shows where it
231
+ * would go); without one the links are plain `<a href>`.
232
+ */
233
+ export const ClickableRows: Story = {
234
+ args: {
235
+ rowLink: (row) => `/applicants/${row.id}`,
236
+ linkComponent: FakeRouterLink,
237
+ },
238
+ render: (args) => ({
239
+ components: { Table, Card, Badge, Button, Ellipsis },
240
+ setup() {
241
+ const pressed = ref("");
242
+ opened.value = "";
243
+ return { args, statusColors, date, opened, pressed };
244
+ },
245
+ template: `
246
+ <div class="flex flex-col gap-3">
247
+ <Card padding="none">
248
+ <Table v-bind="args">
249
+ <template #cell-applied="{ value }">{{ date(value) }}</template>
250
+ <template #cell-score="{ value }">{{ value ?? '—' }}</template>
251
+ <template #cell-status="{ value }"><Badge size="sm" :color="statusColors[value]">{{ value }}</Badge></template>
252
+ <template #cell-actions="{ row }">
253
+ <Button variant="ghost" size="sm" square :aria-label="'More for ' + row.name" @click="pressed = 'More for ' + row.name"><Ellipsis /></Button>
254
+ </template>
255
+ </Table>
256
+ </Card>
257
+ <p class="text-sm">Opened: <code>{{ opened || 'none' }}</code> · Pressed: <code>{{ pressed || 'none' }}</code></p>
258
+ </div>`,
259
+ }),
260
+ };
261
+
262
+ /** Rows whose rowLink returns undefined (here, declined applicants) aren't clickable. */
263
+ export const SomeRowsClickable: Story = {
264
+ args: {
265
+ rowLink: (row) => (row.status === "Declined" ? undefined : `/applicants/${row.id}`),
266
+ linkComponent: FakeRouterLink,
267
+ size: "sm",
268
+ },
269
+ render: ClickableRows.render,
270
+ };