@thekestongroup/ui 0.9.1 → 0.10.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/CardSelect/CardSelect.vue.d.ts +59 -0
- package/dist/components/ChangeIndicator/ChangeIndicator.vue.d.ts +20 -0
- package/dist/components/ChangeIndicator/changeIndicator.d.ts +5 -0
- package/dist/components/Checklist/Checklist.vue.d.ts +2 -0
- package/dist/components/Steps/Steps.vue.d.ts +1 -1
- package/dist/components/UnsavedChangesBar/UnsavedChangesBar.vue.d.ts +46 -0
- package/dist/i18n/en.d.ts +8 -0
- package/dist/index.d.ts +6 -0
- package/dist/keston-ui.js +741 -499
- package/package.json +1 -1
- package/src/components/CardSelect/CardSelect.stories.ts +88 -0
- package/src/components/CardSelect/CardSelect.vue +151 -0
- package/src/components/ChangeIndicator/ChangeIndicator.stories.ts +32 -0
- package/src/components/ChangeIndicator/ChangeIndicator.vue +42 -0
- package/src/components/ChangeIndicator/changeIndicator.test.ts +21 -0
- package/src/components/ChangeIndicator/changeIndicator.ts +11 -0
- package/src/components/Checklist/Checklist.stories.ts +6 -0
- package/src/components/Checklist/Checklist.vue +3 -1
- package/src/components/Header/Header.vue +3 -2
- package/src/components/Slideover/Slideover.vue +5 -3
- package/src/components/Steps/Steps.vue +2 -2
- package/src/components/UnsavedChangesBar/UnsavedChangesBar.stories.ts +62 -0
- package/src/components/UnsavedChangesBar/UnsavedChangesBar.vue +87 -0
- package/src/i18n/en.ts +6 -0
- package/src/i18n/i18n.test.ts +10 -0
- package/src/index.ts +6 -0
package/package.json
CHANGED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite'
|
|
2
|
+
import { ref } from 'vue'
|
|
3
|
+
import { Gauge, ShieldCheck, ShieldAlert, SlidersHorizontal } from '@lucide/vue'
|
|
4
|
+
import CardSelect from './CardSelect.vue'
|
|
5
|
+
|
|
6
|
+
const presets = [
|
|
7
|
+
{ title: 'Baseline', value: 'baseline', description: '8 characters. Nothing extra.' },
|
|
8
|
+
{ title: 'Recommended', value: 'recommended', description: '12 characters and a number.' },
|
|
9
|
+
{ title: 'Strict', value: 'strict', description: '14 characters with every kind of character.' },
|
|
10
|
+
{ title: 'Custom', value: 'custom', description: 'Set each rule yourself.' },
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
const meta = {
|
|
14
|
+
title: 'Components/Form/CardSelect',
|
|
15
|
+
component: CardSelect,
|
|
16
|
+
tags: ['autodocs'],
|
|
17
|
+
argTypes: {
|
|
18
|
+
helperPlacement: { options: ['below', 'icon'], control: { type: 'inline-radio' } },
|
|
19
|
+
columns: { options: [undefined, 1, 2, 3, 4], control: { type: 'inline-radio' } },
|
|
20
|
+
},
|
|
21
|
+
args: {
|
|
22
|
+
label: 'Preset',
|
|
23
|
+
options: presets,
|
|
24
|
+
hideLabel: false,
|
|
25
|
+
helper: '',
|
|
26
|
+
helperPlacement: 'below',
|
|
27
|
+
errorText: '',
|
|
28
|
+
disabled: false,
|
|
29
|
+
},
|
|
30
|
+
render: (args) => ({
|
|
31
|
+
components: { CardSelect },
|
|
32
|
+
setup: () => ({ args, value: ref<string | number | undefined>('recommended') }),
|
|
33
|
+
template: '<CardSelect v-bind="args" v-model="value" />',
|
|
34
|
+
}),
|
|
35
|
+
} satisfies Meta<typeof CardSelect>
|
|
36
|
+
|
|
37
|
+
export default meta
|
|
38
|
+
type Story = StoryObj<typeof meta>
|
|
39
|
+
|
|
40
|
+
/** Playground. Tab into the group, then use the arrow keys to choose. Nothing moves when the choice changes. */
|
|
41
|
+
export const Default: Story = {}
|
|
42
|
+
|
|
43
|
+
/** Icons before the titles. */
|
|
44
|
+
export const WithIcons: Story = {
|
|
45
|
+
args: {
|
|
46
|
+
options: [
|
|
47
|
+
{ title: 'Baseline', value: 'baseline', description: '8 characters.', icon: ShieldAlert },
|
|
48
|
+
{ title: 'Recommended', value: 'recommended', description: '12 characters and a number.', icon: ShieldCheck },
|
|
49
|
+
{ title: 'Strict', value: 'strict', description: '14 characters, every kind.', icon: Gauge },
|
|
50
|
+
{ title: 'Custom', value: 'custom', description: 'Set each rule yourself.', icon: SlidersHorizontal },
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Titles only. */
|
|
56
|
+
export const TitlesOnly: Story = {
|
|
57
|
+
args: {
|
|
58
|
+
label: 'Layout',
|
|
59
|
+
options: [
|
|
60
|
+
{ title: 'List', value: 'list' },
|
|
61
|
+
{ title: 'Grid', value: 'grid' },
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const Nothing: Story = {
|
|
67
|
+
render: (args) => ({
|
|
68
|
+
components: { CardSelect },
|
|
69
|
+
setup: () => ({ args, value: ref<string | number | undefined>() }),
|
|
70
|
+
template: '<CardSelect v-bind="args" v-model="value" />',
|
|
71
|
+
}),
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const HelperBelowLabel: Story = { args: { helper: 'You can change any rule afterwards.' } }
|
|
75
|
+
export const HelperBehindIcon: Story = { args: { helper: 'You can change any rule afterwards.', helperPlacement: 'icon' } }
|
|
76
|
+
export const Error: Story = {
|
|
77
|
+
args: { errorText: 'Choose a preset' },
|
|
78
|
+
render: (args) => ({
|
|
79
|
+
components: { CardSelect },
|
|
80
|
+
setup: () => ({ args, value: ref<string | number | undefined>() }),
|
|
81
|
+
template: '<CardSelect v-bind="args" v-model="value" />',
|
|
82
|
+
}),
|
|
83
|
+
}
|
|
84
|
+
export const DisabledOption: Story = {
|
|
85
|
+
args: { options: presets.map((o) => (o.value === 'strict' ? { ...o, disabled: true } : o)) },
|
|
86
|
+
}
|
|
87
|
+
export const Disabled: Story = { args: { disabled: true } }
|
|
88
|
+
export const TwoColumns: Story = { args: { columns: 2 } }
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useI18n } from 'vue-i18n'
|
|
3
|
+
import { computed, useId, type Component, type HTMLAttributes } from 'vue'
|
|
4
|
+
import { RadioGroupItem, RadioGroupRoot } from 'reka-ui'
|
|
5
|
+
import { cn } from '../../lib/cn'
|
|
6
|
+
import InfoTip from '../InfoTip/InfoTip.vue'
|
|
7
|
+
import FieldMessage from '../FormField/FieldMessage.vue'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* One choice from a few, shown as side-by-side cards, e.g. a preset ("Baseline",
|
|
11
|
+
* "Recommended", "Strict", "Custom"). Behaves as a radio group: Tab moves into
|
|
12
|
+
* it, the arrow keys move and choose. Choosing never moves anything: every
|
|
13
|
+
* card keeps the same size, border width and padding whether chosen or not,
|
|
14
|
+
* and the space for the round indicator is always reserved.
|
|
15
|
+
*
|
|
16
|
+
* For a plain list of options with small text, use RadioGroup.
|
|
17
|
+
*/
|
|
18
|
+
export type CardSelectValue = string | number
|
|
19
|
+
|
|
20
|
+
export interface CardSelectOption {
|
|
21
|
+
/** The card's heading, e.g. "Recommended". */
|
|
22
|
+
title: string
|
|
23
|
+
value: CardSelectValue
|
|
24
|
+
/** A line or two under the title. */
|
|
25
|
+
description?: string
|
|
26
|
+
/** A Lucide icon (or any component) shown before the title. */
|
|
27
|
+
icon?: Component
|
|
28
|
+
disabled?: boolean
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface CardSelectProps {
|
|
32
|
+
/** The question. Also the group's accessible name. */
|
|
33
|
+
label: string
|
|
34
|
+
options: CardSelectOption[]
|
|
35
|
+
/** Visually hide the label (it stays the accessible name). */
|
|
36
|
+
hideLabel?: boolean
|
|
37
|
+
/** Extra guidance about the choice. */
|
|
38
|
+
helper?: string
|
|
39
|
+
/** Show helper text under the label, or behind a `?` icon next to it. */
|
|
40
|
+
helperPlacement?: 'below' | 'icon'
|
|
41
|
+
/** Error message. */
|
|
42
|
+
errorText?: string
|
|
43
|
+
/**
|
|
44
|
+
* Cards per row on wide screens (1–4). Always one or two per row on
|
|
45
|
+
* narrow screens. By default as many as fit, at least 10rem each.
|
|
46
|
+
*/
|
|
47
|
+
columns?: 1 | 2 | 3 | 4
|
|
48
|
+
/** Name for native form submission. */
|
|
49
|
+
name?: string
|
|
50
|
+
required?: boolean
|
|
51
|
+
disabled?: boolean
|
|
52
|
+
class?: HTMLAttributes['class']
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const { t } = useI18n()
|
|
56
|
+
const props = withDefaults(defineProps<CardSelectProps>(), {
|
|
57
|
+
helperPlacement: 'below'
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
/** The chosen card's value; undefined until one is chosen. */
|
|
61
|
+
const model = defineModel<CardSelectValue | undefined>()
|
|
62
|
+
|
|
63
|
+
const id = useId()
|
|
64
|
+
const labelId = `${id}-label`
|
|
65
|
+
const helperId = `${id}-helper`
|
|
66
|
+
const statusId = `${id}-status`
|
|
67
|
+
|
|
68
|
+
const describedBy = computed(
|
|
69
|
+
() => [props.helper && helperId, props.errorText && statusId].filter(Boolean).join(' ') || undefined
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
const grid = computed(() => {
|
|
73
|
+
switch (props.columns) {
|
|
74
|
+
case 1:
|
|
75
|
+
return 'grid-cols-1'
|
|
76
|
+
case 2:
|
|
77
|
+
return 'grid-cols-1 sm:grid-cols-2'
|
|
78
|
+
case 3:
|
|
79
|
+
return 'grid-cols-1 sm:grid-cols-3'
|
|
80
|
+
case 4:
|
|
81
|
+
return 'grid-cols-2 md:grid-cols-4'
|
|
82
|
+
default:
|
|
83
|
+
return 'grid-cols-[repeat(auto-fit,minmax(min(10rem,100%),1fr))]'
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
// Chosen and not chosen have the same 1px border and padding. The chosen
|
|
88
|
+
// card only changes colours and gets a second, inset 1px line drawn with a
|
|
89
|
+
// box-shadow, which takes no space. Text keeps the same weight. Nothing is
|
|
90
|
+
// added or removed in the card, so nothing can move.
|
|
91
|
+
const card = [
|
|
92
|
+
'group relative flex w-full cursor-pointer items-start gap-3 rounded-lg border border-black/15 bg-white p-3 text-left text-black transition-colors',
|
|
93
|
+
'outline-2 outline-offset-2 outline-transparent focus-visible:outline-focus',
|
|
94
|
+
'not-disabled:not-data-[state=checked]:hover:bg-surface-elevated',
|
|
95
|
+
'data-[state=checked]:border-primary data-[state=checked]:bg-primary/6 data-[state=checked]:shadow-[inset_0_0_0_1px_var(--color-primary)]',
|
|
96
|
+
'disabled:cursor-not-allowed disabled:opacity-40',
|
|
97
|
+
'motion-reduce:transition-none'
|
|
98
|
+
]
|
|
99
|
+
</script>
|
|
100
|
+
|
|
101
|
+
<template>
|
|
102
|
+
<div :class="cn('flex flex-col gap-2 text-black', disabled && 'opacity-40', props.class)">
|
|
103
|
+
<div :class="cn('flex flex-col gap-0.5', hideLabel && 'sr-only')">
|
|
104
|
+
<div class="flex items-center gap-1">
|
|
105
|
+
<span :id="labelId" class="text-sm">{{ label }}</span>
|
|
106
|
+
<InfoTip v-if="helper && helperPlacement === 'icon'" :text="helper" :label="t('ui.formField.about', { label })" />
|
|
107
|
+
</div>
|
|
108
|
+
<p v-if="helper" :id="helperId" :hidden="helperPlacement === 'icon'" class="text-xs text-black/65">
|
|
109
|
+
{{ helper }}
|
|
110
|
+
</p>
|
|
111
|
+
</div>
|
|
112
|
+
|
|
113
|
+
<RadioGroupRoot
|
|
114
|
+
v-model="model"
|
|
115
|
+
:name="name"
|
|
116
|
+
:required="required"
|
|
117
|
+
:disabled="disabled"
|
|
118
|
+
:aria-labelledby="labelId"
|
|
119
|
+
:aria-describedby="describedBy"
|
|
120
|
+
:aria-invalid="errorText ? true : undefined"
|
|
121
|
+
:class="cn('grid gap-2', grid)"
|
|
122
|
+
>
|
|
123
|
+
<RadioGroupItem
|
|
124
|
+
v-for="(option, i) in options"
|
|
125
|
+
:id="`${id}-${i}`"
|
|
126
|
+
:key="String(option.value)"
|
|
127
|
+
:value="option.value"
|
|
128
|
+
:disabled="option.disabled"
|
|
129
|
+
:aria-describedby="option.description ? `${id}-${i}-description` : undefined"
|
|
130
|
+
:class="cn(card, errorText && 'not-data-[state=checked]:border-red')"
|
|
131
|
+
>
|
|
132
|
+
<component :is="option.icon" v-if="option.icon" aria-hidden="true" class="mt-0.5 size-4 shrink-0 text-black/65 group-data-[state=checked]:text-primary" />
|
|
133
|
+
<span class="flex min-w-0 flex-1 flex-col gap-0.5">
|
|
134
|
+
<span class="text-sm font-bold">{{ option.title }}</span>
|
|
135
|
+
<span v-if="option.description" :id="`${id}-${i}-description`" class="text-xs text-black/65">
|
|
136
|
+
{{ option.description }}
|
|
137
|
+
</span>
|
|
138
|
+
</span>
|
|
139
|
+
<!-- Always there, so the card is the same size either way: the dot only fades and scales in. -->
|
|
140
|
+
<span
|
|
141
|
+
aria-hidden="true"
|
|
142
|
+
class="mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border border-black/55 bg-white group-data-[state=checked]:border-primary"
|
|
143
|
+
>
|
|
144
|
+
<span class="size-2 scale-0 rounded-full bg-primary transition-transform group-data-[state=checked]:scale-100 motion-reduce:transition-none" />
|
|
145
|
+
</span>
|
|
146
|
+
</RadioGroupItem>
|
|
147
|
+
</RadioGroupRoot>
|
|
148
|
+
|
|
149
|
+
<FieldMessage :id="statusId" :status="errorText ? 'error' : undefined" :text="errorText" />
|
|
150
|
+
</div>
|
|
151
|
+
</template>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite'
|
|
2
|
+
import ChangeIndicator from './ChangeIndicator.vue'
|
|
3
|
+
|
|
4
|
+
const meta = {
|
|
5
|
+
title: 'Components/Element/ChangeIndicator',
|
|
6
|
+
component: ChangeIndicator,
|
|
7
|
+
tags: ['autodocs'],
|
|
8
|
+
args: { from: 15, to: 5 },
|
|
9
|
+
} satisfies Meta<typeof ChangeIndicator>
|
|
10
|
+
|
|
11
|
+
export default meta
|
|
12
|
+
type Story = StoryObj<typeof meta>
|
|
13
|
+
|
|
14
|
+
export const Default: Story = {}
|
|
15
|
+
|
|
16
|
+
/** The unit follows the new value only: `3 → 5 phrases`. */
|
|
17
|
+
export const WithUnit: Story = { args: { from: 3, to: 5, unit: 'phrases' } }
|
|
18
|
+
|
|
19
|
+
/** Text values work too. */
|
|
20
|
+
export const Text: Story = { args: { from: 'Recommended', to: 'Custom' } }
|
|
21
|
+
|
|
22
|
+
/** Nothing is shown when the value is back to what was saved. */
|
|
23
|
+
export const Unchanged: Story = { args: { from: 8, to: 8 } }
|
|
24
|
+
|
|
25
|
+
/** Next to a setting's label, while it has unsaved edits. */
|
|
26
|
+
export const BesideALabel: Story = {
|
|
27
|
+
render: (args) => ({
|
|
28
|
+
components: { ChangeIndicator },
|
|
29
|
+
setup: () => ({ args }),
|
|
30
|
+
template: '<p class="flex items-center gap-2 text-sm">Minimum length <ChangeIndicator v-bind="args" /></p>',
|
|
31
|
+
}),
|
|
32
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useI18n } from 'vue-i18n'
|
|
3
|
+
import { computed, type HTMLAttributes } from 'vue'
|
|
4
|
+
import { ArrowRight } from '@lucide/vue'
|
|
5
|
+
import { cn } from '../../lib/cn'
|
|
6
|
+
import { hasChanged, withUnit, type ChangeValue } from './changeIndicator'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Shows that a setting has been edited and not yet saved, as old value → new
|
|
10
|
+
* value, e.g. `15 → 5` or `3 → 5 phrases`. Put it next to the setting's label.
|
|
11
|
+
* It renders nothing when `from` and `to` are the same, so it can sit in the
|
|
12
|
+
* template permanently and appear only while the setting is edited.
|
|
13
|
+
*/
|
|
14
|
+
export interface ChangeIndicatorProps {
|
|
15
|
+
/** The saved value. */
|
|
16
|
+
from: ChangeValue
|
|
17
|
+
/** The edited value. */
|
|
18
|
+
to: ChangeValue
|
|
19
|
+
/** Unit shown after the new value only, e.g. "phrases". */
|
|
20
|
+
unit?: string
|
|
21
|
+
class?: HTMLAttributes['class']
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const { t } = useI18n()
|
|
25
|
+
const props = defineProps<ChangeIndicatorProps>()
|
|
26
|
+
|
|
27
|
+
const changed = computed(() => hasChanged(props.from, props.to))
|
|
28
|
+
// Screen readers get one sentence; the symbols are hidden from them.
|
|
29
|
+
const label = computed(() => t('ui.changeIndicator.changed', { from: props.from, to: withUnit(props.to, props.unit) }))
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<template>
|
|
33
|
+
<span
|
|
34
|
+
v-if="changed"
|
|
35
|
+
:class="cn('inline-flex items-center gap-1 whitespace-nowrap rounded-full border border-blue/30 bg-blue/10 px-2 text-xs font-bold text-blue', props.class)"
|
|
36
|
+
>
|
|
37
|
+
<span class="sr-only">{{ label }}</span>
|
|
38
|
+
<span aria-hidden="true" class="font-normal line-through decoration-blue/60">{{ from }}</span>
|
|
39
|
+
<ArrowRight aria-hidden="true" class="size-3 shrink-0" />
|
|
40
|
+
<span aria-hidden="true">{{ to }}<template v-if="unit"> {{ unit }}</template></span>
|
|
41
|
+
</span>
|
|
42
|
+
</template>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { hasChanged, withUnit } from './changeIndicator'
|
|
3
|
+
|
|
4
|
+
describe('withUnit', () => {
|
|
5
|
+
it('puts the unit after the value', () => {
|
|
6
|
+
expect(withUnit(5, 'phrases')).toBe('5 phrases')
|
|
7
|
+
})
|
|
8
|
+
it('is just the value without a unit', () => {
|
|
9
|
+
expect(withUnit(5)).toBe('5')
|
|
10
|
+
})
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
describe('hasChanged', () => {
|
|
14
|
+
it('is false for the same value, even as number and string', () => {
|
|
15
|
+
expect(hasChanged(8, 8)).toBe(false)
|
|
16
|
+
expect(hasChanged(8, '8')).toBe(false)
|
|
17
|
+
})
|
|
18
|
+
it('is true when different', () => {
|
|
19
|
+
expect(hasChanged(15, 5)).toBe(true)
|
|
20
|
+
})
|
|
21
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type ChangeValue = string | number
|
|
2
|
+
|
|
3
|
+
/** A value with its unit, e.g. "5 phrases"; just the value when there is no unit. */
|
|
4
|
+
export function withUnit(value: ChangeValue, unit?: string): string {
|
|
5
|
+
return unit ? `${value} ${unit}` : String(value)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** True when there is something to show: the value really changed. */
|
|
9
|
+
export function hasChanged(from: ChangeValue, to: ChangeValue): boolean {
|
|
10
|
+
return String(from) !== String(to)
|
|
11
|
+
}
|
|
@@ -25,6 +25,12 @@ export const Default: Story = {
|
|
|
25
25
|
decorators: [() => ({ template: '<div class="max-w-72"><story /></div>' })],
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
+
/** After submitting without meeting everything: the circles not done yet turn red. */
|
|
29
|
+
export const Invalid: Story = {
|
|
30
|
+
decorators: [() => ({ template: '<div class="max-w-72"><story /></div>' })],
|
|
31
|
+
args: { invalid: true },
|
|
32
|
+
};
|
|
33
|
+
|
|
28
34
|
/** Long steps wrap; the icon stays level with the first line. */
|
|
29
35
|
export const LongItems: Story = {
|
|
30
36
|
decorators: [() => ({ template: '<div class="max-w-72"><story /></div>' })],
|
|
@@ -16,6 +16,8 @@ export interface ChecklistItem {
|
|
|
16
16
|
|
|
17
17
|
export interface ChecklistProps {
|
|
18
18
|
items: ChecklistItem[]
|
|
19
|
+
/** Turns the circles of items not done yet red, e.g. after submitting a form that doesn't meet them. */
|
|
20
|
+
invalid?: boolean
|
|
19
21
|
class?: HTMLAttributes['class']
|
|
20
22
|
}
|
|
21
23
|
|
|
@@ -28,7 +30,7 @@ const props = defineProps<ChecklistProps>()
|
|
|
28
30
|
<!-- h-5 keeps the icon level with the first line of a label that wraps. -->
|
|
29
31
|
<span class="flex h-5 shrink-0 items-center">
|
|
30
32
|
<CircleCheck v-if="item.done" class="size-4 text-green" aria-hidden="true" />
|
|
31
|
-
<Circle v-else class="size-4 text-black/40" aria-hidden="true" />
|
|
33
|
+
<Circle v-else :class="cn('size-4', invalid ? 'text-red' : 'text-black/40')" aria-hidden="true" />
|
|
32
34
|
</span>
|
|
33
35
|
<span :class="item.done ? 'text-black' : 'text-black/65'">
|
|
34
36
|
{{ item.label }}<span class="sr-only">{{ item.done ? ' (done)' : ' (to do)' }}</span>
|
|
@@ -202,6 +202,7 @@ function runAction(action: HeaderUserAction, close: () => void) {
|
|
|
202
202
|
<p
|
|
203
203
|
v-if="user.organisation"
|
|
204
204
|
class="truncate px-4 pt-3 text-xs font-bold text-black/65 uppercase"
|
|
205
|
+
:title="user.organisation"
|
|
205
206
|
>
|
|
206
207
|
{{ user.organisation }}
|
|
207
208
|
</p>
|
|
@@ -211,8 +212,8 @@ function runAction(action: HeaderUserAction, close: () => void) {
|
|
|
211
212
|
<div class="grid grid-cols-[auto_minmax(0,1fr)] items-start gap-x-3 gap-y-2 px-4 py-3">
|
|
212
213
|
<Avatar :user="user" size="lg" decorative />
|
|
213
214
|
<div class="flex min-w-0 flex-col">
|
|
214
|
-
<span class="truncate font-bold">{{ user.name }}</span>
|
|
215
|
-
<span v-if="user.email" class="truncate text-sm text-black/65">{{ user.email }}</span>
|
|
215
|
+
<span class="truncate font-bold" :title="user.name">{{ user.name }}</span>
|
|
216
|
+
<span v-if="user.email" class="truncate text-sm text-black/65" :title="user.email">{{ user.email }}</span>
|
|
216
217
|
</div>
|
|
217
218
|
<Button
|
|
218
219
|
v-if="userActions.includes('account-settings')"
|
|
@@ -295,6 +295,10 @@ const panel = [
|
|
|
295
295
|
v-if="title || description || close || steps || $slots.header || $slots.title"
|
|
296
296
|
:class="cn('flex flex-col gap-4 border-b border-black/15 px-6 py-4', ui?.header)"
|
|
297
297
|
>
|
|
298
|
+
<!-- The step sits above its progress bar. -->
|
|
299
|
+
<p v-if="steps" :id="stepLabelId" class="text-sm text-black/65">
|
|
300
|
+
Step {{ step + 1 }} of {{ stepCount }}: <span class="text-black">{{ steps[step] }}</span>
|
|
301
|
+
</p>
|
|
298
302
|
<Progress v-if="steps" :label="title ?? t('ui.slideover.steps')" segments :value="step + 1" :max="stepCount" />
|
|
299
303
|
<div class="flex items-start gap-4">
|
|
300
304
|
<slot name="header" :close="closePanel">
|
|
@@ -310,9 +314,7 @@ const panel = [
|
|
|
310
314
|
class="flex flex-col gap-1 text-sm text-black/65"
|
|
311
315
|
>
|
|
312
316
|
<p v-if="description || $slots.description"><slot name="description">{{ description }}</slot></p>
|
|
313
|
-
<p v-if="steps"
|
|
314
|
-
Step {{ step + 1 }} of {{ stepCount }}: <span class="text-black">{{ steps[step] }}</span>
|
|
315
|
-
</p>
|
|
317
|
+
<p v-if="steps" class="sr-only">{{ stepText }}</p>
|
|
316
318
|
</DialogDescription>
|
|
317
319
|
<p v-if="steps" aria-live="polite" class="sr-only">{{ announcement }}</p>
|
|
318
320
|
</div>
|
|
@@ -6,7 +6,7 @@ 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"
|
|
9
|
+
* the current one, and "Step 2 of 3: Licences" above it. Put it at the top of
|
|
10
10
|
* a multi-step form. (Slideover's `steps` shows one for you; use this when
|
|
11
11
|
* the steps are on a page, or in a Slideover you drive yourself.) The words
|
|
12
12
|
* are announced when the step changes.
|
|
@@ -26,7 +26,6 @@ const props = defineProps<StepsProps>()
|
|
|
26
26
|
|
|
27
27
|
<template>
|
|
28
28
|
<div :class="cn('flex flex-col gap-3', props.class)">
|
|
29
|
-
<Progress :label="label" segments :value="step + 1" :max="steps.length" />
|
|
30
29
|
<p class="text-sm text-black/65" aria-live="polite">
|
|
31
30
|
<I18nT keypath="ui.steps.stepOfNamed" scope="global" tag="span">
|
|
32
31
|
<template #current>{{ step + 1 }}</template>
|
|
@@ -34,5 +33,6 @@ const props = defineProps<StepsProps>()
|
|
|
34
33
|
<template #name><span class="text-black">{{ steps[step] }}</span></template>
|
|
35
34
|
</I18nT>
|
|
36
35
|
</p>
|
|
36
|
+
<Progress :label="label" segments :value="step + 1" :max="steps.length" />
|
|
37
37
|
</div>
|
|
38
38
|
</template>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite'
|
|
2
|
+
import { ref } from 'vue'
|
|
3
|
+
import Button from '../Button/Button.vue'
|
|
4
|
+
import UnsavedChangesBar from './UnsavedChangesBar.vue'
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'Components/Overlay/UnsavedChangesBar',
|
|
8
|
+
component: UnsavedChangesBar,
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
parameters: { layout: 'fullscreen' },
|
|
11
|
+
args: { open: true, message: '', discardLabel: '', saveLabel: '', status: 'idle', reserveSpace: true },
|
|
12
|
+
argTypes: { status: { options: ['idle', 'loading', 'success', 'error'], control: { type: 'inline-radio' } } },
|
|
13
|
+
} satisfies Meta<typeof UnsavedChangesBar>
|
|
14
|
+
|
|
15
|
+
export default meta
|
|
16
|
+
type Story = StoryObj<typeof meta>
|
|
17
|
+
|
|
18
|
+
/** Shown with its defaults: "Unsaved changes", Discard and Save. */
|
|
19
|
+
export const Default: Story = {
|
|
20
|
+
render: (args) => ({
|
|
21
|
+
components: { UnsavedChangesBar },
|
|
22
|
+
setup: () => ({ args }),
|
|
23
|
+
template: `
|
|
24
|
+
<div class="p-6"><p class="text-sm">Page content. The bar is fixed to the bottom of the screen.</p>
|
|
25
|
+
<UnsavedChangesBar v-bind="args" :message="args.message || undefined" :discard-label="args.discardLabel || undefined" :save-label="args.saveLabel || undefined" /></div>`,
|
|
26
|
+
}),
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Edit to open it; it slides up, and slides back down on Discard or Save. Save shows a spinner for a moment. */
|
|
30
|
+
export const SlidesInAndOut: Story = {
|
|
31
|
+
render: () => ({
|
|
32
|
+
components: { UnsavedChangesBar, Button },
|
|
33
|
+
setup() {
|
|
34
|
+
const open = ref(false)
|
|
35
|
+
const status = ref<'idle' | 'loading' | 'success' | 'error'>('idle')
|
|
36
|
+
function save() {
|
|
37
|
+
status.value = 'loading'
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
status.value = 'idle'
|
|
40
|
+
open.value = false
|
|
41
|
+
}, 1200)
|
|
42
|
+
}
|
|
43
|
+
return { open, status, save }
|
|
44
|
+
},
|
|
45
|
+
template: `
|
|
46
|
+
<div class="flex flex-col items-start gap-4 p-6">
|
|
47
|
+
<p class="text-sm">The bar leaves a gap at the end of the page, so nothing is covered.</p>
|
|
48
|
+
<Button variant="primary" @click="open = true">Make a change</Button>
|
|
49
|
+
<div class="h-[60vh] w-full rounded-lg bg-surface" />
|
|
50
|
+
<p class="text-sm">Last line of the page.</p>
|
|
51
|
+
<UnsavedChangesBar :open="open" :status="status" @discard="open = false" @save="save" />
|
|
52
|
+
</div>`,
|
|
53
|
+
}),
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Words that fit the page, e.g. "Unsaved password policy". */
|
|
57
|
+
export const CustomWords: Story = {
|
|
58
|
+
args: { message: 'Unsaved password policy', discardLabel: 'Undo', saveLabel: 'Apply' },
|
|
59
|
+
render: Default.render,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const Saving: Story = { args: { status: 'loading' }, render: Default.render }
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useI18n } from 'vue-i18n'
|
|
3
|
+
import { computed, type HTMLAttributes } from 'vue'
|
|
4
|
+
import { cn } from '../../lib/cn'
|
|
5
|
+
import Button, { type ButtonStatus } from '../Button/Button.vue'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A bar that slides up from the bottom of the screen while a page or form has
|
|
9
|
+
* edits that haven't been saved, with Discard and Save. It slides back down
|
|
10
|
+
* when `open` is false, e.g. after saving or discarding. With reduced motion
|
|
11
|
+
* it simply appears and disappears.
|
|
12
|
+
*
|
|
13
|
+
* It is fixed to the bottom of the screen, so it would cover the end of the
|
|
14
|
+
* page. By default it therefore leaves an empty space of its own height at its
|
|
15
|
+
* place in the page (put it last in the page content); set `reserveSpace` to
|
|
16
|
+
* false if you handle that yourself, e.g. with padding on the page.
|
|
17
|
+
*
|
|
18
|
+
* Next to a setting that has been edited, show the old and new values with
|
|
19
|
+
* ChangeIndicator.
|
|
20
|
+
*/
|
|
21
|
+
export interface UnsavedChangesBarProps {
|
|
22
|
+
/** Whether it is shown. */
|
|
23
|
+
open: boolean
|
|
24
|
+
/** What it says. Default "Unsaved changes". */
|
|
25
|
+
message?: string
|
|
26
|
+
/** Text of the discard button. Default "Discard". */
|
|
27
|
+
discardLabel?: string
|
|
28
|
+
/** Text of the save button. Default "Save". */
|
|
29
|
+
saveLabel?: string
|
|
30
|
+
/** Progress of saving: `loading` shows a spinner on Save and disables both buttons. */
|
|
31
|
+
status?: ButtonStatus
|
|
32
|
+
/**
|
|
33
|
+
* Keep the end of the page clear of the bar by leaving a blank space as tall
|
|
34
|
+
* as the bar where this component is placed.
|
|
35
|
+
*/
|
|
36
|
+
reserveSpace?: boolean
|
|
37
|
+
class?: HTMLAttributes['class']
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const { t } = useI18n()
|
|
41
|
+
const props = withDefaults(defineProps<UnsavedChangesBarProps>(), {
|
|
42
|
+
status: 'idle',
|
|
43
|
+
reserveSpace: true
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
const emit = defineEmits<{
|
|
47
|
+
/** Discard was pressed: put the edits back. The parent then closes the bar. */
|
|
48
|
+
discard: []
|
|
49
|
+
/** Save was pressed. The parent saves, then sets `open` to false. */
|
|
50
|
+
save: []
|
|
51
|
+
}>()
|
|
52
|
+
|
|
53
|
+
const saving = computed(() => props.status === 'loading')
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<template>
|
|
57
|
+
<!-- Takes the bar's height in the page (only while open), so the last content can be scrolled clear of it. -->
|
|
58
|
+
<div v-if="open && reserveSpace" aria-hidden="true" class="h-20" />
|
|
59
|
+
<Transition
|
|
60
|
+
enter-active-class="transition duration-300 ease-out motion-reduce:transition-none"
|
|
61
|
+
leave-active-class="transition duration-200 ease-in motion-reduce:transition-none"
|
|
62
|
+
enter-from-class="translate-y-full motion-reduce:translate-y-0 motion-reduce:opacity-0"
|
|
63
|
+
leave-to-class="translate-y-full motion-reduce:translate-y-0 motion-reduce:opacity-0"
|
|
64
|
+
>
|
|
65
|
+
<div
|
|
66
|
+
v-if="open"
|
|
67
|
+
role="region"
|
|
68
|
+
:aria-label="message ?? t('ui.unsavedChangesBar.message')"
|
|
69
|
+
:class="cn('fixed inset-x-0 bottom-0 z-40 flex justify-center px-4 pb-4 pointer-events-none', props.class)"
|
|
70
|
+
>
|
|
71
|
+
<div
|
|
72
|
+
class="pointer-events-auto flex w-full max-w-2xl items-center justify-between gap-3 rounded-lg border border-black/15 bg-white p-3 pl-4 shadow-lg"
|
|
73
|
+
>
|
|
74
|
+
<p role="status" class="flex items-center gap-2 text-sm font-bold">
|
|
75
|
+
<span aria-hidden="true" class="size-2 shrink-0 rounded-full bg-yellow" />
|
|
76
|
+
{{ message ?? t('ui.unsavedChangesBar.message') }}
|
|
77
|
+
</p>
|
|
78
|
+
<div class="flex shrink-0 items-center gap-2">
|
|
79
|
+
<Button :disabled="saving" @click="emit('discard')">{{ discardLabel ?? t('ui.unsavedChangesBar.discard') }}</Button>
|
|
80
|
+
<Button variant="primary" :status="status" :disabled="saving" @click="emit('save')">
|
|
81
|
+
{{ saveLabel ?? t('ui.unsavedChangesBar.save') }}
|
|
82
|
+
</Button>
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
</Transition>
|
|
87
|
+
</template>
|
package/src/i18n/en.ts
CHANGED
|
@@ -40,6 +40,7 @@ export const en = {
|
|
|
40
40
|
chooseMonth: 'Choose month',
|
|
41
41
|
chooseYear: 'Choose year'
|
|
42
42
|
},
|
|
43
|
+
changeIndicator: { changed: 'Changed from {from} to {to}' },
|
|
43
44
|
chip: { remove: 'Remove' },
|
|
44
45
|
formField: { about: 'About {label}' },
|
|
45
46
|
header: {
|
|
@@ -120,6 +121,11 @@ export const en = {
|
|
|
120
121
|
selectAll: 'Select all rows',
|
|
121
122
|
selectRow: 'Select row {n}',
|
|
122
123
|
select: 'Select'
|
|
124
|
+
},
|
|
125
|
+
unsavedChangesBar: {
|
|
126
|
+
message: 'Unsaved changes',
|
|
127
|
+
discard: 'Discard',
|
|
128
|
+
save: 'Save'
|
|
123
129
|
}
|
|
124
130
|
}
|
|
125
131
|
}
|
package/src/i18n/i18n.test.ts
CHANGED
|
@@ -54,3 +54,13 @@ describe('createKestonI18n', () => {
|
|
|
54
54
|
}
|
|
55
55
|
})
|
|
56
56
|
})
|
|
57
|
+
|
|
58
|
+
describe('new component words', () => {
|
|
59
|
+
it('has words for the unsaved changes bar and change indicator', () => {
|
|
60
|
+
const i18n = createKestonI18n()
|
|
61
|
+
expect(i18n.global.t('ui.unsavedChangesBar.message')).toBe('Unsaved changes')
|
|
62
|
+
expect(i18n.global.t('ui.unsavedChangesBar.discard')).toBe('Discard')
|
|
63
|
+
expect(i18n.global.t('ui.unsavedChangesBar.save')).toBe('Save')
|
|
64
|
+
expect(i18n.global.t('ui.changeIndicator.changed', { from: 15, to: '5 phrases' })).toBe('Changed from 15 to 5 phrases')
|
|
65
|
+
})
|
|
66
|
+
})
|