@thekestongroup/ui 0.21.0 → 0.23.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 +12 -4
- package/dist/index.d.ts +1 -1
- package/dist/keston-ui.js +1025 -964
- package/dist/lib/theme.d.ts +12 -3
- package/package.json +1 -1
- package/src/components/AppLauncher/AppLauncher.stories.ts +38 -0
- package/src/components/AppLauncher/AppLauncher.vue +50 -21
- package/src/components/AppLauncher/apps.ts +2 -2
- package/src/components/AppLauncher/icons/admin-tile.svg +1 -0
- package/src/components/AppLauncher/icons/admin.svg +1 -0
- package/src/components/AppLauncher/icons/design-tile.svg +1 -0
- package/src/components/AppLauncher/icons/design.svg +1 -0
- package/src/components/AppLauncher/icons/id-tile.svg +1 -0
- package/src/components/AppLauncher/icons/id.svg +1 -0
- package/src/components/AppLauncher/icons/keston-tile.svg +1 -0
- package/src/components/AppLauncher/icons/keston.svg +1 -0
- package/src/components/AppLauncher/icons/utilities-tile.svg +1 -0
- package/src/components/Header/Header.stories.ts +16 -0
- package/src/index.ts +1 -1
- package/src/lib/theme.test.ts +16 -0
- package/src/lib/theme.ts +67 -5
package/dist/lib/theme.d.ts
CHANGED
|
@@ -2,12 +2,21 @@ import { Ref } from 'vue';
|
|
|
2
2
|
/**
|
|
3
3
|
* Light, dark or following the device. Keston UI's colours switch with the
|
|
4
4
|
* `data-theme` attribute on `<html>` (see theme.css, "Dark mode").
|
|
5
|
+
*
|
|
6
|
+
* The choice is shared by every Keston app: it's kept in a cookie for the
|
|
7
|
+
* whole Keston domain (e.g. `.keston.co`), so picking Dark in Keston Admin
|
|
8
|
+
* makes Keston ID dark too. Each app also keeps it in its own localStorage,
|
|
9
|
+
* which is all there is on other hosts (e.g. localhost).
|
|
5
10
|
*/
|
|
6
11
|
export type Theme = 'light' | 'dark' | 'system';
|
|
12
|
+
/** The domains whose apps share one theme (the cookie is set for the whole domain). */
|
|
13
|
+
export declare const sharedThemeDomains: readonly string[];
|
|
14
|
+
/** The shared domain this page is on, e.g. "keston.co" on admin.keston.co. */
|
|
15
|
+
export declare function sharedDomainFor(hostname: string, domains?: readonly string[]): string | undefined;
|
|
7
16
|
/**
|
|
8
17
|
* Applies the person's saved choice (or `fallback` if there is none) and keeps
|
|
9
|
-
* other tabs in step. Call it once in main.ts, before
|
|
10
|
-
* doesn't flash the wrong colours:
|
|
18
|
+
* other tabs and Keston apps in step. Call it once in main.ts, before
|
|
19
|
+
* mounting, so the page doesn't flash the wrong colours:
|
|
11
20
|
*
|
|
12
21
|
* initTheme() // follows the device until someone picks
|
|
13
22
|
* initTheme('light') // an app that starts light
|
|
@@ -15,7 +24,7 @@ export type Theme = 'light' | 'dark' | 'system';
|
|
|
15
24
|
export declare function initTheme(fallback?: Theme): void;
|
|
16
25
|
/**
|
|
17
26
|
* The current theme and a way to change it, e.g. for ThemeSwitcher. A change
|
|
18
|
-
* applies at once and is remembered in this browser.
|
|
27
|
+
* applies at once and is remembered in this browser, for every Keston app.
|
|
19
28
|
*/
|
|
20
29
|
export declare function useTheme(): {
|
|
21
30
|
theme: Readonly<Ref<Theme>>;
|
package/package.json
CHANGED
|
@@ -30,3 +30,41 @@ export const CustomApps: Story = {
|
|
|
30
30
|
],
|
|
31
31
|
},
|
|
32
32
|
};
|
|
33
|
+
|
|
34
|
+
import adminMark from "./icons/admin.svg";
|
|
35
|
+
import adminTile from "./icons/admin-tile.svg";
|
|
36
|
+
import designMark from "./icons/design.svg";
|
|
37
|
+
import designTile from "./icons/design-tile.svg";
|
|
38
|
+
import idMark from "./icons/id.svg";
|
|
39
|
+
import idTile from "./icons/id-tile.svg";
|
|
40
|
+
import kestonMark from "./icons/keston.svg";
|
|
41
|
+
import kestonTile from "./icons/keston-tile.svg";
|
|
42
|
+
import utilitiesTile from "./icons/utilities-tile.svg";
|
|
43
|
+
|
|
44
|
+
const rows = [
|
|
45
|
+
{ label: "App icons (the launcher)", images: [idTile, adminTile, kestonTile, utilitiesTile, designTile] },
|
|
46
|
+
{ label: "Marks (headers and sign-in, beside the app's name)", images: [idMark, adminMark, kestonMark, designMark] },
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The Keston apps' icons, on light and on dark: the app-icon tiles the
|
|
51
|
+
* launcher uses, and the plain marks the apps use beside their names.
|
|
52
|
+
*/
|
|
53
|
+
export const AppIcons: Story = {
|
|
54
|
+
decorators: [],
|
|
55
|
+
parameters: { layout: "fullscreen" },
|
|
56
|
+
render: () => ({
|
|
57
|
+
setup: () => ({ rows }),
|
|
58
|
+
template: `
|
|
59
|
+
<div class="flex flex-col gap-4 p-4">
|
|
60
|
+
<div v-for="row in rows" :key="row.label" class="flex flex-col gap-2">
|
|
61
|
+
<p class="text-sm font-bold">{{ row.label }}</p>
|
|
62
|
+
<div v-for="mode in ['light', 'dark']" :key="mode"
|
|
63
|
+
:class="['flex flex-wrap items-end gap-4 rounded-lg p-5', mode === 'light' ? 'bg-white' : 'bg-[#262626]']">
|
|
64
|
+
<img v-for="(src, i) in row.images" :key="'s' + i" :src="src" alt="" class="size-5" />
|
|
65
|
+
<img v-for="(src, i) in row.images" :key="'l' + i" :src="src" alt="" class="size-12" />
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
</div>`,
|
|
69
|
+
}),
|
|
70
|
+
};
|
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import
|
|
2
|
+
import adminTile from './icons/admin-tile.svg'
|
|
3
|
+
import designTile from './icons/design-tile.svg'
|
|
4
|
+
import idTile from './icons/id-tile.svg'
|
|
5
|
+
import kestonTile from './icons/keston-tile.svg'
|
|
6
|
+
import utilitiesTile from './icons/utilities-tile.svg'
|
|
3
7
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/** An app's icon as an image, with an optional version for dark mode. */
|
|
9
|
+
export type AppLauncherImage = { light: string; dark?: string }
|
|
10
|
+
|
|
11
|
+
// The Keston apps' icons: a rounded square in the app's colour with its mark
|
|
12
|
+
// in white, like a phone's app icons, so they're clear on light and dark.
|
|
13
|
+
// Apps without a mark of their own have The Keston Group's.
|
|
14
|
+
const builtInIcons: Record<string, AppLauncherImage> = {
|
|
15
|
+
id: { light: idTile },
|
|
16
|
+
admin: { light: adminTile },
|
|
17
|
+
work: { light: kestonTile },
|
|
18
|
+
utilities: { light: utilitiesTile },
|
|
19
|
+
design: { light: designTile }
|
|
10
20
|
}
|
|
11
21
|
</script>
|
|
12
22
|
|
|
13
23
|
<script setup lang="ts">
|
|
14
24
|
import { useI18n } from 'vue-i18n'
|
|
15
|
-
import { LayoutGrid } from '@lucide/vue'
|
|
25
|
+
import { AppWindow, Check, LayoutGrid } from '@lucide/vue'
|
|
16
26
|
import type { Component, HTMLAttributes } from 'vue'
|
|
17
27
|
import { cn } from '../../lib/cn'
|
|
18
28
|
import Button from '../Button/Button.vue'
|
|
@@ -24,15 +34,18 @@ export interface AppLauncherApp {
|
|
|
24
34
|
id: string
|
|
25
35
|
label: string
|
|
26
36
|
href: string
|
|
27
|
-
/**
|
|
28
|
-
|
|
37
|
+
/**
|
|
38
|
+
* The app's icon: the name of a Keston app's (id, admin, work, utilities,
|
|
39
|
+
* design), an image (`{ light, dark }`), or an icon component.
|
|
40
|
+
*/
|
|
41
|
+
icon?: Component | string | AppLauncherImage
|
|
29
42
|
/** Signs in with Keston ID, so it's given the `loginHint`. Default true. */
|
|
30
43
|
signsIn?: boolean
|
|
31
44
|
}
|
|
32
45
|
|
|
33
46
|
/**
|
|
34
|
-
* The grid button in the header that opens a
|
|
35
|
-
* them. The same in every app: it lists `kestonApps` and marks the one you are in with `current`. In an app
|
|
47
|
+
* The grid button in the header that opens a list of the Keston Group's apps, so people can move between
|
|
48
|
+
* them: each app's icon and name, in rows like a Select's options, with a tick by the one you're in. The same in every app: it lists `kestonApps` and marks the one you are in with `current`. In an app
|
|
36
49
|
* built on AppShell, pass `launcher` to AppShell instead of using this directly.
|
|
37
50
|
*
|
|
38
51
|
* Apps open in the same tab, as moving between Keston apps is moving on, not a side trip (the footer's
|
|
@@ -72,34 +85,50 @@ function hrefOf(app: AppLauncherApp): string {
|
|
|
72
85
|
}
|
|
73
86
|
}
|
|
74
87
|
|
|
75
|
-
function
|
|
76
|
-
|
|
77
|
-
|
|
88
|
+
function isImage(icon: AppLauncherApp['icon']): icon is AppLauncherImage {
|
|
89
|
+
return typeof icon === 'object' && icon !== null && 'light' in icon
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function imageOf(app: AppLauncherApp): AppLauncherImage | undefined {
|
|
93
|
+
if (typeof app.icon === 'string') return builtInIcons[app.icon]
|
|
94
|
+
return isImage(app.icon) ? app.icon : undefined
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function componentOf(app: AppLauncherApp): Component {
|
|
98
|
+
return typeof app.icon === 'object' && !isImage(app.icon) ? (app.icon as Component) : AppWindow
|
|
78
99
|
}
|
|
79
100
|
</script>
|
|
80
101
|
|
|
81
102
|
<template>
|
|
82
|
-
<Popover :content="{ align }" :ui="{ content: 'w-64
|
|
103
|
+
<Popover :content="{ align }" :ui="{ content: 'w-64 overflow-hidden py-1' }">
|
|
83
104
|
<Button variant="ghost" square :aria-label="label ?? t('ui.appLauncher.label')" :class="props.class">
|
|
84
105
|
<LayoutGrid />
|
|
85
106
|
</Button>
|
|
86
107
|
<template #content="{ close }">
|
|
87
108
|
<nav :aria-label="label ?? t('ui.appLauncher.label')">
|
|
109
|
+
<!-- Like a Select's options: 32px rows the full width of the panel,
|
|
110
|
+
square, tinted on hover and focus; the app's icon, its name, and
|
|
111
|
+
a tick by the app you're in. -->
|
|
88
112
|
<ul>
|
|
89
113
|
<li v-for="app in apps" :key="app.id">
|
|
90
114
|
<a
|
|
91
115
|
:href="hrefOf(app)"
|
|
92
116
|
:aria-current="app.id === current ? 'page' : undefined"
|
|
93
117
|
:class="cn(
|
|
94
|
-
'flex items-center gap-
|
|
95
|
-
app.id === current && '
|
|
118
|
+
'flex min-h-8 items-center gap-2 px-3 py-1.5 text-sm text-ink no-underline outline-none hover:bg-selected focus-visible:bg-selected',
|
|
119
|
+
app.id === current && 'font-bold'
|
|
96
120
|
)"
|
|
97
121
|
@click="close()"
|
|
98
122
|
>
|
|
99
|
-
<
|
|
100
|
-
<
|
|
123
|
+
<template v-if="imageOf(app)">
|
|
124
|
+
<img :src="imageOf(app)!.light" alt="" :class="cn('size-5 shrink-0', imageOf(app)!.dark && 'dark:hidden')" />
|
|
125
|
+
<img v-if="imageOf(app)!.dark" :src="imageOf(app)!.dark" alt="" class="hidden size-5 shrink-0 dark:block" />
|
|
126
|
+
</template>
|
|
127
|
+
<component :is="componentOf(app)" v-else class="size-5 shrink-0" aria-hidden="true" />
|
|
128
|
+
<span class="min-w-0 flex-1 truncate">{{ app.label }}</span>
|
|
129
|
+
<span class="flex w-4 shrink-0 items-center justify-center">
|
|
130
|
+
<Check v-if="app.id === current" class="size-4" aria-hidden="true" />
|
|
101
131
|
</span>
|
|
102
|
-
<span class="min-w-0 truncate">{{ app.label }}</span>
|
|
103
132
|
</a>
|
|
104
133
|
</li>
|
|
105
134
|
</ul>
|
|
@@ -3,8 +3,8 @@ import type { AppLauncherApp } from './AppLauncher.vue'
|
|
|
3
3
|
/** The Keston Group's apps, as the launcher lists them by default. Apps can pass their own `apps`. */
|
|
4
4
|
export const kestonApps: AppLauncherApp[] = [
|
|
5
5
|
{ id: 'id', label: 'Keston ID', href: 'https://id.keston.co', icon: 'id' },
|
|
6
|
-
{ id: 'admin', label: 'Admin', href: 'https://admin.keston.co', icon: 'admin' },
|
|
6
|
+
{ id: 'admin', label: 'Keston Admin', href: 'https://admin.keston.co', icon: 'admin' },
|
|
7
7
|
{ id: 'work', label: 'Work', href: 'https://work.keston.co', icon: 'work' },
|
|
8
8
|
{ id: 'utilities', label: 'Utilities', href: 'https://utilities.keston.co', icon: 'utilities', signsIn: false },
|
|
9
|
-
{ id: 'design', label: '
|
|
9
|
+
{ id: 'design', label: 'Keston UI', href: 'https://ui.keston.co', icon: 'design', signsIn: false }
|
|
10
10
|
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" width="240" height="240"><title>Keston Admin app icon</title><rect width="120" height="120" rx="28" fill="#6B3FE0"/><g transform="translate(18 18) scale(0.7)"><path d="M6 60 L30 30 L42 44 L60 8 L78 38 L88 26 L114 60 L60 112 Z" fill="#FFFFFF" stroke="#FFFFFF" stroke-width="4" stroke-linejoin="round"/><path d="M30 46 L52 80 L60 96 L20 62 Z M88 42 L100 62 L60 96 L70 68 Z" fill="#9474EC"/><path d="M60 24 L86 74 L60 96 L34 74 Z" fill="#6B3FE0"/><path d="M60 24 L86 74 L60 96 Z" fill="#4A23B0"/><path d="M48 60 H72 M48 71 H72" stroke="#FFFFFF" stroke-width="4" stroke-linecap="round" fill="none"/><circle cx="54" cy="60" r="4.5" fill="#FFFFFF"/><circle cx="66" cy="71" r="4.5" fill="#FFFFFF"/></g></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" width="240" height="240"><title>Keston Admin</title><path d="M6 60 L30 30 L42 44 L60 8 L78 38 L88 26 L114 60 L60 112 Z" fill="#6B3FE0" stroke="#6B3FE0" stroke-width="4" stroke-linejoin="round"/><path d="M30 46 L52 80 L60 96 L20 62 Z M88 42 L100 62 L60 96 L70 68 Z" fill="#BFA8F7"/><path d="M60 24 L86 74 L60 96 L34 74 Z" fill="#FFFFFF"/><path d="M60 24 L86 74 L60 96 Z" fill="#E6DCFF"/><path d="M48 60 H72 M48 71 H72" stroke="#6B3FE0" stroke-width="4" stroke-linecap="round" fill="none"/><circle cx="54" cy="60" r="4.5" fill="#6B3FE0"/><circle cx="66" cy="71" r="4.5" fill="#6B3FE0"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" width="240" height="240"><title>Keston UI app icon</title><rect width="120" height="120" rx="28" fill="#E0A800"/><g transform="translate(18 18) scale(0.7)"><path d="M6 60 L30 30 L42 44 L60 8 L78 38 L88 26 L114 60 L60 112 Z" fill="#FFFFFF" stroke="#FFFFFF" stroke-width="4" stroke-linejoin="round"/><path d="M30 46 L52 80 L60 96 L20 62 Z M88 42 L100 62 L60 96 L70 68 Z" fill="#F2C94A"/><path d="M60 24 L86 74 L60 96 L34 74 Z" fill="#E0A800"/><path d="M60 24 L86 74 L60 96 Z" fill="#B08400"/><path d="M60 26 V61 A6.5 6.5 0 1 1 60 71 V94" fill="none" stroke="#FFFFFF" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></g></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" width="240" height="240"><title>Keston UI</title><path d="M6 60 L30 30 L42 44 L60 8 L78 38 L88 26 L114 60 L60 112 Z" fill="#E0A800" stroke="#E0A800" stroke-width="4" stroke-linejoin="round"/><path d="M30 46 L52 80 L60 96 L20 62 Z M88 42 L100 62 L60 96 L70 68 Z" fill="#F5CD57"/><path d="M60 24 L86 74 L60 96 L34 74 Z" fill="#FFFFFF"/><path d="M60 24 L86 74 L60 96 Z" fill="#FEEDB2"/><path d="M60 26 V61 A6.5 6.5 0 1 1 60 71 V94" fill="none" stroke="#E0A800" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" width="240" height="240"><title>Keston ID app icon</title><rect width="120" height="120" rx="28" fill="#2448FF"/><g transform="translate(18 18) scale(0.7)"><path d="M6 60 L30 30 L42 44 L60 8 L78 38 L88 26 L114 60 L60 112 Z" fill="#FFFFFF" stroke="#FFFFFF" stroke-width="4" stroke-linejoin="round"/><path d="M30 46 L52 80 L60 96 L20 62 Z M88 42 L100 62 L60 96 L70 68 Z" fill="#6B85FF"/><path d="M60 24 L86 74 L60 96 L34 74 Z" fill="#2448FF"/><path d="M60 24 L86 74 L60 96 Z" fill="#1532C8"/><path d="M56.5 57 A5.5 5.5 0 1 1 63.5 57 L66 76 H54 Z" fill="#FFFFFF" stroke="#FFFFFF" stroke-width="4" stroke-linejoin="round" stroke-linecap="round"/></g></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" width="240" height="240"><title>Keston ID</title><path d="M6 60 L30 30 L42 44 L60 8 L78 38 L88 26 L114 60 L60 112 Z" fill="#2448FF" stroke="#2448FF" stroke-width="4" stroke-linejoin="round"/><path d="M30 46 L52 80 L60 96 L20 62 Z M88 42 L100 62 L60 96 L70 68 Z" fill="#9DB0FF"/><path d="M60 24 L86 74 L60 96 L34 74 Z" fill="#FFFFFF"/><path d="M60 24 L86 74 L60 96 Z" fill="#D3DCFF"/><path d="M56.5 57 A5.5 5.5 0 1 1 63.5 57 L66 76 H54 Z" fill="#2448FF" stroke="#2448FF" stroke-width="4" stroke-linejoin="round" stroke-linecap="round"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" width="240" height="240"><title>The Keston Group app icon</title><rect width="120" height="120" rx="28" fill="#14161A"/><g transform="translate(18 18) scale(0.7)"><path d="M6 60 L30 30 L42 44 L60 8 L78 38 L88 26 L114 60 L60 112 Z" fill="#FFFFFF" stroke="#FFFFFF" stroke-width="4" stroke-linejoin="round"/><path d="M30 46 L52 80 L60 96 L20 62 Z M88 42 L100 62 L60 96 L70 68 Z" fill="#4A4F58"/><path d="M60 24 L86 74 L60 96 L34 74 Z" fill="#14161A"/><path d="M60 24 L86 74 L60 96 Z" fill="#000000"/></g></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" width="240" height="240"><title>Keston</title><path d="M6 60 L30 30 L42 44 L60 8 L78 38 L88 26 L114 60 L60 112 Z" fill="#14161A" stroke="#14161A" stroke-width="4" stroke-linejoin="round"/><path d="M30 46 L52 80 L60 96 L20 62 Z M88 42 L100 62 L60 96 L70 68 Z" fill="#9EA3AD"/><path d="M60 24 L86 74 L60 96 L34 74 Z" fill="#FFFFFF"/><path d="M60 24 L86 74 L60 96 Z" fill="#DADDE3"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" rx="7" fill="#023750"/><path d="M9 11h14M9 16h14M9 21h9" stroke="#fafafa" stroke-width="2.5" stroke-linecap="round"/></svg>
|
|
@@ -4,6 +4,8 @@ import { ref } from "vue";
|
|
|
4
4
|
import Button from "../Button/Button.vue";
|
|
5
5
|
import Header, { type HeaderUser } from "./Header.vue";
|
|
6
6
|
import ThemeSwitcher from "../ThemeSwitcher/ThemeSwitcher.vue";
|
|
7
|
+
import AppLauncher from "../AppLauncher/AppLauncher.vue";
|
|
8
|
+
import idMark from "../AppLauncher/icons/id.svg";
|
|
7
9
|
|
|
8
10
|
const user: HeaderUser = {
|
|
9
11
|
name: "Ben Smith",
|
|
@@ -215,6 +217,20 @@ export const WithLogo: Story = {
|
|
|
215
217
|
args: { logo: sampleIcon, titleTo: "#home" },
|
|
216
218
|
};
|
|
217
219
|
|
|
220
|
+
/**
|
|
221
|
+
* A Keston app's header: its coloured mark beside its name (in colour in dark
|
|
222
|
+
* mode too), and the app launcher at the start. Switch the theme in the
|
|
223
|
+
* toolbar to see it on dark.
|
|
224
|
+
*/
|
|
225
|
+
export const KestonApp: Story = {
|
|
226
|
+
args: { title: "Keston ID", logo: idMark, titleTo: "#home" },
|
|
227
|
+
render: (args) => ({
|
|
228
|
+
components: { Header, AppLauncher },
|
|
229
|
+
setup: () => ({ args }),
|
|
230
|
+
template: `<Header v-bind="args"><template #start><AppLauncher current="id" align="start" class="-ml-2.5" /></template></Header>`,
|
|
231
|
+
}),
|
|
232
|
+
};
|
|
233
|
+
|
|
218
234
|
/**
|
|
219
235
|
* lockup: icon and name in one image, in place of the title text. Its alt
|
|
220
236
|
* text is the title.
|
package/src/index.ts
CHANGED
|
@@ -18,7 +18,7 @@ export type { PageHeaderAction, PageHeaderProps } from './components/PageHeader/
|
|
|
18
18
|
export { default as SettingsRow } from './components/SettingsRow/SettingsRow.vue'
|
|
19
19
|
export type { SettingsRowProps } from './components/SettingsRow/SettingsRow.vue'
|
|
20
20
|
export { default as AppLauncher } from './components/AppLauncher/AppLauncher.vue'
|
|
21
|
-
export type { AppLauncherApp, AppLauncherProps } from './components/AppLauncher/AppLauncher.vue'
|
|
21
|
+
export type { AppLauncherApp, AppLauncherImage, AppLauncherProps } from './components/AppLauncher/AppLauncher.vue'
|
|
22
22
|
export { kestonApps } from './components/AppLauncher/apps'
|
|
23
23
|
export { default as Footer } from './components/Footer/Footer.vue'
|
|
24
24
|
export type { FooterLink, FooterProps } from './components/Footer/Footer.vue'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { sharedDomainFor } from './theme'
|
|
3
|
+
|
|
4
|
+
describe('sharedDomainFor', () => {
|
|
5
|
+
it('finds the Keston domain for the apex and its apps', () => {
|
|
6
|
+
expect(sharedDomainFor('keston.co')).toBe('keston.co')
|
|
7
|
+
expect(sharedDomainFor('admin.keston.co')).toBe('keston.co')
|
|
8
|
+
expect(sharedDomainFor('ID.Keston.co.')).toBe('keston.co')
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it("doesn't share with other hosts", () => {
|
|
12
|
+
expect(sharedDomainFor('localhost')).toBeUndefined()
|
|
13
|
+
expect(sharedDomainFor('notkeston.co')).toBeUndefined()
|
|
14
|
+
expect(sharedDomainFor('keston.co.evil.com')).toBeUndefined()
|
|
15
|
+
})
|
|
16
|
+
})
|
package/src/lib/theme.ts
CHANGED
|
@@ -3,19 +3,58 @@ import { readonly, ref, type Ref } from 'vue'
|
|
|
3
3
|
/**
|
|
4
4
|
* Light, dark or following the device. Keston UI's colours switch with the
|
|
5
5
|
* `data-theme` attribute on `<html>` (see theme.css, "Dark mode").
|
|
6
|
+
*
|
|
7
|
+
* The choice is shared by every Keston app: it's kept in a cookie for the
|
|
8
|
+
* whole Keston domain (e.g. `.keston.co`), so picking Dark in Keston Admin
|
|
9
|
+
* makes Keston ID dark too. Each app also keeps it in its own localStorage,
|
|
10
|
+
* which is all there is on other hosts (e.g. localhost).
|
|
6
11
|
*/
|
|
7
12
|
export type Theme = 'light' | 'dark' | 'system'
|
|
8
13
|
|
|
9
14
|
const STORAGE_KEY = 'keston-theme'
|
|
15
|
+
const COOKIE = 'keston-theme'
|
|
10
16
|
const themes: readonly Theme[] = ['light', 'dark', 'system']
|
|
11
17
|
|
|
18
|
+
/** The domains whose apps share one theme (the cookie is set for the whole domain). */
|
|
19
|
+
export const sharedThemeDomains: readonly string[] = ['keston.co']
|
|
20
|
+
|
|
12
21
|
function isTheme(value: unknown): value is Theme {
|
|
13
22
|
return typeof value === 'string' && (themes as readonly string[]).includes(value)
|
|
14
23
|
}
|
|
15
24
|
|
|
25
|
+
/** The shared domain this page is on, e.g. "keston.co" on admin.keston.co. */
|
|
26
|
+
export function sharedDomainFor(hostname: string, domains: readonly string[] = sharedThemeDomains): string | undefined {
|
|
27
|
+
const host = hostname.toLowerCase().replace(/\.$/, '')
|
|
28
|
+
return domains.find((d) => host === d || host.endsWith(`.${d}`))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function readCookie(): Theme | undefined {
|
|
32
|
+
if (typeof document === 'undefined') return undefined
|
|
33
|
+
try {
|
|
34
|
+
const match = document.cookie.split('; ').find((c) => c.startsWith(`${COOKIE}=`))
|
|
35
|
+
const value = match?.slice(COOKIE.length + 1)
|
|
36
|
+
return isTheme(value) ? value : undefined
|
|
37
|
+
} catch {
|
|
38
|
+
return undefined
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function writeCookie(theme: Theme) {
|
|
43
|
+
if (typeof document === 'undefined' || typeof location === 'undefined') return
|
|
44
|
+
const domain = sharedDomainFor(location.hostname)
|
|
45
|
+
if (!domain) return
|
|
46
|
+
try {
|
|
47
|
+
const secure = location.protocol === 'https:' ? '; Secure' : ''
|
|
48
|
+
// A year; re-saved each time someone picks.
|
|
49
|
+
document.cookie = `${COOKIE}=${theme}; Domain=.${domain}; Path=/; Max-Age=31536000; SameSite=Lax${secure}`
|
|
50
|
+
} catch {
|
|
51
|
+
// Cookies blocked: this app still remembers it (localStorage).
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
16
55
|
// Storage can be missing or blocked (private windows, strict settings): the
|
|
17
56
|
// choice then lasts until the page is closed.
|
|
18
|
-
function
|
|
57
|
+
function readStored(): Theme | undefined {
|
|
19
58
|
try {
|
|
20
59
|
const saved = localStorage.getItem(STORAGE_KEY)
|
|
21
60
|
return isTheme(saved) ? saved : undefined
|
|
@@ -24,7 +63,13 @@ function readSaved(): Theme | undefined {
|
|
|
24
63
|
}
|
|
25
64
|
}
|
|
26
65
|
|
|
66
|
+
// The shared choice wins: it's the one picked most recently in any Keston app.
|
|
67
|
+
function readSaved(): Theme | undefined {
|
|
68
|
+
return readCookie() ?? readStored()
|
|
69
|
+
}
|
|
70
|
+
|
|
27
71
|
function save(theme: Theme) {
|
|
72
|
+
writeCookie(theme)
|
|
28
73
|
try {
|
|
29
74
|
localStorage.setItem(STORAGE_KEY, theme)
|
|
30
75
|
} catch {
|
|
@@ -43,8 +88,8 @@ function apply(theme: Theme) {
|
|
|
43
88
|
|
|
44
89
|
/**
|
|
45
90
|
* Applies the person's saved choice (or `fallback` if there is none) and keeps
|
|
46
|
-
* other tabs in step. Call it once in main.ts, before
|
|
47
|
-
* doesn't flash the wrong colours:
|
|
91
|
+
* other tabs and Keston apps in step. Call it once in main.ts, before
|
|
92
|
+
* mounting, so the page doesn't flash the wrong colours:
|
|
48
93
|
*
|
|
49
94
|
* initTheme() // follows the device until someone picks
|
|
50
95
|
* initTheme('light') // an app that starts light
|
|
@@ -53,15 +98,32 @@ export function initTheme(fallback: Theme = 'system') {
|
|
|
53
98
|
apply(readSaved() ?? fallback)
|
|
54
99
|
if (started || typeof window === 'undefined') return
|
|
55
100
|
started = true
|
|
56
|
-
// Picked in another tab: follow it here too.
|
|
101
|
+
// Picked in another tab of this app: follow it here too.
|
|
57
102
|
window.addEventListener('storage', (event) => {
|
|
58
103
|
if (event.key === STORAGE_KEY && isTheme(event.newValue)) apply(event.newValue)
|
|
59
104
|
})
|
|
105
|
+
// Picked in another Keston app (the shared cookie): follow it when this
|
|
106
|
+
// tab is looked at again. Browsers don't announce cookie changes.
|
|
107
|
+
const follow = () => {
|
|
108
|
+
const shared = readCookie()
|
|
109
|
+
if (shared && shared !== current.value) {
|
|
110
|
+
apply(shared)
|
|
111
|
+
try {
|
|
112
|
+
localStorage.setItem(STORAGE_KEY, shared)
|
|
113
|
+
} catch {
|
|
114
|
+
// Fine: the cookie has it.
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
document.addEventListener('visibilitychange', () => {
|
|
119
|
+
if (document.visibilityState === 'visible') follow()
|
|
120
|
+
})
|
|
121
|
+
window.addEventListener('focus', follow)
|
|
60
122
|
}
|
|
61
123
|
|
|
62
124
|
/**
|
|
63
125
|
* The current theme and a way to change it, e.g. for ThemeSwitcher. A change
|
|
64
|
-
* applies at once and is remembered in this browser.
|
|
126
|
+
* applies at once and is remembered in this browser, for every Keston app.
|
|
65
127
|
*/
|
|
66
128
|
export function useTheme(): { theme: Readonly<Ref<Theme>>; setTheme: (theme: Theme) => void } {
|
|
67
129
|
if (!started) initTheme(isTheme(document.documentElement.dataset.theme) ? document.documentElement.dataset.theme : 'system')
|