@thekestongroup/ui 0.10.0 → 0.12.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 +8 -12
- package/dist/components/AppShell/AppShell.vue.d.ts +11 -1
- package/dist/components/CardSelect/CardSelect.vue.d.ts +1 -1
- package/dist/components/CheckboxGroup/CheckboxGroup.vue.d.ts +1 -1
- package/dist/components/Footer/Footer.vue.d.ts +66 -0
- package/dist/components/Footer/footer.d.ts +6 -0
- package/dist/components/Footer/links.d.ts +8 -0
- package/dist/components/FormField/FormField.vue.d.ts +1 -1
- package/dist/components/Header/Header.vue.d.ts +7 -2
- package/dist/components/Input/Input.vue.d.ts +1 -1
- package/dist/components/InputCode/InputCode.vue.d.ts +1 -1
- package/dist/components/InputDate/InputDate.vue.d.ts +1 -1
- package/dist/components/InputNumber/InputNumber.vue.d.ts +1 -1
- package/dist/components/InputPassword/InputPassword.vue.d.ts +1 -1
- package/dist/components/InputRichText/InputRichText.vue.d.ts +1 -1
- package/dist/components/InputTextArea/InputTextArea.vue.d.ts +1 -1
- package/dist/components/RadioGroup/RadioGroup.vue.d.ts +1 -1
- package/dist/components/Select/Select.vue.d.ts +1 -1
- package/dist/components/Slideover/Slideover.vue.d.ts +1 -1
- package/dist/components/StatTile/StatTile.vue.d.ts +10 -1
- package/dist/i18n/en.d.ts +6 -0
- package/dist/index.d.ts +3 -0
- package/dist/keston-ui.js +805 -617
- package/package.json +1 -1
- package/src/components/AppShell/AppShell.stories.ts +8 -0
- package/src/components/AppShell/AppShell.vue +17 -4
- package/src/components/Avatar/Avatar.vue +6 -3
- package/src/components/Card/Card.stories.ts +1 -1
- package/src/components/Checklist/Checklist.stories.ts +1 -1
- package/src/components/Footer/Footer.stories.ts +82 -0
- package/src/components/Footer/Footer.vue +123 -0
- package/src/components/Footer/footer.test.ts +41 -0
- package/src/components/Footer/footer.ts +15 -0
- package/src/components/Footer/links.ts +19 -0
- package/src/components/Header/Header.stories.ts +29 -0
- package/src/components/Header/Header.vue +14 -9
- package/src/components/Input/Input.vue +1 -0
- package/src/components/StatTile/StatTile.stories.ts +11 -2
- package/src/components/StatTile/StatTile.vue +43 -6
- package/src/examples/AppPages.stories.ts +1 -1
- package/src/examples/SchoolPages.stories.ts +2 -2
- package/src/i18n/en.ts +6 -0
- package/src/index.ts +3 -0
- package/src/lib/parseDate.ts +1 -1
package/package.json
CHANGED
|
@@ -60,6 +60,14 @@ type Story = StoryObj<typeof meta>;
|
|
|
60
60
|
*/
|
|
61
61
|
export const Default: Story = {};
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* footer: the Keston Group footer under the page, with this app's name, version and build. On a short page
|
|
65
|
+
* it sits at the bottom of the screen; on a long one it follows the content (scroll down).
|
|
66
|
+
*/
|
|
67
|
+
export const WithFooter: Story = {
|
|
68
|
+
args: { footer: { appName: "Keston Admissions", version: "2.3.0", build: "a1b2c3d", since: 2024 } },
|
|
69
|
+
};
|
|
70
|
+
|
|
63
71
|
/** titleTo: the app's name in the header links to its dashboard (`to` for `linkComponent`, or an href). */
|
|
64
72
|
export const TitleLink: Story = {
|
|
65
73
|
args: { titleTo: "#dashboard" },
|
|
@@ -5,6 +5,7 @@ import { Menu } from '@lucide/vue'
|
|
|
5
5
|
import { TooltipProvider } from 'reka-ui'
|
|
6
6
|
import { cn } from '../../lib/cn'
|
|
7
7
|
import Button from '../Button/Button.vue'
|
|
8
|
+
import Footer, { type FooterProps } from '../Footer/Footer.vue'
|
|
8
9
|
import Header, { type HeaderProps, type HeaderUser, type HeaderUserAction } from '../Header/Header.vue'
|
|
9
10
|
import Sidebar, { type SidebarItem, type SidebarProps } from '../Sidebar/Sidebar.vue'
|
|
10
11
|
import Slideover from '../Slideover/Slideover.vue'
|
|
@@ -28,8 +29,12 @@ import Slideover from '../Slideover/Slideover.vue'
|
|
|
28
29
|
* The account menu (top right) is the Header's: pass `user` and listen for
|
|
29
30
|
* account-settings, switch-account, log-out (and sign-in when signed out).
|
|
30
31
|
*
|
|
32
|
+
* The footer: pass `footer` (the Footer's props, e.g. `{ appName, version }`) to put the
|
|
33
|
+
* Keston Group footer at the bottom of the page, under the content. It sits at the bottom of the
|
|
34
|
+
* screen on short pages and after the content on long ones.
|
|
35
|
+
*
|
|
31
36
|
* Slots: default (the page), header-leading, header-middle, header-trailing,
|
|
32
|
-
* account, account-menu (passed to Header), sidebar-header and sidebar-footer (passed to Sidebar;
|
|
37
|
+
* account, account-menu and organisation (passed to Header), sidebar-header and sidebar-footer (passed to Sidebar;
|
|
33
38
|
* sidebar-header is only shown on wide screens, as the Slideover has its own
|
|
34
39
|
* title).
|
|
35
40
|
*/
|
|
@@ -50,6 +55,8 @@ export interface AppShellProps {
|
|
|
50
55
|
sections?: SidebarProps['sections']
|
|
51
56
|
/** Wide screens: show the header's menu button, which collapses the sidebar to icons. */
|
|
52
57
|
collapsible?: boolean
|
|
58
|
+
/** Show the Keston Group footer under the page. The Footer's props: `{ appName, version, … }`. Without it there is no footer. */
|
|
59
|
+
footer?: FooterProps
|
|
53
60
|
/** Component used for sidebar items with `to`, and the title link, e.g. RouterLink. */
|
|
54
61
|
linkComponent?: SidebarProps['linkComponent']
|
|
55
62
|
/** Other Header props, e.g. `{ ui: { title: '…' } }`. */
|
|
@@ -86,6 +93,7 @@ defineSlots<{
|
|
|
86
93
|
'header-trailing'?(): unknown
|
|
87
94
|
account?(): unknown
|
|
88
95
|
'account-menu'?(props: { close: () => void }): unknown
|
|
96
|
+
organisation?(props: { close: () => void }): unknown
|
|
89
97
|
'sidebar-header'?(props: { collapsed: boolean }): unknown
|
|
90
98
|
'sidebar-footer'?(props: { collapsed: boolean; mobile: boolean }): unknown
|
|
91
99
|
}>()
|
|
@@ -166,6 +174,7 @@ const sidebarId = `${uid}-sidebar`
|
|
|
166
174
|
<template v-if="$slots['header-trailing']" #trailing><slot name="header-trailing" /></template>
|
|
167
175
|
<template v-if="$slots.account" #account><slot name="account" /></template>
|
|
168
176
|
<template v-if="$slots['account-menu']" #account-menu="slotProps"><slot name="account-menu" v-bind="slotProps" /></template>
|
|
177
|
+
<template v-if="$slots.organisation" #organisation="slotProps"><slot name="organisation" v-bind="slotProps" /></template>
|
|
169
178
|
</Header>
|
|
170
179
|
|
|
171
180
|
<div class="flex flex-1">
|
|
@@ -218,9 +227,13 @@ const sidebarId = `${uid}-sidebar`
|
|
|
218
227
|
</template>
|
|
219
228
|
</Slideover>
|
|
220
229
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
230
|
+
<!-- The page, and under it the footer: the page grows, so the footer is at the bottom of a short page. -->
|
|
231
|
+
<div class="flex min-w-0 flex-1 flex-col">
|
|
232
|
+
<main :id="mainId" tabindex="-1" :class="cn('min-w-0 flex-1 outline-none', ui?.main)">
|
|
233
|
+
<slot />
|
|
234
|
+
</main>
|
|
235
|
+
<Footer v-if="footer" v-bind="{ linkComponent, ...footer }" />
|
|
236
|
+
</div>
|
|
224
237
|
</div>
|
|
225
238
|
</div>
|
|
226
239
|
</TooltipProvider>
|
|
@@ -59,6 +59,9 @@ const sizes: Record<NonNullable<AvatarProps['size']>, string> = {
|
|
|
59
59
|
xl: 'size-16 text-xl'
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
// Pixel size of each `sizes` entry, so the browser can reserve the space before the image loads.
|
|
63
|
+
const pixels: Record<NonNullable<AvatarProps['size']>, number> = { xs: 20, sm: 28, md: 36, lg: 48, xl: 64 }
|
|
64
|
+
|
|
62
65
|
const circle = 'relative inline-flex shrink-0 items-center justify-center overflow-hidden rounded-full bg-primary font-bold text-white select-none'
|
|
63
66
|
</script>
|
|
64
67
|
|
|
@@ -74,7 +77,7 @@ const circle = 'relative inline-flex shrink-0 items-center justify-center overfl
|
|
|
74
77
|
props.class
|
|
75
78
|
)"
|
|
76
79
|
>
|
|
77
|
-
<img v-if="showImage" :src="user.avatar" alt="" class="size-full object-cover" @error="failed = true">
|
|
80
|
+
<img v-if="showImage" :src="user.avatar" :width="pixels[size]" :height="pixels[size]" loading="lazy" decoding="async" alt="" class="size-full object-cover" @error="failed = true">
|
|
78
81
|
<span v-else aria-hidden="true">{{ initials }}</span>
|
|
79
82
|
</button>
|
|
80
83
|
|
|
@@ -85,7 +88,7 @@ const circle = 'relative inline-flex shrink-0 items-center justify-center overfl
|
|
|
85
88
|
</p>
|
|
86
89
|
<div class="flex items-center gap-3 px-4 py-3">
|
|
87
90
|
<span :class="cn(circle, sizes.lg)" aria-hidden="true">
|
|
88
|
-
<img v-if="showImage" :src="user.avatar" alt="" class="size-full object-cover">
|
|
91
|
+
<img v-if="showImage" :src="user.avatar" :width="pixels.lg" :height="pixels.lg" loading="lazy" decoding="async" alt="" class="size-full object-cover">
|
|
89
92
|
<template v-else>{{ initials }}</template>
|
|
90
93
|
</span>
|
|
91
94
|
<div class="flex min-w-0 flex-col">
|
|
@@ -112,7 +115,7 @@ const circle = 'relative inline-flex shrink-0 items-center justify-center overfl
|
|
|
112
115
|
:aria-hidden="decorative || undefined"
|
|
113
116
|
:class="cn(circle, sizes[size], props.class)"
|
|
114
117
|
>
|
|
115
|
-
<img v-if="showImage" :src="user.avatar" alt="" class="size-full object-cover" @error="failed = true">
|
|
118
|
+
<img v-if="showImage" :src="user.avatar" :width="pixels[size]" :height="pixels[size]" loading="lazy" decoding="async" alt="" class="size-full object-cover" @error="failed = true">
|
|
116
119
|
<span v-else aria-hidden="true">{{ initials }}</span>
|
|
117
120
|
</span>
|
|
118
121
|
</template>
|
|
@@ -78,7 +78,7 @@ export const Stats: Story = {
|
|
|
78
78
|
render: () => ({
|
|
79
79
|
components: { Card, Badge },
|
|
80
80
|
template: `
|
|
81
|
-
<div class="grid grid-cols-1 gap-
|
|
81
|
+
<div class="grid grid-cols-1 gap-6 sm:grid-cols-3">
|
|
82
82
|
<Card v-for="stat in [['Open applications', '48'], ['Interviews this week', '9'], ['Offers accepted', '31']]" :key="stat[0]" padding="sm" :ui="{ body: 'gap-1' }">
|
|
83
83
|
<span class="text-sm text-black/65">{{ stat[0] }}</span>
|
|
84
84
|
<span class="text-2xl font-bold">{{ stat[1] }}</span>
|
|
@@ -58,7 +58,7 @@ export const FollowingAForm: Story = {
|
|
|
58
58
|
template: `
|
|
59
59
|
<!-- Laid out by the space it has (container query), not the window. -->
|
|
60
60
|
<div class="@container max-w-160">
|
|
61
|
-
<div class="grid grid-cols-1 items-start gap-
|
|
61
|
+
<div class="grid grid-cols-1 items-start gap-6 @lg:grid-cols-[minmax(0,1fr)_14rem]">
|
|
62
62
|
<Card title="Documents">
|
|
63
63
|
<Checkbox v-model="form.address" label="Proof of address received" />
|
|
64
64
|
<Checkbox v-model="form.report" label="School report received" />
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite'
|
|
2
|
+
import Footer from './Footer.vue'
|
|
3
|
+
import { kestonGroupLinks } from './links'
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: 'Components/Layout/Footer',
|
|
7
|
+
component: Footer,
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
parameters: { layout: 'fullscreen' },
|
|
10
|
+
args: {
|
|
11
|
+
appName: 'Keston Admin',
|
|
12
|
+
version: '1.4.2',
|
|
13
|
+
build: 'a1b2c3d',
|
|
14
|
+
},
|
|
15
|
+
} satisfies Meta<typeof Footer>
|
|
16
|
+
|
|
17
|
+
export default meta
|
|
18
|
+
type Story = StoryObj<typeof meta>
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Playground: use the controls below. Help & support and the legal links on the left; the app's name, version and build,
|
|
22
|
+
* and the copyright, on the right. Narrow the preview to see it stack.
|
|
23
|
+
*/
|
|
24
|
+
export const Default: Story = {}
|
|
25
|
+
|
|
26
|
+
/** No build: only the version (e.g. a local run, where there is no CI build). */
|
|
27
|
+
export const NoBuild: Story = {
|
|
28
|
+
args: { build: undefined },
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** `since` shows a range of years. */
|
|
32
|
+
export const SinceYear: Story = {
|
|
33
|
+
args: { since: 2024 },
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** `moreLinks`: more links after the standard ones, e.g. Contact us. */
|
|
37
|
+
export const WithMoreLinks: Story = {
|
|
38
|
+
args: {
|
|
39
|
+
moreLinks: [{ label: 'Contact us', href: 'https://example.com/contact' }],
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** `kestonGroupLinks` as `moreLinks`, to point people at the other Keston apps. */
|
|
44
|
+
export const WithGroupLinks: Story = {
|
|
45
|
+
args: { moreLinks: kestonGroupLinks },
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** `links` replaces the standard links altogether, e.g. for an app with its own help and policies. Rarely needed: prefer `moreLinks`. */
|
|
49
|
+
export const CustomLinks: Story = {
|
|
50
|
+
args: {
|
|
51
|
+
links: [
|
|
52
|
+
{ label: 'Help & support', href: '#help', newTab: false },
|
|
53
|
+
{ label: 'Privacy Policy', href: '#privacy', newTab: false },
|
|
54
|
+
{ label: 'Terms of use', href: '#terms', newTab: false },
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** No app name, version or build (e.g. a public page): just the links and the copyright. */
|
|
60
|
+
export const NoVersion: Story = {
|
|
61
|
+
args: { appName: undefined, version: undefined, build: undefined },
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The slot `end`, after the copyright: here a stand-in for a language switcher. */
|
|
65
|
+
export const WithEndSlot: Story = {
|
|
66
|
+
render: (args) => ({
|
|
67
|
+
components: { Footer },
|
|
68
|
+
setup: () => ({ args }),
|
|
69
|
+
template: `
|
|
70
|
+
<Footer v-bind="args">
|
|
71
|
+
<template #end><button type="button" class="underline underline-offset-2">English</button></template>
|
|
72
|
+
</Footer>`,
|
|
73
|
+
}),
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Phone-sized: the links, then the version and copyright, stacked. */
|
|
77
|
+
export const Mobile: Story = {
|
|
78
|
+
globals: { viewport: { value: 'mobile1', isRotated: false } },
|
|
79
|
+
args: {
|
|
80
|
+
moreLinks: [{ label: 'Contact us', href: 'https://example.com/contact' }],
|
|
81
|
+
},
|
|
82
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useI18n } from 'vue-i18n'
|
|
3
|
+
import { computed, type Component, type HTMLAttributes } from 'vue'
|
|
4
|
+
import { cn } from '../../lib/cn'
|
|
5
|
+
import Link from '../Link/Link.vue'
|
|
6
|
+
import { bareVersion, displayVersion, yearRange } from './footer'
|
|
7
|
+
import { kestonFooterLinks } from './links'
|
|
8
|
+
|
|
9
|
+
export interface FooterLink {
|
|
10
|
+
label: string
|
|
11
|
+
/** A plain link. */
|
|
12
|
+
href?: string
|
|
13
|
+
/** Link through `linkComponent` (e.g. RouterLink), which receives `to`. */
|
|
14
|
+
to?: unknown
|
|
15
|
+
/** Open in a new tab. Default true for `href` links (they leave the app), false for `to`. */
|
|
16
|
+
newTab?: boolean
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The bottom of an app's page: on the left Help & support and the legal links (Privacy Policy, Terms & Conditions), and
|
|
21
|
+
* on the right the app's name, version and build (so a bug report can say exactly which build) with
|
|
22
|
+
* the copyright. The same in every Keston app; pass the app's `version` and `build`.
|
|
23
|
+
*
|
|
24
|
+
* Without `links` it shows the Keston Group's footer links (`kestonFooterLinks`). Add to them rather than
|
|
25
|
+
* replacing them with `moreLinks` (e.g. Contact us, or `kestonGroupLinks` to point at the other Keston
|
|
26
|
+
* apps), which follow, after a divider. The version comes from the app's package.json and the build
|
|
27
|
+
* from its CI: in Vite, put them in with `define` (see the spec).
|
|
28
|
+
*
|
|
29
|
+
* Slots: nav (instead of the whole link list), end (after the copyright, e.g. a language switcher).
|
|
30
|
+
*/
|
|
31
|
+
export interface FooterProps {
|
|
32
|
+
/** The links on the left. Default: `kestonFooterLinks` (Help & support, Privacy Policy, Terms & Conditions). */
|
|
33
|
+
links?: FooterLink[]
|
|
34
|
+
/** More links after a divider, e.g. Contact us, or `kestonGroupLinks` to point at the other Keston apps. */
|
|
35
|
+
moreLinks?: FooterLink[]
|
|
36
|
+
/** Component used for links with `to`, e.g. RouterLink. */
|
|
37
|
+
linkComponent?: string | Component
|
|
38
|
+
/** The app's name, shown before its version. */
|
|
39
|
+
appName?: string
|
|
40
|
+
/** The app's version, e.g. "1.4.2" or "v1.4.2". */
|
|
41
|
+
version?: string
|
|
42
|
+
/** The build, e.g. a commit "a1b2c3d" or a CI run number, shown after the version so a bug report can name the exact build. */
|
|
43
|
+
build?: string
|
|
44
|
+
/** Who owns the copyright. */
|
|
45
|
+
holder?: string
|
|
46
|
+
/** The current year. Default: this year, from the device's clock. */
|
|
47
|
+
year?: number
|
|
48
|
+
/** The first year, to show a range such as 2024–2026. */
|
|
49
|
+
since?: number
|
|
50
|
+
class?: HTMLAttributes['class']
|
|
51
|
+
/** Extra classes for the parts. */
|
|
52
|
+
ui?: {
|
|
53
|
+
links?: HTMLAttributes['class']
|
|
54
|
+
meta?: HTMLAttributes['class']
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const { t } = useI18n()
|
|
59
|
+
const props = withDefaults(defineProps<FooterProps>(), {
|
|
60
|
+
links: () => kestonFooterLinks,
|
|
61
|
+
moreLinks: () => [],
|
|
62
|
+
linkComponent: undefined,
|
|
63
|
+
holder: 'The Keston Group'
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
defineSlots<{
|
|
67
|
+
nav?(): unknown
|
|
68
|
+
end?(): unknown
|
|
69
|
+
}>()
|
|
70
|
+
|
|
71
|
+
const years = computed(() => yearRange(props.year ?? new Date().getFullYear(), props.since))
|
|
72
|
+
const shownVersion = computed(() => displayVersion(props.version))
|
|
73
|
+
const versionLabel = computed(() => (props.version ? t('ui.footer.version', { version: bareVersion(props.version) }) : ''))
|
|
74
|
+
const buildLabel = computed(() => (props.build ? t('ui.footer.build', { build: props.build }) : ''))
|
|
75
|
+
|
|
76
|
+
// Links that leave the app open in a new tab, so people don't lose their place.
|
|
77
|
+
function linkAttrs(link: FooterLink) {
|
|
78
|
+
return link.to !== undefined
|
|
79
|
+
? { as: props.linkComponent as never, to: link.to, newTab: link.newTab ?? false }
|
|
80
|
+
: { href: link.href, newTab: link.newTab ?? true }
|
|
81
|
+
}
|
|
82
|
+
</script>
|
|
83
|
+
|
|
84
|
+
<template>
|
|
85
|
+
<footer
|
|
86
|
+
:class="cn(
|
|
87
|
+
'flex shrink-0 flex-col gap-3 border-t border-black/15 bg-white px-4 py-4 text-sm text-black/65 sm:flex-row sm:items-center sm:justify-between sm:px-6',
|
|
88
|
+
props.class
|
|
89
|
+
)"
|
|
90
|
+
>
|
|
91
|
+
<nav :aria-label="t('ui.footer.label')" :class="cn('min-w-0', ui?.links)">
|
|
92
|
+
<slot name="nav">
|
|
93
|
+
<ul class="flex flex-wrap items-center gap-x-4 gap-y-1">
|
|
94
|
+
<li v-for="link in links" :key="link.label">
|
|
95
|
+
<Link v-bind="linkAttrs(link)" :icon="false">{{ link.label }}</Link>
|
|
96
|
+
</li>
|
|
97
|
+
<li v-if="moreLinks.length" class="hidden h-4 w-px bg-black/15 sm:block" aria-hidden="true"></li>
|
|
98
|
+
<li v-for="link in moreLinks" :key="link.label">
|
|
99
|
+
<Link v-bind="linkAttrs(link)" :icon="false">{{ link.label }}</Link>
|
|
100
|
+
</li>
|
|
101
|
+
</ul>
|
|
102
|
+
</slot>
|
|
103
|
+
</nav>
|
|
104
|
+
|
|
105
|
+
<div :class="cn('flex flex-wrap items-center gap-x-3 gap-y-1 sm:justify-end', ui?.meta)">
|
|
106
|
+
<p v-if="appName || version || build" class="flex flex-wrap items-baseline gap-x-1.5">
|
|
107
|
+
<span v-if="appName" class="font-bold text-black/80">{{ appName }}</span>
|
|
108
|
+
<!-- Shows as "v1.4.2" but reads as "Version 1.4.2". -->
|
|
109
|
+
<span v-if="version">
|
|
110
|
+
<span class="sr-only">{{ versionLabel }}</span>
|
|
111
|
+
<span aria-hidden="true">{{ shownVersion }}</span>
|
|
112
|
+
</span>
|
|
113
|
+
<!-- Shows as "a1b2c3d" in monospace but reads as "Build a1b2c3d". -->
|
|
114
|
+
<span v-if="build" :title="buildLabel">
|
|
115
|
+
<span class="sr-only">{{ buildLabel }}</span>
|
|
116
|
+
<span class="font-mono text-xs text-black/55" aria-hidden="true">{{ build }}</span>
|
|
117
|
+
</span>
|
|
118
|
+
</p>
|
|
119
|
+
<p>{{ t('ui.footer.copyright', { years, holder }) }}</p>
|
|
120
|
+
<slot name="end" />
|
|
121
|
+
</div>
|
|
122
|
+
</footer>
|
|
123
|
+
</template>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { bareVersion, displayVersion, yearRange } from './footer'
|
|
3
|
+
import { kestonFooterLinks, kestonGroupLinks } from './links'
|
|
4
|
+
|
|
5
|
+
describe('yearRange', () => {
|
|
6
|
+
it('shows a range from an earlier year, and a single year otherwise', () => {
|
|
7
|
+
expect(yearRange(2026, 2024)).toBe('2024–2026')
|
|
8
|
+
expect(yearRange(2026, 2026)).toBe('2026')
|
|
9
|
+
expect(yearRange(2026)).toBe('2026')
|
|
10
|
+
expect(yearRange(2026, 2030)).toBe('2026')
|
|
11
|
+
})
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
describe('version', () => {
|
|
15
|
+
it('shows a v in front, once', () => {
|
|
16
|
+
expect(displayVersion('1.4.2')).toBe('v1.4.2')
|
|
17
|
+
expect(displayVersion('v1.4.2')).toBe('v1.4.2')
|
|
18
|
+
expect(displayVersion('V1.4.2')).toBe('v1.4.2')
|
|
19
|
+
expect(displayVersion(undefined)).toBe('')
|
|
20
|
+
expect(displayVersion('')).toBe('')
|
|
21
|
+
})
|
|
22
|
+
it('gives the plain number for screen readers', () => {
|
|
23
|
+
expect(bareVersion('v1.4.2')).toBe('1.4.2')
|
|
24
|
+
expect(bareVersion('1.4.2')).toBe('1.4.2')
|
|
25
|
+
expect(bareVersion(undefined)).toBe('')
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
describe('kestonFooterLinks', () => {
|
|
30
|
+
it('are Help & support, Privacy Policy and Terms & Conditions, on secure keston.co addresses', () => {
|
|
31
|
+
expect(kestonFooterLinks.map((l) => l.label)).toEqual(['Help & support', 'Privacy Policy', 'Terms & Conditions'])
|
|
32
|
+
for (const link of kestonFooterLinks) expect(link.href).toMatch(/^https:\/\/keston\.co\//)
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
describe('kestonGroupLinks', () => {
|
|
37
|
+
it('are all secure addresses on keston.co', () => {
|
|
38
|
+
expect(kestonGroupLinks.length).toBeGreaterThan(0)
|
|
39
|
+
for (const link of kestonGroupLinks) expect(link.href).toMatch(/^https:\/\/[a-z]+\.keston\.co\/?$/)
|
|
40
|
+
})
|
|
41
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** "2024–2026" when `since` is before `year`, otherwise just the year. */
|
|
2
|
+
export function yearRange(year: number, since?: number): string {
|
|
3
|
+
return since && since < year ? `${since}–${year}` : String(year)
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/** "1.4.2" and "v1.4.2" both show as "v1.4.2". Empty for no version. */
|
|
7
|
+
export function displayVersion(version?: string): string {
|
|
8
|
+
if (!version) return ''
|
|
9
|
+
return /^v/i.test(version) ? `v${version.slice(1)}` : `v${version}`
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** The version without a leading "v", for the screen reader's "Version 1.4.2". */
|
|
13
|
+
export function bareVersion(version?: string): string {
|
|
14
|
+
return version ? version.replace(/^v/i, '') : ''
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { FooterLink } from './Footer.vue'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The links every Keston app shows on the left of its footer: help first, then the legal pages.
|
|
5
|
+
* Apps can pass their own `links`, or add to these with `moreLinks`.
|
|
6
|
+
*/
|
|
7
|
+
export const kestonFooterLinks: FooterLink[] = [
|
|
8
|
+
{ label: 'Help & support', href: 'https://keston.co/help' },
|
|
9
|
+
{ label: 'Privacy Policy', href: 'https://keston.co/privacy' },
|
|
10
|
+
{ label: 'Terms & Conditions', href: 'https://keston.co/terms' }
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
/** Links to the rest of the Keston Group. Not shown by default: pass them as `moreLinks` where an app should offer them. */
|
|
14
|
+
export const kestonGroupLinks: FooterLink[] = [
|
|
15
|
+
{ label: 'Keston ID', href: 'https://id.keston.co' },
|
|
16
|
+
{ label: 'Admin', href: 'https://admin.keston.co' },
|
|
17
|
+
{ label: 'Work', href: 'https://work.keston.co' },
|
|
18
|
+
{ label: 'Design system', href: 'https://ui.keston.co' }
|
|
19
|
+
]
|
|
@@ -94,6 +94,35 @@ export const CustomUserMenu: Story = {
|
|
|
94
94
|
}),
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
+
/**
|
|
98
|
+
* The organisation slot replaces the organisation heading at the top of the
|
|
99
|
+
* account menu, e.g. with a row that switches organisation. A divider sits
|
|
100
|
+
* under it.
|
|
101
|
+
*/
|
|
102
|
+
export const OrganisationSwitcher: Story = {
|
|
103
|
+
render: (args) => ({
|
|
104
|
+
components: { Header, Building2, ChevronRight },
|
|
105
|
+
setup: () => ({ args }),
|
|
106
|
+
template: `
|
|
107
|
+
<Header v-bind="args">
|
|
108
|
+
<template #organisation="{ close }">
|
|
109
|
+
<button
|
|
110
|
+
type="button"
|
|
111
|
+
class="flex w-full items-center gap-2 px-4 py-3 text-left text-sm hover:bg-black/5 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus"
|
|
112
|
+
@click="close"
|
|
113
|
+
>
|
|
114
|
+
<Building2 class="size-4 shrink-0" aria-hidden="true" />
|
|
115
|
+
<span class="flex min-w-0 flex-1 flex-col">
|
|
116
|
+
<span class="truncate font-bold">The Keston School</span>
|
|
117
|
+
<span class="text-xs text-black/65">Switch organisation</span>
|
|
118
|
+
</span>
|
|
119
|
+
<ChevronRight class="size-4 shrink-0" aria-hidden="true" />
|
|
120
|
+
</button>
|
|
121
|
+
</template>
|
|
122
|
+
</Header>`,
|
|
123
|
+
}),
|
|
124
|
+
};
|
|
125
|
+
|
|
97
126
|
/** The whole account area replaced with the account slot. */
|
|
98
127
|
export const CustomUser: Story = {
|
|
99
128
|
render: (args) => ({
|
|
@@ -30,7 +30,9 @@ export type HeaderUserAction = 'account-settings' | 'switch-account' | 'log-out'
|
|
|
30
30
|
* fills the space between title and trailing), trailing (actions before the
|
|
31
31
|
* account menu), account (replaces the account menu, or the Sign in button),
|
|
32
32
|
* account-menu (extra content in the account menu, above Switch account /
|
|
33
|
-
* Log out: `{ close }`)
|
|
33
|
+
* Log out: `{ close }`), organisation (replaces the organisation heading at the
|
|
34
|
+
* very top of the account menu, e.g. with a row that switches organisation:
|
|
35
|
+
* `{ close }`).
|
|
34
36
|
*/
|
|
35
37
|
export interface HeaderProps {
|
|
36
38
|
/** Name of the app or area, shown next to the menu button. */
|
|
@@ -108,6 +110,7 @@ defineSlots<{
|
|
|
108
110
|
trailing?(): unknown
|
|
109
111
|
account?(): unknown
|
|
110
112
|
'account-menu'?(props: { close: () => void }): unknown
|
|
113
|
+
organisation?(props: { close: () => void }): unknown
|
|
111
114
|
}>()
|
|
112
115
|
|
|
113
116
|
// "Ben Smith" → "BS", "Ben" → "B".
|
|
@@ -192,20 +195,22 @@ function runAction(action: HeaderUserAction, close: () => void) {
|
|
|
192
195
|
<slot name="account">
|
|
193
196
|
<!-- Account menu: the user's avatar opens a panel with who is signed
|
|
194
197
|
in and the account actions. -->
|
|
195
|
-
<Popover v-if="user" :content="{ align: 'end' }" :ui="{ content: cn('w-
|
|
198
|
+
<Popover v-if="user" :content="{ align: 'end' }" :ui="{ content: cn('w-80', ui?.userMenu) }">
|
|
196
199
|
<Button variant="ghost" square :aria-label="accountLabel" class="-mr-1.5 rounded-full">
|
|
197
200
|
<Avatar :user="user" size="sm" decorative />
|
|
198
201
|
</Button>
|
|
199
202
|
|
|
200
203
|
<template #content="{ close }">
|
|
201
204
|
<div class="flex flex-col">
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
205
|
+
<!-- The organisation at the top, with a divider under it. The
|
|
206
|
+
organisation slot replaces the plain heading. -->
|
|
207
|
+
<div v-if="user.organisation || $slots.organisation" class="border-b border-black/15">
|
|
208
|
+
<slot name="organisation" :close="close">
|
|
209
|
+
<p class="truncate px-4 py-3 text-xs font-bold text-black/65 uppercase" :title="user.organisation">
|
|
210
|
+
{{ user.organisation }}
|
|
211
|
+
</p>
|
|
212
|
+
</slot>
|
|
213
|
+
</div>
|
|
209
214
|
<!-- Two columns: the avatar at the top left, beside the name and
|
|
210
215
|
email; Account settings sits under them in the text column,
|
|
211
216
|
without moving the avatar. -->
|
|
@@ -42,15 +42,24 @@ export const Grid: Story = {
|
|
|
42
42
|
components: { StatTile },
|
|
43
43
|
setup: () => ({ Users, FileText, CalendarCheck, UserX }),
|
|
44
44
|
template: `
|
|
45
|
-
<div class="grid grid-cols-1 gap-
|
|
45
|
+
<div class="grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-4">
|
|
46
46
|
<StatTile label="Students on roll" value="1,204" :icon="Users" change="+38" change-label="since September" trend="up" />
|
|
47
47
|
<StatTile label="Open applications" value="48" :icon="FileText" change="+12%" change-label="on last year" trend="up" />
|
|
48
|
-
<StatTile label="Attendance" value="95.8%" :icon="CalendarCheck" change="0.0 pts" change-label="on last week" trend="flat" />
|
|
48
|
+
<StatTile label="Attendance" value="95.8%" :icon="CalendarCheck" change="0.0 pts" change-label="on last week" trend="flat" href="#attendance" />
|
|
49
49
|
<StatTile label="Persistent absence" value="7.4%" :icon="UserX" change="+0.9 pts" change-label="this term" trend="up" sentiment="negative" />
|
|
50
50
|
</div>`,
|
|
51
51
|
}),
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* With an `href` (or `as` for a router link) the whole tile is one link: an
|
|
56
|
+
* arrow in the corner shows it's clickable, the border darkens on hover and
|
|
57
|
+
* the background on press. Tab to it to see the focus ring.
|
|
58
|
+
*/
|
|
59
|
+
export const Clickable: Story = {
|
|
60
|
+
args: { href: "#open-applications", icon: FileText, description: "Waiting for an interview or a decision." },
|
|
61
|
+
};
|
|
62
|
+
|
|
54
63
|
/** With a description and a footer link. */
|
|
55
64
|
export const WithDescriptionAndFooter: Story = {
|
|
56
65
|
args: { description: "Waiting for an interview or a decision.", change: undefined, changeLabel: undefined, trend: undefined },
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { useI18n } from 'vue-i18n'
|
|
3
|
-
import { computed, type Component, type HTMLAttributes } from 'vue'
|
|
3
|
+
import { computed, watchEffect, type Component, type HTMLAttributes } from 'vue'
|
|
4
|
+
import { Primitive, type PrimitiveProps } from 'reka-ui'
|
|
4
5
|
import { ArrowDownRight, ArrowRight, ArrowUpRight } from '@lucide/vue'
|
|
5
6
|
import { cn } from '../../lib/cn'
|
|
6
7
|
import Card from '../Card/Card.vue'
|
|
@@ -10,8 +11,12 @@ import Card from '../Card/Card.vue'
|
|
|
10
11
|
* Put several in a grid. Optionally with how it's changed ("+12% on last
|
|
11
12
|
* year") and a short description.
|
|
12
13
|
*
|
|
14
|
+
* Give it an `href` (or `as`, e.g. a router link, with its own `to`) and the
|
|
15
|
+
* whole tile becomes one link: an arrow in the corner shows it's clickable,
|
|
16
|
+
* and it darkens its border on hover and its background when pressed.
|
|
17
|
+
*
|
|
13
18
|
* Slots: value (e.g. a value with a unit in smaller text), description,
|
|
14
|
-
* footer (e.g. a "View all" link).
|
|
19
|
+
* footer (e.g. a "View all" link; not in a tile that is itself a link).
|
|
15
20
|
*/
|
|
16
21
|
export interface StatTileProps {
|
|
17
22
|
/** What the number is, e.g. "Open applications". */
|
|
@@ -34,18 +39,30 @@ export interface StatTileProps {
|
|
|
34
39
|
sentiment?: 'positive' | 'negative' | 'neutral'
|
|
35
40
|
/** Grey text under the value. */
|
|
36
41
|
description?: string
|
|
42
|
+
/** Makes the whole tile a link to here. */
|
|
43
|
+
href?: string
|
|
44
|
+
/** Element or component to render the link as, e.g. RouterLink (then pass its `to`). Makes the tile a link. */
|
|
45
|
+
as?: PrimitiveProps['as']
|
|
37
46
|
class?: HTMLAttributes['class']
|
|
38
47
|
}
|
|
39
48
|
|
|
40
49
|
const { t } = useI18n()
|
|
41
50
|
const props = defineProps<StatTileProps>()
|
|
42
51
|
|
|
43
|
-
defineSlots<{
|
|
52
|
+
const slots = defineSlots<{
|
|
44
53
|
value?(): unknown
|
|
45
54
|
description?(): unknown
|
|
46
55
|
footer?(): unknown
|
|
47
56
|
}>()
|
|
48
57
|
|
|
58
|
+
const isLink = computed(() => Boolean(props.href || props.as))
|
|
59
|
+
// A link can't hold another link or button, so the footer is for static tiles.
|
|
60
|
+
watchEffect(() => {
|
|
61
|
+
if (import.meta.env.DEV && isLink.value && slots.footer) {
|
|
62
|
+
console.warn('[StatTile] The footer slot is ignored when the tile is a link (href or as).')
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
|
|
49
66
|
const tone = computed(() => {
|
|
50
67
|
if (props.sentiment) return props.sentiment
|
|
51
68
|
if (props.trend === 'up') return 'positive'
|
|
@@ -62,8 +79,27 @@ const trendWords = computed(() => ({ up: t('ui.statTile.up'), down: t('ui.statTi
|
|
|
62
79
|
</script>
|
|
63
80
|
|
|
64
81
|
<template>
|
|
65
|
-
|
|
66
|
-
|
|
82
|
+
<!-- A link wraps the card; a static tile is just the card (as="template" hands the attributes to it). -->
|
|
83
|
+
<Primitive
|
|
84
|
+
:as="isLink ? (as ?? 'a') : 'template'"
|
|
85
|
+
:href="isLink ? href : undefined"
|
|
86
|
+
:class="isLink && 'group block h-full cursor-pointer rounded-lg outline-2 outline-offset-2 outline-transparent focus-visible:outline-focus'"
|
|
87
|
+
>
|
|
88
|
+
<Card
|
|
89
|
+
padding="sm"
|
|
90
|
+
:class="
|
|
91
|
+
cn(
|
|
92
|
+
isLink &&
|
|
93
|
+
'relative h-full transition-[border-color,box-shadow,background-color] duration-150 motion-reduce:transition-none group-hover:border-black/40 group-hover:shadow-md group-active:bg-black/1',
|
|
94
|
+
props.class
|
|
95
|
+
)
|
|
96
|
+
"
|
|
97
|
+
:ui="{ body: 'gap-1' }"
|
|
98
|
+
>
|
|
99
|
+
<!-- Still, decorative: the link role is what screen readers get. -->
|
|
100
|
+
<ArrowUpRight v-if="isLink" class="absolute end-4 top-4 size-4 text-black/65" aria-hidden="true" />
|
|
101
|
+
|
|
102
|
+
<p :class="cn('flex items-center gap-2 text-sm text-black/65', isLink && 'pe-6')">
|
|
67
103
|
<component :is="icon" v-if="icon" class="size-4 shrink-0" aria-hidden="true" />
|
|
68
104
|
{{ label }}
|
|
69
105
|
</p>
|
|
@@ -84,8 +120,9 @@ const trendWords = computed(() => ({ up: t('ui.statTile.up'), down: t('ui.statTi
|
|
|
84
120
|
<slot name="description">{{ description }}</slot>
|
|
85
121
|
</p>
|
|
86
122
|
|
|
87
|
-
<div v-if="$slots.footer" class="mt-2 text-sm">
|
|
123
|
+
<div v-if="$slots.footer && !isLink" class="mt-2 text-sm">
|
|
88
124
|
<slot name="footer" />
|
|
89
125
|
</div>
|
|
90
126
|
</Card>
|
|
127
|
+
</Primitive>
|
|
91
128
|
</template>
|