@thekestongroup/ui 0.15.0 → 0.18.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/ActionList/ActionList.vue.d.ts +74 -0
- package/dist/components/Alert/Alert.vue.d.ts +55 -0
- package/dist/components/AsyncState/AsyncState.vue.d.ts +53 -0
- package/dist/components/AvatarGroup/AvatarGroup.vue.d.ts +1 -1
- package/dist/components/BarChart/BarChart.vue.d.ts +37 -0
- package/dist/components/BarChart/ChartData.vue.d.ts +20 -0
- package/dist/components/Button/Button.vue.d.ts +1 -1
- package/dist/components/Collapsible/Collapsible.vue.d.ts +48 -0
- package/dist/components/ConfirmDialog/ConfirmDialog.vue.d.ts +62 -0
- package/dist/components/FileUpload/FileUpload.vue.d.ts +55 -0
- package/dist/components/Footer/Footer.vue.d.ts +11 -1
- package/dist/components/Header/Header.vue.d.ts +1 -1
- package/dist/components/InputRichText/InputRichText.vue.d.ts +12 -6
- package/dist/components/LineChart/LineChart.vue.d.ts +37 -0
- package/dist/components/Notification/Notification.vue.d.ts +2 -2
- package/dist/components/Progress/Progress.vue.d.ts +14 -1
- package/dist/components/Prose/Prose.vue.d.ts +36 -0
- package/dist/components/ResultState/ResultState.vue.d.ts +48 -0
- package/dist/components/Slideover/Slideover.vue.d.ts +7 -5
- package/dist/components/Spinner/Spinner.vue.d.ts +1 -1
- package/dist/components/Steps/Steps.vue.d.ts +16 -5
- package/dist/components/ThemeSwitcher/ThemeSwitcher.vue.d.ts +18 -0
- package/dist/i18n/en.d.ts +43 -0
- package/dist/index.d.ts +25 -0
- package/dist/keston-ui.js +5287 -4028
- package/dist/lib/chart.d.ts +32 -0
- package/dist/lib/initials.d.ts +6 -1
- package/dist/lib/theme.d.ts +23 -0
- package/package.json +10 -3
- package/src/components/ActionList/ActionList.stories.ts +92 -0
- package/src/components/ActionList/ActionList.vue +138 -0
- package/src/components/Alert/Alert.stories.ts +65 -0
- package/src/components/Alert/Alert.vue +110 -0
- package/src/components/AsyncState/AsyncState.stories.ts +46 -0
- package/src/components/AsyncState/AsyncState.vue +78 -0
- package/src/components/BarChart/BarChart.stories.ts +62 -0
- package/src/components/BarChart/BarChart.vue +153 -0
- package/src/components/BarChart/ChartData.vue +64 -0
- package/src/components/Button/Button.vue +4 -4
- package/src/components/Calendar/Calendar.vue +3 -2
- package/src/components/CardSelect/CardSelect.vue +1 -1
- package/src/components/Checkbox/Checkbox.vue +1 -1
- package/src/components/CheckboxGroup/CheckboxGroup.vue +1 -1
- package/src/components/Collapsible/Collapsible.stories.ts +32 -0
- package/src/components/Collapsible/Collapsible.vue +68 -0
- package/src/components/ConfirmDialog/ConfirmDialog.stories.ts +54 -0
- package/src/components/ConfirmDialog/ConfirmDialog.vue +119 -0
- package/src/components/FileUpload/FileUpload.stories.ts +38 -0
- package/src/components/FileUpload/FileUpload.vue +150 -0
- package/src/components/Footer/Footer.stories.ts +10 -2
- package/src/components/Footer/Footer.vue +22 -4
- package/src/components/Header/Header.stories.ts +20 -0
- package/src/components/InputRichText/InputRichText.stories.ts +19 -0
- package/src/components/InputRichText/InputRichText.vue +129 -13
- package/src/components/LineChart/LineChart.stories.ts +47 -0
- package/src/components/LineChart/LineChart.vue +173 -0
- package/src/components/Notification/Toaster.vue +3 -1
- package/src/components/Progress/Progress.stories.ts +18 -0
- package/src/components/Progress/Progress.vue +57 -0
- package/src/components/Prose/Prose.stories.ts +46 -0
- package/src/components/Prose/Prose.vue +54 -0
- package/src/components/RadioGroup/RadioGroup.vue +2 -2
- package/src/components/ResultState/ResultState.stories.ts +44 -0
- package/src/components/ResultState/ResultState.vue +76 -0
- package/src/components/Select/Select.vue +6 -4
- package/src/components/Slideover/Slideover.vue +107 -31
- package/src/components/Steps/Steps.stories.ts +18 -0
- package/src/components/Steps/Steps.vue +28 -8
- package/src/components/ThemeSwitcher/ThemeSwitcher.stories.ts +22 -0
- package/src/components/ThemeSwitcher/ThemeSwitcher.vue +48 -0
- package/src/components/Tooltip/Tooltip.vue +1 -1
- package/src/i18n/en.ts +29 -7
- package/src/index.ts +25 -0
- package/src/lib/chart.ts +47 -0
- package/src/lib/initials.test.ts +19 -0
- package/src/lib/initials.ts +12 -3
- package/src/lib/theme.ts +75 -0
- package/src/styles/theme.css +34 -2
package/src/lib/theme.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { readonly, ref, type Ref } from 'vue'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Light, dark or following the device. Keston UI's colours switch with the
|
|
5
|
+
* `data-theme` attribute on `<html>` (see theme.css, "Dark mode").
|
|
6
|
+
*/
|
|
7
|
+
export type Theme = 'light' | 'dark' | 'system'
|
|
8
|
+
|
|
9
|
+
const STORAGE_KEY = 'keston-theme'
|
|
10
|
+
const themes: readonly Theme[] = ['light', 'dark', 'system']
|
|
11
|
+
|
|
12
|
+
function isTheme(value: unknown): value is Theme {
|
|
13
|
+
return typeof value === 'string' && (themes as readonly string[]).includes(value)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Storage can be missing or blocked (private windows, strict settings): the
|
|
17
|
+
// choice then lasts until the page is closed.
|
|
18
|
+
function readSaved(): Theme | undefined {
|
|
19
|
+
try {
|
|
20
|
+
const saved = localStorage.getItem(STORAGE_KEY)
|
|
21
|
+
return isTheme(saved) ? saved : undefined
|
|
22
|
+
} catch {
|
|
23
|
+
return undefined
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function save(theme: Theme) {
|
|
28
|
+
try {
|
|
29
|
+
localStorage.setItem(STORAGE_KEY, theme)
|
|
30
|
+
} catch {
|
|
31
|
+
// Not saved; still applied for this page.
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// One choice for the whole page, however many switchers are showing.
|
|
36
|
+
const current = ref<Theme>('system')
|
|
37
|
+
let started = false
|
|
38
|
+
|
|
39
|
+
function apply(theme: Theme) {
|
|
40
|
+
current.value = theme
|
|
41
|
+
if (typeof document !== 'undefined') document.documentElement.dataset.theme = theme
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 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 mounting, so the page
|
|
47
|
+
* doesn't flash the wrong colours:
|
|
48
|
+
*
|
|
49
|
+
* initTheme() // follows the device until someone picks
|
|
50
|
+
* initTheme('light') // an app that starts light
|
|
51
|
+
*/
|
|
52
|
+
export function initTheme(fallback: Theme = 'system') {
|
|
53
|
+
apply(readSaved() ?? fallback)
|
|
54
|
+
if (started || typeof window === 'undefined') return
|
|
55
|
+
started = true
|
|
56
|
+
// Picked in another tab: follow it here too.
|
|
57
|
+
window.addEventListener('storage', (event) => {
|
|
58
|
+
if (event.key === STORAGE_KEY && isTheme(event.newValue)) apply(event.newValue)
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 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.
|
|
65
|
+
*/
|
|
66
|
+
export function useTheme(): { theme: Readonly<Ref<Theme>>; setTheme: (theme: Theme) => void } {
|
|
67
|
+
if (!started) initTheme(isTheme(document.documentElement.dataset.theme) ? document.documentElement.dataset.theme : 'system')
|
|
68
|
+
return {
|
|
69
|
+
theme: readonly(current),
|
|
70
|
+
setTheme(theme: Theme) {
|
|
71
|
+
apply(theme)
|
|
72
|
+
save(theme)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
package/src/styles/theme.css
CHANGED
|
@@ -82,8 +82,9 @@
|
|
|
82
82
|
* - hover / pressed / selected: see-through tints for things with no fill
|
|
83
83
|
* of their own (ghost buttons, menu items, table rows, sidebar items).
|
|
84
84
|
* - surface-hover / surface-pressed: solid, for things filled with surface
|
|
85
|
-
* (
|
|
86
|
-
* mode rather than darken.
|
|
85
|
+
* (the buttons inside fields, cards you can press), so they lighten in
|
|
86
|
+
* dark mode rather than darken.
|
|
87
|
+
* - control / control-hover / control-pressed: basic buttons (see above).
|
|
87
88
|
* Coloured fills (primary, danger) darken instead: brightness-90 / 80.
|
|
88
89
|
* Disabled is opacity-40. Focus is a 2px outline-focus ring, keyboard only.
|
|
89
90
|
*/
|
|
@@ -93,6 +94,14 @@
|
|
|
93
94
|
--color-surface-hover: color-mix(in oklab, var(--color-surface) 95%, var(--color-ink));
|
|
94
95
|
--color-surface-pressed: color-mix(in oklab, var(--color-surface) 90%, var(--color-ink));
|
|
95
96
|
|
|
97
|
+
/* Controls with a fill of their own (basic buttons): always a step above
|
|
98
|
+
whatever they sit on. Light: white, darkening on hover / press. Dark: a
|
|
99
|
+
see-through white, so a button is lighter than a card, a menu or the page
|
|
100
|
+
alike (a solid colour would be darker than a lighter panel). */
|
|
101
|
+
--color-control: light-dark(#ffffff, oklch(98.5% 0 0 / 0.06));
|
|
102
|
+
--color-control-hover: light-dark(color-mix(in oklab, #ffffff 95%, #050505), oklch(98.5% 0 0 / 0.1));
|
|
103
|
+
--color-control-pressed: light-dark(color-mix(in oklab, #ffffff 90%, #050505), oklch(98.5% 0 0 / 0.14));
|
|
104
|
+
|
|
96
105
|
/* Radius e.g. --radius-control: …; */
|
|
97
106
|
|
|
98
107
|
/* Typography e.g. --font-sans: …; */
|
|
@@ -153,6 +162,29 @@
|
|
|
153
162
|
}
|
|
154
163
|
}
|
|
155
164
|
|
|
165
|
+
@theme static {
|
|
166
|
+
/*
|
|
167
|
+
* Chart series, for BarChart and LineChart: eight hues in a fixed order,
|
|
168
|
+
* each stepped separately for light and dark. The order is what keeps
|
|
169
|
+
* neighbours apart for colour-blind readers (checked with the data-viz
|
|
170
|
+
* palette validator), so take them in order and never cycle: past eight
|
|
171
|
+
* series, group the rest as "Other". Marks only: chart text uses ink.
|
|
172
|
+
* Slots 3, 4 and 5 are under 3:1 on white in light mode, so every chart
|
|
173
|
+
* keeps its data table.
|
|
174
|
+
*
|
|
175
|
+
* `static`: the charts set these through inline styles, not classes, so
|
|
176
|
+
* Tailwind must output them even when no class uses them.
|
|
177
|
+
*/
|
|
178
|
+
--color-chart-1: light-dark(#2a78d6, #3987e5); /* blue */
|
|
179
|
+
--color-chart-2: light-dark(#eb6834, #d95926); /* orange */
|
|
180
|
+
--color-chart-3: light-dark(#1baf7a, #199e70); /* aqua */
|
|
181
|
+
--color-chart-4: light-dark(#eda100, #c98500); /* yellow */
|
|
182
|
+
--color-chart-5: light-dark(#e87ba4, #d55181); /* magenta */
|
|
183
|
+
--color-chart-6: light-dark(#008300, #0ca30c); /* green */
|
|
184
|
+
--color-chart-7: light-dark(#6250d6, #9085e9); /* violet */
|
|
185
|
+
--color-chart-8: light-dark(#e34948, #e66767); /* red */
|
|
186
|
+
}
|
|
187
|
+
|
|
156
188
|
/*
|
|
157
189
|
* Dark mode
|
|
158
190
|
* ---------
|