@thekestongroup/ui 0.9.2 → 0.11.1
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/README.md +8 -12
- package/dist/components/AppShell/AppShell.vue.d.ts +4 -1
- 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/Header/Header.vue.d.ts +6 -1
- package/dist/components/StatTile/StatTile.vue.d.ts +10 -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 +698 -441
- package/package.json +1 -1
- package/src/components/AppShell/AppShell.vue +3 -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/Header/Header.stories.ts +29 -0
- package/src/components/Header/Header.vue +14 -9
- package/src/components/StatTile/StatTile.stories.ts +10 -1
- package/src/components/StatTile/StatTile.vue +43 -6
- 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
|
@@ -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
|
+
})
|
package/src/index.ts
CHANGED
|
@@ -34,6 +34,8 @@ export { default as Spinner } from './components/Spinner/Spinner.vue'
|
|
|
34
34
|
export type { SpinnerProps } from './components/Spinner/Spinner.vue'
|
|
35
35
|
export { default as Progress } from './components/Progress/Progress.vue'
|
|
36
36
|
export type { ProgressProps } from './components/Progress/Progress.vue'
|
|
37
|
+
export { default as ChangeIndicator } from './components/ChangeIndicator/ChangeIndicator.vue'
|
|
38
|
+
export type { ChangeIndicatorProps } from './components/ChangeIndicator/ChangeIndicator.vue'
|
|
37
39
|
|
|
38
40
|
// Form
|
|
39
41
|
export { default as FormField } from './components/FormField/FormField.vue'
|
|
@@ -66,6 +68,8 @@ export { default as CheckboxGroup } from './components/CheckboxGroup/CheckboxGro
|
|
|
66
68
|
export type { CheckboxGroupProps, CheckboxOption, CheckboxGroupValue } from './components/CheckboxGroup/CheckboxGroup.vue'
|
|
67
69
|
export { default as LanguageSwitcher } from './components/LanguageSwitcher/LanguageSwitcher.vue'
|
|
68
70
|
export type { LanguageSwitcherProps } from './components/LanguageSwitcher/LanguageSwitcher.vue'
|
|
71
|
+
export { default as CardSelect } from './components/CardSelect/CardSelect.vue'
|
|
72
|
+
export type { CardSelectProps } from './components/CardSelect/CardSelect.vue'
|
|
69
73
|
|
|
70
74
|
// Data
|
|
71
75
|
export { default as Table } from './components/Table/Table.vue'
|
|
@@ -124,6 +128,8 @@ export type {
|
|
|
124
128
|
NotificationType,
|
|
125
129
|
ToastOptions
|
|
126
130
|
} from './components/Notification/notifications'
|
|
131
|
+
export { default as UnsavedChangesBar } from './components/UnsavedChangesBar/UnsavedChangesBar.vue'
|
|
132
|
+
export type { UnsavedChangesBarProps } from './components/UnsavedChangesBar/UnsavedChangesBar.vue'
|
|
127
133
|
|
|
128
134
|
// Languages
|
|
129
135
|
export { createKestonI18n, uiMessages, en } from './i18n'
|