@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.
Files changed (78) hide show
  1. package/dist/components/ActionList/ActionList.vue.d.ts +74 -0
  2. package/dist/components/Alert/Alert.vue.d.ts +55 -0
  3. package/dist/components/AsyncState/AsyncState.vue.d.ts +53 -0
  4. package/dist/components/AvatarGroup/AvatarGroup.vue.d.ts +1 -1
  5. package/dist/components/BarChart/BarChart.vue.d.ts +37 -0
  6. package/dist/components/BarChart/ChartData.vue.d.ts +20 -0
  7. package/dist/components/Button/Button.vue.d.ts +1 -1
  8. package/dist/components/Collapsible/Collapsible.vue.d.ts +48 -0
  9. package/dist/components/ConfirmDialog/ConfirmDialog.vue.d.ts +62 -0
  10. package/dist/components/FileUpload/FileUpload.vue.d.ts +55 -0
  11. package/dist/components/Footer/Footer.vue.d.ts +11 -1
  12. package/dist/components/Header/Header.vue.d.ts +1 -1
  13. package/dist/components/InputRichText/InputRichText.vue.d.ts +12 -6
  14. package/dist/components/LineChart/LineChart.vue.d.ts +37 -0
  15. package/dist/components/Notification/Notification.vue.d.ts +2 -2
  16. package/dist/components/Progress/Progress.vue.d.ts +14 -1
  17. package/dist/components/Prose/Prose.vue.d.ts +36 -0
  18. package/dist/components/ResultState/ResultState.vue.d.ts +48 -0
  19. package/dist/components/Slideover/Slideover.vue.d.ts +7 -5
  20. package/dist/components/Spinner/Spinner.vue.d.ts +1 -1
  21. package/dist/components/Steps/Steps.vue.d.ts +16 -5
  22. package/dist/components/ThemeSwitcher/ThemeSwitcher.vue.d.ts +18 -0
  23. package/dist/i18n/en.d.ts +43 -0
  24. package/dist/index.d.ts +25 -0
  25. package/dist/keston-ui.js +5287 -4028
  26. package/dist/lib/chart.d.ts +32 -0
  27. package/dist/lib/initials.d.ts +6 -1
  28. package/dist/lib/theme.d.ts +23 -0
  29. package/package.json +10 -3
  30. package/src/components/ActionList/ActionList.stories.ts +92 -0
  31. package/src/components/ActionList/ActionList.vue +138 -0
  32. package/src/components/Alert/Alert.stories.ts +65 -0
  33. package/src/components/Alert/Alert.vue +110 -0
  34. package/src/components/AsyncState/AsyncState.stories.ts +46 -0
  35. package/src/components/AsyncState/AsyncState.vue +78 -0
  36. package/src/components/BarChart/BarChart.stories.ts +62 -0
  37. package/src/components/BarChart/BarChart.vue +153 -0
  38. package/src/components/BarChart/ChartData.vue +64 -0
  39. package/src/components/Button/Button.vue +4 -4
  40. package/src/components/Calendar/Calendar.vue +3 -2
  41. package/src/components/CardSelect/CardSelect.vue +1 -1
  42. package/src/components/Checkbox/Checkbox.vue +1 -1
  43. package/src/components/CheckboxGroup/CheckboxGroup.vue +1 -1
  44. package/src/components/Collapsible/Collapsible.stories.ts +32 -0
  45. package/src/components/Collapsible/Collapsible.vue +68 -0
  46. package/src/components/ConfirmDialog/ConfirmDialog.stories.ts +54 -0
  47. package/src/components/ConfirmDialog/ConfirmDialog.vue +119 -0
  48. package/src/components/FileUpload/FileUpload.stories.ts +38 -0
  49. package/src/components/FileUpload/FileUpload.vue +150 -0
  50. package/src/components/Footer/Footer.stories.ts +10 -2
  51. package/src/components/Footer/Footer.vue +22 -4
  52. package/src/components/Header/Header.stories.ts +20 -0
  53. package/src/components/InputRichText/InputRichText.stories.ts +19 -0
  54. package/src/components/InputRichText/InputRichText.vue +129 -13
  55. package/src/components/LineChart/LineChart.stories.ts +47 -0
  56. package/src/components/LineChart/LineChart.vue +173 -0
  57. package/src/components/Notification/Toaster.vue +3 -1
  58. package/src/components/Progress/Progress.stories.ts +18 -0
  59. package/src/components/Progress/Progress.vue +57 -0
  60. package/src/components/Prose/Prose.stories.ts +46 -0
  61. package/src/components/Prose/Prose.vue +54 -0
  62. package/src/components/RadioGroup/RadioGroup.vue +2 -2
  63. package/src/components/ResultState/ResultState.stories.ts +44 -0
  64. package/src/components/ResultState/ResultState.vue +76 -0
  65. package/src/components/Select/Select.vue +6 -4
  66. package/src/components/Slideover/Slideover.vue +107 -31
  67. package/src/components/Steps/Steps.stories.ts +18 -0
  68. package/src/components/Steps/Steps.vue +28 -8
  69. package/src/components/ThemeSwitcher/ThemeSwitcher.stories.ts +22 -0
  70. package/src/components/ThemeSwitcher/ThemeSwitcher.vue +48 -0
  71. package/src/components/Tooltip/Tooltip.vue +1 -1
  72. package/src/i18n/en.ts +29 -7
  73. package/src/index.ts +25 -0
  74. package/src/lib/chart.ts +47 -0
  75. package/src/lib/initials.test.ts +19 -0
  76. package/src/lib/initials.ts +12 -3
  77. package/src/lib/theme.ts +75 -0
  78. package/src/styles/theme.css +34 -2
