@thekestongroup/ui 0.15.0 → 0.16.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 +63 -0
- package/dist/components/Alert/Alert.vue.d.ts +55 -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/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/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/Slideover/Slideover.vue.d.ts +7 -5
- package/dist/components/Spinner/Spinner.vue.d.ts +1 -1
- package/dist/components/ThemeSwitcher/ThemeSwitcher.vue.d.ts +18 -0
- package/dist/i18n/en.d.ts +27 -0
- package/dist/index.d.ts +17 -0
- package/dist/keston-ui.js +4106 -3247
- package/dist/lib/chart.d.ts +32 -0
- package/dist/lib/theme.d.ts +23 -0
- package/package.json +8 -3
- package/src/components/ActionList/ActionList.stories.ts +59 -0
- package/src/components/ActionList/ActionList.vue +116 -0
- package/src/components/Alert/Alert.stories.ts +65 -0
- package/src/components/Alert/Alert.vue +110 -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/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/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/LineChart/LineChart.stories.ts +47 -0
- package/src/components/LineChart/LineChart.vue +173 -0
- package/src/components/Progress/Progress.stories.ts +18 -0
- package/src/components/Progress/Progress.vue +57 -0
- package/src/components/RadioGroup/RadioGroup.vue +2 -2
- package/src/components/Select/Select.vue +6 -4
- package/src/components/Slideover/Slideover.vue +107 -31
- 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 +16 -4
- package/src/index.ts +17 -0
- package/src/lib/chart.ts +47 -0
- package/src/lib/theme.ts +75 -0
- package/src/styles/theme.css +23 -0
package/src/i18n/en.ts
CHANGED
|
@@ -37,10 +37,12 @@ export const en = {
|
|
|
37
37
|
nextYear: 'Next year',
|
|
38
38
|
previousYears: 'Previous years',
|
|
39
39
|
nextYears: 'Next years',
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
// Start with what the button shows, so voice control ("click June") finds it.
|
|
41
|
+
chooseMonth: '{month}, choose month',
|
|
42
|
+
chooseYear: '{year}, choose year'
|
|
42
43
|
},
|
|
43
44
|
changeIndicator: { changed: 'Changed from {from} to {to}' },
|
|
45
|
+
chart: { category: 'Category', showTable: 'Show as table', hideTable: 'Hide table' },
|
|
44
46
|
chip: { remove: 'Remove' },
|
|
45
47
|
appLauncher: { label: 'Keston apps' },
|
|
46
48
|
footer: {
|
|
@@ -75,7 +77,15 @@ export const en = {
|
|
|
75
77
|
italic: 'Italic',
|
|
76
78
|
underline: 'Underline'
|
|
77
79
|
},
|
|
80
|
+
alert: { info: 'Information', success: 'Success', warning: 'Warning', error: 'Error', dismiss: 'Dismiss' },
|
|
81
|
+
fileUpload: {
|
|
82
|
+
chooseFile: 'Choose a file',
|
|
83
|
+
chooseFiles: 'Choose files',
|
|
84
|
+
dropFile: 'Drop a file here, or choose one.',
|
|
85
|
+
dropFiles: 'Drop files here, or choose them.'
|
|
86
|
+
},
|
|
78
87
|
languageSwitcher: { label: 'Language' },
|
|
88
|
+
themeSwitcher: { label: 'Appearance', light: 'Light', dark: 'Dark', system: 'Match device' },
|
|
79
89
|
notifications: {
|
|
80
90
|
title: 'Notifications',
|
|
81
91
|
region: 'Notification',
|
|
@@ -92,7 +102,7 @@ export const en = {
|
|
|
92
102
|
actions: '{title} actions',
|
|
93
103
|
moreActions: 'More actions'
|
|
94
104
|
},
|
|
95
|
-
progress: { stepOf: 'Step {current} of {total}' },
|
|
105
|
+
progress: { stepOf: 'Step {current} of {total}', backTo: 'Back to step {current}: {name}' },
|
|
96
106
|
select: {
|
|
97
107
|
choose: 'Choose…',
|
|
98
108
|
search: 'Search…',
|
|
@@ -113,7 +123,9 @@ export const en = {
|
|
|
113
123
|
next: 'Next',
|
|
114
124
|
finish: 'Finish',
|
|
115
125
|
steps: 'Steps',
|
|
116
|
-
stepOf: 'Step {current} of {total}: {name}'
|
|
126
|
+
stepOf: 'Step {current} of {total}: {name}',
|
|
127
|
+
/** Shown under the title, e.g. "Step 1 of 3 – Name". */
|
|
128
|
+
stepHeading: 'Step {current} of {total} – {name}'
|
|
117
129
|
},
|
|
118
130
|
spinner: { loading: 'Loading' },
|
|
119
131
|
statTile: { up: 'Up', down: 'Down', flat: 'No change' },
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
// at the end of its group.
|
|
5
5
|
|
|
6
6
|
export { cn } from './lib/cn'
|
|
7
|
+
export { initTheme, useTheme } from './lib/theme'
|
|
8
|
+
export type { ChartPoint, ChartSeries } from './lib/chart'
|
|
9
|
+
export type { Theme } from './lib/theme'
|
|
7
10
|
|
|
8
11
|
// Layout
|
|
9
12
|
export { default as AppShell } from './components/AppShell/AppShell.vue'
|
|
@@ -42,6 +45,10 @@ export { default as Progress } from './components/Progress/Progress.vue'
|
|
|
42
45
|
export type { ProgressProps } from './components/Progress/Progress.vue'
|
|
43
46
|
export { default as ChangeIndicator } from './components/ChangeIndicator/ChangeIndicator.vue'
|
|
44
47
|
export type { ChangeIndicatorProps } from './components/ChangeIndicator/ChangeIndicator.vue'
|
|
48
|
+
export { default as Alert } from './components/Alert/Alert.vue'
|
|
49
|
+
export type { AlertProps } from './components/Alert/Alert.vue'
|
|
50
|
+
export { default as Collapsible } from './components/Collapsible/Collapsible.vue'
|
|
51
|
+
export type { CollapsibleProps } from './components/Collapsible/Collapsible.vue'
|
|
45
52
|
|
|
46
53
|
// Form
|
|
47
54
|
export { default as FormField } from './components/FormField/FormField.vue'
|
|
@@ -74,8 +81,12 @@ export { default as CheckboxGroup } from './components/CheckboxGroup/CheckboxGro
|
|
|
74
81
|
export type { CheckboxGroupProps, CheckboxOption, CheckboxGroupValue } from './components/CheckboxGroup/CheckboxGroup.vue'
|
|
75
82
|
export { default as LanguageSwitcher } from './components/LanguageSwitcher/LanguageSwitcher.vue'
|
|
76
83
|
export type { LanguageSwitcherProps } from './components/LanguageSwitcher/LanguageSwitcher.vue'
|
|
84
|
+
export { default as ThemeSwitcher } from './components/ThemeSwitcher/ThemeSwitcher.vue'
|
|
85
|
+
export type { ThemeSwitcherProps } from './components/ThemeSwitcher/ThemeSwitcher.vue'
|
|
77
86
|
export { default as CardSelect } from './components/CardSelect/CardSelect.vue'
|
|
78
87
|
export type { CardSelectProps } from './components/CardSelect/CardSelect.vue'
|
|
88
|
+
export { default as FileUpload } from './components/FileUpload/FileUpload.vue'
|
|
89
|
+
export type { FileUploadProps } from './components/FileUpload/FileUpload.vue'
|
|
79
90
|
|
|
80
91
|
// Data
|
|
81
92
|
export { default as Table } from './components/Table/Table.vue'
|
|
@@ -94,6 +105,10 @@ export { default as Age } from './components/Age/Age.vue'
|
|
|
94
105
|
export type { AgeProps } from './components/Age/Age.vue'
|
|
95
106
|
export { default as EmptyState } from './components/EmptyState/EmptyState.vue'
|
|
96
107
|
export type { EmptyStateProps } from './components/EmptyState/EmptyState.vue'
|
|
108
|
+
export { default as BarChart } from './components/BarChart/BarChart.vue'
|
|
109
|
+
export type { BarChartProps } from './components/BarChart/BarChart.vue'
|
|
110
|
+
export { default as LineChart } from './components/LineChart/LineChart.vue'
|
|
111
|
+
export type { LineChartProps } from './components/LineChart/LineChart.vue'
|
|
97
112
|
|
|
98
113
|
// Navigation
|
|
99
114
|
export { default as Breadcrumb } from './components/Breadcrumb/Breadcrumb.vue'
|
|
@@ -105,6 +120,8 @@ export { default as Link } from './components/Link/Link.vue'
|
|
|
105
120
|
export type { LinkProps } from './components/Link/Link.vue'
|
|
106
121
|
export { default as Steps } from './components/Steps/Steps.vue'
|
|
107
122
|
export type { StepsProps } from './components/Steps/Steps.vue'
|
|
123
|
+
export { default as ActionList } from './components/ActionList/ActionList.vue'
|
|
124
|
+
export type { ActionListItem, ActionListProps } from './components/ActionList/ActionList.vue'
|
|
108
125
|
|
|
109
126
|
// Overlay
|
|
110
127
|
export { default as Popover } from './components/Popover/Popover.vue'
|
package/src/lib/chart.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** One series in a chart: a name for the legend and table, and its colour slot. */
|
|
2
|
+
export interface ChartSeries {
|
|
3
|
+
/** The key of this series' number in each point's `values`. */
|
|
4
|
+
key: string
|
|
5
|
+
/** Its name in the legend, the tooltip and the table, e.g. "Failed". */
|
|
6
|
+
label: string
|
|
7
|
+
/**
|
|
8
|
+
* Which of the eight chart colours (1–8). Default: the series' place in
|
|
9
|
+
* the list. Set it so a series keeps its colour when others are filtered
|
|
10
|
+
* out, e.g. failed sign-ins always red (8).
|
|
11
|
+
*/
|
|
12
|
+
color?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** One point along the chart: a day, a month, a school. */
|
|
16
|
+
export interface ChartPoint {
|
|
17
|
+
/** Short label under the bar or along the axis, e.g. "Mon". */
|
|
18
|
+
label: string
|
|
19
|
+
/** Full label for the tooltip and table, e.g. "Monday 24 November". Default `label`. */
|
|
20
|
+
fullLabel?: string
|
|
21
|
+
/** A number for each series, by its key. Missing counts as 0. */
|
|
22
|
+
values: Record<string, number | null | undefined>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function seriesColor(series: ChartSeries, index: number): string {
|
|
26
|
+
const slot = series.color ?? Math.min(index + 1, 8)
|
|
27
|
+
return `var(--color-chart-${slot})`
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const valueOf = (point: ChartPoint, key: string) => point.values[key] ?? 0
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A clean top for the value axis and the ticks up to it: 0, 5, 10, 15
|
|
34
|
+
* rather than 0, 4.3, 8.6, 12.9. About `count` steps of 1, 2, 2.5 or 5 × 10ⁿ.
|
|
35
|
+
*/
|
|
36
|
+
export function niceScale(max: number, count = 4): { max: number; ticks: number[] } {
|
|
37
|
+
if (!(max > 0)) return { max: 1, ticks: [0, 1] }
|
|
38
|
+
const rough = max / count
|
|
39
|
+
const power = 10 ** Math.floor(Math.log10(rough))
|
|
40
|
+
const step = ([1, 2, 2.5, 5, 10].find((m) => m * power >= rough) ?? 10) * power
|
|
41
|
+
// Whole numbers only for counts: a step under 1 shows as 0, 0, 1, 1.
|
|
42
|
+
const safeStep = max >= 1 && step < 1 ? 1 : step
|
|
43
|
+
const top = Math.ceil(max / safeStep) * safeStep
|
|
44
|
+
const ticks: number[] = []
|
|
45
|
+
for (let v = 0; v <= top + safeStep / 2; v += safeStep) ticks.push(Number(v.toFixed(10)))
|
|
46
|
+
return { max: top, ticks }
|
|
47
|
+
}
|
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
|
@@ -153,6 +153,29 @@
|
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
+
@theme static {
|
|
157
|
+
/*
|
|
158
|
+
* Chart series, for BarChart and LineChart: eight hues in a fixed order,
|
|
159
|
+
* each stepped separately for light and dark. The order is what keeps
|
|
160
|
+
* neighbours apart for colour-blind readers (checked with the data-viz
|
|
161
|
+
* palette validator), so take them in order and never cycle: past eight
|
|
162
|
+
* series, group the rest as "Other". Marks only: chart text uses ink.
|
|
163
|
+
* Slots 3, 4 and 5 are under 3:1 on white in light mode, so every chart
|
|
164
|
+
* keeps its data table.
|
|
165
|
+
*
|
|
166
|
+
* `static`: the charts set these through inline styles, not classes, so
|
|
167
|
+
* Tailwind must output them even when no class uses them.
|
|
168
|
+
*/
|
|
169
|
+
--color-chart-1: light-dark(#2a78d6, #3987e5); /* blue */
|
|
170
|
+
--color-chart-2: light-dark(#eb6834, #d95926); /* orange */
|
|
171
|
+
--color-chart-3: light-dark(#1baf7a, #199e70); /* aqua */
|
|
172
|
+
--color-chart-4: light-dark(#eda100, #c98500); /* yellow */
|
|
173
|
+
--color-chart-5: light-dark(#e87ba4, #d55181); /* magenta */
|
|
174
|
+
--color-chart-6: light-dark(#008300, #0ca30c); /* green */
|
|
175
|
+
--color-chart-7: light-dark(#6250d6, #9085e9); /* violet */
|
|
176
|
+
--color-chart-8: light-dark(#e34948, #e66767); /* red */
|
|
177
|
+
}
|
|
178
|
+
|
|
156
179
|
/*
|
|
157
180
|
* Dark mode
|
|
158
181
|
* ---------
|