@thekestongroup/ui 0.3.0 → 0.5.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 +18 -9
- package/dist/components/AppShell/AppShell.vue.d.ts +4 -2
- package/dist/components/EmptyState/EmptyState.vue.d.ts +55 -0
- package/dist/components/Header/Header.vue.d.ts +9 -1
- package/dist/components/Sidebar/Sidebar.vue.d.ts +1 -1
- package/dist/components/Table/Table.vue.d.ts +14 -1
- package/dist/index.d.ts +2 -0
- package/dist/keston-ui.js +260 -156
- package/package.json +5 -1
- package/src/components/AppShell/AppShell.stories.ts +5 -0
- package/src/components/AppShell/AppShell.vue +16 -3
- package/src/components/EmptyState/EmptyState.stories.ts +99 -0
- package/src/components/EmptyState/EmptyState.vue +87 -0
- package/src/components/Header/Header.stories.ts +9 -0
- package/src/components/Header/Header.vue +27 -4
- package/src/components/Notification/NotificationPane.vue +8 -9
- package/src/components/Table/Table.stories.ts +73 -9
- package/src/components/Table/Table.vue +61 -5
- package/src/index.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thekestongroup/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Keston UI — Vue 3 + Reka UI + Tailwind CSS component library",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"repository": {
|
|
@@ -29,6 +29,9 @@
|
|
|
29
29
|
"build": "vue-tsc -p tsconfig.app.json --noEmit && vite build",
|
|
30
30
|
"typecheck": "vue-tsc -b",
|
|
31
31
|
"build-storybook": "storybook build",
|
|
32
|
+
"docs:dev": "vitepress dev site",
|
|
33
|
+
"docs:build": "vitepress build site && storybook build --quiet -o site/.vitepress/dist/storybook",
|
|
34
|
+
"docs:preview": "vitepress preview site",
|
|
32
35
|
"new": "node scripts/new-component.mjs",
|
|
33
36
|
"changeset": "changeset",
|
|
34
37
|
"test": "vitest run",
|
|
@@ -77,6 +80,7 @@
|
|
|
77
80
|
"typescript": "^6.0.3",
|
|
78
81
|
"vite": "^8.3.5",
|
|
79
82
|
"vite-plugin-dts": "^5.1.2",
|
|
83
|
+
"vitepress": "1.6.4",
|
|
80
84
|
"vitest": "^5.1.0",
|
|
81
85
|
"vue": "^3.5.44",
|
|
82
86
|
"vue-tsc": "^3.3.14"
|
|
@@ -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"
|
|
@@ -185,7 +189,16 @@ const sidebarId = `${uid}-sidebar`
|
|
|
185
189
|
v-model:open="menuOpen"
|
|
186
190
|
side="left"
|
|
187
191
|
:title="title || 'Menu'"
|
|
188
|
-
:ui="{
|
|
192
|
+
:ui="{
|
|
193
|
+
content: 'max-w-72',
|
|
194
|
+
// The header is a column (it also holds a Progress for steps), so
|
|
195
|
+
// justify-center centres the title row vertically in the 48px bar,
|
|
196
|
+
// and the row keeps the full width: title left, × right. 20px in,
|
|
197
|
+
// so the title lines up with the menu items' icons below it.
|
|
198
|
+
header: 'h-12 justify-center px-5 py-0',
|
|
199
|
+
title: 'text-base font-bold',
|
|
200
|
+
body: 'flex p-0'
|
|
201
|
+
}"
|
|
189
202
|
>
|
|
190
203
|
<template #body>
|
|
191
204
|
<Sidebar
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
|
2
|
+
import { AppWindow, BellOff, Inbox, SearchX, Users } from "@lucide/vue";
|
|
3
|
+
import Button from "../Button/Button.vue";
|
|
4
|
+
import Card from "../Card/Card.vue";
|
|
5
|
+
import EmptyState from "./EmptyState.vue";
|
|
6
|
+
|
|
7
|
+
const meta = {
|
|
8
|
+
title: "Components/Data/EmptyState",
|
|
9
|
+
component: EmptyState,
|
|
10
|
+
tags: ["autodocs"],
|
|
11
|
+
argTypes: {
|
|
12
|
+
size: { options: ["sm", "md"], control: { type: "inline-radio" } },
|
|
13
|
+
headingLevel: { options: [undefined, 2, 3, 4], control: { type: "select" } },
|
|
14
|
+
icon: { control: false },
|
|
15
|
+
},
|
|
16
|
+
args: {
|
|
17
|
+
title: "No connected apps",
|
|
18
|
+
description: "When you sign in to an app with your Keston account, it'll show here and you can remove its access.",
|
|
19
|
+
icon: AppWindow,
|
|
20
|
+
size: "md",
|
|
21
|
+
},
|
|
22
|
+
render: (args) => ({
|
|
23
|
+
components: { EmptyState, Card },
|
|
24
|
+
setup: () => ({ args }),
|
|
25
|
+
template: `<Card><EmptyState v-bind="args" /></Card>`,
|
|
26
|
+
}),
|
|
27
|
+
} satisfies Meta<typeof EmptyState>;
|
|
28
|
+
|
|
29
|
+
export default meta;
|
|
30
|
+
type Story = StoryObj<typeof meta>;
|
|
31
|
+
|
|
32
|
+
/** Playground: use the controls below. In a Card, as on a page with nothing in it yet. */
|
|
33
|
+
export const Default: Story = {};
|
|
34
|
+
|
|
35
|
+
/** With what to do next, in the actions slot. */
|
|
36
|
+
export const WithAction: Story = {
|
|
37
|
+
args: {
|
|
38
|
+
title: "No students in this class",
|
|
39
|
+
description: "Add students one by one, or import them from a spreadsheet.",
|
|
40
|
+
icon: Users,
|
|
41
|
+
},
|
|
42
|
+
render: (args) => ({
|
|
43
|
+
components: { EmptyState, Card, Button },
|
|
44
|
+
setup: () => ({ args }),
|
|
45
|
+
template: `
|
|
46
|
+
<Card>
|
|
47
|
+
<EmptyState v-bind="args">
|
|
48
|
+
<template #actions>
|
|
49
|
+
<Button>Import</Button>
|
|
50
|
+
<Button variant="primary">Add a student</Button>
|
|
51
|
+
</template>
|
|
52
|
+
</EmptyState>
|
|
53
|
+
</Card>`,
|
|
54
|
+
}),
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** Nothing matched a search or filter: say so, and offer a way back. */
|
|
58
|
+
export const NoResults: Story = {
|
|
59
|
+
args: {
|
|
60
|
+
title: "No results for “Smyth”",
|
|
61
|
+
description: "Check the spelling, or search by student number instead.",
|
|
62
|
+
icon: SearchX,
|
|
63
|
+
},
|
|
64
|
+
render: (args) => ({
|
|
65
|
+
components: { EmptyState, Card, Button },
|
|
66
|
+
setup: () => ({ args }),
|
|
67
|
+
template: `
|
|
68
|
+
<Card>
|
|
69
|
+
<EmptyState v-bind="args">
|
|
70
|
+
<template #actions><Button>Clear search</Button></template>
|
|
71
|
+
</EmptyState>
|
|
72
|
+
</Card>`,
|
|
73
|
+
}),
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/** Both sizes: md for a Card or page, sm for panels, popovers and tables. */
|
|
77
|
+
export const Sizes: Story = {
|
|
78
|
+
render: () => ({
|
|
79
|
+
components: { EmptyState, Card },
|
|
80
|
+
setup: () => ({ Inbox, BellOff }),
|
|
81
|
+
template: `
|
|
82
|
+
<div class="grid gap-4 sm:grid-cols-2">
|
|
83
|
+
<Card title="md">
|
|
84
|
+
<EmptyState :icon="Inbox" title="No messages" description="Messages from families show here." />
|
|
85
|
+
</Card>
|
|
86
|
+
<Card title="sm">
|
|
87
|
+
<EmptyState size="sm" :icon="BellOff" description="You're all caught up." />
|
|
88
|
+
</Card>
|
|
89
|
+
</div>`,
|
|
90
|
+
}),
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Filling a page's main area: give the title a heading level so it's in the
|
|
95
|
+
* page outline (screen readers can jump to it).
|
|
96
|
+
*/
|
|
97
|
+
export const AsHeading: Story = {
|
|
98
|
+
args: { headingLevel: 2 },
|
|
99
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { Component, HTMLAttributes } from 'vue'
|
|
3
|
+
import { cn } from '../../lib/cn'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* What to show where a list, table or panel has nothing in it yet: an icon,
|
|
7
|
+
* a short title, a line of explanation, and optionally what to do about it
|
|
8
|
+
* (e.g. a Button). "No connected apps", "You're all caught up", "No
|
|
9
|
+
* applications yet".
|
|
10
|
+
*
|
|
11
|
+
* Slots: title, description, actions (under the text, e.g. a Button),
|
|
12
|
+
* default (anything else, under the description). To animate the icon, pass
|
|
13
|
+
* classes in `ui.icon`.
|
|
14
|
+
*/
|
|
15
|
+
export interface EmptyStateProps {
|
|
16
|
+
/** Short and specific, e.g. "No connected apps". */
|
|
17
|
+
title?: string
|
|
18
|
+
/** What this space is for, or what to do next. */
|
|
19
|
+
description?: string
|
|
20
|
+
/** A Lucide (or any) icon component, shown above the title. */
|
|
21
|
+
icon?: Component
|
|
22
|
+
/**
|
|
23
|
+
* Make the title a heading, at this level, to fit the page outline (e.g. 2
|
|
24
|
+
* when it fills a page's main area). Without it the title is plain text,
|
|
25
|
+
* as in a panel or table that already has a heading.
|
|
26
|
+
*/
|
|
27
|
+
headingLevel?: 2 | 3 | 4
|
|
28
|
+
/**
|
|
29
|
+
* - sm: compact, for panels, popovers and tables.
|
|
30
|
+
* - md (default): for a Card or a page's main area.
|
|
31
|
+
*/
|
|
32
|
+
size?: 'sm' | 'md'
|
|
33
|
+
class?: HTMLAttributes['class']
|
|
34
|
+
/** Extra classes for the parts. */
|
|
35
|
+
ui?: {
|
|
36
|
+
icon?: HTMLAttributes['class']
|
|
37
|
+
title?: HTMLAttributes['class']
|
|
38
|
+
description?: HTMLAttributes['class']
|
|
39
|
+
actions?: HTMLAttributes['class']
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const props = withDefaults(defineProps<EmptyStateProps>(), {
|
|
44
|
+
size: 'md'
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
defineSlots<{
|
|
48
|
+
default?(): unknown
|
|
49
|
+
title?(): unknown
|
|
50
|
+
description?(): unknown
|
|
51
|
+
actions?(): unknown
|
|
52
|
+
}>()
|
|
53
|
+
|
|
54
|
+
const sizes = {
|
|
55
|
+
sm: { root: 'gap-2 px-4 py-10', icon: 'size-6', title: 'text-sm', description: 'text-sm' },
|
|
56
|
+
md: { root: 'gap-2 px-4 py-12', icon: 'size-8', title: 'text-base', description: 'text-sm' }
|
|
57
|
+
} as const
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<template>
|
|
61
|
+
<div :class="cn('flex flex-col items-center text-center', sizes[size].root, props.class)">
|
|
62
|
+
<div v-if="icon" :class="cn('flex text-black/45', size === 'md' && 'mb-1', ui?.icon)" aria-hidden="true">
|
|
63
|
+
<component :is="icon" :class="sizes[size].icon" />
|
|
64
|
+
</div>
|
|
65
|
+
|
|
66
|
+
<component
|
|
67
|
+
:is="headingLevel ? `h${headingLevel}` : 'p'"
|
|
68
|
+
v-if="$slots.title || title"
|
|
69
|
+
:class="cn('font-bold text-black', sizes[size].title, ui?.title)"
|
|
70
|
+
>
|
|
71
|
+
<slot name="title">{{ title }}</slot>
|
|
72
|
+
</component>
|
|
73
|
+
|
|
74
|
+
<p
|
|
75
|
+
v-if="$slots.description || description"
|
|
76
|
+
:class="cn('max-w-sm text-black/65', sizes[size].description, ui?.description)"
|
|
77
|
+
>
|
|
78
|
+
<slot name="description">{{ description }}</slot>
|
|
79
|
+
</p>
|
|
80
|
+
|
|
81
|
+
<slot />
|
|
82
|
+
|
|
83
|
+
<div v-if="$slots.actions" :class="cn('mt-2 flex flex-wrap justify-center gap-2', ui?.actions)">
|
|
84
|
+
<slot name="actions" />
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
</template>
|
|
@@ -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
|
-
<
|
|
172
|
+
<component
|
|
173
|
+
:is="titleLink ? linkComponent : 'span'"
|
|
152
174
|
v-if="title || $slots.title"
|
|
153
|
-
|
|
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
|
-
</
|
|
179
|
+
</component>
|
|
157
180
|
|
|
158
181
|
<div :class="cn('flex min-w-0 flex-1 items-center', ui?.middle)">
|
|
159
182
|
<slot />
|
|
@@ -3,6 +3,7 @@ import { computed, nextTick, ref, useId, watch, type HTMLAttributes } from 'vue'
|
|
|
3
3
|
import { Bell, BellOff } from '@lucide/vue'
|
|
4
4
|
import { cn } from '../../lib/cn'
|
|
5
5
|
import Button from '../Button/Button.vue'
|
|
6
|
+
import EmptyState from '../EmptyState/EmptyState.vue'
|
|
6
7
|
import Popover from '../Popover/Popover.vue'
|
|
7
8
|
import Notification from './Notification.vue'
|
|
8
9
|
import { useNotifications, type Notifications } from './notifications'
|
|
@@ -171,16 +172,14 @@ async function finishClear() {
|
|
|
171
172
|
</li>
|
|
172
173
|
</ul>
|
|
173
174
|
|
|
174
|
-
<
|
|
175
|
+
<EmptyState
|
|
175
176
|
v-else
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
{{ emptyText }}
|
|
183
|
-
</div>
|
|
177
|
+
size="sm"
|
|
178
|
+
:icon="BellOff"
|
|
179
|
+
:description="emptyText"
|
|
180
|
+
:class="cn(emptied && 'motion-safe:animate-empty-in')"
|
|
181
|
+
:ui="{ icon: cn('origin-top', emptied && 'motion-safe:animate-bell-wobble') }"
|
|
182
|
+
/>
|
|
184
183
|
</section>
|
|
185
184
|
</template>
|
|
186
185
|
</Popover>
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
|
2
|
-
import { ref } from "vue";
|
|
3
|
-
import { Ellipsis } from "@lucide/vue";
|
|
2
|
+
import { defineComponent, h, ref } from "vue";
|
|
3
|
+
import { Ellipsis, Inbox } from "@lucide/vue";
|
|
4
4
|
import Badge from "../Badge/Badge.vue";
|
|
5
5
|
import Button from "../Button/Button.vue";
|
|
6
6
|
import Card from "../Card/Card.vue";
|
|
7
|
+
import EmptyState from "../EmptyState/EmptyState.vue";
|
|
7
8
|
import Table, { type TableProps } from "./Table.vue";
|
|
8
9
|
import type { TableColumn, TableSort } from "./table";
|
|
9
10
|
|
|
@@ -36,6 +37,17 @@ const columns: TableColumn<Applicant>[] = [
|
|
|
36
37
|
{ key: "actions", label: "Actions", hideLabel: true, align: "end" },
|
|
37
38
|
];
|
|
38
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
|
+
|
|
39
51
|
const date = (d: Date) => d.toLocaleDateString("en-GB", { day: "numeric", month: "short", year: "numeric" });
|
|
40
52
|
|
|
41
53
|
const meta = {
|
|
@@ -162,20 +174,25 @@ export const StickyHeader: Story = {
|
|
|
162
174
|
},
|
|
163
175
|
};
|
|
164
176
|
|
|
165
|
-
/** No rows yet, with
|
|
177
|
+
/** No rows yet: an EmptyState in the empty slot, with what to do next. */
|
|
166
178
|
export const Empty: Story = {
|
|
167
179
|
args: { rows: [] },
|
|
168
180
|
render: (args) => ({
|
|
169
|
-
components: { Table, Card, Button },
|
|
170
|
-
setup: () => ({ args }),
|
|
181
|
+
components: { Table, Card, Button, EmptyState },
|
|
182
|
+
setup: () => ({ args, Inbox }),
|
|
171
183
|
template: `
|
|
172
184
|
<Card padding="none">
|
|
173
185
|
<Table v-bind="args">
|
|
174
186
|
<template #empty>
|
|
175
|
-
<
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
187
|
+
<EmptyState
|
|
188
|
+
size="sm"
|
|
189
|
+
:icon="Inbox"
|
|
190
|
+
title="No applications yet"
|
|
191
|
+
description="Applications appear here as families send them."
|
|
192
|
+
class="p-0"
|
|
193
|
+
>
|
|
194
|
+
<template #actions><Button size="sm">Share the application form</Button></template>
|
|
195
|
+
</EmptyState>
|
|
179
196
|
</template>
|
|
180
197
|
</Table>
|
|
181
198
|
</Card>`,
|
|
@@ -204,3 +221,50 @@ export const ManualSort: Story = {
|
|
|
204
221
|
</div>`,
|
|
205
222
|
}),
|
|
206
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
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<script setup lang="ts" generic="Row extends Record<string, any>">
|
|
2
|
-
import { computed, onBeforeUnmount, onMounted, ref, useId, type HTMLAttributes } from 'vue'
|
|
2
|
+
import { computed, onBeforeUnmount, onMounted, ref, useId, type Component, type HTMLAttributes } from 'vue'
|
|
3
3
|
import { ArrowDown, ArrowUp, ChevronsUpDown } from '@lucide/vue'
|
|
4
4
|
import { cn } from '../../lib/cn'
|
|
5
|
+
import EmptyState from '../EmptyState/EmptyState.vue'
|
|
5
6
|
import Spinner from '../Spinner/Spinner.vue'
|
|
6
7
|
import { nextSort, sortRows, type TableColumn, type TableSort } from './table'
|
|
7
8
|
|
|
@@ -18,6 +19,11 @@ import { nextSort, sortRows, type TableColumn, type TableSort } from './table'
|
|
|
18
19
|
* `manualSort` it only reports the sort (`v-model:sort`) so you can sort on
|
|
19
20
|
* the server.
|
|
20
21
|
*
|
|
22
|
+
* Clickable rows: `rowLink` gives each row a page to go to. The row-header
|
|
23
|
+
* cell (or the first column) becomes a real link, stretched over the whole
|
|
24
|
+
* row, so the row highlights on hover and a click anywhere on it follows the
|
|
25
|
+
* link. Buttons and links in other cells still work on their own.
|
|
26
|
+
*
|
|
21
27
|
* Slots: cell-{key}, header-{key}, empty, footer (rows for a `<tfoot>`,
|
|
22
28
|
* e.g. totals), caption.
|
|
23
29
|
*/
|
|
@@ -42,6 +48,14 @@ export interface TableProps<Row = Record<string, any>> {
|
|
|
42
48
|
stickyHeader?: boolean
|
|
43
49
|
/** Don't sort the rows: just update `sort`, e.g. to sort on the server. */
|
|
44
50
|
manualSort?: boolean
|
|
51
|
+
/**
|
|
52
|
+
* Where each row goes when clicked: passed as `to` to `linkComponent`
|
|
53
|
+
* (e.g. a route), or as `href` without one. Return undefined for rows that
|
|
54
|
+
* don't go anywhere.
|
|
55
|
+
*/
|
|
56
|
+
rowLink?: (row: Row, index: number) => unknown
|
|
57
|
+
/** Component for row links, e.g. RouterLink. It receives `to`. Default a plain `<a href>`. */
|
|
58
|
+
linkComponent?: string | Component
|
|
45
59
|
class?: HTMLAttributes['class']
|
|
46
60
|
ui?: {
|
|
47
61
|
table?: HTMLAttributes['class']
|
|
@@ -52,7 +66,8 @@ export interface TableProps<Row = Record<string, any>> {
|
|
|
52
66
|
|
|
53
67
|
const props = withDefaults(defineProps<TableProps<Row>>(), {
|
|
54
68
|
emptyText: 'Nothing to show.',
|
|
55
|
-
size: 'md'
|
|
69
|
+
size: 'md',
|
|
70
|
+
linkComponent: 'a'
|
|
56
71
|
})
|
|
57
72
|
|
|
58
73
|
const sort = defineModel<TableSort | null>('sort', { default: null })
|
|
@@ -85,6 +100,30 @@ function ariaSort(column: TableColumn<Row>) {
|
|
|
85
100
|
return sort.value.direction === 'asc' ? 'ascending' : 'descending'
|
|
86
101
|
}
|
|
87
102
|
|
|
103
|
+
// The column whose cell holds the row's link: the row header, else the first.
|
|
104
|
+
const linkColumn = computed(() => (props.columns.find((c) => c.rowHeader) ?? props.columns[0])?.key)
|
|
105
|
+
|
|
106
|
+
function linkFor(row: Row, index: number) {
|
|
107
|
+
const target = props.rowLink?.(row, index)
|
|
108
|
+
if (target === undefined || target === null || target === '') return undefined
|
|
109
|
+
return props.linkComponent === 'a' ? { href: target as string } : { to: target }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// The link's ::after covers the row (the row is `relative`), so a click
|
|
113
|
+
// anywhere follows it. Controls in other cells are lifted above it, so they
|
|
114
|
+
// still get their own clicks. The focus ring is drawn on the ::after, round
|
|
115
|
+
// the whole row, just inside its edge.
|
|
116
|
+
const rowLinkClass = [
|
|
117
|
+
'text-inherit no-underline outline-none group-hover/row:underline underline-offset-2',
|
|
118
|
+
'after:absolute after:inset-0 after:outline-2 after:-outline-offset-2 after:outline-transparent',
|
|
119
|
+
'focus-visible:after:outline-focus forced-colors:not-focus-visible:after:outline-0'
|
|
120
|
+
]
|
|
121
|
+
const linkedRowClass = [
|
|
122
|
+
'relative cursor-pointer hover:bg-black/5',
|
|
123
|
+
'[&_:is(a,button,input,select,textarea,label,[tabindex]):not([data-row-link])]:relative',
|
|
124
|
+
'[&_:is(a,button,input,select,textarea,label,[tabindex]):not([data-row-link])]:z-1'
|
|
125
|
+
]
|
|
126
|
+
|
|
88
127
|
const cellPadding = computed(() => (props.size === 'sm' ? 'px-4 py-2' : 'px-4 py-3'))
|
|
89
128
|
|
|
90
129
|
function columnClasses(column: TableColumn<Row>) {
|
|
@@ -177,10 +216,16 @@ onBeforeUnmount(() => observer?.disconnect())
|
|
|
177
216
|
<Spinner size="sm" />
|
|
178
217
|
Loading…
|
|
179
218
|
</span>
|
|
180
|
-
<slot v-else name="empty">
|
|
219
|
+
<slot v-else name="empty">
|
|
220
|
+
<EmptyState size="sm" :description="emptyText" class="p-0" />
|
|
221
|
+
</slot>
|
|
181
222
|
</td>
|
|
182
223
|
</tr>
|
|
183
|
-
<tr
|
|
224
|
+
<tr
|
|
225
|
+
v-for="(row, index) in shownRows"
|
|
226
|
+
:key="keyOf(row, index)"
|
|
227
|
+
:class="cn('group/row', linkFor(row, index) && linkedRowClass, ui?.row)"
|
|
228
|
+
>
|
|
184
229
|
<component
|
|
185
230
|
:is="column.rowHeader ? 'th' : 'td'"
|
|
186
231
|
v-for="column in columns"
|
|
@@ -196,7 +241,18 @@ onBeforeUnmount(() => observer?.disconnect())
|
|
|
196
241
|
)
|
|
197
242
|
"
|
|
198
243
|
>
|
|
199
|
-
<
|
|
244
|
+
<component
|
|
245
|
+
:is="linkComponent"
|
|
246
|
+
v-if="column.key === linkColumn && linkFor(row, index)"
|
|
247
|
+
v-bind="linkFor(row, index)"
|
|
248
|
+
data-row-link
|
|
249
|
+
:class="rowLinkClass"
|
|
250
|
+
>
|
|
251
|
+
<slot :name="`cell-${column.key}`" :row="row" :value="row[column.key]" :index="index">
|
|
252
|
+
{{ row[column.key] ?? '' }}
|
|
253
|
+
</slot>
|
|
254
|
+
</component>
|
|
255
|
+
<slot v-else :name="`cell-${column.key}`" :row="row" :value="row[column.key]" :index="index">
|
|
200
256
|
{{ row[column.key] ?? '' }}
|
|
201
257
|
</slot>
|
|
202
258
|
</component>
|
package/src/index.ts
CHANGED
|
@@ -74,6 +74,8 @@ export { default as RelativeTime } from './components/RelativeTime/RelativeTime.
|
|
|
74
74
|
export type { RelativeTimeProps } from './components/RelativeTime/RelativeTime.vue'
|
|
75
75
|
export { default as Age } from './components/Age/Age.vue'
|
|
76
76
|
export type { AgeProps } from './components/Age/Age.vue'
|
|
77
|
+
export { default as EmptyState } from './components/EmptyState/EmptyState.vue'
|
|
78
|
+
export type { EmptyStateProps } from './components/EmptyState/EmptyState.vue'
|
|
77
79
|
|
|
78
80
|
// Navigation
|
|
79
81
|
export { default as Breadcrumb } from './components/Breadcrumb/Breadcrumb.vue'
|