@thekestongroup/ui 0.20.0 → 0.22.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/components/Header/Header.vue.d.ts +5 -0
- package/dist/components/Popover/popover.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/keston-ui.js +1057 -973
- package/dist/lib/theme.d.ts +12 -3
- package/package.json +1 -1
- package/src/components/AppLauncher/AppLauncher.vue +52 -21
- package/src/components/AppLauncher/apps.ts +1 -1
- package/src/components/AppLauncher/icons/admin-dark.svg +1 -0
- package/src/components/AppLauncher/icons/admin.svg +1 -0
- package/src/components/AppLauncher/icons/design.svg +5 -0
- package/src/components/AppLauncher/icons/id-dark.svg +1 -0
- package/src/components/AppLauncher/icons/id.svg +1 -0
- package/src/components/AppLauncher/icons/keston-dark.svg +1 -0
- package/src/components/AppLauncher/icons/keston.svg +1 -0
- package/src/components/AppLauncher/icons/utilities.svg +1 -0
- package/src/components/Header/Header.stories.ts +20 -0
- package/src/components/Header/Header.vue +35 -9
- package/src/components/Popover/popover.ts +2 -2
- package/src/components/Tooltip/Tooltip.vue +1 -1
- 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
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import
|
|
2
|
+
import adminIcon from './icons/admin.svg'
|
|
3
|
+
import adminIconDark from './icons/admin-dark.svg'
|
|
4
|
+
import designIcon from './icons/design.svg'
|
|
5
|
+
import idIcon from './icons/id.svg'
|
|
6
|
+
import idIconDark from './icons/id-dark.svg'
|
|
7
|
+
import kestonIcon from './icons/keston.svg'
|
|
8
|
+
import kestonIconDark from './icons/keston-dark.svg'
|
|
9
|
+
import utilitiesIcon from './icons/utilities.svg'
|
|
3
10
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
/** An app's icon as an image, with an optional version for dark mode. */
|
|
12
|
+
export type AppLauncherImage = { light: string; dark?: string }
|
|
13
|
+
|
|
14
|
+
// The Keston apps' own marks (never a logo with the name in it: the name is
|
|
15
|
+
// beside it). Apps without a mark of their own have The Keston Group's.
|
|
16
|
+
const builtInIcons: Record<string, AppLauncherImage> = {
|
|
17
|
+
id: { light: idIcon, dark: idIconDark },
|
|
18
|
+
admin: { light: adminIcon, dark: adminIconDark },
|
|
19
|
+
work: { light: kestonIcon, dark: kestonIconDark },
|
|
20
|
+
utilities: { light: utilitiesIcon },
|
|
21
|
+
design: { light: designIcon }
|
|
10
22
|
}
|
|
11
23
|
</script>
|
|
12
24
|
|
|
13
25
|
<script setup lang="ts">
|
|
14
26
|
import { useI18n } from 'vue-i18n'
|
|
15
|
-
import { LayoutGrid } from '@lucide/vue'
|
|
27
|
+
import { AppWindow, Check, LayoutGrid } from '@lucide/vue'
|
|
16
28
|
import type { Component, HTMLAttributes } from 'vue'
|
|
17
29
|
import { cn } from '../../lib/cn'
|
|
18
30
|
import Button from '../Button/Button.vue'
|
|
@@ -24,15 +36,18 @@ export interface AppLauncherApp {
|
|
|
24
36
|
id: string
|
|
25
37
|
label: string
|
|
26
38
|
href: string
|
|
27
|
-
/**
|
|
28
|
-
|
|
39
|
+
/**
|
|
40
|
+
* The app's icon: the name of a Keston app's (id, admin, work, utilities,
|
|
41
|
+
* design), an image (`{ light, dark }`), or an icon component.
|
|
42
|
+
*/
|
|
43
|
+
icon?: Component | string | AppLauncherImage
|
|
29
44
|
/** Signs in with Keston ID, so it's given the `loginHint`. Default true. */
|
|
30
45
|
signsIn?: boolean
|
|
31
46
|
}
|
|
32
47
|
|
|
33
48
|
/**
|
|
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
|
|
49
|
+
* The grid button in the header that opens a list of the Keston Group's apps, so people can move between
|
|
50
|
+
* 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
51
|
* built on AppShell, pass `launcher` to AppShell instead of using this directly.
|
|
37
52
|
*
|
|
38
53
|
* Apps open in the same tab, as moving between Keston apps is moving on, not a side trip (the footer's
|
|
@@ -72,34 +87,50 @@ function hrefOf(app: AppLauncherApp): string {
|
|
|
72
87
|
}
|
|
73
88
|
}
|
|
74
89
|
|
|
75
|
-
function
|
|
76
|
-
|
|
77
|
-
|
|
90
|
+
function isImage(icon: AppLauncherApp['icon']): icon is AppLauncherImage {
|
|
91
|
+
return typeof icon === 'object' && icon !== null && 'light' in icon
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function imageOf(app: AppLauncherApp): AppLauncherImage | undefined {
|
|
95
|
+
if (typeof app.icon === 'string') return builtInIcons[app.icon]
|
|
96
|
+
return isImage(app.icon) ? app.icon : undefined
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function componentOf(app: AppLauncherApp): Component {
|
|
100
|
+
return typeof app.icon === 'object' && !isImage(app.icon) ? (app.icon as Component) : AppWindow
|
|
78
101
|
}
|
|
79
102
|
</script>
|
|
80
103
|
|
|
81
104
|
<template>
|
|
82
|
-
<Popover :content="{ align }" :ui="{ content: 'w-64
|
|
105
|
+
<Popover :content="{ align }" :ui="{ content: 'w-64 overflow-hidden py-1' }">
|
|
83
106
|
<Button variant="ghost" square :aria-label="label ?? t('ui.appLauncher.label')" :class="props.class">
|
|
84
107
|
<LayoutGrid />
|
|
85
108
|
</Button>
|
|
86
109
|
<template #content="{ close }">
|
|
87
110
|
<nav :aria-label="label ?? t('ui.appLauncher.label')">
|
|
111
|
+
<!-- Like a Select's options: 32px rows the full width of the panel,
|
|
112
|
+
square, tinted on hover and focus; the app's icon, its name, and
|
|
113
|
+
a tick by the app you're in. -->
|
|
88
114
|
<ul>
|
|
89
115
|
<li v-for="app in apps" :key="app.id">
|
|
90
116
|
<a
|
|
91
117
|
:href="hrefOf(app)"
|
|
92
118
|
:aria-current="app.id === current ? 'page' : undefined"
|
|
93
119
|
:class="cn(
|
|
94
|
-
'flex items-center gap-
|
|
95
|
-
app.id === current && '
|
|
120
|
+
'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',
|
|
121
|
+
app.id === current && 'font-bold'
|
|
96
122
|
)"
|
|
97
123
|
@click="close()"
|
|
98
124
|
>
|
|
99
|
-
<
|
|
100
|
-
<
|
|
125
|
+
<template v-if="imageOf(app)">
|
|
126
|
+
<img :src="imageOf(app)!.light" alt="" :class="cn('size-5 shrink-0', imageOf(app)!.dark && 'dark:hidden')" />
|
|
127
|
+
<img v-if="imageOf(app)!.dark" :src="imageOf(app)!.dark" alt="" class="hidden size-5 shrink-0 dark:block" />
|
|
128
|
+
</template>
|
|
129
|
+
<component :is="componentOf(app)" v-else class="size-5 shrink-0" aria-hidden="true" />
|
|
130
|
+
<span class="min-w-0 flex-1 truncate">{{ app.label }}</span>
|
|
131
|
+
<span class="flex w-4 shrink-0 items-center justify-center">
|
|
132
|
+
<Check v-if="app.id === current" class="size-4" aria-hidden="true" />
|
|
101
133
|
</span>
|
|
102
|
-
<span class="min-w-0 truncate">{{ app.label }}</span>
|
|
103
134
|
</a>
|
|
104
135
|
</li>
|
|
105
136
|
</ul>
|
|
@@ -3,7 +3,7 @@ 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
9
|
{ id: 'design', label: 'Design system', href: 'https://ui.keston.co', icon: 'design', signsIn: false }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" width="240" height="240"><title>Keston Admin one-colour white</title><defs><mask id="peaks"><rect width="120" height="120" fill="#fff"/><path d="M30 46 L52 80 L60 96 L20 62 Z M88 42 L100 62 L60 96 L70 68 Z" fill="#000"/><path d="M60 24 L86 74 L60 96 L34 74 Z" fill="#000"/></mask></defs><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" mask="url(#peaks)"/><path d="M60 24 L86 74 L60 96 L34 74 Z" fill="none" stroke="#FFFFFF" stroke-width="3" stroke-linejoin="round"/><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"/></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,5 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
|
|
2
|
+
<!-- Keston blue rounded square with a white K, drawn as strokes so it doesn't depend on a font. -->
|
|
3
|
+
<rect width="32" height="32" rx="6" fill="#023750"/>
|
|
4
|
+
<path d="M11 8v16M21.5 8 11.5 17.5M14.5 15l7.5 9" fill="none" stroke="#fafafa" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
|
|
5
|
+
</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 one-colour white</title><path fill-rule="evenodd" d="M58.61 113.44 L58.76 113.57 L58.91 113.68 L59.08 113.77 L59.25 113.85 L59.43 113.92 L59.62 113.96 L59.81 113.99 L60.00 114.00 L60.19 113.99 L60.38 113.96 L60.57 113.92 L60.75 113.85 L60.92 113.77 L61.09 113.68 L61.24 113.57 L61.39 113.44 L115.39 61.44 L115.52 61.30 L115.64 61.15 L115.74 60.98 L115.83 60.81 L115.90 60.63 L115.95 60.44 L115.98 60.25 L116.00 60.05 L116.00 59.86 L115.97 59.67 L115.93 59.48 L115.87 59.29 L115.79 59.11 L115.70 58.94 L115.59 58.79 L89.59 24.79 L89.46 24.63 L89.32 24.49 L89.16 24.37 L88.99 24.26 L88.81 24.17 L88.63 24.10 L88.44 24.05 L88.24 24.01 L88.04 24.00 L87.84 24.01 L87.65 24.03 L87.45 24.08 L87.26 24.14 L87.08 24.22 L86.91 24.32 L86.75 24.44 L86.60 24.57 L86.46 24.72 L78.27 34.56 L61.71 6.97 L61.61 6.81 L61.48 6.66 L61.35 6.52 L61.20 6.40 L61.04 6.29 L60.87 6.20 L60.69 6.12 L60.50 6.06 L60.31 6.02 L60.12 6.00 L59.92 6.00 L59.73 6.02 L59.54 6.05 L59.35 6.11 L59.17 6.18 L59.00 6.27 L58.84 6.37 L58.68 6.49 L58.54 6.63 L58.42 6.78 L58.31 6.94 L58.21 7.11 L41.56 40.41 L31.52 28.70 L31.38 28.56 L31.24 28.43 L31.08 28.32 L30.91 28.22 L30.73 28.14 L30.55 28.08 L30.35 28.03 L30.16 28.01 L29.97 28.00 L29.77 28.01 L29.58 28.04 L29.39 28.10 L29.21 28.16 L29.03 28.25 L28.87 28.35 L28.71 28.47 L28.57 28.60 L28.44 28.75 L4.44 58.75 L4.32 58.91 L4.22 59.08 L4.14 59.26 L4.08 59.45 L4.03 59.64 L4.01 59.83 L4.00 60.03 L4.01 60.23 L4.05 60.42 L4.10 60.61 L4.17 60.80 L4.25 60.97 L4.36 61.14 L4.48 61.30 L4.61 61.44 L58.61 113.44 Z M77.36 57.38 L88.00 42.00 L100.00 62.00 L85.96 73.93 L86.00 74.00 L60.00 96.00 L34.00 74.00 L34.04 73.93 L20.00 62.00 L30.00 46.00 L40.29 61.90 L60.00 24.00 L77.36 57.38 Z" fill="#FFFFFF"/><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"/></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>Keston one-colour white</title><path fill-rule="evenodd" d="M58.61 113.44 L58.76 113.57 L58.91 113.68 L59.08 113.77 L59.25 113.85 L59.43 113.92 L59.62 113.96 L59.81 113.99 L60.00 114.00 L60.19 113.99 L60.38 113.96 L60.57 113.92 L60.75 113.85 L60.92 113.77 L61.09 113.68 L61.24 113.57 L61.39 113.44 L115.39 61.44 L115.52 61.30 L115.64 61.15 L115.74 60.98 L115.83 60.81 L115.90 60.63 L115.95 60.44 L115.98 60.25 L116.00 60.05 L116.00 59.86 L115.97 59.67 L115.93 59.48 L115.87 59.29 L115.79 59.11 L115.70 58.94 L115.59 58.79 L89.59 24.79 L89.46 24.63 L89.32 24.49 L89.16 24.37 L88.99 24.26 L88.81 24.17 L88.63 24.10 L88.44 24.05 L88.24 24.01 L88.04 24.00 L87.84 24.01 L87.65 24.03 L87.45 24.08 L87.26 24.14 L87.08 24.22 L86.91 24.32 L86.75 24.44 L86.60 24.57 L86.46 24.72 L78.27 34.56 L61.71 6.97 L61.61 6.81 L61.48 6.66 L61.35 6.52 L61.20 6.40 L61.04 6.29 L60.87 6.20 L60.69 6.12 L60.50 6.06 L60.31 6.02 L60.12 6.00 L59.92 6.00 L59.73 6.02 L59.54 6.05 L59.35 6.11 L59.17 6.18 L59.00 6.27 L58.84 6.37 L58.68 6.49 L58.54 6.63 L58.42 6.78 L58.31 6.94 L58.21 7.11 L41.56 40.41 L31.52 28.70 L31.38 28.56 L31.24 28.43 L31.08 28.32 L30.91 28.22 L30.73 28.14 L30.55 28.08 L30.35 28.03 L30.16 28.01 L29.97 28.00 L29.77 28.01 L29.58 28.04 L29.39 28.10 L29.21 28.16 L29.03 28.25 L28.87 28.35 L28.71 28.47 L28.57 28.60 L28.44 28.75 L4.44 58.75 L4.32 58.91 L4.22 59.08 L4.14 59.26 L4.08 59.45 L4.03 59.64 L4.01 59.83 L4.00 60.03 L4.01 60.23 L4.05 60.42 L4.10 60.61 L4.17 60.80 L4.25 60.97 L4.36 61.14 L4.48 61.30 L4.61 61.44 L58.61 113.44 Z M77.36 57.38 L88.00 42.00 L100.00 62.00 L85.96 73.93 L86.00 74.00 L60.00 96.00 L34.00 74.00 L34.04 73.93 L20.00 62.00 L30.00 46.00 L40.29 61.90 L60.00 24.00 L77.36 57.38 Z" fill="#FFFFFF"/></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>
|
|
@@ -223,6 +223,26 @@ export const WithLockup: Story = {
|
|
|
223
223
|
args: { lockup: sampleLockup, titleTo: "#home" },
|
|
224
224
|
};
|
|
225
225
|
|
|
226
|
+
const sampleOrgLogo = (colour: string) =>
|
|
227
|
+
"data:image/svg+xml," +
|
|
228
|
+
encodeURIComponent(
|
|
229
|
+
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 180 24"><path d="M12 1 2 5v7c0 6 4.5 9.5 10 11 5.5-1.5 10-5 10-11V5Z" fill="${colour}"/><text x="30" y="17" font-family="Georgia, serif" font-weight="700" font-size="15" fill="${colour}">The Keston School</text></svg>`,
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* organisationLogo: the organisation's logo at the top of the account menu
|
|
234
|
+
* (open it) instead of its name. Pass `{ light, dark }` for a dark-mode
|
|
235
|
+
* version; its alt text is the organisation's name.
|
|
236
|
+
*/
|
|
237
|
+
export const WithOrganisationLogo: Story = {
|
|
238
|
+
args: {
|
|
239
|
+
user: {
|
|
240
|
+
...user,
|
|
241
|
+
organisationLogo: { light: sampleOrgLogo("#023750"), dark: sampleOrgLogo("#ffffff") },
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
|
|
226
246
|
/** Stays at the top while the page scrolls (the default). Scroll the box below. */
|
|
227
247
|
export const Sticky: Story = {
|
|
228
248
|
render: (args) => ({
|
|
@@ -13,6 +13,11 @@ export interface HeaderUser {
|
|
|
13
13
|
email?: string
|
|
14
14
|
/** Organisation or school the account belongs to, shown at the top of the account menu. */
|
|
15
15
|
organisation?: string
|
|
16
|
+
/**
|
|
17
|
+
* The organisation's logo (e.g. a wordmark), shown at the top of the
|
|
18
|
+
* account menu instead of its name. Its alt text is the organisation's name.
|
|
19
|
+
*/
|
|
20
|
+
organisationLogo?: HeaderImage
|
|
16
21
|
/** Picture URL. Initials are shown without one. */
|
|
17
22
|
avatar?: string
|
|
18
23
|
}
|
|
@@ -157,6 +162,7 @@ const titleLinkClass = [
|
|
|
157
162
|
|
|
158
163
|
const image = (i: HeaderImage | undefined) => (typeof i === 'string' ? { light: i, dark: undefined } : i)
|
|
159
164
|
const logoImage = computed(() => image(props.logo))
|
|
165
|
+
const organisationLogo = computed(() => image(props.user?.organisationLogo))
|
|
160
166
|
const lockupImage = computed(() => image(props.lockup))
|
|
161
167
|
|
|
162
168
|
function runAction(action: HeaderUserAction, close: () => void) {
|
|
@@ -239,11 +245,25 @@ function runAction(action: HeaderUserAction, close: () => void) {
|
|
|
239
245
|
|
|
240
246
|
<template #content="{ close }">
|
|
241
247
|
<div class="flex flex-col">
|
|
242
|
-
<!-- The organisation at the top, with a divider under it
|
|
243
|
-
|
|
244
|
-
|
|
248
|
+
<!-- The organisation at the top, with a divider under it: its
|
|
249
|
+
logo if it has one, otherwise its name. The organisation
|
|
250
|
+
slot replaces both. -->
|
|
251
|
+
<div v-if="user.organisation || organisationLogo || $slots.organisation" class="border-b border-ink/10">
|
|
245
252
|
<slot name="organisation" :close="close">
|
|
246
|
-
<
|
|
253
|
+
<div v-if="organisationLogo" class="p-3">
|
|
254
|
+
<img
|
|
255
|
+
:src="organisationLogo.light"
|
|
256
|
+
:alt="user.organisation ?? ''"
|
|
257
|
+
:class="cn('h-6 w-auto max-w-full object-contain object-left', organisationLogo.dark && 'dark:hidden')"
|
|
258
|
+
/>
|
|
259
|
+
<img
|
|
260
|
+
v-if="organisationLogo.dark"
|
|
261
|
+
:src="organisationLogo.dark"
|
|
262
|
+
:alt="user.organisation ?? ''"
|
|
263
|
+
class="hidden h-6 w-auto max-w-full object-contain object-left dark:block"
|
|
264
|
+
/>
|
|
265
|
+
</div>
|
|
266
|
+
<p v-else class="truncate p-3 text-xs font-bold text-ink/65 uppercase" :title="user.organisation">
|
|
247
267
|
{{ user.organisation }}
|
|
248
268
|
</p>
|
|
249
269
|
</slot>
|
|
@@ -251,7 +271,7 @@ function runAction(action: HeaderUserAction, close: () => void) {
|
|
|
251
271
|
<!-- Two columns: the avatar at the top left, beside the name and
|
|
252
272
|
email; Account settings sits under them in the text column,
|
|
253
273
|
without moving the avatar. -->
|
|
254
|
-
<div class="grid grid-cols-[auto_minmax(0,1fr)] items-start gap-x-3 gap-y-2
|
|
274
|
+
<div class="grid grid-cols-[auto_minmax(0,1fr)] items-start gap-x-3 gap-y-2 p-3">
|
|
255
275
|
<Avatar :user="user" size="lg" decorative />
|
|
256
276
|
<div class="flex min-w-0 flex-col">
|
|
257
277
|
<span class="truncate font-bold" :title="user.name">{{ user.name }}</span>
|
|
@@ -270,18 +290,24 @@ function runAction(action: HeaderUserAction, close: () => void) {
|
|
|
270
290
|
|
|
271
291
|
<slot name="account-menu" :close="close" />
|
|
272
292
|
|
|
273
|
-
<!-- Switch account
|
|
293
|
+
<!-- Switch account and Log out fill the row, each growing from its
|
|
294
|
+
own text width (so Switch account stays the wider), with the
|
|
295
|
+
same 12px around them on every side, like the rest of the menu. -->
|
|
274
296
|
<div
|
|
275
297
|
v-if="userActions.includes('switch-account') || userActions.includes('log-out')"
|
|
276
|
-
class="flex items-center gap-2 border-t border-ink/10
|
|
298
|
+
class="flex items-center gap-2 border-t border-ink/10 p-3"
|
|
277
299
|
>
|
|
278
|
-
<Button
|
|
300
|
+
<Button
|
|
301
|
+
v-if="userActions.includes('switch-account')"
|
|
302
|
+
class="flex-auto"
|
|
303
|
+
@click="runAction('switch-account', close)"
|
|
304
|
+
>
|
|
279
305
|
<template #leading><ArrowLeftRight /></template>
|
|
280
306
|
Switch account
|
|
281
307
|
</Button>
|
|
282
308
|
<Button
|
|
283
309
|
v-if="userActions.includes('log-out')"
|
|
284
|
-
class="
|
|
310
|
+
class="flex-auto"
|
|
285
311
|
@click="runAction('log-out', close)"
|
|
286
312
|
>
|
|
287
313
|
<template #leading><LogOut /></template>
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
* Reka's popper (e.g. InputDate's calendar), so they all match.
|
|
4
4
|
*
|
|
5
5
|
* An elevated panel (white; a step lighter than the page in dark mode) with
|
|
6
|
-
* the same border
|
|
6
|
+
* the same border as a basic Button, 8px corners like a Card or dialog, a shadow,
|
|
7
7
|
* and the theme's fade in / out (Reka waits for the fade-out to finish
|
|
8
8
|
* before removing the panel).
|
|
9
9
|
*/
|
|
10
10
|
export const popoverContent = [
|
|
11
|
-
'z-50 rounded border border-ink/10 bg-surface-elevated text-ink shadow-md outline-none',
|
|
11
|
+
'z-50 rounded-lg border border-ink/10 bg-surface-elevated text-ink shadow-md outline-none',
|
|
12
12
|
'data-[state=open]:animate-fade-in data-[state=closed]:animate-fade-out'
|
|
13
13
|
]
|
|
14
14
|
|
|
@@ -72,7 +72,7 @@ const MaybeProvider: FunctionalComponent = (_, { slots }) =>
|
|
|
72
72
|
:collision-padding="8"
|
|
73
73
|
:class="
|
|
74
74
|
cn(
|
|
75
|
-
'z-100 max-w-72 rounded-
|
|
75
|
+
'z-100 max-w-72 rounded-lg bg-neutral-900 dark:bg-neutral-700 px-2.5 py-1.5 text-xs/4 text-white shadow-lg ring-1 ring-white/10',
|
|
76
76
|
'data-[state=closed]:animate-fade-out data-[state=delayed-open]:animate-fade-in data-[state=instant-open]:animate-fade-in',
|
|
77
77
|
props.class
|
|
78
78
|
)
|
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')
|