@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,64 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref } from 'vue'
|
|
3
|
+
import { useI18n } from 'vue-i18n'
|
|
4
|
+
import { seriesColor, valueOf, type ChartPoint, type ChartSeries } from '../../lib/chart'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The parts every Keston chart shares, under the plot: the legend (for two
|
|
8
|
+
* or more series), a button to see the numbers as a table, and the table.
|
|
9
|
+
* The table is always there for screen readers; the button shows it to
|
|
10
|
+
* everyone (keyboard users can't hover for tooltips). Internal: used by
|
|
11
|
+
* BarChart and LineChart.
|
|
12
|
+
*/
|
|
13
|
+
const props = defineProps<{
|
|
14
|
+
/** The chart's name: the table's caption. */
|
|
15
|
+
label: string
|
|
16
|
+
/** Heading of the table's first column, e.g. "Date". */
|
|
17
|
+
categoryLabel: string
|
|
18
|
+
series: ChartSeries[]
|
|
19
|
+
data: ChartPoint[]
|
|
20
|
+
format: (value: number) => string
|
|
21
|
+
}>()
|
|
22
|
+
|
|
23
|
+
const { t } = useI18n()
|
|
24
|
+
const showTable = ref(false)
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<template>
|
|
28
|
+
<div class="flex flex-col gap-2">
|
|
29
|
+
<div class="flex flex-wrap items-center gap-x-4 gap-y-1">
|
|
30
|
+
<!-- The legend: hidden from screen readers, which get the table's headings. -->
|
|
31
|
+
<ul v-if="series.length > 1" class="flex flex-wrap gap-x-4 gap-y-1 text-xs text-ink/65" aria-hidden="true">
|
|
32
|
+
<li v-for="(s, i) in series" :key="s.key" class="flex items-center gap-1.5">
|
|
33
|
+
<span class="size-2.5 rounded-sm" :style="{ background: seriesColor(s, i) }" />{{ s.label }}
|
|
34
|
+
</li>
|
|
35
|
+
</ul>
|
|
36
|
+
<button
|
|
37
|
+
type="button"
|
|
38
|
+
class="ml-auto cursor-pointer rounded-sm text-xs text-ink/65 underline underline-offset-2 hover:text-ink outline-2 outline-offset-1 outline-transparent focus-visible:outline-focus"
|
|
39
|
+
:aria-expanded="showTable"
|
|
40
|
+
@click="showTable = !showTable"
|
|
41
|
+
>
|
|
42
|
+
{{ showTable ? t('ui.chart.hideTable') : t('ui.chart.showTable') }}
|
|
43
|
+
</button>
|
|
44
|
+
</div>
|
|
45
|
+
<!-- The numbers. For screen readers always; for everyone with the button. -->
|
|
46
|
+
<div :class="showTable ? 'overflow-x-auto' : 'sr-only'">
|
|
47
|
+
<table class="w-full text-left text-xs tabular-nums">
|
|
48
|
+
<caption class="sr-only">{{ props.label }}</caption>
|
|
49
|
+
<thead class="text-ink/65">
|
|
50
|
+
<tr class="border-b border-ink/10">
|
|
51
|
+
<th scope="col" class="py-1.5 pr-4 font-normal">{{ categoryLabel }}</th>
|
|
52
|
+
<th v-for="s in series" :key="s.key" scope="col" class="py-1.5 pr-4 text-right font-normal">{{ s.label }}</th>
|
|
53
|
+
</tr>
|
|
54
|
+
</thead>
|
|
55
|
+
<tbody>
|
|
56
|
+
<tr v-for="point in data" :key="point.label" class="border-b border-ink/10 last:border-b-0">
|
|
57
|
+
<th scope="row" class="py-1.5 pr-4 font-normal">{{ point.fullLabel ?? point.label }}</th>
|
|
58
|
+
<td v-for="s in series" :key="s.key" class="py-1.5 pr-4 text-right">{{ format(valueOf(point, s.key)) }}</td>
|
|
59
|
+
</tr>
|
|
60
|
+
</tbody>
|
|
61
|
+
</table>
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
</template>
|
|
@@ -237,6 +237,7 @@ const day = [
|
|
|
237
237
|
:initial-focus="initialFocus"
|
|
238
238
|
:week-starts-on="1"
|
|
239
239
|
fixed-weeks
|
|
240
|
+
:data-disabled="disabled || undefined"
|
|
240
241
|
:class="cn('w-fit text-ink', disabled && 'opacity-40', props.class)"
|
|
241
242
|
@update:model-value="setValue"
|
|
242
243
|
@update:placeholder="onPlaceholderChange"
|
|
@@ -263,7 +264,7 @@ const day = [
|
|
|
263
264
|
v-if="view === 'days'"
|
|
264
265
|
type="button"
|
|
265
266
|
:class="headingButton"
|
|
266
|
-
:aria-label="t('ui.calendar.chooseMonth')"
|
|
267
|
+
:aria-label="t('ui.calendar.chooseMonth', { month: monthLongName })"
|
|
267
268
|
:disabled="disabled"
|
|
268
269
|
@click="showMonths"
|
|
269
270
|
>
|
|
@@ -273,7 +274,7 @@ const day = [
|
|
|
273
274
|
v-if="view !== 'years'"
|
|
274
275
|
type="button"
|
|
275
276
|
:class="headingButton"
|
|
276
|
-
:aria-label="t('ui.calendar.chooseYear')"
|
|
277
|
+
:aria-label="t('ui.calendar.chooseYear', { year: placeholder.year })"
|
|
277
278
|
:disabled="disabled"
|
|
278
279
|
@click="showYears"
|
|
279
280
|
>
|
|
@@ -102,7 +102,7 @@ const card = [
|
|
|
102
102
|
</script>
|
|
103
103
|
|
|
104
104
|
<template>
|
|
105
|
-
<div :class="cn('flex flex-col gap-2 text-ink', disabled && 'opacity-40', props.class)">
|
|
105
|
+
<div :data-disabled="disabled || undefined" :class="cn('flex flex-col gap-2 text-ink', disabled && 'opacity-40', props.class)">
|
|
106
106
|
<div :class="cn('flex flex-col gap-0.5', hideLabel && 'sr-only')">
|
|
107
107
|
<div class="flex items-center gap-1">
|
|
108
108
|
<span :id="labelId" class="text-sm">{{ label }}</span>
|
|
@@ -71,7 +71,7 @@ const box = [
|
|
|
71
71
|
</script>
|
|
72
72
|
|
|
73
73
|
<template>
|
|
74
|
-
<div :class="cn('flex flex-col gap-1.5 text-ink', disabled && 'opacity-40', props.class)">
|
|
74
|
+
<div :data-disabled="disabled || undefined" :class="cn('flex flex-col gap-1.5 text-ink', disabled && 'opacity-40', props.class)">
|
|
75
75
|
<div class="flex items-start gap-2">
|
|
76
76
|
<CheckboxRoot
|
|
77
77
|
:id="controlId"
|
|
@@ -61,7 +61,7 @@ function toggle(value: CheckboxGroupValue, on: boolean) {
|
|
|
61
61
|
</script>
|
|
62
62
|
|
|
63
63
|
<template>
|
|
64
|
-
<div :class="cn('flex flex-col gap-1.5 text-ink', props.class)">
|
|
64
|
+
<div :data-disabled="disabled || undefined" :class="cn('flex flex-col gap-1.5 text-ink', props.class)">
|
|
65
65
|
<div :class="cn('flex flex-col gap-0.5', hideLabel && 'sr-only')">
|
|
66
66
|
<div class="flex items-center gap-1">
|
|
67
67
|
<span :id="labelId" class="text-sm">{{ label }}</span>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite'
|
|
2
|
+
import Collapsible from './Collapsible.vue'
|
|
3
|
+
import Input from '../Input/Input.vue'
|
|
4
|
+
import Switch from '../Switch/Switch.vue'
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'Components/Element/Collapsible',
|
|
8
|
+
component: Collapsible,
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
args: { title: 'Advanced options', defaultOpen: false, divided: false, disabled: false },
|
|
11
|
+
render: (args) => ({
|
|
12
|
+
components: { Collapsible, Input, Switch },
|
|
13
|
+
setup: () => ({ args }),
|
|
14
|
+
template: `
|
|
15
|
+
<div class="max-w-xl">
|
|
16
|
+
<Collapsible v-bind="args">
|
|
17
|
+
<Input label="Issuer name" helper="Shown in people's authenticator apps." />
|
|
18
|
+
<Switch label="Include backup codes" />
|
|
19
|
+
</Collapsible>
|
|
20
|
+
</div>`,
|
|
21
|
+
}),
|
|
22
|
+
} satisfies Meta<typeof Collapsible>
|
|
23
|
+
|
|
24
|
+
export default meta
|
|
25
|
+
type Story = StoryObj<typeof meta>
|
|
26
|
+
|
|
27
|
+
export const Default: Story = {}
|
|
28
|
+
|
|
29
|
+
export const Open: Story = { args: { defaultOpen: true } }
|
|
30
|
+
|
|
31
|
+
/** At the end of a form, with a line above it. */
|
|
32
|
+
export const Divided: Story = { args: { divided: true, title: 'Customise rules' } }
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { HTMLAttributes } from 'vue'
|
|
3
|
+
import { CollapsibleContent, CollapsibleRoot, CollapsibleTrigger } from 'reka-ui'
|
|
4
|
+
import { ChevronRight } from '@lucide/vue'
|
|
5
|
+
import { cn } from '../../lib/cn'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A section that opens and closes: "Advanced options", "Customise rules",
|
|
9
|
+
* "How does this work?". The title row is a button; the content shows under
|
|
10
|
+
* it. Closed by default; use `defaultOpen` or `v-model:open`.
|
|
11
|
+
*
|
|
12
|
+
* Built on Reka UI's Collapsible, so the button says whether it's open
|
|
13
|
+
* (aria-expanded) and points at what it opens (aria-controls).
|
|
14
|
+
*
|
|
15
|
+
* Slots: default (the content), title (replaces the title text).
|
|
16
|
+
*/
|
|
17
|
+
export interface CollapsibleProps {
|
|
18
|
+
/** The title row's text, e.g. "Advanced options". */
|
|
19
|
+
title?: string
|
|
20
|
+
/** Start open (when not using v-model:open). */
|
|
21
|
+
defaultOpen?: boolean
|
|
22
|
+
/** A line between it and what's above, e.g. at the end of a Card's fields. */
|
|
23
|
+
divided?: boolean
|
|
24
|
+
disabled?: boolean
|
|
25
|
+
class?: HTMLAttributes['class']
|
|
26
|
+
/** Extra classes for the parts. */
|
|
27
|
+
ui?: {
|
|
28
|
+
trigger?: HTMLAttributes['class']
|
|
29
|
+
content?: HTMLAttributes['class']
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const props = defineProps<CollapsibleProps>()
|
|
34
|
+
const open = defineModel<boolean | undefined>('open', { default: undefined })
|
|
35
|
+
|
|
36
|
+
defineSlots<{
|
|
37
|
+
default?(): unknown
|
|
38
|
+
title?(): unknown
|
|
39
|
+
}>()
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<template>
|
|
43
|
+
<CollapsibleRoot
|
|
44
|
+
v-model:open="open"
|
|
45
|
+
:default-open="defaultOpen"
|
|
46
|
+
:disabled="disabled"
|
|
47
|
+
:class="cn('flex flex-col', divided && 'border-t border-ink/10', props.class)"
|
|
48
|
+
>
|
|
49
|
+
<!-- The row: a chevron that turns to point down when open, then the title. -->
|
|
50
|
+
<CollapsibleTrigger
|
|
51
|
+
:class="cn(
|
|
52
|
+
'group/collapsible -mx-2 flex items-center gap-2 rounded px-2 py-3 text-left text-sm font-bold text-ink transition-colors',
|
|
53
|
+
'cursor-pointer not-disabled:hover:bg-hover not-disabled:active:bg-pressed disabled:cursor-not-allowed disabled:opacity-40',
|
|
54
|
+
'outline-2 -outline-offset-2 outline-transparent focus-visible:outline-focus',
|
|
55
|
+
ui?.trigger
|
|
56
|
+
)"
|
|
57
|
+
>
|
|
58
|
+
<ChevronRight
|
|
59
|
+
class="size-4 shrink-0 text-ink/65 transition-transform duration-150 group-data-[state=open]/collapsible:rotate-90 motion-reduce:transition-none"
|
|
60
|
+
aria-hidden="true"
|
|
61
|
+
/>
|
|
62
|
+
<slot name="title">{{ title }}</slot>
|
|
63
|
+
</CollapsibleTrigger>
|
|
64
|
+
<CollapsibleContent :class="cn('flex flex-col gap-4 pb-3', ui?.content)">
|
|
65
|
+
<slot />
|
|
66
|
+
</CollapsibleContent>
|
|
67
|
+
</CollapsibleRoot>
|
|
68
|
+
</template>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite'
|
|
2
|
+
import { ref } from 'vue'
|
|
3
|
+
import FileUpload from './FileUpload.vue'
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: 'Components/Form/FileUpload',
|
|
7
|
+
component: FileUpload,
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
args: { drop: false, multiple: false, disabled: false, accept: undefined },
|
|
10
|
+
} satisfies Meta<typeof FileUpload>
|
|
11
|
+
|
|
12
|
+
export default meta
|
|
13
|
+
type Story = StoryObj<typeof meta>
|
|
14
|
+
|
|
15
|
+
/** Just the button, e.g. "Upload a photo" beside an avatar. */
|
|
16
|
+
export const Default: Story = {}
|
|
17
|
+
|
|
18
|
+
/** With a drop area: drag files onto it, or press the button. */
|
|
19
|
+
export const Drop: Story = {
|
|
20
|
+
args: { drop: true },
|
|
21
|
+
render: (args) => ({
|
|
22
|
+
components: { FileUpload },
|
|
23
|
+
setup: () => ({ args, names: ref<string[]>([]) }),
|
|
24
|
+
template: `
|
|
25
|
+
<div class="max-w-xl">
|
|
26
|
+
<FileUpload v-bind="args" @select="names = $event.map(f => f.name)">
|
|
27
|
+
<p v-if="names.length" class="text-sm font-bold">{{ names.join(', ') }}</p>
|
|
28
|
+
</FileUpload>
|
|
29
|
+
</div>`,
|
|
30
|
+
}),
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Several files, of one type. Dropped files of other types are ignored, as in the picker. */
|
|
34
|
+
export const MultiplePdfs: Story = { args: { drop: true, multiple: true, accept: 'application/pdf,.pdf' } }
|
|
35
|
+
|
|
36
|
+
export const CustomLabel: Story = { args: { label: 'Import a CSV', accept: '.csv,text/csv' } }
|
|
37
|
+
|
|
38
|
+
export const Disabled: Story = { args: { drop: true, disabled: true } }
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, type HTMLAttributes } from 'vue'
|
|
3
|
+
import { useI18n } from 'vue-i18n'
|
|
4
|
+
import { FileUp, Upload } from '@lucide/vue'
|
|
5
|
+
import { cn } from '../../lib/cn'
|
|
6
|
+
import Button, { type ButtonProps } from '../Button/Button.vue'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Choosing files to upload: a Button that opens the device's file picker
|
|
10
|
+
* and, with `drop`, a dashed area around it that files can be dragged onto.
|
|
11
|
+
* Emits `select` with the chosen files (only ones `accept` allows; just the
|
|
12
|
+
* first unless `multiple`). It doesn't upload anything itself.
|
|
13
|
+
*
|
|
14
|
+
* The button is always there, so it works by keyboard, on touch screens and
|
|
15
|
+
* with screen readers; dropping is a shortcut for mouse users.
|
|
16
|
+
*
|
|
17
|
+
* Slots: default (in the drop area above the button, e.g. the chosen file's
|
|
18
|
+
* name; replaces the description), leading (the button's icon).
|
|
19
|
+
*/
|
|
20
|
+
export interface FileUploadProps {
|
|
21
|
+
/** The button's text. Default "Choose a file" (or "Choose files" with `multiple`). */
|
|
22
|
+
label?: string
|
|
23
|
+
/** File types to allow, as for `<input accept>`: ".csv,text/csv", "image/*". */
|
|
24
|
+
accept?: string
|
|
25
|
+
multiple?: boolean
|
|
26
|
+
/** Show a drop area around the button. */
|
|
27
|
+
drop?: boolean
|
|
28
|
+
/** Text in the drop area. Default "Drop a file here, or choose one." */
|
|
29
|
+
description?: string
|
|
30
|
+
disabled?: boolean
|
|
31
|
+
/** The button's look; default basic. */
|
|
32
|
+
variant?: ButtonProps['variant']
|
|
33
|
+
size?: ButtonProps['size']
|
|
34
|
+
/** Button status, e.g. `loading` while the chosen file uploads. */
|
|
35
|
+
status?: ButtonProps['status']
|
|
36
|
+
/** Text beside the spinner while `status` is loading, e.g. "Uploading…". */
|
|
37
|
+
loadingText?: string
|
|
38
|
+
class?: HTMLAttributes['class']
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const { t } = useI18n()
|
|
42
|
+
const props = withDefaults(defineProps<FileUploadProps>(), {
|
|
43
|
+
variant: 'basic',
|
|
44
|
+
size: 'md',
|
|
45
|
+
status: 'idle'
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const emit = defineEmits<{
|
|
49
|
+
/** Files were chosen or dropped. */
|
|
50
|
+
select: [files: File[]]
|
|
51
|
+
}>()
|
|
52
|
+
|
|
53
|
+
defineSlots<{
|
|
54
|
+
default?(): unknown
|
|
55
|
+
leading?(): unknown
|
|
56
|
+
}>()
|
|
57
|
+
|
|
58
|
+
const input = ref<HTMLInputElement>()
|
|
59
|
+
|
|
60
|
+
const buttonLabel = computed(() => props.label ?? (props.multiple ? t('ui.fileUpload.chooseFiles') : t('ui.fileUpload.chooseFile')))
|
|
61
|
+
const dropText = computed(() => props.description ?? (props.multiple ? t('ui.fileUpload.dropFiles') : t('ui.fileUpload.dropFile')))
|
|
62
|
+
|
|
63
|
+
// The same check the file picker does, for dropped files: an extension
|
|
64
|
+
// (".csv"), an exact type ("text/csv") or a family ("image/*").
|
|
65
|
+
function allowed(file: File) {
|
|
66
|
+
if (!props.accept) return true
|
|
67
|
+
const name = file.name.toLowerCase()
|
|
68
|
+
const type = file.type.toLowerCase()
|
|
69
|
+
return props.accept.split(',').some((raw) => {
|
|
70
|
+
const rule = raw.trim().toLowerCase()
|
|
71
|
+
if (!rule) return false
|
|
72
|
+
if (rule.startsWith('.')) return name.endsWith(rule)
|
|
73
|
+
if (rule.endsWith('/*')) return type.startsWith(rule.slice(0, -1))
|
|
74
|
+
return type === rule
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function choose(list: FileList | null | undefined) {
|
|
79
|
+
const files = Array.from(list ?? []).filter(allowed)
|
|
80
|
+
if (!files.length) return
|
|
81
|
+
emit('select', props.multiple ? files : files.slice(0, 1))
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function open() {
|
|
85
|
+
if (!props.disabled) input.value?.click()
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function onPick(event: Event) {
|
|
89
|
+
const target = event.target as HTMLInputElement
|
|
90
|
+
choose(target.files)
|
|
91
|
+
// Clear it, so choosing the same file again still counts.
|
|
92
|
+
target.value = ''
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Dragging over the area. A counter, not a flag: dragenter / dragleave fire
|
|
96
|
+
// for every child the pointer crosses.
|
|
97
|
+
const over = ref(0)
|
|
98
|
+
const dragging = computed(() => over.value > 0)
|
|
99
|
+
|
|
100
|
+
function onDragEnter() {
|
|
101
|
+
if (!props.disabled) over.value++
|
|
102
|
+
}
|
|
103
|
+
function onDragLeave() {
|
|
104
|
+
over.value = Math.max(0, over.value - 1)
|
|
105
|
+
}
|
|
106
|
+
function onDrop(event: DragEvent) {
|
|
107
|
+
over.value = 0
|
|
108
|
+
if (!props.disabled) choose(event.dataTransfer?.files)
|
|
109
|
+
}
|
|
110
|
+
</script>
|
|
111
|
+
|
|
112
|
+
<template>
|
|
113
|
+
<!-- One root: the drop area, or just a wrapper round the button. The real
|
|
114
|
+
file input sits inside it, hidden: the Button opens it. -->
|
|
115
|
+
<div
|
|
116
|
+
:data-disabled="disabled || undefined"
|
|
117
|
+
:class="cn(
|
|
118
|
+
drop
|
|
119
|
+
? ['flex flex-col items-center gap-3 rounded-lg border-2 border-dashed p-8 text-center transition-colors', dragging ? 'border-primary bg-primary/5' : 'border-ink/25', disabled && 'opacity-40']
|
|
120
|
+
: 'inline-flex',
|
|
121
|
+
props.class
|
|
122
|
+
)"
|
|
123
|
+
@dragenter.prevent="drop && onDragEnter()"
|
|
124
|
+
@dragover.prevent
|
|
125
|
+
@dragleave="drop && onDragLeave()"
|
|
126
|
+
@drop.prevent="drop && onDrop($event)"
|
|
127
|
+
>
|
|
128
|
+
<template v-if="drop">
|
|
129
|
+
<FileUp class="size-8 text-primary-fg" aria-hidden="true" />
|
|
130
|
+
<slot>
|
|
131
|
+
<p class="text-sm text-ink/65">{{ dropText }}</p>
|
|
132
|
+
</slot>
|
|
133
|
+
</template>
|
|
134
|
+
<Button :variant="variant" :size="size" :status="status" :loading-text="loadingText" :disabled="disabled" @click="open">
|
|
135
|
+
<template #leading><slot name="leading"><Upload /></slot></template>
|
|
136
|
+
{{ buttonLabel }}
|
|
137
|
+
</Button>
|
|
138
|
+
<input
|
|
139
|
+
ref="input"
|
|
140
|
+
type="file"
|
|
141
|
+
class="sr-only"
|
|
142
|
+
tabindex="-1"
|
|
143
|
+
aria-hidden="true"
|
|
144
|
+
:accept="accept"
|
|
145
|
+
:multiple="multiple"
|
|
146
|
+
:disabled="disabled"
|
|
147
|
+
@change="onPick"
|
|
148
|
+
/>
|
|
149
|
+
</div>
|
|
150
|
+
</template>
|
|
@@ -57,18 +57,26 @@ export const CustomLinks: Story = {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
/** No app name, version or build (e.g. a public page): just the links and the copyright. */
|
|
60
|
+
/**
|
|
61
|
+
* Without the Appearance dropdown (`themeSwitcher: false`). The Language
|
|
62
|
+
* dropdown shows by itself once the app has more than one language.
|
|
63
|
+
*/
|
|
64
|
+
export const NoSwitchers: Story = {
|
|
65
|
+
args: { themeSwitcher: false, languageSwitcher: false },
|
|
66
|
+
}
|
|
67
|
+
|
|
60
68
|
export const NoVersion: Story = {
|
|
61
69
|
args: { appName: undefined, version: undefined, build: undefined },
|
|
62
70
|
}
|
|
63
71
|
|
|
64
|
-
/** The slot `end`, after the copyright
|
|
72
|
+
/** The slot `end`, after the copyright, e.g. a link to the status page. */
|
|
65
73
|
export const WithEndSlot: Story = {
|
|
66
74
|
render: (args) => ({
|
|
67
75
|
components: { Footer },
|
|
68
76
|
setup: () => ({ args }),
|
|
69
77
|
template: `
|
|
70
78
|
<Footer v-bind="args">
|
|
71
|
-
<template #end><
|
|
79
|
+
<template #end><a href="https://example.com/status" class="underline underline-offset-2">Status</a></template>
|
|
72
80
|
</Footer>`,
|
|
73
81
|
}),
|
|
74
82
|
}
|
|
@@ -3,6 +3,8 @@ import { useI18n } from 'vue-i18n'
|
|
|
3
3
|
import { computed, type Component, type HTMLAttributes } from 'vue'
|
|
4
4
|
import { cn } from '../../lib/cn'
|
|
5
5
|
import Link from '../Link/Link.vue'
|
|
6
|
+
import LanguageSwitcher from '../LanguageSwitcher/LanguageSwitcher.vue'
|
|
7
|
+
import ThemeSwitcher from '../ThemeSwitcher/ThemeSwitcher.vue'
|
|
6
8
|
import { bareVersion, displayVersion, yearRange } from './footer'
|
|
7
9
|
import { kestonFooterLinks } from './links'
|
|
8
10
|
|
|
@@ -26,7 +28,11 @@ export interface FooterLink {
|
|
|
26
28
|
* apps), which follow, after a divider. The version comes from the app's package.json and the build
|
|
27
29
|
* from its CI: in Vite, put them in with `define` (see the spec).
|
|
28
30
|
*
|
|
29
|
-
*
|
|
31
|
+
* On the right too: a Language dropdown (when the app has more than one
|
|
32
|
+
* language) and an Appearance dropdown (Light / Dark / Match device). Turn
|
|
33
|
+
* either off with `languageSwitcher` / `themeSwitcher`.
|
|
34
|
+
*
|
|
35
|
+
* Slots: nav (instead of the whole link list), end (after the copyright).
|
|
30
36
|
*/
|
|
31
37
|
export interface FooterProps {
|
|
32
38
|
/** The links on the left. Default: `kestonFooterLinks` (Help & support, Privacy Policy, Terms & Conditions). */
|
|
@@ -47,6 +53,10 @@ export interface FooterProps {
|
|
|
47
53
|
year?: number
|
|
48
54
|
/** The first year, to show a range such as 2024–2026. */
|
|
49
55
|
since?: number
|
|
56
|
+
/** Show the Language dropdown. Default true; it only shows when the app has more than one language. */
|
|
57
|
+
languageSwitcher?: boolean
|
|
58
|
+
/** Show the Appearance dropdown (Light / Dark / Match device). Default true. */
|
|
59
|
+
themeSwitcher?: boolean
|
|
50
60
|
class?: HTMLAttributes['class']
|
|
51
61
|
/** Extra classes for the parts. */
|
|
52
62
|
ui?: {
|
|
@@ -55,12 +65,15 @@ export interface FooterProps {
|
|
|
55
65
|
}
|
|
56
66
|
}
|
|
57
67
|
|
|
58
|
-
const { t } = useI18n()
|
|
68
|
+
const { t, availableLocales } = useI18n()
|
|
69
|
+
const showLanguages = computed(() => props.languageSwitcher && availableLocales.length > 1)
|
|
59
70
|
const props = withDefaults(defineProps<FooterProps>(), {
|
|
60
71
|
links: () => kestonFooterLinks,
|
|
61
72
|
moreLinks: () => [],
|
|
62
73
|
linkComponent: undefined,
|
|
63
|
-
holder: 'The Keston Group'
|
|
74
|
+
holder: 'The Keston Group',
|
|
75
|
+
languageSwitcher: true,
|
|
76
|
+
themeSwitcher: true
|
|
64
77
|
})
|
|
65
78
|
|
|
66
79
|
defineSlots<{
|
|
@@ -102,7 +115,12 @@ function linkAttrs(link: FooterLink) {
|
|
|
102
115
|
</slot>
|
|
103
116
|
</nav>
|
|
104
117
|
|
|
105
|
-
<div :class="cn('flex flex-wrap items-center gap-x-3 gap-y-
|
|
118
|
+
<div :class="cn('flex flex-wrap items-center gap-x-3 gap-y-2 sm:justify-end', ui?.meta)">
|
|
119
|
+
<!-- Language and appearance: compact dropdowns, labelled for screen readers. -->
|
|
120
|
+
<div v-if="showLanguages || themeSwitcher" class="flex flex-wrap items-center gap-2">
|
|
121
|
+
<LanguageSwitcher v-if="showLanguages" hide-label class="w-44" />
|
|
122
|
+
<ThemeSwitcher v-if="themeSwitcher" hide-label class="w-44" />
|
|
123
|
+
</div>
|
|
106
124
|
<p v-if="appName || version || build" class="flex flex-wrap items-baseline gap-x-1.5">
|
|
107
125
|
<span v-if="appName" class="font-bold text-ink/80">{{ appName }}</span>
|
|
108
126
|
<!-- Shows as "v1.4.2" but reads as "Version 1.4.2". -->
|
|
@@ -3,6 +3,7 @@ import { Bell, Building2, ChevronRight } from "@lucide/vue";
|
|
|
3
3
|
import { ref } from "vue";
|
|
4
4
|
import Button from "../Button/Button.vue";
|
|
5
5
|
import Header, { type HeaderUser } from "./Header.vue";
|
|
6
|
+
import ThemeSwitcher from "../ThemeSwitcher/ThemeSwitcher.vue";
|
|
6
7
|
|
|
7
8
|
const user: HeaderUser = {
|
|
8
9
|
name: "Ben Smith",
|
|
@@ -94,6 +95,25 @@ export const CustomUserMenu: Story = {
|
|
|
94
95
|
}),
|
|
95
96
|
};
|
|
96
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Light / Dark / Match device in the account menu: ThemeSwitcher in the
|
|
100
|
+
* account-menu slot, in a row with the menu's divider and padding.
|
|
101
|
+
*/
|
|
102
|
+
export const WithThemeSwitcher: Story = {
|
|
103
|
+
render: (args) => ({
|
|
104
|
+
components: { Header, ThemeSwitcher },
|
|
105
|
+
setup: () => ({ args }),
|
|
106
|
+
template: `
|
|
107
|
+
<Header v-bind="args">
|
|
108
|
+
<template #account-menu>
|
|
109
|
+
<div class="border-t border-ink/10 px-4 py-3">
|
|
110
|
+
<ThemeSwitcher />
|
|
111
|
+
</div>
|
|
112
|
+
</template>
|
|
113
|
+
</Header>`,
|
|
114
|
+
}),
|
|
115
|
+
};
|
|
116
|
+
|
|
97
117
|
/**
|
|
98
118
|
* The organisation slot replaces the organisation heading at the top of the
|
|
99
119
|
* account menu, e.g. with a row that switches organisation. A divider sits
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite'
|
|
2
|
+
import LineChart from './LineChart.vue'
|
|
3
|
+
import Card from '../Card/Card.vue'
|
|
4
|
+
|
|
5
|
+
const weeks = Array.from({ length: 12 }, (_, i) => ({
|
|
6
|
+
label: `W${i + 1}`,
|
|
7
|
+
fullLabel: `Week ${i + 1}`,
|
|
8
|
+
values: {
|
|
9
|
+
thisYear: [12, 18, 25, 31, 44, 52, 61, 58, 70, 83, 91, 104][i],
|
|
10
|
+
lastYear: [10, 14, 20, 29, 35, 41, 50, 55, 60, 66, 73, 80][i],
|
|
11
|
+
},
|
|
12
|
+
}))
|
|
13
|
+
|
|
14
|
+
const meta = {
|
|
15
|
+
title: 'Components/Data/LineChart',
|
|
16
|
+
component: LineChart,
|
|
17
|
+
tags: ['autodocs'],
|
|
18
|
+
args: {
|
|
19
|
+
label: 'Applications per week',
|
|
20
|
+
categoryLabel: 'Week',
|
|
21
|
+
data: weeks,
|
|
22
|
+
series: [
|
|
23
|
+
{ key: 'thisYear', label: 'This year' },
|
|
24
|
+
{ key: 'lastYear', label: 'Last year' },
|
|
25
|
+
],
|
|
26
|
+
area: false,
|
|
27
|
+
},
|
|
28
|
+
render: (args) => ({
|
|
29
|
+
components: { LineChart, Card },
|
|
30
|
+
setup: () => ({ args }),
|
|
31
|
+
template: `
|
|
32
|
+
<Card title="Applications per week" description="This admissions round against last year's." class="max-w-2xl">
|
|
33
|
+
<LineChart v-bind="args" />
|
|
34
|
+
</Card>`,
|
|
35
|
+
}),
|
|
36
|
+
} satisfies Meta<typeof LineChart>
|
|
37
|
+
|
|
38
|
+
export default meta
|
|
39
|
+
type Story = StoryObj<typeof meta>
|
|
40
|
+
|
|
41
|
+
/** Two lines to compare. Hover for the values at a week; "Show as table" for all of them. */
|
|
42
|
+
export const Default: Story = {}
|
|
43
|
+
|
|
44
|
+
/** One line with a light wash under it. */
|
|
45
|
+
export const OneSeriesWithArea: Story = {
|
|
46
|
+
args: { series: [{ key: 'thisYear', label: 'Applications' }], area: true },
|
|
47
|
+
}
|