@thekestongroup/ui 0.18.0 → 0.19.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/AppLauncher/AppLauncher.vue.d.ts +8 -0
- package/dist/components/Footer/Footer.vue.d.ts +2 -2
- package/dist/components/Header/Header.vue.d.ts +19 -1
- package/dist/components/SegmentedControl/SegmentedControl.vue.d.ts +50 -0
- package/dist/components/ThemeSwitcher/ThemeSwitcher.vue.d.ts +8 -1
- package/dist/i18n/en.d.ts +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/keston-ui.js +696 -564
- package/package.json +1 -1
- package/src/components/AppLauncher/AppLauncher.vue +22 -1
- package/src/components/AppLauncher/apps.ts +2 -2
- package/src/components/AppShell/AppShell.vue +2 -1
- package/src/components/Footer/Footer.stories.ts +3 -3
- package/src/components/Footer/Footer.vue +5 -4
- package/src/components/Footer/footer.test.ts +2 -2
- package/src/components/Footer/links.ts +3 -3
- package/src/components/FormField/FormField.vue +5 -1
- package/src/components/Header/Header.stories.ts +25 -12
- package/src/components/Header/Header.vue +38 -4
- package/src/components/SegmentedControl/SegmentedControl.stories.ts +57 -0
- package/src/components/SegmentedControl/SegmentedControl.vue +93 -0
- package/src/components/ThemeSwitcher/ThemeSwitcher.vue +24 -2
- package/src/i18n/en.ts +1 -1
- package/src/index.ts +3 -1
- package/src/styles/theme.css +14 -0
package/package.json
CHANGED
|
@@ -26,6 +26,8 @@ export interface AppLauncherApp {
|
|
|
26
26
|
href: string
|
|
27
27
|
/** An icon component, or the name of one of the Keston app icons (id, admin, work, utilities, design). */
|
|
28
28
|
icon?: Component | string
|
|
29
|
+
/** Signs in with Keston ID, so it's given the `loginHint`. Default true. */
|
|
30
|
+
signsIn?: boolean
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
/**
|
|
@@ -45,12 +47,31 @@ export interface AppLauncherProps {
|
|
|
45
47
|
align?: 'start' | 'end'
|
|
46
48
|
/** Name of the button for screen readers. Default "Keston apps". */
|
|
47
49
|
label?: string
|
|
50
|
+
/**
|
|
51
|
+
* The signed-in person's email. Added to the other apps' links as
|
|
52
|
+
* `?login_hint=`, so they sign in as the same account without asking
|
|
53
|
+
* which. AppShell passes its `user`'s email.
|
|
54
|
+
*/
|
|
55
|
+
loginHint?: string
|
|
48
56
|
class?: HTMLAttributes['class']
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
const { t } = useI18n()
|
|
52
60
|
const props = withDefaults(defineProps<AppLauncherProps>(), { apps: () => kestonApps, align: 'end' })
|
|
53
61
|
|
|
62
|
+
// The other apps that sign in get ?login_hint=email; the current one, and
|
|
63
|
+
// sites that don't sign in (the design system), don't.
|
|
64
|
+
function hrefOf(app: AppLauncherApp): string {
|
|
65
|
+
if (!props.loginHint || app.id === props.current || app.signsIn === false) return app.href
|
|
66
|
+
try {
|
|
67
|
+
const url = new URL(app.href)
|
|
68
|
+
url.searchParams.set('login_hint', props.loginHint)
|
|
69
|
+
return url.toString()
|
|
70
|
+
} catch {
|
|
71
|
+
return app.href
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
54
75
|
function iconOf(app: AppLauncherApp): Component {
|
|
55
76
|
if (typeof app.icon === 'string') return builtInIcons[app.icon] ?? AppWindow
|
|
56
77
|
return app.icon ?? AppWindow
|
|
@@ -67,7 +88,7 @@ function iconOf(app: AppLauncherApp): Component {
|
|
|
67
88
|
<ul>
|
|
68
89
|
<li v-for="app in apps" :key="app.id">
|
|
69
90
|
<a
|
|
70
|
-
:href="app
|
|
91
|
+
:href="hrefOf(app)"
|
|
71
92
|
:aria-current="app.id === current ? 'page' : undefined"
|
|
72
93
|
:class="cn(
|
|
73
94
|
'flex items-center gap-3 rounded-lg px-3 py-2 text-sm font-bold text-ink outline-none hover:bg-hover focus-visible:outline-2 focus-visible:outline-focus',
|
|
@@ -5,6 +5,6 @@ export const kestonApps: AppLauncherApp[] = [
|
|
|
5
5
|
{ id: 'id', label: 'Keston ID', href: 'https://id.keston.co', icon: 'id' },
|
|
6
6
|
{ id: 'admin', label: 'Admin', href: 'https://admin.keston.co', icon: 'admin' },
|
|
7
7
|
{ id: 'work', label: 'Work', href: 'https://work.keston.co', icon: 'work' },
|
|
8
|
-
{ id: 'utilities', label: 'Utilities', href: 'https://utilities.keston.co', icon: 'utilities' },
|
|
9
|
-
{ id: 'design', label: 'Design system', href: 'https://ui.keston.co', icon: 'design' }
|
|
8
|
+
{ id: 'utilities', label: 'Utilities', href: 'https://utilities.keston.co', icon: 'utilities', signsIn: false },
|
|
9
|
+
{ id: 'design', label: 'Design system', href: 'https://ui.keston.co', icon: 'design', signsIn: false }
|
|
10
10
|
]
|
|
@@ -158,7 +158,8 @@ const sidebarId = `${uid}-sidebar`
|
|
|
158
158
|
>
|
|
159
159
|
<!-- First in the header, to the left of the menu / collapse button. -->
|
|
160
160
|
<template v-if="launcher" #start>
|
|
161
|
-
|
|
161
|
+
<!-- The other apps sign in as the same account (login_hint). -->
|
|
162
|
+
<AppLauncher align="start" :login-hint="user?.email" v-bind="launcher === true ? {} : launcher" class="-ml-2.5" />
|
|
162
163
|
</template>
|
|
163
164
|
<template #leading>
|
|
164
165
|
<!-- Wide screens: in place of the menu button (same look and spot),
|
|
@@ -18,7 +18,7 @@ export default meta
|
|
|
18
18
|
type Story = StoryObj<typeof meta>
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* Playground: use the controls below. Help
|
|
21
|
+
* Playground: use the controls below. Help and the legal links on the left; the app's name, version and build,
|
|
22
22
|
* and the copyright, on the right. Narrow the preview to see it stack.
|
|
23
23
|
*/
|
|
24
24
|
export const Default: Story = {}
|
|
@@ -49,8 +49,8 @@ export const WithGroupLinks: Story = {
|
|
|
49
49
|
export const CustomLinks: Story = {
|
|
50
50
|
args: {
|
|
51
51
|
links: [
|
|
52
|
-
{ label: 'Help
|
|
53
|
-
{ label: 'Privacy
|
|
52
|
+
{ label: 'Help', href: '#help', newTab: false },
|
|
53
|
+
{ label: 'Privacy', href: '#privacy', newTab: false },
|
|
54
54
|
{ label: 'Terms of use', href: '#terms', newTab: false },
|
|
55
55
|
],
|
|
56
56
|
},
|
|
@@ -19,7 +19,7 @@ export interface FooterLink {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* The bottom of an app's page: on the left Help
|
|
22
|
+
* The bottom of an app's page: on the left Help and the legal links (Privacy, Terms), and
|
|
23
23
|
* on the right the app's name, version and build (so a bug report can say exactly which build) with
|
|
24
24
|
* the copyright. The same in every Keston app; pass the app's `version` and `build`.
|
|
25
25
|
*
|
|
@@ -35,7 +35,7 @@ export interface FooterLink {
|
|
|
35
35
|
* Slots: nav (instead of the whole link list), end (after the copyright).
|
|
36
36
|
*/
|
|
37
37
|
export interface FooterProps {
|
|
38
|
-
/** The links on the left. Default: `kestonFooterLinks` (Help
|
|
38
|
+
/** The links on the left. Default: `kestonFooterLinks` (Help, Privacy, Terms). */
|
|
39
39
|
links?: FooterLink[]
|
|
40
40
|
/** More links after a divider, e.g. Contact us, or `kestonGroupLinks` to point at the other Keston apps. */
|
|
41
41
|
moreLinks?: FooterLink[]
|
|
@@ -116,10 +116,11 @@ function linkAttrs(link: FooterLink) {
|
|
|
116
116
|
</nav>
|
|
117
117
|
|
|
118
118
|
<div :class="cn('flex flex-wrap items-center gap-x-3 gap-y-2 sm:justify-end', ui?.meta)">
|
|
119
|
-
<!-- Language and appearance
|
|
119
|
+
<!-- Language (a compact dropdown) and appearance (Light / Dark / System
|
|
120
|
+
side by side), labelled for screen readers. -->
|
|
120
121
|
<div v-if="showLanguages || themeSwitcher" class="flex flex-wrap items-center gap-2">
|
|
121
122
|
<LanguageSwitcher v-if="showLanguages" hide-label class="w-44" />
|
|
122
|
-
<ThemeSwitcher v-if="themeSwitcher" hide-label
|
|
123
|
+
<ThemeSwitcher v-if="themeSwitcher" hide-label appearance="segmented" />
|
|
123
124
|
</div>
|
|
124
125
|
<p v-if="appName || version || build" class="flex flex-wrap items-baseline gap-x-1.5">
|
|
125
126
|
<span v-if="appName" class="font-bold text-ink/80">{{ appName }}</span>
|
|
@@ -27,8 +27,8 @@ describe('version', () => {
|
|
|
27
27
|
})
|
|
28
28
|
|
|
29
29
|
describe('kestonFooterLinks', () => {
|
|
30
|
-
it('are Help
|
|
31
|
-
expect(kestonFooterLinks.map((l) => l.label)).toEqual(['Help
|
|
30
|
+
it('are Help, Privacy and Terms, on secure thekestongroup.com addresses', () => {
|
|
31
|
+
expect(kestonFooterLinks.map((l) => l.label)).toEqual(['Help', 'Privacy', 'Terms'])
|
|
32
32
|
for (const link of kestonFooterLinks) expect(link.href).toMatch(/^https:\/\/thekestongroup\.com\/(help|privacy|terms)$/)
|
|
33
33
|
})
|
|
34
34
|
})
|
|
@@ -5,9 +5,9 @@ import type { FooterLink } from './Footer.vue'
|
|
|
5
5
|
* Apps can pass their own `links`, or add to these with `moreLinks`.
|
|
6
6
|
*/
|
|
7
7
|
export const kestonFooterLinks: FooterLink[] = [
|
|
8
|
-
{ label: 'Help
|
|
9
|
-
{ label: 'Privacy
|
|
10
|
-
{ label: 'Terms
|
|
8
|
+
{ label: 'Help', href: 'https://thekestongroup.com/help' },
|
|
9
|
+
{ label: 'Privacy', href: 'https://thekestongroup.com/privacy' },
|
|
10
|
+
{ label: 'Terms', href: 'https://thekestongroup.com/terms' }
|
|
11
11
|
]
|
|
12
12
|
|
|
13
13
|
/** Links to the rest of the Keston Group. Not shown by default: pass them as `moreLinks` where an app should offer them. */
|
|
@@ -117,7 +117,11 @@ const box = [
|
|
|
117
117
|
'has-focus-visible:outline-focus',
|
|
118
118
|
// A control can mark itself data-pointer-focus to hide the ring while it
|
|
119
119
|
// holds focus that came from the mouse (Select, after its list closes).
|
|
120
|
-
'has-[[data-pointer-focus]]:outline-transparent!'
|
|
120
|
+
'has-[[data-pointer-focus]]:outline-transparent!',
|
|
121
|
+
// Filled in by the browser (saved email or password): the whole field is
|
|
122
|
+
// tinted, rounded corners and padding included, rather than the browser
|
|
123
|
+
// painting a square behind the text only (theme.css keeps that off).
|
|
124
|
+
'has-[input:autofill]:bg-autofill has-[input:-webkit-autofill]:bg-autofill'
|
|
121
125
|
]
|
|
122
126
|
|
|
123
127
|
const statusBorder: Record<FormFieldStatus, string> = {
|
|
@@ -195,19 +195,32 @@ export const WithMiddle: Story = {
|
|
|
195
195
|
}),
|
|
196
196
|
};
|
|
197
197
|
|
|
198
|
-
|
|
198
|
+
// A made-up app icon (a rounded square with a K) and lockup, as data URLs.
|
|
199
|
+
const sampleIcon =
|
|
200
|
+
"data:image/svg+xml," +
|
|
201
|
+
encodeURIComponent(
|
|
202
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect width="24" height="24" rx="6" fill="#023750"/><path d="M8 6v12M8 12l7-6M10.5 10l5 8" stroke="#fff" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" fill="none"/></svg>',
|
|
203
|
+
);
|
|
204
|
+
const sampleLockup =
|
|
205
|
+
"data:image/svg+xml," +
|
|
206
|
+
encodeURIComponent(
|
|
207
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 150 24"><rect width="24" height="24" rx="6" fill="#023750"/><path d="M8 6v12M8 12l7-6M10.5 10l5 8" stroke="#fff" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" fill="none"/><text x="32" y="18" font-family="Lato, sans-serif" font-weight="700" font-size="16" fill="#023750">Admissions</text></svg>',
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* logo: the app's icon before its name, sized to the text and inside the
|
|
212
|
+
* title link (hover it). Pass `{ light, dark }` for a dark-mode version.
|
|
213
|
+
*/
|
|
199
214
|
export const WithLogo: Story = {
|
|
200
|
-
args: {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
</Header>`,
|
|
210
|
-
}),
|
|
215
|
+
args: { logo: sampleIcon, titleTo: "#home" },
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* lockup: icon and name in one image, in place of the title text. Its alt
|
|
220
|
+
* text is the title.
|
|
221
|
+
*/
|
|
222
|
+
export const WithLockup: Story = {
|
|
223
|
+
args: { lockup: sampleLockup, titleTo: "#home" },
|
|
211
224
|
};
|
|
212
225
|
|
|
213
226
|
/** Stays at the top while the page scrolls (the default). Scroll the box below. */
|
|
@@ -19,6 +19,9 @@ export interface HeaderUser {
|
|
|
19
19
|
|
|
20
20
|
export type HeaderUserAction = 'account-settings' | 'switch-account' | 'log-out'
|
|
21
21
|
|
|
22
|
+
/** An image, with an optional version for dark mode (e.g. white). */
|
|
23
|
+
export type HeaderImage = string | { light: string; dark?: string }
|
|
24
|
+
|
|
22
25
|
/**
|
|
23
26
|
* The bar across the top of every Keston app. It is the same in every app:
|
|
24
27
|
* a menu button (to open the Sidebar on small screens), the app's name, an
|
|
@@ -26,7 +29,9 @@ export type HeaderUserAction = 'account-settings' | 'switch-account' | 'log-out'
|
|
|
26
29
|
* the right (Account settings, Switch account, Log out). Each part can be
|
|
27
30
|
* overridden with a slot.
|
|
28
31
|
*
|
|
29
|
-
*
|
|
32
|
+
* The app's brand: `title` with a `logo` (icon) beside it, or a `lockup` (one image).
|
|
33
|
+
*
|
|
34
|
+
* Slots: start (the very first thing, before the menu button, e.g. the app launcher; give it a `-ml-2.5` button to line up with the padding), leading (before the title), title, default (the middle,
|
|
30
35
|
* fills the space between title and trailing), trailing (actions before the
|
|
31
36
|
* account menu), account (replaces the account menu, or the Sign in button),
|
|
32
37
|
* account-menu (extra content in the account menu, above Switch account /
|
|
@@ -37,6 +42,17 @@ export type HeaderUserAction = 'account-settings' | 'switch-account' | 'log-out'
|
|
|
37
42
|
export interface HeaderProps {
|
|
38
43
|
/** Name of the app or area, shown next to the menu button. */
|
|
39
44
|
title?: string
|
|
45
|
+
/**
|
|
46
|
+
* The app's icon, before its name: sized to the text (20px) and part of
|
|
47
|
+
* the title link. Decorative: the name is what's read out. Use this or
|
|
48
|
+
* `lockup`.
|
|
49
|
+
*/
|
|
50
|
+
logo?: HeaderImage
|
|
51
|
+
/**
|
|
52
|
+
* The app's lockup (icon and name in one image), in place of the title
|
|
53
|
+
* text, 24px tall and part of the title link. Its alt text is `title`.
|
|
54
|
+
*/
|
|
55
|
+
lockup?: HeaderImage
|
|
40
56
|
/**
|
|
41
57
|
* Make the title a link, e.g. to the app's dashboard: passed as `to` to
|
|
42
58
|
* `linkComponent` (e.g. a route), or as `href` without one.
|
|
@@ -139,6 +155,10 @@ const titleLinkClass = [
|
|
|
139
155
|
'outline-2 outline-offset-1 outline-transparent focus-visible:outline-focus forced-colors:not-focus-visible:outline-0'
|
|
140
156
|
]
|
|
141
157
|
|
|
158
|
+
const image = (i: HeaderImage | undefined) => (typeof i === 'string' ? { light: i, dark: undefined } : i)
|
|
159
|
+
const logoImage = computed(() => image(props.logo))
|
|
160
|
+
const lockupImage = computed(() => image(props.lockup))
|
|
161
|
+
|
|
142
162
|
function runAction(action: HeaderUserAction, close: () => void) {
|
|
143
163
|
close()
|
|
144
164
|
// Vue can't emit a name held in a variable with full typing, so switch.
|
|
@@ -176,13 +196,27 @@ function runAction(action: HeaderUserAction, close: () => void) {
|
|
|
176
196
|
|
|
177
197
|
<slot name="leading" />
|
|
178
198
|
|
|
199
|
+
<!-- The app's name (with its icon), or its lockup: all inside the title
|
|
200
|
+
link, so the whole thing goes home and gets the hover background. -->
|
|
179
201
|
<component
|
|
180
202
|
:is="titleLink ? linkComponent : 'span'"
|
|
181
|
-
v-if="title || $slots.title"
|
|
203
|
+
v-if="title || lockup || $slots.title"
|
|
182
204
|
v-bind="titleLink"
|
|
183
|
-
:class="cn('min-w-0
|
|
205
|
+
:class="cn('flex min-w-0 items-center gap-2 text-base font-bold', titleLink && titleLinkClass, ui?.title)"
|
|
184
206
|
>
|
|
185
|
-
<slot name="title">
|
|
207
|
+
<slot name="title">
|
|
208
|
+
<template v-if="lockupImage">
|
|
209
|
+
<img :src="lockupImage.light" :alt="title ?? ''" :class="cn('h-6 w-auto max-w-full', lockupImage.dark && 'dark:hidden')" />
|
|
210
|
+
<img v-if="lockupImage.dark" :src="lockupImage.dark" :alt="title ?? ''" class="hidden h-6 w-auto max-w-full dark:block" />
|
|
211
|
+
</template>
|
|
212
|
+
<template v-else>
|
|
213
|
+
<template v-if="logoImage">
|
|
214
|
+
<img :src="logoImage.light" alt="" :class="cn('size-5 shrink-0', logoImage.dark && 'dark:hidden')" />
|
|
215
|
+
<img v-if="logoImage.dark" :src="logoImage.dark" alt="" class="hidden size-5 shrink-0 dark:block" />
|
|
216
|
+
</template>
|
|
217
|
+
<span class="truncate">{{ title }}</span>
|
|
218
|
+
</template>
|
|
219
|
+
</slot>
|
|
186
220
|
</component>
|
|
187
221
|
|
|
188
222
|
<div :class="cn('flex min-w-0 flex-1 items-center', ui?.middle)">
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
|
2
|
+
import { List, LayoutGrid, Monitor, Moon, Sun } from "@lucide/vue";
|
|
3
|
+
import { ref } from "vue";
|
|
4
|
+
import SegmentedControl from "./SegmentedControl.vue";
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: "Components/Form/SegmentedControl",
|
|
8
|
+
component: SegmentedControl,
|
|
9
|
+
tags: ["autodocs"],
|
|
10
|
+
parameters: { layout: "padded" },
|
|
11
|
+
args: {
|
|
12
|
+
label: "Appearance",
|
|
13
|
+
options: [
|
|
14
|
+
{ label: "Light", value: "light", icon: Sun },
|
|
15
|
+
{ label: "Dark", value: "dark", icon: Moon },
|
|
16
|
+
{ label: "System", value: "system", icon: Monitor },
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
render: (args) => ({
|
|
20
|
+
components: { SegmentedControl },
|
|
21
|
+
setup: () => ({ args, value: ref(args.options[0]?.value) }),
|
|
22
|
+
template: `<SegmentedControl v-bind="args" v-model="value" />`,
|
|
23
|
+
}),
|
|
24
|
+
} satisfies Meta<typeof SegmentedControl>;
|
|
25
|
+
|
|
26
|
+
export default meta;
|
|
27
|
+
type Story = StoryObj<typeof meta>;
|
|
28
|
+
|
|
29
|
+
/** Light, Dark or System, with icons. Arrow keys move the choice. */
|
|
30
|
+
export const Default: Story = {};
|
|
31
|
+
|
|
32
|
+
/** Small, with the label for screen readers only: for a footer or toolbar. */
|
|
33
|
+
export const Small: Story = { args: { size: "sm", hideLabel: true } };
|
|
34
|
+
|
|
35
|
+
/** Icons only: each label is the option's accessible name and its tooltip. */
|
|
36
|
+
export const IconOnly: Story = {
|
|
37
|
+
args: {
|
|
38
|
+
label: "View",
|
|
39
|
+
iconOnly: true,
|
|
40
|
+
options: [
|
|
41
|
+
{ label: "List", value: "list", icon: List },
|
|
42
|
+
{ label: "Grid", value: "grid", icon: LayoutGrid },
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Without icons, one option turned off. */
|
|
48
|
+
export const Plain: Story = {
|
|
49
|
+
args: {
|
|
50
|
+
label: "Period",
|
|
51
|
+
options: [
|
|
52
|
+
{ label: "Day", value: "day" },
|
|
53
|
+
{ label: "Week", value: "week" },
|
|
54
|
+
{ label: "Term", value: "term", disabled: true },
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, useId, type Component, type HTMLAttributes } from 'vue'
|
|
3
|
+
import { RadioGroupItem, RadioGroupRoot } from 'reka-ui'
|
|
4
|
+
import { cn } from '../../lib/cn'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One choice from two to four short options, shown as a row of tab-like
|
|
8
|
+
* buttons, e.g. Light / Dark / System. It's a radio group: arrow keys move
|
|
9
|
+
* the choice, and it applies at once. Smaller than a Select and shows every
|
|
10
|
+
* option, so it suits settings that sit in a toolbar or footer.
|
|
11
|
+
*
|
|
12
|
+
* For a choice that changes what's on the page below (sections), use Tabs.
|
|
13
|
+
* For longer options or ones with descriptions, use RadioGroup.
|
|
14
|
+
*/
|
|
15
|
+
export type SegmentedValue = string | number
|
|
16
|
+
|
|
17
|
+
export interface SegmentedOption {
|
|
18
|
+
label: string
|
|
19
|
+
value: SegmentedValue
|
|
20
|
+
/** An icon before the label (decorative). */
|
|
21
|
+
icon?: Component
|
|
22
|
+
disabled?: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface SegmentedControlProps {
|
|
26
|
+
/** What's being chosen, e.g. "Appearance". The group's accessible name. */
|
|
27
|
+
label: string
|
|
28
|
+
/** Keep the label for screen readers only. */
|
|
29
|
+
hideLabel?: boolean
|
|
30
|
+
options: SegmentedOption[]
|
|
31
|
+
/**
|
|
32
|
+
* Icons only: each option's label becomes its accessible name and shows
|
|
33
|
+
* as a tooltip-style title. Every option needs an icon.
|
|
34
|
+
*/
|
|
35
|
+
iconOnly?: boolean
|
|
36
|
+
size?: 'sm' | 'md'
|
|
37
|
+
disabled?: boolean
|
|
38
|
+
/** Name for native form submission. */
|
|
39
|
+
name?: string
|
|
40
|
+
class?: HTMLAttributes['class']
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const props = withDefaults(defineProps<SegmentedControlProps>(), { size: 'md' })
|
|
44
|
+
|
|
45
|
+
/** The chosen option's value. */
|
|
46
|
+
const model = defineModel<SegmentedValue | undefined>()
|
|
47
|
+
|
|
48
|
+
const labelId = `${useId()}-label`
|
|
49
|
+
|
|
50
|
+
const sizes = {
|
|
51
|
+
sm: { item: 'h-7 px-2.5 text-xs gap-1.5 [&_svg]:size-3.5', icon: 'size-7' },
|
|
52
|
+
md: { item: 'h-8 px-3 text-sm gap-2 [&_svg]:size-4', icon: 'size-8' }
|
|
53
|
+
}
|
|
54
|
+
const itemSize = computed(() => (props.iconOnly ? `${sizes[props.size].icon} justify-center [&_svg]:size-4` : sizes[props.size].item))
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
<template>
|
|
58
|
+
<div :class="cn('inline-flex flex-col gap-1.5', props.class)">
|
|
59
|
+
<span :id="labelId" :class="hideLabel ? 'sr-only' : 'text-sm font-bold text-ink'">{{ label }}</span>
|
|
60
|
+
<RadioGroupRoot
|
|
61
|
+
v-model="model"
|
|
62
|
+
:aria-labelledby="labelId"
|
|
63
|
+
:disabled="disabled"
|
|
64
|
+
:name="name"
|
|
65
|
+
orientation="horizontal"
|
|
66
|
+
loop
|
|
67
|
+
class="inline-flex w-max max-w-full gap-0.5 rounded-lg bg-ink/5 p-0.5"
|
|
68
|
+
>
|
|
69
|
+
<!-- The chosen one is raised like a basic button (control colours: a
|
|
70
|
+
step above the track in light and dark). -->
|
|
71
|
+
<RadioGroupItem
|
|
72
|
+
v-for="option in options"
|
|
73
|
+
:key="option.value"
|
|
74
|
+
:value="option.value"
|
|
75
|
+
:disabled="option.disabled"
|
|
76
|
+
:aria-label="iconOnly ? option.label : undefined"
|
|
77
|
+
:title="iconOnly ? option.label : undefined"
|
|
78
|
+
:class="
|
|
79
|
+
cn(
|
|
80
|
+
'inline-flex shrink-0 cursor-pointer items-center rounded-md font-bold whitespace-nowrap text-ink/65 outline-2 outline-offset-1 outline-transparent transition-colors duration-150 motion-reduce:transition-none',
|
|
81
|
+
'not-disabled:hover:text-ink focus-visible:outline-focus',
|
|
82
|
+
'data-[state=checked]:bg-control data-[state=checked]:text-ink data-[state=checked]:shadow-xs',
|
|
83
|
+
'disabled:cursor-not-allowed disabled:opacity-40',
|
|
84
|
+
itemSize
|
|
85
|
+
)
|
|
86
|
+
"
|
|
87
|
+
>
|
|
88
|
+
<component :is="option.icon" v-if="option.icon" aria-hidden="true" />
|
|
89
|
+
<span v-if="!iconOnly">{{ option.label }}</span>
|
|
90
|
+
</RadioGroupItem>
|
|
91
|
+
</RadioGroupRoot>
|
|
92
|
+
</div>
|
|
93
|
+
</template>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { computed, type HTMLAttributes } from 'vue'
|
|
3
3
|
import { useI18n } from 'vue-i18n'
|
|
4
4
|
import { Monitor, Moon, Sun } from '@lucide/vue'
|
|
5
|
+
import SegmentedControl from '../SegmentedControl/SegmentedControl.vue'
|
|
5
6
|
import Select from '../Select/Select.vue'
|
|
6
7
|
import { useTheme, type Theme } from '../../lib/theme'
|
|
7
8
|
|
|
@@ -17,17 +18,27 @@ export interface ThemeSwitcherProps {
|
|
|
17
18
|
/** Keep the label for screen readers only. */
|
|
18
19
|
hideLabel?: boolean
|
|
19
20
|
disabled?: boolean
|
|
21
|
+
/**
|
|
22
|
+
* select: a dropdown (Settings, the account menu). segmented: Light / Dark
|
|
23
|
+
* / System side by side with icons, small: for the footer.
|
|
24
|
+
*/
|
|
25
|
+
appearance?: 'select' | 'segmented'
|
|
20
26
|
class?: HTMLAttributes['class']
|
|
21
27
|
}
|
|
22
28
|
|
|
23
|
-
const props = defineProps<ThemeSwitcherProps>()
|
|
29
|
+
const props = withDefaults(defineProps<ThemeSwitcherProps>(), { appearance: 'select' })
|
|
24
30
|
const { t } = useI18n()
|
|
25
31
|
const { theme, setTheme } = useTheme()
|
|
26
32
|
|
|
27
33
|
const options = computed(() => [
|
|
28
34
|
{ label: t('ui.themeSwitcher.light'), value: 'light', icon: Sun },
|
|
29
35
|
{ label: t('ui.themeSwitcher.dark'), value: 'dark', icon: Moon },
|
|
30
|
-
{
|
|
36
|
+
{
|
|
37
|
+
// "System" fits the row; the dropdown has room for "Match device".
|
|
38
|
+
label: props.appearance === 'segmented' ? t('ui.themeSwitcher.systemShort') : t('ui.themeSwitcher.system'),
|
|
39
|
+
value: 'system',
|
|
40
|
+
icon: Monitor
|
|
41
|
+
}
|
|
31
42
|
])
|
|
32
43
|
|
|
33
44
|
const model = computed({
|
|
@@ -37,7 +48,18 @@ const model = computed({
|
|
|
37
48
|
</script>
|
|
38
49
|
|
|
39
50
|
<template>
|
|
51
|
+
<SegmentedControl
|
|
52
|
+
v-if="appearance === 'segmented'"
|
|
53
|
+
v-model="model"
|
|
54
|
+
size="sm"
|
|
55
|
+
:label="label ?? t('ui.themeSwitcher.label')"
|
|
56
|
+
:hide-label="hideLabel"
|
|
57
|
+
:options="options"
|
|
58
|
+
:disabled="disabled"
|
|
59
|
+
:class="props.class"
|
|
60
|
+
/>
|
|
40
61
|
<Select
|
|
62
|
+
v-else
|
|
41
63
|
v-model="model"
|
|
42
64
|
:label="label ?? t('ui.themeSwitcher.label')"
|
|
43
65
|
:hide-label="hideLabel"
|
package/src/i18n/en.ts
CHANGED
|
@@ -93,7 +93,7 @@ export const en = {
|
|
|
93
93
|
confirmDialog: { confirm: 'Confirm', cancel: 'Cancel' },
|
|
94
94
|
asyncState: { error: "Couldn't load this", retry: 'Try again' },
|
|
95
95
|
languageSwitcher: { label: 'Language' },
|
|
96
|
-
themeSwitcher: { label: 'Appearance', light: 'Light', dark: 'Dark', system: 'Match device' },
|
|
96
|
+
themeSwitcher: { label: 'Appearance', light: 'Light', dark: 'Dark', system: 'Match device', systemShort: 'System' },
|
|
97
97
|
notifications: {
|
|
98
98
|
title: 'Notifications',
|
|
99
99
|
region: 'Notification',
|
package/src/index.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type { Theme } from './lib/theme'
|
|
|
12
12
|
export { default as AppShell } from './components/AppShell/AppShell.vue'
|
|
13
13
|
export type { AppShellProps } from './components/AppShell/AppShell.vue'
|
|
14
14
|
export { default as Header } from './components/Header/Header.vue'
|
|
15
|
-
export type { HeaderProps, HeaderUser, HeaderUserAction } from './components/Header/Header.vue'
|
|
15
|
+
export type { HeaderImage, HeaderProps, HeaderUser, HeaderUserAction } from './components/Header/Header.vue'
|
|
16
16
|
export { default as PageHeader } from './components/PageHeader/PageHeader.vue'
|
|
17
17
|
export type { PageHeaderAction, PageHeaderProps } from './components/PageHeader/PageHeader.vue'
|
|
18
18
|
export { default as SettingsRow } from './components/SettingsRow/SettingsRow.vue'
|
|
@@ -134,6 +134,8 @@ export { default as Popover } from './components/Popover/Popover.vue'
|
|
|
134
134
|
export type { PopoverProps } from './components/Popover/Popover.vue'
|
|
135
135
|
export { default as Menu } from './components/Menu/Menu.vue'
|
|
136
136
|
export type { MenuItem, MenuProps } from './components/Menu/Menu.vue'
|
|
137
|
+
export { default as SegmentedControl } from './components/SegmentedControl/SegmentedControl.vue'
|
|
138
|
+
export type { SegmentedControlProps, SegmentedOption, SegmentedValue } from './components/SegmentedControl/SegmentedControl.vue'
|
|
137
139
|
export { default as Tabs } from './components/Tabs/Tabs.vue'
|
|
138
140
|
export type { Tab, TabsProps } from './components/Tabs/Tabs.vue'
|
|
139
141
|
export { default as Slideover } from './components/Slideover/Slideover.vue'
|
package/src/styles/theme.css
CHANGED
|
@@ -90,6 +90,8 @@
|
|
|
90
90
|
*/
|
|
91
91
|
--color-hover: color-mix(in oklab, var(--color-ink) 5%, transparent);
|
|
92
92
|
--color-pressed: color-mix(in oklab, var(--color-ink) 10%, transparent);
|
|
93
|
+
/* A field the browser filled in (saved email, password): a light tint of Keston blue. */
|
|
94
|
+
--color-autofill: light-dark(color-mix(in oklab, var(--color-kblue) 8%, var(--color-surface)), color-mix(in oklab, var(--color-primary-fg) 14%, var(--color-surface)));
|
|
93
95
|
--color-selected: var(--color-pressed);
|
|
94
96
|
--color-surface-hover: color-mix(in oklab, var(--color-surface) 95%, var(--color-ink));
|
|
95
97
|
--color-surface-pressed: color-mix(in oklab, var(--color-surface) 90%, var(--color-ink));
|
|
@@ -208,6 +210,18 @@
|
|
|
208
210
|
color-scheme: light dark;
|
|
209
211
|
}
|
|
210
212
|
|
|
213
|
+
/* Autofill: browsers paint their own background (and, in Chrome, black
|
|
214
|
+
text) on the <input> itself, a square inside the field's padding. Keep the
|
|
215
|
+
input see-through with our text colour; FormField tints the whole field
|
|
216
|
+
instead (--color-autofill). The long transition is the only way to stop
|
|
217
|
+
Chrome's background, which it sets with !important. */
|
|
218
|
+
input:autofill,
|
|
219
|
+
input:-webkit-autofill {
|
|
220
|
+
-webkit-text-fill-color: var(--color-ink);
|
|
221
|
+
caret-color: var(--color-ink);
|
|
222
|
+
transition: background-color 0s 600000s, color 0s 600000s;
|
|
223
|
+
}
|
|
224
|
+
|
|
211
225
|
/* Tailwind's dark: variant follows the same switch, for the rare case a
|
|
212
226
|
colour token can't express (e.g. Tooltip). */
|
|
213
227
|
@custom-variant dark {
|