@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
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, type HTMLAttributes } from 'vue'
|
|
3
|
+
import { useI18n } from 'vue-i18n'
|
|
4
|
+
import { cn } from '../../lib/cn'
|
|
5
|
+
import { niceScale, seriesColor, valueOf, type ChartPoint, type ChartSeries } from '../../lib/chart'
|
|
6
|
+
import ChartData from '../BarChart/ChartData.vue'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Change over time as lines: applications per week across a term,
|
|
10
|
+
* attendance by month. One series, or a few to compare (up to four reads
|
|
11
|
+
* well; past that, use separate charts).
|
|
12
|
+
*
|
|
13
|
+
* Every chart carries its numbers as a table: always there for screen
|
|
14
|
+
* readers, and shown to anyone with "Show as table". Hovering shows a line
|
|
15
|
+
* across the chart and every series' value at that point. Put it in a Card
|
|
16
|
+
* whose title says what it shows.
|
|
17
|
+
*
|
|
18
|
+
* Colours come from the chart palette (chart-1 to chart-8), in order unless a
|
|
19
|
+
* series sets its own `color`.
|
|
20
|
+
*/
|
|
21
|
+
export interface LineChartProps {
|
|
22
|
+
/** What the chart shows, e.g. "Applications per week". The table's caption; not shown (the Card's title says it). */
|
|
23
|
+
label: string
|
|
24
|
+
/** One point per step along the bottom, in order (oldest first). */
|
|
25
|
+
data: ChartPoint[]
|
|
26
|
+
/** The lines. One series needs no legend; two or more get one. */
|
|
27
|
+
series: ChartSeries[]
|
|
28
|
+
/** A light wash under a single line, to show it as an amount. */
|
|
29
|
+
area?: boolean
|
|
30
|
+
/** Heading of the table's first column, e.g. "Week". Default "Category". */
|
|
31
|
+
categoryLabel?: string
|
|
32
|
+
/** Height of the plot in px. */
|
|
33
|
+
height?: number
|
|
34
|
+
/** How values are written on the axis, in tooltips and the table. Default: whole numbers in the app's language. */
|
|
35
|
+
format?: (value: number) => string
|
|
36
|
+
class?: HTMLAttributes['class']
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const { t, locale } = useI18n()
|
|
40
|
+
const props = withDefaults(defineProps<LineChartProps>(), {
|
|
41
|
+
height: 160
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const numberFormat = computed(() => new Intl.NumberFormat(locale.value))
|
|
45
|
+
const fmt = (value: number) => (props.format ? props.format(value) : numberFormat.value.format(value))
|
|
46
|
+
|
|
47
|
+
const scale = computed(() =>
|
|
48
|
+
niceScale(Math.max(0, ...props.data.flatMap((point) => props.series.map((s) => valueOf(point, s.key)))))
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
// Positions in percent of the plot: x along, y up from the bottom.
|
|
52
|
+
const count = computed(() => props.data.length)
|
|
53
|
+
const xAt = (i: number) => (count.value > 1 ? (i / (count.value - 1)) * 100 : 50)
|
|
54
|
+
const yAt = (value: number) => (value / scale.value.max) * 100
|
|
55
|
+
|
|
56
|
+
const lines = computed(() =>
|
|
57
|
+
props.series.map((s, i) => {
|
|
58
|
+
const points = props.data.map((point, p) => `${xAt(p)},${100 - yAt(valueOf(point, s.key))}`)
|
|
59
|
+
return {
|
|
60
|
+
series: s,
|
|
61
|
+
color: seriesColor(s, i),
|
|
62
|
+
points: points.join(' '),
|
|
63
|
+
// Closed down to the baseline, for the wash.
|
|
64
|
+
area: `0,100 ${points.join(' ')} ${xAt(count.value - 1)},100`,
|
|
65
|
+
last: count.value ? yAt(valueOf(props.data[count.value - 1], s.key)) : 0
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
// Labels along the bottom: at most about seven, evenly spaced, so they don't collide.
|
|
71
|
+
const labelEvery = computed(() => Math.max(1, Math.ceil(count.value / 7)))
|
|
72
|
+
// The last point is always labelled; a regular one too close to it is skipped.
|
|
73
|
+
const showLabel = (i: number) =>
|
|
74
|
+
i === count.value - 1 || (i % labelEvery.value === 0 && count.value - 1 - i >= labelEvery.value)
|
|
75
|
+
</script>
|
|
76
|
+
|
|
77
|
+
<template>
|
|
78
|
+
<div :class="cn('flex flex-col gap-3', props.class)">
|
|
79
|
+
<!-- The plot, hidden from screen readers: ChartData's table has the same numbers. -->
|
|
80
|
+
<div class="flex gap-2" aria-hidden="true">
|
|
81
|
+
<div class="relative w-8 shrink-0 text-right text-xs text-ink/65 tabular-nums" :style="{ height: `${height}px` }">
|
|
82
|
+
<span
|
|
83
|
+
v-for="tick in scale.ticks"
|
|
84
|
+
:key="tick"
|
|
85
|
+
class="absolute right-0 translate-y-1/2 leading-none"
|
|
86
|
+
:style="{ bottom: `${yAt(tick)}%` }"
|
|
87
|
+
>{{ fmt(tick) }}</span>
|
|
88
|
+
</div>
|
|
89
|
+
|
|
90
|
+
<div class="flex min-w-0 flex-1 flex-col gap-1.5">
|
|
91
|
+
<div class="relative" :style="{ height: `${height}px` }">
|
|
92
|
+
<div
|
|
93
|
+
v-for="tick in scale.ticks"
|
|
94
|
+
:key="tick"
|
|
95
|
+
class="absolute inset-x-0 h-px bg-ink/10"
|
|
96
|
+
:style="{ bottom: `${yAt(tick)}%` }"
|
|
97
|
+
/>
|
|
98
|
+
<!-- Lines: stretched to the plot, with strokes kept at 2px. -->
|
|
99
|
+
<svg class="absolute inset-0 size-full overflow-visible" viewBox="0 0 100 100" preserveAspectRatio="none">
|
|
100
|
+
<polygon
|
|
101
|
+
v-if="area && lines.length === 1"
|
|
102
|
+
:points="lines[0].area"
|
|
103
|
+
:fill="lines[0].color"
|
|
104
|
+
fill-opacity="0.1"
|
|
105
|
+
/>
|
|
106
|
+
<polyline
|
|
107
|
+
v-for="line in lines"
|
|
108
|
+
:key="line.series.key"
|
|
109
|
+
:points="line.points"
|
|
110
|
+
fill="none"
|
|
111
|
+
:stroke="line.color"
|
|
112
|
+
stroke-width="2"
|
|
113
|
+
stroke-linejoin="round"
|
|
114
|
+
stroke-linecap="round"
|
|
115
|
+
vector-effect="non-scaling-stroke"
|
|
116
|
+
/>
|
|
117
|
+
</svg>
|
|
118
|
+
<!-- End dots: 8px, with a ring of the surface so they stand clear of the lines. -->
|
|
119
|
+
<span
|
|
120
|
+
v-for="line in lines"
|
|
121
|
+
:key="line.series.key"
|
|
122
|
+
class="absolute size-2 -translate-x-1/2 translate-y-1/2 rounded-full ring-2 ring-surface"
|
|
123
|
+
:style="{ left: `${xAt(count - 1)}%`, bottom: `${line.last}%`, background: line.color }"
|
|
124
|
+
/>
|
|
125
|
+
|
|
126
|
+
<!-- Hover: a slice per point. Shows a line across, a dot on each series and the values. -->
|
|
127
|
+
<div
|
|
128
|
+
v-for="(point, i) in data"
|
|
129
|
+
:key="i"
|
|
130
|
+
class="group/point absolute inset-y-0 hover:z-20"
|
|
131
|
+
:style="{ left: `${count > 1 ? xAt(i) - 50 / (count - 1) : 0}%`, width: `${count > 1 ? 100 / (count - 1) : 100}%` }"
|
|
132
|
+
>
|
|
133
|
+
<div class="absolute inset-y-0 left-1/2 hidden w-px bg-ink/25 group-hover/point:block" />
|
|
134
|
+
<span
|
|
135
|
+
v-for="line in lines"
|
|
136
|
+
:key="line.series.key"
|
|
137
|
+
class="absolute left-1/2 hidden size-2 -translate-x-1/2 translate-y-1/2 rounded-full ring-2 ring-surface group-hover/point:block"
|
|
138
|
+
:style="{ bottom: `${yAt(valueOf(point, line.series.key))}%`, background: line.color }"
|
|
139
|
+
/>
|
|
140
|
+
<div
|
|
141
|
+
class="pointer-events-none absolute bottom-full left-1/2 mb-1 hidden w-max max-w-56 -translate-x-1/2 flex-col gap-1 rounded-md border border-ink/10 bg-surface-elevated px-2.5 py-1.5 text-xs text-ink shadow-md group-hover/point:flex"
|
|
142
|
+
>
|
|
143
|
+
<span class="font-bold">{{ point.fullLabel ?? point.label }}</span>
|
|
144
|
+
<span v-for="(s, si) in series" :key="s.key" class="flex items-center gap-1.5">
|
|
145
|
+
<span class="size-2 rounded-full" :style="{ background: seriesColor(s, si) }" />
|
|
146
|
+
{{ s.label }}<span class="ml-auto pl-3 tabular-nums">{{ fmt(valueOf(point, s.key)) }}</span>
|
|
147
|
+
</span>
|
|
148
|
+
</div>
|
|
149
|
+
</div>
|
|
150
|
+
</div>
|
|
151
|
+
<!-- Labels along the bottom, under their points. -->
|
|
152
|
+
<div class="relative h-4 text-xs text-ink/65">
|
|
153
|
+
<template v-for="(point, i) in data" :key="i">
|
|
154
|
+
<span
|
|
155
|
+
v-if="showLabel(i)"
|
|
156
|
+
class="absolute whitespace-nowrap"
|
|
157
|
+
:class="i === 0 && count > 1 ? '' : i === count - 1 && count > 1 ? '-translate-x-full' : '-translate-x-1/2'"
|
|
158
|
+
:style="{ left: `${xAt(i)}%` }"
|
|
159
|
+
>{{ point.label }}</span>
|
|
160
|
+
</template>
|
|
161
|
+
</div>
|
|
162
|
+
</div>
|
|
163
|
+
</div>
|
|
164
|
+
|
|
165
|
+
<ChartData
|
|
166
|
+
:label="label"
|
|
167
|
+
:category-label="categoryLabel ?? t('ui.chart.category')"
|
|
168
|
+
:series="series"
|
|
169
|
+
:data="data"
|
|
170
|
+
:format="fmt"
|
|
171
|
+
/>
|
|
172
|
+
</div>
|
|
173
|
+
</template>
|
|
@@ -422,11 +422,13 @@ const positions = {
|
|
|
422
422
|
)
|
|
423
423
|
"
|
|
424
424
|
>
|
|
425
|
+
<!-- It floats over the page with the toasts: the floating-panel
|
|
426
|
+
colour, with the same 5% hover as everything else. -->
|
|
425
427
|
<button
|
|
426
428
|
type="button"
|
|
427
429
|
:class="
|
|
428
430
|
cn(
|
|
429
|
-
'flex cursor-pointer items-center justify-center overflow-hidden border border-ink/10 bg-surface font-bold whitespace-nowrap text-ink shadow-md hover:bg-surface-
|
|
431
|
+
'flex cursor-pointer items-center justify-center overflow-hidden border border-ink/10 bg-surface-elevated font-bold whitespace-nowrap text-ink shadow-md hover:bg-[color-mix(in_oklab,var(--color-surface-elevated)_95%,var(--color-ink))]',
|
|
430
432
|
'h-7 w-24 rounded-2xl text-xs',
|
|
431
433
|
hidden && 'in-data-expanded:h-9 in-data-expanded:w-full in-data-expanded:rounded in-data-expanded:text-sm',
|
|
432
434
|
'transition-[width,height,border-radius,font-size,background-color] duration-300 ease-out motion-reduce:transition-none',
|
|
@@ -72,3 +72,21 @@ export const Stepping: Story = {
|
|
|
72
72
|
</div>`,
|
|
73
73
|
}),
|
|
74
74
|
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Going back: with `segmentLabels`, each finished segment before the current
|
|
78
|
+
* one is a button ("Back to step 1: Name") that emits `select`. Steps ahead
|
|
79
|
+
* can't be picked. Slideover's multi-step form uses this.
|
|
80
|
+
*/
|
|
81
|
+
export const GoBack: Story = {
|
|
82
|
+
render: () => ({
|
|
83
|
+
components: { Progress, Button },
|
|
84
|
+
setup: () => ({ step: ref(3), names: ["Name", "Date of birth", "Contact", "Check and add"] }),
|
|
85
|
+
template: `
|
|
86
|
+
<div class="flex flex-col gap-3">
|
|
87
|
+
<Progress label="Add a student" segments :value="step" :max="4" :segment-labels="names" @select="step = $event + 1" />
|
|
88
|
+
<p class="text-sm">Step {{ step }}: {{ names[step - 1] }}</p>
|
|
89
|
+
<Button size="sm" class="self-start" :disabled="step === 4" @click="step++">Next</Button>
|
|
90
|
+
</div>`,
|
|
91
|
+
}),
|
|
92
|
+
};
|
|
@@ -11,6 +11,11 @@ import { cn } from '../../lib/cn'
|
|
|
11
11
|
* steps filled out of `max`);
|
|
12
12
|
* - indeterminate, when there's no telling how long it'll take (no `value`).
|
|
13
13
|
* Built on Reka UI's Progress, so it's announced as a progress bar.
|
|
14
|
+
*
|
|
15
|
+
* Segments can take you back: give `segmentLabels` (one name per segment) and
|
|
16
|
+
* the finished segments before the current one become buttons ("Back to step
|
|
17
|
+
* 1: Name") that emit `select` with the segment's index, from 0. Steps ahead
|
|
18
|
+
* can't be picked, so each step's checks still run in order.
|
|
14
19
|
*/
|
|
15
20
|
export interface ProgressProps {
|
|
16
21
|
/** Done so far, out of `max`. Leave it out (or null) for indeterminate. */
|
|
@@ -21,6 +26,10 @@ export interface ProgressProps {
|
|
|
21
26
|
segments?: boolean
|
|
22
27
|
/** What's progressing, e.g. "Uploading report.pdf". Its accessible name; not shown. */
|
|
23
28
|
label: string
|
|
29
|
+
/** With `segments`: a name per segment. Finished segments become buttons that emit `select`. */
|
|
30
|
+
segmentLabels?: string[]
|
|
31
|
+
/** Stops the segment buttons working, e.g. while a step is saving. */
|
|
32
|
+
disabled?: boolean
|
|
24
33
|
class?: HTMLAttributes['class']
|
|
25
34
|
}
|
|
26
35
|
|
|
@@ -30,6 +39,11 @@ const props = withDefaults(defineProps<ProgressProps>(), {
|
|
|
30
39
|
max: 100
|
|
31
40
|
})
|
|
32
41
|
|
|
42
|
+
const emit = defineEmits<{
|
|
43
|
+
/** A finished segment was pressed: its index, from 0. */
|
|
44
|
+
select: [index: number]
|
|
45
|
+
}>()
|
|
46
|
+
|
|
33
47
|
const indeterminate = computed(() => props.value === null || props.value === undefined)
|
|
34
48
|
const clamped = computed(() => Math.min(Math.max(props.value ?? 0, 0), props.max))
|
|
35
49
|
const percent = computed(() => (clamped.value / props.max) * 100)
|
|
@@ -46,10 +60,53 @@ const valueText = () =>
|
|
|
46
60
|
const track = 'h-1.5 overflow-hidden rounded-full bg-ink/10'
|
|
47
61
|
// Filling and segments colouring in ease over 300ms.
|
|
48
62
|
const fill = 'h-full rounded-full bg-primary transition-[translate,background-color] duration-300 ease-out motion-reduce:transition-none'
|
|
63
|
+
|
|
64
|
+
// Segment buttons sit over the bar, not inside it: a progress bar's contents
|
|
65
|
+
// are hidden from screen readers. Each is 24px tall (WCAG 2.5.8 target size)
|
|
66
|
+
// around a 6px segment; hover and press darken the segment, focus rings it.
|
|
67
|
+
const navigable = computed(() => props.segments && !indeterminate.value && !!props.segmentLabels?.length)
|
|
68
|
+
const segmentButton = [
|
|
69
|
+
'flex h-6 flex-1 cursor-pointer items-center rounded-sm',
|
|
70
|
+
'outline-2 outline-offset-0 outline-transparent focus-visible:outline-focus',
|
|
71
|
+
'not-disabled:hover:[&>span]:bg-black/20 not-disabled:active:[&>span]:bg-black/35',
|
|
72
|
+
'disabled:cursor-not-allowed'
|
|
73
|
+
]
|
|
74
|
+
const segmentShade = 'h-1.5 w-full rounded-full transition-colors'
|
|
49
75
|
</script>
|
|
50
76
|
|
|
51
77
|
<template>
|
|
78
|
+
<div v-if="navigable" :class="cn('relative', props.class)">
|
|
79
|
+
<ProgressRoot
|
|
80
|
+
:model-value="clamped"
|
|
81
|
+
:max="max"
|
|
82
|
+
:get-value-label="() => label"
|
|
83
|
+
:get-value-text="valueText"
|
|
84
|
+
class="flex gap-1"
|
|
85
|
+
>
|
|
86
|
+
<div v-for="i in max" :key="i" :class="cn(track, 'flex-1')">
|
|
87
|
+
<div :class="cn(fill, i <= clamped ? 'translate-x-0' : '-translate-x-full')" />
|
|
88
|
+
</div>
|
|
89
|
+
</ProgressRoot>
|
|
90
|
+
<!-- Over the bar: a button for each finished segment, a spacer for the rest. -->
|
|
91
|
+
<div class="absolute inset-x-0 top-1/2 flex -translate-y-1/2 gap-1">
|
|
92
|
+
<template v-for="i in max" :key="i">
|
|
93
|
+
<button
|
|
94
|
+
v-if="i < clamped"
|
|
95
|
+
type="button"
|
|
96
|
+
data-progress-segment
|
|
97
|
+
:class="segmentButton"
|
|
98
|
+
:disabled="disabled"
|
|
99
|
+
:aria-label="t('ui.progress.backTo', { current: i, name: segmentLabels![i - 1] })"
|
|
100
|
+
@click="emit('select', i - 1)"
|
|
101
|
+
>
|
|
102
|
+
<span :class="segmentShade" />
|
|
103
|
+
</button>
|
|
104
|
+
<span v-else class="flex-1" />
|
|
105
|
+
</template>
|
|
106
|
+
</div>
|
|
107
|
+
</div>
|
|
52
108
|
<ProgressRoot
|
|
109
|
+
v-else
|
|
53
110
|
:model-value="indeterminate ? null : clamped"
|
|
54
111
|
:max="max"
|
|
55
112
|
:get-value-label="() => label"
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite'
|
|
2
|
+
import Prose from './Prose.vue'
|
|
3
|
+
|
|
4
|
+
const meta = {
|
|
5
|
+
title: 'Components/Element/Prose',
|
|
6
|
+
component: Prose,
|
|
7
|
+
tags: ['autodocs'],
|
|
8
|
+
args: { size: 'base' },
|
|
9
|
+
render: (args) => ({
|
|
10
|
+
components: { Prose },
|
|
11
|
+
setup: () => ({ args }),
|
|
12
|
+
template: `
|
|
13
|
+
<Prose v-bind="args">
|
|
14
|
+
<h1>Privacy policy</h1>
|
|
15
|
+
<p>This policy explains what personal information The Keston Group collects when you use our apps, why, and your rights. Read the <a href="#terms">terms</a> too.</p>
|
|
16
|
+
<h2>What we collect</h2>
|
|
17
|
+
<p>We collect only what we need to run the service:</p>
|
|
18
|
+
<ul>
|
|
19
|
+
<li>Your name and work email, from your organisation.</li>
|
|
20
|
+
<li>When and where you sign in, to keep your account secure.</li>
|
|
21
|
+
<li>Settings you ask us to remember.</li>
|
|
22
|
+
</ul>
|
|
23
|
+
<h3>How long we keep it</h3>
|
|
24
|
+
<p>Sign-in records are kept for <strong>12 months</strong>, then deleted. Run <code>pnpm tokens</code> to see a code sample.</p>
|
|
25
|
+
<blockquote>We never sell your information or use it for advertising.</blockquote>
|
|
26
|
+
<h2>Your rights</h2>
|
|
27
|
+
<ol>
|
|
28
|
+
<li>See the information we hold about you.</li>
|
|
29
|
+
<li>Ask us to correct or delete it.</li>
|
|
30
|
+
</ol>
|
|
31
|
+
<table>
|
|
32
|
+
<thead><tr><th>Data</th><th>Kept for</th></tr></thead>
|
|
33
|
+
<tbody><tr><td>Sign-ins</td><td>12 months</td></tr><tr><td>Audit logs</td><td>7 years</td></tr></tbody>
|
|
34
|
+
</table>
|
|
35
|
+
<p><small>Last updated 30 November 2026.</small></p>
|
|
36
|
+
</Prose>`,
|
|
37
|
+
}),
|
|
38
|
+
} satisfies Meta<typeof Prose>
|
|
39
|
+
|
|
40
|
+
export default meta
|
|
41
|
+
type Story = StoryObj<typeof meta>
|
|
42
|
+
|
|
43
|
+
export const Default: Story = {}
|
|
44
|
+
|
|
45
|
+
/** Smaller, for help text in a panel or card. */
|
|
46
|
+
export const Small: Story = { args: { size: 'sm' } }
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { HTMLAttributes } from 'vue'
|
|
3
|
+
import { cn } from '../../lib/cn'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Long-form text written as plain HTML: privacy policies, terms, help
|
|
7
|
+
* articles, release notes. Gives headings, paragraphs, lists, links, quotes,
|
|
8
|
+
* code and tables Keston's look without a class on each, at a readable line
|
|
9
|
+
* length (about 65 characters).
|
|
10
|
+
*
|
|
11
|
+
* Headings follow the guide's scale: h1 text-2xl (when the page has no
|
|
12
|
+
* PageHeader), h2 text-lg, h3 text-base, h4 text-sm. Links look and behave
|
|
13
|
+
* like Link (Keston blue, underlined, focus ring); use Link itself for
|
|
14
|
+
* links that open in a new tab, so they get its icon and screen-reader text.
|
|
15
|
+
*
|
|
16
|
+
* Not for app screens: those are built from components.
|
|
17
|
+
*/
|
|
18
|
+
export interface ProseProps {
|
|
19
|
+
/** The text size. base (default) for reading pages, sm in a panel or card. */
|
|
20
|
+
size?: 'sm' | 'base'
|
|
21
|
+
class?: HTMLAttributes['class']
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const props = withDefaults(defineProps<ProseProps>(), { size: 'base' })
|
|
25
|
+
|
|
26
|
+
const prose = [
|
|
27
|
+
'max-w-prose text-ink [&>*+*]:mt-4',
|
|
28
|
+
// Headings: space above to separate sections, less below to tie them to their text.
|
|
29
|
+
'[&_h1]:text-2xl [&_h1]:font-bold',
|
|
30
|
+
'[&_h2]:mt-10 [&_h2]:text-lg [&_h2]:font-bold [&_h2+*]:mt-2',
|
|
31
|
+
'[&_h3]:mt-8 [&_h3]:text-base [&_h3]:font-bold [&_h3+*]:mt-2',
|
|
32
|
+
'[&_h4]:mt-6 [&_h4]:text-sm [&_h4]:font-bold [&_h4+*]:mt-1',
|
|
33
|
+
// Lists.
|
|
34
|
+
'[&_ul]:list-disc [&_ol]:list-decimal [&_ul,&_ol]:pl-6 [&_li+li]:mt-1 [&_li::marker]:text-ink/55',
|
|
35
|
+
// Links, as Link.
|
|
36
|
+
'[&_a]:text-primary-fg [&_a]:underline [&_a]:underline-offset-2 [&_a]:rounded-sm',
|
|
37
|
+
'[&_a]:outline-2 [&_a]:outline-offset-1 [&_a]:outline-transparent [&_a:focus-visible]:outline-focus',
|
|
38
|
+
// Quotes, code, rules, small print.
|
|
39
|
+
'[&_blockquote]:border-l-2 [&_blockquote]:border-ink/10 [&_blockquote]:pl-4 [&_blockquote]:text-ink/65',
|
|
40
|
+
'[&_code]:rounded-sm [&_code]:bg-surface-muted [&_code]:px-1 [&_code]:font-mono [&_code]:text-[0.875em]',
|
|
41
|
+
'[&_hr]:border-ink/10 [&_small]:text-ink/65 [&_strong]:font-bold',
|
|
42
|
+
// Tables: lines between rows, headings quieter.
|
|
43
|
+
'[&_table]:w-full [&_table]:text-left [&_table]:text-sm [&_th]:py-2 [&_th]:pr-4 [&_th]:font-normal [&_th]:text-ink/65',
|
|
44
|
+
'[&_td]:py-2 [&_td]:pr-4 [&_tr]:border-b [&_tr]:border-ink/10'
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
const sizes = { sm: 'text-sm leading-relaxed', base: 'text-base leading-relaxed' }
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<template>
|
|
51
|
+
<div :class="cn(prose, sizes[size], props.class)">
|
|
52
|
+
<slot />
|
|
53
|
+
</div>
|
|
54
|
+
</template>
|
|
@@ -76,7 +76,7 @@ const circle = [
|
|
|
76
76
|
</script>
|
|
77
77
|
|
|
78
78
|
<template>
|
|
79
|
-
<div :class="cn('flex flex-col gap-1.5 text-ink', disabled && 'opacity-40', props.class)">
|
|
79
|
+
<div :data-disabled="disabled || undefined" :class="cn('flex flex-col gap-1.5 text-ink', disabled && 'opacity-40', props.class)">
|
|
80
80
|
<div class="flex flex-col gap-0.5">
|
|
81
81
|
<div class="flex items-center gap-1">
|
|
82
82
|
<span :id="labelId" class="text-sm">{{ label }}</span>
|
|
@@ -98,7 +98,7 @@ const circle = [
|
|
|
98
98
|
:aria-invalid="errorText ? true : undefined"
|
|
99
99
|
class="flex flex-col gap-2"
|
|
100
100
|
>
|
|
101
|
-
<div v-for="(option, i) in options" :key="String(option.value)" class="flex items-start gap-2">
|
|
101
|
+
<div v-for="(option, i) in options" :key="String(option.value)" :data-disabled="option.disabled || undefined" class="flex items-start gap-2">
|
|
102
102
|
<RadioGroupItem
|
|
103
103
|
:id="`${id}-${i}`"
|
|
104
104
|
:value="option.value"
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite'
|
|
2
|
+
import ResultState from './ResultState.vue'
|
|
3
|
+
import Button from '../Button/Button.vue'
|
|
4
|
+
import Card from '../Card/Card.vue'
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'Components/Data/ResultState',
|
|
8
|
+
component: ResultState,
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
args: {
|
|
11
|
+
type: 'success',
|
|
12
|
+
title: '3 users added',
|
|
13
|
+
description: "They'll get an email with how to sign in for the first time.",
|
|
14
|
+
focus: false,
|
|
15
|
+
},
|
|
16
|
+
render: (args) => ({
|
|
17
|
+
components: { ResultState, Button, Card },
|
|
18
|
+
setup: () => ({ args }),
|
|
19
|
+
template: `
|
|
20
|
+
<Card class="max-w-xl">
|
|
21
|
+
<ResultState v-bind="args">
|
|
22
|
+
<template #actions>
|
|
23
|
+
<Button>Add more users</Button>
|
|
24
|
+
<Button variant="primary">Done</Button>
|
|
25
|
+
</template>
|
|
26
|
+
</ResultState>
|
|
27
|
+
</Card>`,
|
|
28
|
+
}),
|
|
29
|
+
} satisfies Meta<typeof ResultState>
|
|
30
|
+
|
|
31
|
+
export default meta
|
|
32
|
+
type Story = StoryObj<typeof meta>
|
|
33
|
+
|
|
34
|
+
export const Success: Story = {}
|
|
35
|
+
|
|
36
|
+
/** Nothing happened. */
|
|
37
|
+
export const Error: Story = {
|
|
38
|
+
args: { type: 'error', title: 'Nobody was added', description: 'Every email address is already in use. Check the list and try again.' },
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Partly worked: say what didn't. */
|
|
42
|
+
export const Warning: Story = {
|
|
43
|
+
args: { type: 'warning', title: '2 of 3 users added', description: "jo@keston.school couldn't be added: that email is already in use." },
|
|
44
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { onMounted, ref, type Component, type HTMLAttributes } from 'vue'
|
|
3
|
+
import { CircleCheck, CircleX, Info, TriangleAlert } from '@lucide/vue'
|
|
4
|
+
import { cn } from '../../lib/cn'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The end of a task: what happened, and what next. "3 users added", "Nobody
|
|
8
|
+
* was added", "Password changed". A large icon, a heading, a line or two,
|
|
9
|
+
* and actions (e.g. Add more, Done), centred.
|
|
10
|
+
*
|
|
11
|
+
* It usually replaces the form that was just sent, so focus moves to its
|
|
12
|
+
* heading when it appears and screen readers read the outcome. Turn that off
|
|
13
|
+
* with `:focus="false"` when it's on the page from the start.
|
|
14
|
+
*
|
|
15
|
+
* For a list or table with nothing in it, use EmptyState.
|
|
16
|
+
*
|
|
17
|
+
* Slots: description (instead of `description`), default (under the
|
|
18
|
+
* description, e.g. a list of what failed), actions.
|
|
19
|
+
*/
|
|
20
|
+
export interface ResultStateProps {
|
|
21
|
+
/** success (default), error (nothing happened), warning (partly), info. Sets the icon and its colour. */
|
|
22
|
+
type?: 'success' | 'error' | 'warning' | 'info'
|
|
23
|
+
/** What happened, e.g. "3 users added". */
|
|
24
|
+
title: string
|
|
25
|
+
/** What it means or what to do next. */
|
|
26
|
+
description?: string
|
|
27
|
+
/** A different icon from the type's own. */
|
|
28
|
+
icon?: Component
|
|
29
|
+
/** The heading's level, to fit the page outline. */
|
|
30
|
+
headingLevel?: 1 | 2 | 3
|
|
31
|
+
/** Move focus to the heading when it appears. */
|
|
32
|
+
focus?: boolean
|
|
33
|
+
class?: HTMLAttributes['class']
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const props = withDefaults(defineProps<ResultStateProps>(), {
|
|
37
|
+
type: 'success',
|
|
38
|
+
headingLevel: 2,
|
|
39
|
+
focus: true
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
defineSlots<{
|
|
43
|
+
default?(): unknown
|
|
44
|
+
description?(): unknown
|
|
45
|
+
actions?(): unknown
|
|
46
|
+
}>()
|
|
47
|
+
|
|
48
|
+
const types = {
|
|
49
|
+
success: { icon: CircleCheck, colour: 'text-green-fg' },
|
|
50
|
+
error: { icon: CircleX, colour: 'text-red-fg' },
|
|
51
|
+
warning: { icon: TriangleAlert, colour: 'text-yellow-fg' },
|
|
52
|
+
info: { icon: Info, colour: 'text-blue-fg' }
|
|
53
|
+
} as const
|
|
54
|
+
|
|
55
|
+
const heading = ref<HTMLElement>()
|
|
56
|
+
onMounted(() => {
|
|
57
|
+
if (props.focus) heading.value?.focus()
|
|
58
|
+
})
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
<template>
|
|
62
|
+
<div :class="cn('flex flex-col items-center gap-2 px-4 py-8 text-center', props.class)">
|
|
63
|
+
<component :is="icon ?? types[type].icon" :class="cn('mb-1 size-10', types[type].colour)" aria-hidden="true" />
|
|
64
|
+
<!-- Focusable only by script, with no ring: it's not a control. -->
|
|
65
|
+
<component :is="`h${headingLevel}`" ref="heading" tabindex="-1" class="text-xl font-bold outline-none">
|
|
66
|
+
{{ title }}
|
|
67
|
+
</component>
|
|
68
|
+
<div v-if="description || $slots.description" class="max-w-prose text-sm text-ink/65">
|
|
69
|
+
<slot name="description">{{ description }}</slot>
|
|
70
|
+
</div>
|
|
71
|
+
<slot />
|
|
72
|
+
<div v-if="$slots.actions" class="mt-3 flex flex-wrap justify-center gap-2">
|
|
73
|
+
<slot name="actions" />
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
</template>
|
|
@@ -428,8 +428,10 @@ const item = [
|
|
|
428
428
|
const searchText = (row: Row) =>
|
|
429
429
|
props.searchable ? [row.option.label, row.option.description, row.path].filter(Boolean).join(' ') : row.option.label
|
|
430
430
|
|
|
431
|
-
// Turns over while
|
|
432
|
-
|
|
431
|
+
// Turns over while this list is open. A named group on the trigger, so a
|
|
432
|
+
// Select inside something else that's open (e.g. the account menu) doesn't
|
|
433
|
+
// turn over with it.
|
|
434
|
+
const chevron = 'transition-transform duration-150 group-data-[state=open]/select:rotate-180 motion-reduce:transition-none'
|
|
433
435
|
</script>
|
|
434
436
|
|
|
435
437
|
<template>
|
|
@@ -508,7 +510,7 @@ const chevron = 'transition-transform duration-150 in-data-[state=open]:rotate-1
|
|
|
508
510
|
@keydown.backspace="onSearchBackspace"
|
|
509
511
|
/>
|
|
510
512
|
</span>
|
|
511
|
-
<ComboboxTrigger tabindex="-1" :aria-label="t('ui.select.showOptions')" class="-mr-0.5 flex cursor-pointer disabled:cursor-not-allowed">
|
|
513
|
+
<ComboboxTrigger tabindex="-1" :aria-label="t('ui.select.showOptions')" class="group/select -mr-0.5 flex cursor-pointer disabled:cursor-not-allowed">
|
|
512
514
|
<ChevronDown aria-hidden="true" :class="chevron" />
|
|
513
515
|
</ComboboxTrigger>
|
|
514
516
|
</ComboboxAnchor>
|
|
@@ -521,7 +523,7 @@ const chevron = 'transition-transform duration-150 in-data-[state=open]:rotate-1
|
|
|
521
523
|
:aria-describedby="describedBy"
|
|
522
524
|
:data-pointer-focus="pointerFocus || undefined"
|
|
523
525
|
@blur="pointerFocus = false"
|
|
524
|
-
:class="cn(fill, 'cursor-pointer text-left outline-none disabled:cursor-not-allowed data-placeholder:text-ink/55')"
|
|
526
|
+
:class="cn(fill, 'group/select cursor-pointer text-left outline-none disabled:cursor-not-allowed data-placeholder:text-ink/55')"
|
|
525
527
|
>
|
|
526
528
|
<slot name="leading">
|
|
527
529
|
<component :is="selected.icon" v-if="selected?.icon" aria-hidden="true" />
|