@thekestongroup/ui 0.5.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.
- 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 +23 -1
- 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 +749 -559
- 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 +33 -1
- package/src/components/PageHeader/PageHeader.vue +52 -1
- 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 { 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"
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { Component, HTMLAttributes } from 'vue'
|
|
3
|
+
import { TabsContent, TabsIndicator, TabsList, TabsRoot, TabsTrigger } from 'reka-ui'
|
|
4
|
+
import { cn } from '../../lib/cn'
|
|
5
|
+
|
|
6
|
+
export interface Tab {
|
|
7
|
+
/** Identifies the tab: v-model's value, and the name of its content slot. */
|
|
8
|
+
value: string
|
|
9
|
+
label: string
|
|
10
|
+
/** A Lucide (or any) icon component, shown before the label. */
|
|
11
|
+
icon?: Component
|
|
12
|
+
disabled?: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Sections of one page, one shown at a time, e.g. a user's Account and
|
|
17
|
+
* Licences & Apps. Built on Reka UI's Tabs: a tab list (arrow keys move
|
|
18
|
+
* between tabs, Home / End jump), each tab's content in a slot named after
|
|
19
|
+
* its value. Use v-model to know or set the open tab (e.g. to keep it in
|
|
20
|
+
* the URL).
|
|
21
|
+
*/
|
|
22
|
+
export interface TabsProps {
|
|
23
|
+
tabs: Tab[]
|
|
24
|
+
/** The tab list's accessible name, e.g. "User details". */
|
|
25
|
+
label: string
|
|
26
|
+
class?: HTMLAttributes['class']
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const props = defineProps<TabsProps>()
|
|
30
|
+
/** The open tab's value. Defaults to the first tab. */
|
|
31
|
+
const model = defineModel<string>()
|
|
32
|
+
|
|
33
|
+
defineSlots<Record<string, () => unknown>>()
|
|
34
|
+
|
|
35
|
+
// Like Sidebar's items: muted until hovered or chosen; the chosen one is
|
|
36
|
+
// primary, with a bar under it that slides between tabs.
|
|
37
|
+
const trigger = [
|
|
38
|
+
'relative inline-flex h-10 items-center gap-2 px-3 text-sm whitespace-nowrap text-black/65 outline-none',
|
|
39
|
+
'[&_svg]:size-4 [&_svg]:shrink-0',
|
|
40
|
+
'not-data-disabled:hover:text-black',
|
|
41
|
+
'data-[state=active]:font-bold data-[state=active]:text-primary',
|
|
42
|
+
'focus-visible:rounded focus-visible:ring-2 focus-visible:ring-primary',
|
|
43
|
+
'data-disabled:cursor-not-allowed data-disabled:opacity-40'
|
|
44
|
+
]
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<template>
|
|
48
|
+
<TabsRoot
|
|
49
|
+
:model-value="model ?? tabs[0]?.value"
|
|
50
|
+
:class="cn('flex flex-col gap-6', props.class)"
|
|
51
|
+
@update:model-value="model = String($event)"
|
|
52
|
+
>
|
|
53
|
+
<!-- Scrolls sideways on narrow screens rather than wrapping. -->
|
|
54
|
+
<TabsList :aria-label="label" class="relative flex overflow-x-auto overflow-y-hidden border-b border-black/15">
|
|
55
|
+
<TabsTrigger v-for="t in tabs" :key="t.value" :value="t.value" :disabled="t.disabled" :class="trigger">
|
|
56
|
+
<component :is="t.icon" v-if="t.icon" aria-hidden="true" />
|
|
57
|
+
{{ t.label }}
|
|
58
|
+
</TabsTrigger>
|
|
59
|
+
<TabsIndicator
|
|
60
|
+
class="absolute bottom-0 left-0 h-0.5 w-(--reka-tabs-indicator-size) translate-x-(--reka-tabs-indicator-position) rounded-full transition-[width,translate] duration-200 motion-reduce:transition-none"
|
|
61
|
+
>
|
|
62
|
+
<span class="block size-full rounded-full bg-primary" />
|
|
63
|
+
</TabsIndicator>
|
|
64
|
+
</TabsList>
|
|
65
|
+
<TabsContent v-for="t in tabs" :key="t.value" :value="t.value" class="outline-none">
|
|
66
|
+
<slot :name="t.value" />
|
|
67
|
+
</TabsContent>
|
|
68
|
+
</TabsRoot>
|
|
69
|
+
</template>
|
package/src/index.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type { AppShellProps } from './components/AppShell/AppShell.vue'
|
|
|
11
11
|
export { default as Header } from './components/Header/Header.vue'
|
|
12
12
|
export type { HeaderProps, HeaderUser, HeaderUserAction } from './components/Header/Header.vue'
|
|
13
13
|
export { default as PageHeader } from './components/PageHeader/PageHeader.vue'
|
|
14
|
-
export type { PageHeaderProps } from './components/PageHeader/PageHeader.vue'
|
|
14
|
+
export type { PageHeaderAction, PageHeaderProps } from './components/PageHeader/PageHeader.vue'
|
|
15
15
|
|
|
16
16
|
// Element
|
|
17
17
|
export { default as Avatar } from './components/Avatar/Avatar.vue'
|
|
@@ -89,6 +89,10 @@ export type { LinkProps } from './components/Link/Link.vue'
|
|
|
89
89
|
// Overlay
|
|
90
90
|
export { default as Popover } from './components/Popover/Popover.vue'
|
|
91
91
|
export type { PopoverProps } from './components/Popover/Popover.vue'
|
|
92
|
+
export { default as Menu } from './components/Menu/Menu.vue'
|
|
93
|
+
export type { MenuItem, MenuProps } from './components/Menu/Menu.vue'
|
|
94
|
+
export { default as Tabs } from './components/Tabs/Tabs.vue'
|
|
95
|
+
export type { Tab, TabsProps } from './components/Tabs/Tabs.vue'
|
|
92
96
|
export { default as Slideover } from './components/Slideover/Slideover.vue'
|
|
93
97
|
export type { SlideoverProps } from './components/Slideover/Slideover.vue'
|
|
94
98
|
export { default as Tooltip } from './components/Tooltip/Tooltip.vue'
|