@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
|
@@ -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>
|
|
@@ -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"
|
|
@@ -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"
|
|
@@ -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" />
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { useI18n } from 'vue-i18n'
|
|
3
|
-
import { computed,
|
|
3
|
+
import { computed, ref, useId, watch, type HTMLAttributes } from 'vue'
|
|
4
4
|
import {
|
|
5
5
|
DialogClose,
|
|
6
6
|
DialogContent,
|
|
@@ -30,9 +30,11 @@ import Progress from '../Progress/Progress.vue'
|
|
|
30
30
|
*
|
|
31
31
|
* Multi-step forms: pass `steps` (one name per step) and show the current
|
|
32
32
|
* step's fields in the body slot, which gets `{ step }`. The header shows a
|
|
33
|
-
* segment per step
|
|
34
|
-
*
|
|
35
|
-
*
|
|
33
|
+
* segment per step (press a finished one to go back to it), then the title
|
|
34
|
+
* with the step under it (e.g. "Turn on MFA" / "Step 2 of 3 – Enter the
|
|
35
|
+
* code"). Changing step slides the step line, the body and the buttons. The
|
|
36
|
+
* footer gets Cancel / Previous and Next / Finish, unless you fill the footer
|
|
37
|
+
* slot. Enter in a text field presses Next / Finish.
|
|
36
38
|
*/
|
|
37
39
|
export interface SlideoverProps {
|
|
38
40
|
/** Heading of the panel. Also its accessible name, so always set it (or the title slot). */
|
|
@@ -149,24 +151,68 @@ const stepText = computed(() => (props.steps ? t('ui.slideover.stepOf', { curren
|
|
|
149
151
|
const announcement = ref('')
|
|
150
152
|
const body = ref<HTMLElement>()
|
|
151
153
|
|
|
154
|
+
// Changing step: the step line under the title, the body's content and the
|
|
155
|
+
// footer's buttons all slide and fade, one page after the other (mode out-in, so the old and new
|
|
156
|
+
// never overlap). Forward (Next) slides left, back slides right; 16px, inside
|
|
157
|
+
// the 24px padding, so nothing needs clipping. Fade only with reduced motion.
|
|
158
|
+
const direction = ref<'forward' | 'back'>('forward')
|
|
159
|
+
const stepTransition = computed(() => {
|
|
160
|
+
const ahead = direction.value === 'forward' ? 'translate-x-4' : '-translate-x-4'
|
|
161
|
+
const behind = direction.value === 'forward' ? '-translate-x-4' : 'translate-x-4'
|
|
162
|
+
return {
|
|
163
|
+
mode: 'out-in' as const,
|
|
164
|
+
enterActiveClass: 'transition duration-200 ease-out motion-reduce:transition-opacity',
|
|
165
|
+
enterFromClass: `opacity-0 motion-reduce:translate-x-0 ${ahead}`,
|
|
166
|
+
// pointer-events-none: a double-click can't press a button on its way out.
|
|
167
|
+
leaveActiveClass: 'pointer-events-none transition duration-150 ease-in motion-reduce:transition-opacity',
|
|
168
|
+
leaveToClass: `opacity-0 motion-reduce:translate-x-0 ${behind}`
|
|
169
|
+
}
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
// The new step's content only arrives once the old one has gone, so goTo
|
|
173
|
+
// waits for it before moving focus into it.
|
|
174
|
+
let stepEntered: (() => void) | undefined
|
|
175
|
+
function onStepEnter() {
|
|
176
|
+
body.value?.scrollTo({ top: 0 })
|
|
177
|
+
stepEntered?.()
|
|
178
|
+
stepEntered = undefined
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// The footer's buttons are replaced too. If one had focus (Next / Previous),
|
|
182
|
+
// the new step's matching button gets it, so keyboard use carries on: Next →
|
|
183
|
+
// Next or Finish, Previous → Previous or Cancel.
|
|
184
|
+
let buttonToFocus: string | undefined
|
|
185
|
+
function onFooterEnter(el: Element) {
|
|
186
|
+
if (!buttonToFocus) return
|
|
187
|
+
el.querySelector<HTMLElement>(`[data-step-button="${buttonToFocus}"]`)?.focus()
|
|
188
|
+
buttonToFocus = undefined
|
|
189
|
+
}
|
|
190
|
+
|
|
152
191
|
async function goTo(index: number) {
|
|
153
192
|
// If focus is in this step's fields (e.g. Enter was pressed in one), they're
|
|
154
193
|
// about to go: carry on in the new step's first control (or the panel, on
|
|
155
194
|
// touch screens, so the keyboard doesn't pop up). Focus on Next / Previous
|
|
156
|
-
//
|
|
195
|
+
// moves to the new step's matching button (onFooterEnter).
|
|
157
196
|
const focusInStep = !!body.value?.contains(document.activeElement)
|
|
197
|
+
const panel = body.value?.closest('[role=dialog]')
|
|
198
|
+
const focusedButton = document.activeElement?.closest<HTMLElement>('[data-step-button]')
|
|
199
|
+
buttonToFocus = focusedButton && panel?.contains(focusedButton) ? focusedButton.dataset.stepButton : undefined
|
|
200
|
+
// A step picked on the progress bar: its button goes once you're on it.
|
|
201
|
+
const fromSegment = !!document.activeElement?.closest('[data-progress-segment]')
|
|
158
202
|
announcement.value = ''
|
|
203
|
+
direction.value = index < step.value ? 'back' : 'forward'
|
|
204
|
+
stepEntered?.()
|
|
205
|
+
const entered = new Promise<void>((resolve) => (stepEntered = resolve))
|
|
159
206
|
step.value = index
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
await nextTick()
|
|
207
|
+
// The new step starts from the top (onStepEnter).
|
|
208
|
+
await entered
|
|
163
209
|
const touch = window.matchMedia('(pointer: coarse)').matches
|
|
164
210
|
const field = focusInStep && !touch ? body.value?.querySelector<HTMLElement>(stepControlSelector) : null
|
|
165
211
|
if (field) {
|
|
166
212
|
field.focus()
|
|
167
213
|
return
|
|
168
214
|
}
|
|
169
|
-
if (focusInStep) body.value?.closest<HTMLElement>('[role=dialog]')?.focus()
|
|
215
|
+
if (focusInStep || fromSegment) body.value?.closest<HTMLElement>('[role=dialog]')?.focus()
|
|
170
216
|
announcement.value = stepText.value
|
|
171
217
|
}
|
|
172
218
|
|
|
@@ -295,17 +341,34 @@ const panel = [
|
|
|
295
341
|
v-if="title || description || close || steps || $slots.header || $slots.title"
|
|
296
342
|
:class="cn('flex flex-col gap-4 border-b border-ink/10 px-6 py-4', ui?.header)"
|
|
297
343
|
>
|
|
298
|
-
<!--
|
|
299
|
-
<
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
344
|
+
<!-- Finished steps can be picked to go back to them. -->
|
|
345
|
+
<Progress
|
|
346
|
+
v-if="steps"
|
|
347
|
+
:label="title ?? t('ui.slideover.steps')"
|
|
348
|
+
segments
|
|
349
|
+
:value="step + 1"
|
|
350
|
+
:max="stepCount"
|
|
351
|
+
:segment-labels="steps"
|
|
352
|
+
:disabled="nextStatus === 'loading'"
|
|
353
|
+
@select="goTo"
|
|
354
|
+
/>
|
|
303
355
|
<div class="flex items-start gap-4">
|
|
304
356
|
<slot name="header" :close="closePanel">
|
|
305
357
|
<div class="flex min-w-0 flex-1 flex-col gap-1">
|
|
306
358
|
<DialogTitle :class="title || $slots.title ? cn('text-lg', ui?.title) : 'sr-only'">
|
|
307
359
|
<slot name="title">{{ title }}</slot>
|
|
308
360
|
</DialogTitle>
|
|
361
|
+
<!--
|
|
362
|
+
Steps: "Step 2 of 4 – Contact" under the title, sliding with
|
|
363
|
+
the body (stepTransition). The line keeps its height (h-5)
|
|
364
|
+
while it's briefly empty. Hidden from screen readers, which
|
|
365
|
+
get "Step 2 of 4: …" instead.
|
|
366
|
+
-->
|
|
367
|
+
<div v-if="steps" class="h-5" aria-hidden="true">
|
|
368
|
+
<Transition v-bind="stepTransition">
|
|
369
|
+
<p :key="step" class="truncate text-sm text-ink/65">{{ t('ui.slideover.stepHeading', { current: step + 1, total: stepCount, name: steps[step] }) }}</p>
|
|
370
|
+
</Transition>
|
|
371
|
+
</div>
|
|
309
372
|
<!-- The step is part of the description, so it's read out with
|
|
310
373
|
the title when the panel opens. -->
|
|
311
374
|
<DialogDescription
|
|
@@ -314,7 +377,7 @@ const panel = [
|
|
|
314
377
|
class="flex flex-col gap-1 text-sm text-ink/65"
|
|
315
378
|
>
|
|
316
379
|
<p v-if="description || $slots.description"><slot name="description">{{ description }}</slot></p>
|
|
317
|
-
<p v-if="steps" class="sr-only">{{ stepText }}</p>
|
|
380
|
+
<p v-if="steps" :id="stepLabelId" class="sr-only">{{ stepText }}</p>
|
|
318
381
|
</DialogDescription>
|
|
319
382
|
<p v-if="steps" aria-live="polite" class="sr-only">{{ announcement }}</p>
|
|
320
383
|
</div>
|
|
@@ -336,7 +399,13 @@ const panel = [
|
|
|
336
399
|
:class="cn('flex-1 overflow-y-auto px-6 py-4', ui?.body)"
|
|
337
400
|
@keydown.enter="onBodyEnter"
|
|
338
401
|
>
|
|
339
|
-
|
|
402
|
+
<!-- Steps: the content slides with the step line (stepTransition). -->
|
|
403
|
+
<Transition v-if="steps" v-bind="stepTransition" @enter="onStepEnter">
|
|
404
|
+
<div :key="step">
|
|
405
|
+
<slot name="body" :close="closePanel" :step="step" />
|
|
406
|
+
</div>
|
|
407
|
+
</Transition>
|
|
408
|
+
<slot v-else name="body" :close="closePanel" :step="step" />
|
|
340
409
|
</div>
|
|
341
410
|
|
|
342
411
|
<footer
|
|
@@ -344,21 +413,28 @@ const panel = [
|
|
|
344
413
|
:class="cn('flex justify-end gap-2 border-t border-ink/10 px-6 py-4', ui?.footer)"
|
|
345
414
|
>
|
|
346
415
|
<slot name="footer" :close="closePanel">
|
|
347
|
-
<!-- Steps: Cancel or Previous on the left, Next or Finish on the
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
<
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
416
|
+
<!-- Steps: Cancel or Previous on the left, Next or Finish on the
|
|
417
|
+
right. They slide with the step (stepTransition); the row
|
|
418
|
+
keeps a button's height (min-h-9.5) while it's empty. -->
|
|
419
|
+
<div v-if="steps" class="flex min-h-9.5 flex-1">
|
|
420
|
+
<Transition v-bind="stepTransition" @enter="onFooterEnter">
|
|
421
|
+
<div :key="step" class="flex flex-1 justify-end gap-2">
|
|
422
|
+
<Button
|
|
423
|
+
data-step-button="back"
|
|
424
|
+
class="mr-auto"
|
|
425
|
+
:disabled="step > 0 && nextStatus === 'loading'"
|
|
426
|
+
@click="step === 0 ? closePanel() : goTo(step - 1)"
|
|
427
|
+
>
|
|
428
|
+
<template v-if="step > 0" #leading><ChevronLeft /></template>
|
|
429
|
+
{{ step === 0 ? t('ui.slideover.cancel') : t('ui.slideover.previous') }}
|
|
430
|
+
</Button>
|
|
431
|
+
<Button data-step-button="next" variant="primary" :status="nextStatus" @click="next">
|
|
432
|
+
{{ isLastStep ? (finishLabel ?? t('ui.slideover.finish')) : t('ui.slideover.next') }}
|
|
433
|
+
<template v-if="!isLastStep" #trailing><ChevronRight /></template>
|
|
434
|
+
</Button>
|
|
435
|
+
</div>
|
|
436
|
+
</Transition>
|
|
437
|
+
</div>
|
|
362
438
|
</slot>
|
|
363
439
|
</footer>
|
|
364
440
|
</slot>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
|
2
|
+
import ThemeSwitcher from "./ThemeSwitcher.vue";
|
|
3
|
+
|
|
4
|
+
const meta = {
|
|
5
|
+
title: "Components/Form/ThemeSwitcher",
|
|
6
|
+
component: ThemeSwitcher,
|
|
7
|
+
tags: ["autodocs"],
|
|
8
|
+
args: { hideLabel: false, disabled: false },
|
|
9
|
+
decorators: [() => ({ template: '<div class="max-w-80"><story /></div>' })],
|
|
10
|
+
} satisfies Meta<typeof ThemeSwitcher>;
|
|
11
|
+
|
|
12
|
+
export default meta;
|
|
13
|
+
type Story = StoryObj<typeof meta>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Light, Dark or Match device. The page changes as soon as one is chosen, and
|
|
17
|
+
* the choice is remembered in this browser. (Storybook's Theme toolbar sets
|
|
18
|
+
* it again when you change story.)
|
|
19
|
+
*/
|
|
20
|
+
export const Default: Story = {};
|
|
21
|
+
|
|
22
|
+
export const HiddenLabel: Story = { args: { hideLabel: true } };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, type HTMLAttributes } from 'vue'
|
|
3
|
+
import { useI18n } from 'vue-i18n'
|
|
4
|
+
import { Monitor, Moon, Sun } from '@lucide/vue'
|
|
5
|
+
import Select from '../Select/Select.vue'
|
|
6
|
+
import { useTheme, type Theme } from '../../lib/theme'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Chooses light, dark or matching the device, e.g. in the account menu
|
|
10
|
+
* (Header's `account-menu` slot) or Settings. Applies at once and is
|
|
11
|
+
* remembered in this browser. Call `initTheme()` in main.ts so the saved
|
|
12
|
+
* choice is applied before the app shows.
|
|
13
|
+
*/
|
|
14
|
+
export interface ThemeSwitcherProps {
|
|
15
|
+
/** Visible label. Default "Appearance". */
|
|
16
|
+
label?: string
|
|
17
|
+
/** Keep the label for screen readers only. */
|
|
18
|
+
hideLabel?: boolean
|
|
19
|
+
disabled?: boolean
|
|
20
|
+
class?: HTMLAttributes['class']
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const props = defineProps<ThemeSwitcherProps>()
|
|
24
|
+
const { t } = useI18n()
|
|
25
|
+
const { theme, setTheme } = useTheme()
|
|
26
|
+
|
|
27
|
+
const options = computed(() => [
|
|
28
|
+
{ label: t('ui.themeSwitcher.light'), value: 'light', icon: Sun },
|
|
29
|
+
{ label: t('ui.themeSwitcher.dark'), value: 'dark', icon: Moon },
|
|
30
|
+
{ label: t('ui.themeSwitcher.system'), value: 'system', icon: Monitor }
|
|
31
|
+
])
|
|
32
|
+
|
|
33
|
+
const model = computed({
|
|
34
|
+
get: () => theme.value,
|
|
35
|
+
set: (value) => setTheme(value as Theme)
|
|
36
|
+
})
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<template>
|
|
40
|
+
<Select
|
|
41
|
+
v-model="model"
|
|
42
|
+
:label="label ?? t('ui.themeSwitcher.label')"
|
|
43
|
+
:hide-label="hideLabel"
|
|
44
|
+
:options="options"
|
|
45
|
+
:disabled="disabled"
|
|
46
|
+
:class="props.class"
|
|
47
|
+
/>
|
|
48
|
+
</template>
|
|
@@ -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-md bg-neutral-900 dark:bg-neutral-700 px-2.5 py-1.5 text-xs/4
|
|
75
|
+
'z-100 max-w-72 rounded-md 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
|
)
|