@thekestongroup/ui 0.5.0 → 0.7.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/dist/components/FormField/FormField.vue.d.ts +5 -0
- package/dist/components/Input/Input.vue.d.ts +2 -0
- package/dist/components/InputDate/InputDate.vue.d.ts +2 -0
- package/dist/components/InputNumber/InputNumber.vue.d.ts +2 -0
- package/dist/components/InputPassword/InputPassword.vue.d.ts +2 -0
- package/dist/components/InputRichText/InputRichText.vue.d.ts +2 -0
- package/dist/components/Menu/Menu.vue.d.ts +38 -0
- package/dist/components/PageHeader/PageHeader.vue.d.ts +30 -3
- package/dist/components/Select/Select.vue.d.ts +2 -0
- package/dist/components/Tabs/Tabs.vue.d.ts +42 -0
- package/dist/index.d.ts +5 -1
- package/dist/keston-ui.js +983 -721
- package/package.json +1 -1
- package/src/components/FormField/FormField.vue +7 -2
- package/src/components/Input/Input.stories.ts +21 -0
- package/src/components/Input/Input.vue +3 -0
- package/src/components/InputDate/InputDate.vue +3 -0
- package/src/components/InputNumber/InputNumber.vue +3 -0
- package/src/components/InputPassword/InputPassword.vue +3 -0
- package/src/components/InputRichText/InputRichText.vue +3 -0
- package/src/components/Menu/Menu.stories.ts +40 -0
- package/src/components/Menu/Menu.vue +104 -0
- package/src/components/PageHeader/PageHeader.stories.ts +61 -1
- package/src/components/PageHeader/PageHeader.vue +131 -5
- package/src/components/Select/Select.vue +3 -0
- package/src/components/Tabs/Tabs.stories.ts +47 -0
- package/src/components/Tabs/Tabs.vue +69 -0
- package/src/index.ts +5 -1
package/package.json
CHANGED
|
@@ -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
|
|
|
@@ -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 { Ban, Building2, CalendarCog, KeyRound, Layers, LockOpen, LogOut, Pencil, Trash2, UserPlus, Users, UsersRound, X } 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,63 @@ 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
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Something before the buttons (`toolbar-start`), e.g. how many rows are
|
|
115
|
+
* ticked. Narrow the preview: actions that don't fit move into the "⋯" menu
|
|
116
|
+
* at the end, and come back as it widens.
|
|
117
|
+
*/
|
|
118
|
+
export const ToolbarWithSelection: Story = {
|
|
119
|
+
args: {
|
|
120
|
+
title: "Users",
|
|
121
|
+
description: undefined,
|
|
122
|
+
breadcrumb: undefined,
|
|
123
|
+
toolbar: [
|
|
124
|
+
{ label: "Reset password", icon: KeyRound, onSelect: () => {} },
|
|
125
|
+
{ label: "Change sign-in status", icon: Ban, onSelect: () => {} },
|
|
126
|
+
{ label: "Manage group memberships", icon: UsersRound, onSelect: () => {} },
|
|
127
|
+
{ label: "Delete users", icon: Trash2, onSelect: () => {} },
|
|
128
|
+
{ label: "Clear selection", icon: X, onSelect: () => {} },
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
render: (args) => ({
|
|
132
|
+
components: { PageHeader },
|
|
133
|
+
setup: () => ({ args }),
|
|
134
|
+
template: `
|
|
135
|
+
<PageHeader v-bind="args">
|
|
136
|
+
<template #toolbar-start>2 users selected</template>
|
|
137
|
+
</PageHeader>`,
|
|
138
|
+
}),
|
|
139
|
+
};
|
|
@@ -1,16 +1,39 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import type
|
|
2
|
+
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch, type Component, type 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
|
+
import Menu, { type MenuItem } from '../Menu/Menu.vue'
|
|
7
|
+
|
|
8
|
+
/** One of the page's everyday actions, in the toolbar under the title. */
|
|
9
|
+
export interface PageHeaderAction {
|
|
10
|
+
label: string
|
|
11
|
+
icon?: Component
|
|
12
|
+
/** Runs on click, e.g. opens a Slideover. */
|
|
13
|
+
onSelect?: () => void
|
|
14
|
+
/** Link with a plain <a href>. */
|
|
15
|
+
href?: string
|
|
16
|
+
/** Link through `linkComponent` (e.g. RouterLink), which receives `to`. */
|
|
17
|
+
to?: unknown
|
|
18
|
+
disabled?: boolean
|
|
19
|
+
}
|
|
5
20
|
|
|
6
21
|
/**
|
|
7
22
|
* The top of a page: where it is (breadcrumb), what it is (the h1 title, with
|
|
8
23
|
* an optional status badge and description), and its main actions on the
|
|
9
24
|
* right. Actions wrap under the title on narrow screens.
|
|
10
25
|
*
|
|
26
|
+
* `toolbar`: the everyday things people do to what the page is about (e.g.
|
|
27
|
+
* on a user: Reset password, Unblock sign-in, Delete user), as a row of quiet
|
|
28
|
+
* buttons under the title. Those that don't fit go in a "⋯" Menu at its
|
|
29
|
+
* right-hand end (and come back as it widens). `toolbar-start` and `toolbar-end` slots put
|
|
30
|
+
* something before or after them, e.g. "2 users selected". Keep the one main action (Save, Add…) in the
|
|
31
|
+
* actions slot on the right; the toolbar is for the rest.
|
|
32
|
+
*
|
|
11
33
|
* Slots: badge (after the title, e.g. a Badge), description (instead of the
|
|
12
|
-
* prop, for links or formatting), actions (e.g. Buttons),
|
|
13
|
-
*
|
|
34
|
+
* prop, for links or formatting), actions (e.g. Buttons), toolbar-start and
|
|
35
|
+
* toolbar-end (in the toolbar, before and after its buttons), default
|
|
36
|
+
* (anything under, e.g. an alert or tabs).
|
|
14
37
|
*/
|
|
15
38
|
export interface PageHeaderProps {
|
|
16
39
|
/** The page's name: its h1. */
|
|
@@ -21,23 +44,80 @@ export interface PageHeaderProps {
|
|
|
21
44
|
breadcrumb?: BreadcrumbItem[]
|
|
22
45
|
/** Component used for breadcrumb steps with `to`, e.g. RouterLink. */
|
|
23
46
|
linkComponent?: string | Component
|
|
47
|
+
/** Everyday actions, in a row under the title. */
|
|
48
|
+
toolbar?: PageHeaderAction[]
|
|
24
49
|
class?: HTMLAttributes['class']
|
|
25
50
|
/** Extra classes for the parts. */
|
|
26
51
|
ui?: {
|
|
27
52
|
title?: HTMLAttributes['class']
|
|
28
53
|
description?: HTMLAttributes['class']
|
|
29
54
|
actions?: HTMLAttributes['class']
|
|
55
|
+
toolbar?: HTMLAttributes['class']
|
|
30
56
|
}
|
|
31
57
|
}
|
|
32
58
|
|
|
33
|
-
const props = defineProps<PageHeaderProps>()
|
|
59
|
+
const props = withDefaults(defineProps<PageHeaderProps>(), { linkComponent: 'a' })
|
|
60
|
+
|
|
61
|
+
// Links render as links, the rest as buttons.
|
|
62
|
+
function as(item: PageHeaderAction) {
|
|
63
|
+
if (item.to !== undefined) return props.linkComponent
|
|
64
|
+
if (item.href !== undefined) return 'a'
|
|
65
|
+
return 'button'
|
|
66
|
+
}
|
|
34
67
|
|
|
35
|
-
defineSlots<{
|
|
68
|
+
const slots = defineSlots<{
|
|
36
69
|
badge?(): unknown
|
|
37
70
|
description?(): unknown
|
|
38
71
|
actions?(): unknown
|
|
72
|
+
'toolbar-start'?(): unknown
|
|
73
|
+
'toolbar-end'?(): unknown
|
|
39
74
|
default?(): unknown
|
|
40
75
|
}>()
|
|
76
|
+
|
|
77
|
+
const hasToolbar = computed(() => !!props.toolbar?.length || !!slots['toolbar-start'] || !!slots['toolbar-end'])
|
|
78
|
+
|
|
79
|
+
// ── Toolbar overflow ────────────────────────────────────────────────────────
|
|
80
|
+
// A hidden copy of every button is measured; as many as fit are shown, and
|
|
81
|
+
// the rest go in the "⋯" Menu (whose width is kept free for it).
|
|
82
|
+
const fitArea = ref<HTMLElement>()
|
|
83
|
+
const measure = ref<HTMLElement>()
|
|
84
|
+
const shown = ref(Infinity)
|
|
85
|
+
|
|
86
|
+
function fit() {
|
|
87
|
+
const area = fitArea.value
|
|
88
|
+
const copy = measure.value
|
|
89
|
+
const items = props.toolbar ?? []
|
|
90
|
+
if (!area || !copy || !items.length) return
|
|
91
|
+
const buttons = Array.from(copy.children) as HTMLElement[]
|
|
92
|
+
const more = buttons.pop()! // the ⋯ button, last in the copy
|
|
93
|
+
const gap = parseFloat(getComputedStyle(copy).columnGap) || 0
|
|
94
|
+
const widths = buttons.map((b) => b.getBoundingClientRect().width)
|
|
95
|
+
const available = area.clientWidth
|
|
96
|
+
const all = widths.reduce((sum, w) => sum + w, 0) + gap * Math.max(widths.length - 1, 0)
|
|
97
|
+
if (all <= available) {
|
|
98
|
+
shown.value = items.length
|
|
99
|
+
return
|
|
100
|
+
}
|
|
101
|
+
let used = more.getBoundingClientRect().width
|
|
102
|
+
let n = 0
|
|
103
|
+
while (n < widths.length && used + gap + widths[n]! <= available) used += gap + widths[n++]!
|
|
104
|
+
shown.value = n
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let observer: ResizeObserver | undefined
|
|
108
|
+
onMounted(() => {
|
|
109
|
+
observer = new ResizeObserver(() => fit())
|
|
110
|
+
if (fitArea.value) observer.observe(fitArea.value)
|
|
111
|
+
fit()
|
|
112
|
+
})
|
|
113
|
+
onBeforeUnmount(() => observer?.disconnect())
|
|
114
|
+
watch(
|
|
115
|
+
() => props.toolbar?.map((i) => `${i.label}${i.disabled ? '-' : ''}`).join('|'),
|
|
116
|
+
() => nextTick(fit),
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
const visible = computed(() => (props.toolbar ?? []).slice(0, shown.value))
|
|
120
|
+
const overflow = computed<MenuItem[]>(() => (props.toolbar ?? []).slice(shown.value))
|
|
41
121
|
</script>
|
|
42
122
|
|
|
43
123
|
<template>
|
|
@@ -61,6 +141,52 @@ defineSlots<{
|
|
|
61
141
|
</div>
|
|
62
142
|
</div>
|
|
63
143
|
|
|
144
|
+
<!-- Ghost buttons in a white bar, like a Card; those that don't fit go
|
|
145
|
+
in the ⋯ Menu at the end. -->
|
|
146
|
+
<div
|
|
147
|
+
v-if="hasToolbar"
|
|
148
|
+
role="group"
|
|
149
|
+
:aria-label="`${title} actions`"
|
|
150
|
+
:class="cn('flex items-center gap-1 rounded-lg border border-black/15 bg-white p-1', ui?.toolbar)"
|
|
151
|
+
>
|
|
152
|
+
<!-- Text here reads as the toolbar's own: bold, spaced like a button. -->
|
|
153
|
+
<div v-if="$slots['toolbar-start']" class="flex shrink-0 items-center gap-2 px-3 text-sm font-bold" aria-live="polite">
|
|
154
|
+
<slot name="toolbar-start" />
|
|
155
|
+
</div>
|
|
156
|
+
<div ref="fitArea" class="relative flex min-w-0 flex-1 items-center gap-1">
|
|
157
|
+
<Button
|
|
158
|
+
v-for="item in visible"
|
|
159
|
+
:key="item.label"
|
|
160
|
+
:as="as(item)"
|
|
161
|
+
:to="item.to"
|
|
162
|
+
:href="item.href"
|
|
163
|
+
variant="ghost"
|
|
164
|
+
:disabled="item.disabled"
|
|
165
|
+
class="shrink-0"
|
|
166
|
+
@click="item.onSelect?.()"
|
|
167
|
+
>
|
|
168
|
+
<template v-if="item.icon" #leading><component :is="item.icon" aria-hidden="true" /></template>
|
|
169
|
+
{{ item.label }}
|
|
170
|
+
</Button>
|
|
171
|
+
<!-- Always at the right-hand end. -->
|
|
172
|
+
<Menu v-if="overflow.length" :items="overflow" label="More actions" :link-component="linkComponent" class="ml-auto shrink-0" />
|
|
173
|
+
|
|
174
|
+
<!-- For measuring only: every button, and the ⋯ one, at full width. -->
|
|
175
|
+
<div aria-hidden="true" inert class="invisible absolute top-0 left-0 size-0 overflow-hidden">
|
|
176
|
+
<div ref="measure" class="flex w-max gap-1">
|
|
177
|
+
<Button v-for="item in toolbar" :key="item.label" variant="ghost" tabindex="-1" class="shrink-0">
|
|
178
|
+
<template v-if="item.icon" #leading><component :is="item.icon" /></template>
|
|
179
|
+
{{ item.label }}
|
|
180
|
+
</Button>
|
|
181
|
+
<Button variant="ghost" square tabindex="-1" class="shrink-0"><span /></Button>
|
|
182
|
+
</div>
|
|
183
|
+
</div>
|
|
184
|
+
</div>
|
|
185
|
+
<div v-if="$slots['toolbar-end']" class="flex shrink-0 items-center gap-2 px-3 text-sm">
|
|
186
|
+
<slot name="toolbar-end" />
|
|
187
|
+
</div>
|
|
188
|
+
</div>
|
|
189
|
+
|
|
64
190
|
<slot />
|
|
65
191
|
</header>
|
|
66
192
|
</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"
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
|
2
|
+
import { AppWindow, UserRound } from "@lucide/vue";
|
|
3
|
+
import { ref } from "vue";
|
|
4
|
+
import Card from "../Card/Card.vue";
|
|
5
|
+
import Tabs from "./Tabs.vue";
|
|
6
|
+
|
|
7
|
+
const meta = {
|
|
8
|
+
title: "Components/Navigation/Tabs",
|
|
9
|
+
component: Tabs,
|
|
10
|
+
tags: ["autodocs"],
|
|
11
|
+
parameters: { layout: "padded" },
|
|
12
|
+
args: {
|
|
13
|
+
label: "User details",
|
|
14
|
+
tabs: [
|
|
15
|
+
{ value: "account", label: "Account", icon: UserRound },
|
|
16
|
+
{ value: "licences", label: "Licences & Apps", icon: AppWindow },
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
render: (args) => ({
|
|
20
|
+
components: { Tabs, Card },
|
|
21
|
+
setup: () => ({ args, tab: ref("account") }),
|
|
22
|
+
template: `
|
|
23
|
+
<Tabs v-bind="args" v-model="tab">
|
|
24
|
+
<template #account><Card title="Profile">Name, email, password and MFA.</Card></template>
|
|
25
|
+
<template #licences><Card title="Licences">Keston Work, and which apps they have.</Card></template>
|
|
26
|
+
</Tabs>`,
|
|
27
|
+
}),
|
|
28
|
+
} satisfies Meta<typeof Tabs>;
|
|
29
|
+
|
|
30
|
+
export default meta;
|
|
31
|
+
type Story = StoryObj<typeof meta>;
|
|
32
|
+
|
|
33
|
+
/** A user's page: Account, and Licences & Apps. Arrow keys move between tabs. */
|
|
34
|
+
export const Default: Story = {};
|
|
35
|
+
|
|
36
|
+
/** Without icons, with more tabs, one turned off. Narrow the preview to see the list scroll. */
|
|
37
|
+
export const Plain: Story = {
|
|
38
|
+
args: {
|
|
39
|
+
label: "Organisation",
|
|
40
|
+
tabs: [
|
|
41
|
+
{ value: "account", label: "Overview" },
|
|
42
|
+
{ value: "licences", label: "Users" },
|
|
43
|
+
{ value: "groups", label: "Groups" },
|
|
44
|
+
{ value: "billing", label: "Billing", disabled: true },
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
};
|