@@ -1,6 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import { useI18n } from 'vue-i18n'
3
- import { computed, nextTick, ref, useId, watch, type HTMLAttributes } from 'vue'
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 and "Step 2 of 4: Contact details"; the footer gets
34
- * Cancel / Previous and Next / Finish, unless you fill the footer slot.
35
- * Enter in a text field presses Next / Finish.
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
- // stays where it is.
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
- // Start the new step from the top.
161
- body.value?.scrollTo({ top: 0 })
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
- <!-- The step sits above its progress bar. -->
299
- <p v-if="steps" :id="stepLabelId" class="text-sm text-ink/65">
300
- Step {{ step + 1 }} of {{ stepCount }}: <span class="text-ink">{{ steps[step] }}</span>
301
- </p>
302
- <Progress v-if="steps" :label="title ?? t('ui.slideover.steps')" segments :value="step + 1" :max="stepCount" />
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
- <slot name="body" :close="closePanel" :step="step" />
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 right. -->
348
- <!-- One button that turns from Previous into Cancel on the first
349
- step, so keyboard focus stays on it. -->
350
- <Button
351
- class="mr-auto"
352
- :disabled="step > 0 && nextStatus === 'loading'"
353
- @click="step === 0 ? closePanel() : goTo(step - 1)"
354
- >
355
- <template v-if="step > 0" #leading><ChevronLeft /></template>
356
- {{ step === 0 ? t('ui.slideover.cancel') : t('ui.slideover.previous') }}
357
- </Button>
358
- <Button variant="primary" :status="nextStatus" @click="next">
359
- {{ isLastStep ? (finishLabel ?? t('ui.slideover.finish')) : t('ui.slideover.next') }}
360
- <template v-if="!isLastStep" #trailing><ChevronRight /></template>
361
- </Button>
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>
@@ -36,3 +36,21 @@ export const WithButtons: Story = {
36
36
  </div>`,
37
37
  }),
38
38
  };
39
+
40
+ /**
41
+ * With `v-model:step`, finished segments go back to their step ("Back to
42
+ * step 1: User info"). Steps ahead can't be picked.
43
+ */
44
+ export const GoBack: Story = {
45
+ render: (args) => ({
46
+ components: { Steps, Button },
47
+ setup: () => ({ args, step: ref(2) }),
48
+ template: `
49
+ <div class="flex flex-col gap-4">
50
+ <Steps v-bind="args" v-model:step="step" />
51
+ <div class="flex gap-2">
52
+ <Button size="sm" :disabled="step === args.steps.length - 1" @click="step++">Next</Button>
53
+ </div>
54
+ </div>`,
55
+ }),
56
+ };
@@ -1,15 +1,20 @@
1
1
  <script setup lang="ts">
2
- import type { HTMLAttributes } from 'vue'
2
+ import { computed, getCurrentInstance, type HTMLAttributes } from 'vue'
3
3
  import { I18nT } from 'vue-i18n'
4
4
  import { cn } from '../../lib/cn'
5
5
  import Progress from '../Progress/Progress.vue'
6
6
 
7
7
  /**
8
8
  * Where someone is in a set of steps: a segment for each step, filled up to
9
- * the current one, and "Step 2 of 3: Licences" above it. Put it at the top of
10
- * a multi-step form. (Slideover's `steps` shows one for you; use this when
11
- * the steps are on a page, or in a Slideover you drive yourself.) The words
12
- * are announced when the step changes.
9
+ * the current one, and "Step 2 of 3 – Licences" under it, as in Slideover's
10
+ * multi-step form. Put it at the top of a multi-step form on a page, or in a
11
+ * Slideover you drive yourself. The words are announced when the step
12
+ * changes.
13
+ *
14
+ * With `v-model:step`, finished segments are buttons ("Back to step 1: User
15
+ * info") that go back to that step; steps ahead can't be picked, so each
16
+ * step's checks still run in order. With just `:step`, it only shows where
17
+ * you are.
13
18
  */
14
19
  export interface StepsProps {
15
20
  /** The name of each step, in order, e.g. `['User info', 'Licences']`. */
@@ -18,21 +23,36 @@ export interface StepsProps {
18
23
  step: number
19
24
  /** What the steps are for, e.g. "Add a user". The progress bar's accessible name; not shown. */
20
25
  label: string
26
+ /** Stops going back, e.g. while a step saves. */
27
+ disabled?: boolean
21
28
  class?: HTMLAttributes['class']
22
29
  }
23
30
 
24
31
  const props = defineProps<StepsProps>()
32
+ const emit = defineEmits<{ 'update:step': [step: number] }>()
33
+
34
+ // Going back is offered only when someone is listening (v-model:step).
35
+ const instance = getCurrentInstance()
36
+ const canGoBack = computed(() => !!instance?.vnode.props?.['onUpdate:step'])
25
37
  </script>
26
38
 
27
39
  <template>
28
- <div :class="cn('flex flex-col gap-3', props.class)">
40
+ <div :class="cn('flex flex-col gap-2', props.class)">
41
+ <Progress
42
+ :label="label"
43
+ segments
44
+ :value="step + 1"
45
+ :max="steps.length"
46
+ :segment-labels="canGoBack ? steps : undefined"
47
+ :disabled="disabled"
48
+ @select="emit('update:step', $event)"
49
+ />
29
50
  <p class="text-sm text-ink/65" aria-live="polite">
30
- <I18nT keypath="ui.steps.stepOfNamed" scope="global" tag="span">
51
+ <I18nT keypath="ui.steps.stepOfDash" scope="global" tag="span">
31
52
  <template #current>{{ step + 1 }}</template>
32
53
  <template #total>{{ steps.length }}</template>
33
54
  <template #name><span class="text-ink">{{ steps[step] }}</span></template>
34
55
  </I18nT>
35
56
  </p>
36
- <Progress :label="label" segments :value="step + 1" :max="steps.length" />
37
57
  </div>
38
58
  </template>
@@ -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 font-medium text-white shadow-lg ring-1 ring-white/10',
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
  )
package/src/i18n/en.ts CHANGED
@@ -37,10 +37,12 @@ export const en = {
37
37
  nextYear: 'Next year',
38
38
  previousYears: 'Previous years',
39
39
  nextYears: 'Next years',
40
- chooseMonth: 'Choose month',
41
- chooseYear: 'Choose year'
40
+ // Start with what the button shows, so voice control ("click June") finds it.
41
+ chooseMonth: '{month}, choose month',
42
+ chooseYear: '{year}, choose year'
42
43
  },
43
44
  changeIndicator: { changed: 'Changed from {from} to {to}' },
45
+ chart: { category: 'Category', showTable: 'Show as table', hideTable: 'Hide table' },
44
46
  chip: { remove: 'Remove' },
45
47
  appLauncher: { label: 'Keston apps' },
46
48
  footer: {
@@ -73,9 +75,25 @@ export const en = {
73
75
  formattingFor: 'Formatting for {label}',
74
76
  bold: 'Bold',
75
77
  italic: 'Italic',
76
- underline: 'Underline'
77
- },
78
+ underline: 'Underline',
79
+ link: 'Link',
80
+ linkAddress: 'Link address',
81
+ addLink: 'Add link',
82
+ updateLink: 'Update link',
83
+ removeLink: 'Remove link',
84
+ linkInvalid: 'Enter an address starting with https://, mailto: or tel:'
85
+ },
86
+ alert: { info: 'Information', success: 'Success', warning: 'Warning', error: 'Error', dismiss: 'Dismiss' },
87
+ fileUpload: {
88
+ chooseFile: 'Choose a file',
89
+ chooseFiles: 'Choose files',
90
+ dropFile: 'Drop a file here, or choose one.',
91
+ dropFiles: 'Drop files here, or choose them.'
92
+ },
93
+ confirmDialog: { confirm: 'Confirm', cancel: 'Cancel' },
94
+ asyncState: { error: "Couldn't load this", retry: 'Try again' },
78
95
  languageSwitcher: { label: 'Language' },
96
+ themeSwitcher: { label: 'Appearance', light: 'Light', dark: 'Dark', system: 'Match device' },
79
97
  notifications: {
80
98
  title: 'Notifications',
81
99
  region: 'Notification',
@@ -92,7 +110,7 @@ export const en = {
92
110
  actions: '{title} actions',
93
111
  moreActions: 'More actions'
94
112
  },
95
- progress: { stepOf: 'Step {current} of {total}' },
113
+ progress: { stepOf: 'Step {current} of {total}', backTo: 'Back to step {current}: {name}' },
96
114
  select: {
97
115
  choose: 'Choose…',
98
116
  search: 'Search…',
@@ -113,13 +131,17 @@ export const en = {
113
131
  next: 'Next',
114
132
  finish: 'Finish',
115
133
  steps: 'Steps',
116
- stepOf: 'Step {current} of {total}: {name}'
134
+ stepOf: 'Step {current} of {total}: {name}',
135
+ /** Shown under the title, e.g. "Step 1 of 3 – Name". */
136
+ stepHeading: 'Step {current} of {total} – {name}'
117
137
  },
118
138
  spinner: { loading: 'Loading' },
119
139
  statTile: { up: 'Up', down: 'Down', flat: 'No change' },
120
140
  steps: {
121
141
  stepOf: 'Step {current} of {total}',
122
- stepOfNamed: 'Step {current} of {total}: {name}'
142
+ stepOfNamed: 'Step {current} of {total}: {name}',
143
+ /** Under the segments, e.g. "Step 2 of 3 – Licences", as in Slideover. */
144
+ stepOfDash: 'Step {current} of {total} – {name}'
123
145
  },
124
146
  summaryList: { notSet: 'Not set' },
125
147
  table: {
package/src/index.ts CHANGED
@@ -4,6 +4,9 @@
4
4
  // at the end of its group.
5
5
 
6
6
  export { cn } from './lib/cn'
7
+ export { initTheme, useTheme } from './lib/theme'
8
+ export type { ChartPoint, ChartSeries } from './lib/chart'
9
+ export type { Theme } from './lib/theme'
7
10
 
8
11
  // Layout
9
12
  export { default as AppShell } from './components/AppShell/AppShell.vue'
@@ -42,6 +45,12 @@ export { default as Progress } from './components/Progress/Progress.vue'
42
45
  export type { ProgressProps } from './components/Progress/Progress.vue'
43
46
  export { default as ChangeIndicator } from './components/ChangeIndicator/ChangeIndicator.vue'
44
47
  export type { ChangeIndicatorProps } from './components/ChangeIndicator/ChangeIndicator.vue'
48
+ export { default as Alert } from './components/Alert/Alert.vue'
49
+ export type { AlertProps } from './components/Alert/Alert.vue'
50
+ export { default as Collapsible } from './components/Collapsible/Collapsible.vue'
51
+ export type { CollapsibleProps } from './components/Collapsible/Collapsible.vue'
52
+ export { default as Prose } from './components/Prose/Prose.vue'
53
+ export type { ProseProps } from './components/Prose/Prose.vue'
45
54
 
46
55
  // Form
47
56
  export { default as FormField } from './components/FormField/FormField.vue'
@@ -74,8 +83,12 @@ export { default as CheckboxGroup } from './components/CheckboxGroup/CheckboxGro
74
83
  export type { CheckboxGroupProps, CheckboxOption, CheckboxGroupValue } from './components/CheckboxGroup/CheckboxGroup.vue'
75
84
  export { default as LanguageSwitcher } from './components/LanguageSwitcher/LanguageSwitcher.vue'
76
85
  export type { LanguageSwitcherProps } from './components/LanguageSwitcher/LanguageSwitcher.vue'
86
+ export { default as ThemeSwitcher } from './components/ThemeSwitcher/ThemeSwitcher.vue'
87
+ export type { ThemeSwitcherProps } from './components/ThemeSwitcher/ThemeSwitcher.vue'
77
88
  export { default as CardSelect } from './components/CardSelect/CardSelect.vue'
78
89
  export type { CardSelectProps } from './components/CardSelect/CardSelect.vue'
90
+ export { default as FileUpload } from './components/FileUpload/FileUpload.vue'
91
+ export type { FileUploadProps } from './components/FileUpload/FileUpload.vue'
79
92
 
80
93
  // Data
81
94
  export { default as Table } from './components/Table/Table.vue'
@@ -94,6 +107,14 @@ export { default as Age } from './components/Age/Age.vue'
94
107
  export type { AgeProps } from './components/Age/Age.vue'
95
108
  export { default as EmptyState } from './components/EmptyState/EmptyState.vue'
96
109
  export type { EmptyStateProps } from './components/EmptyState/EmptyState.vue'
110
+ export { default as BarChart } from './components/BarChart/BarChart.vue'
111
+ export type { BarChartProps } from './components/BarChart/BarChart.vue'
112
+ export { default as LineChart } from './components/LineChart/LineChart.vue'
113
+ export type { LineChartProps } from './components/LineChart/LineChart.vue'
114
+ export { default as AsyncState } from './components/AsyncState/AsyncState.vue'
115
+ export type { AsyncStateProps } from './components/AsyncState/AsyncState.vue'
116
+ export { default as ResultState } from './components/ResultState/ResultState.vue'
117
+ export type { ResultStateProps } from './components/ResultState/ResultState.vue'
97
118
 
98
119
  // Navigation
99
120
  export { default as Breadcrumb } from './components/Breadcrumb/Breadcrumb.vue'
@@ -105,6 +126,8 @@ export { default as Link } from './components/Link/Link.vue'
105
126
  export type { LinkProps } from './components/Link/Link.vue'
106
127
  export { default as Steps } from './components/Steps/Steps.vue'
107
128
  export type { StepsProps } from './components/Steps/Steps.vue'
129
+ export { default as ActionList } from './components/ActionList/ActionList.vue'
130
+ export type { ActionListItem, ActionListProps } from './components/ActionList/ActionList.vue'
108
131
 
109
132
  // Overlay
110
133
  export { default as Popover } from './components/Popover/Popover.vue'
@@ -136,6 +159,8 @@ export type {
136
159
  } from './components/Notification/notifications'
137
160
  export { default as UnsavedChangesBar } from './components/UnsavedChangesBar/UnsavedChangesBar.vue'
138
161
  export type { UnsavedChangesBarProps } from './components/UnsavedChangesBar/UnsavedChangesBar.vue'
162
+ export { default as ConfirmDialog } from './components/ConfirmDialog/ConfirmDialog.vue'
163
+ export type { ConfirmDialogProps } from './components/ConfirmDialog/ConfirmDialog.vue'
139
164
 
140
165
  // Languages
141
166
  export { createKestonI18n, uiMessages, en } from './i18n'
@@ -0,0 +1,47 @@
1
+ /** One series in a chart: a name for the legend and table, and its colour slot. */
2
+ export interface ChartSeries {
3
+ /** The key of this series' number in each point's `values`. */
4
+ key: string
5
+ /** Its name in the legend, the tooltip and the table, e.g. "Failed". */
6
+ label: string
7
+ /**
8
+ * Which of the eight chart colours (1–8). Default: the series' place in
9
+ * the list. Set it so a series keeps its colour when others are filtered
10
+ * out, e.g. failed sign-ins always red (8).
11
+ */
12
+ color?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8
13
+ }
14
+
15
+ /** One point along the chart: a day, a month, a school. */
16
+ export interface ChartPoint {
17
+ /** Short label under the bar or along the axis, e.g. "Mon". */
18
+ label: string
19
+ /** Full label for the tooltip and table, e.g. "Monday 24 November". Default `label`. */
20
+ fullLabel?: string
21
+ /** A number for each series, by its key. Missing counts as 0. */
22
+ values: Record<string, number | null | undefined>
23
+ }
24
+
25
+ export function seriesColor(series: ChartSeries, index: number): string {
26
+ const slot = series.color ?? Math.min(index + 1, 8)
27
+ return `var(--color-chart-${slot})`
28
+ }
29
+
30
+ export const valueOf = (point: ChartPoint, key: string) => point.values[key] ?? 0
31
+
32
+ /**
33
+ * A clean top for the value axis and the ticks up to it: 0, 5, 10, 15
34
+ * rather than 0, 4.3, 8.6, 12.9. About `count` steps of 1, 2, 2.5 or 5 × 10ⁿ.
35
+ */
36
+ export function niceScale(max: number, count = 4): { max: number; ticks: number[] } {
37
+ if (!(max > 0)) return { max: 1, ticks: [0, 1] }
38
+ const rough = max / count
39
+ const power = 10 ** Math.floor(Math.log10(rough))
40
+ const step = ([1, 2, 2.5, 5, 10].find((m) => m * power >= rough) ?? 10) * power
41
+ // Whole numbers only for counts: a step under 1 shows as 0, 0, 1, 1.
42
+ const safeStep = max >= 1 && step < 1 ? 1 : step
43
+ const top = Math.ceil(max / safeStep) * safeStep
44
+ const ticks: number[] = []
45
+ for (let v = 0; v <= top + safeStep / 2; v += safeStep) ticks.push(Number(v.toFixed(10)))
46
+ return { max: top, ticks }
47
+ }
@@ -0,0 +1,19 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { initials } from './initials'
3
+
4
+ describe('initials', () => {
5
+ it.each([
6
+ ['Ben Smith', 'BS'],
7
+ ['Ben', 'B'],
8
+ ['Mary Jane Watson', 'MW'],
9
+ [' ben smith ', 'BS'],
10
+ ['', ''],
11
+ ['Keston Admin (support)', 'KA'],
12
+ ['Jo Bloggs [guest]', 'JB'],
13
+ ["'Jo' Bloggs", 'JB'],
14
+ ['Élodie Durand', 'ÉD'],
15
+ ['(support)', ''],
16
+ ])('%j → %j', (name, want) => {
17
+ expect(initials(name)).toBe(want)
18
+ })
19
+ })
@@ -1,8 +1,17 @@
1
- /** "Ben Smith" → "BS", "Ben" → "B", "Mary Jane Watson" → "MW". Empty for an empty name. */
1
+ /**
2
+ * "Ben Smith" → "BS", "Ben" → "B", "Mary Jane Watson" → "MW". Empty for an
3
+ * empty name. Anything in brackets is a note, not part of the name, so it's
4
+ * left out ("Keston Admin (support)" → "KA"), and so is anything that isn't a
5
+ * letter at the start of a word ("'Jo' Bloggs" → "JB").
6
+ */
2
7
  export function initials(name: string): string {
3
- const words = name.trim().split(/\s+/).filter(Boolean)
8
+ const words = name
9
+ .replace(/\([^)]*\)|\[[^\]]*\]/g, ' ')
10
+ .split(/\s+/)
11
+ .map((word) => word.replace(/^[^\p{L}\p{N}]+/u, ''))
12
+ .filter(Boolean)
4
13
  if (!words.length) return ''
5
14
  const first = words[0]!
6
15
  const last = words.length > 1 ? words[words.length - 1]! : ''
7
- return (first[0]! + (last[0] ?? '')).toUpperCase()
16
+ return ([...first][0]! + ([...last][0] ?? '')).toUpperCase()
8
17
  }