@thekestongroup/ui 0.6.0 → 0.9.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/Breadcrumb/Breadcrumb.vue.d.ts +0 -1
- package/dist/components/Checkbox/Checkbox.vue.d.ts +2 -0
- package/dist/components/CheckboxGroup/CheckboxGroup.vue.d.ts +45 -0
- package/dist/components/Chip/Chip.vue.d.ts +0 -1
- package/dist/components/Header/Header.vue.d.ts +0 -1
- package/dist/components/InputDate/InputDate.vue.d.ts +1 -1
- package/dist/components/InputTextArea/InputTextArea.vue.d.ts +49 -0
- package/dist/components/LanguageSwitcher/LanguageSwitcher.vue.d.ts +24 -0
- package/dist/components/Notification/NotificationPane.vue.d.ts +1 -4
- package/dist/components/PageHeader/PageHeader.vue.d.ts +8 -3
- package/dist/components/Select/Select.vue.d.ts +0 -1
- package/dist/components/SettingsRow/SettingsRow.vue.d.ts +28 -0
- package/dist/components/Sidebar/Sidebar.vue.d.ts +0 -1
- package/dist/components/Slideover/Slideover.vue.d.ts +0 -1
- package/dist/components/Spinner/Spinner.vue.d.ts +0 -1
- package/dist/components/Steps/Steps.vue.d.ts +20 -0
- package/dist/components/Switch/Switch.vue.d.ts +2 -0
- package/dist/components/Table/Table.vue.d.ts +21 -1
- package/dist/i18n/en.d.ts +146 -0
- package/dist/i18n/index.d.ts +32 -0
- package/dist/index.d.ts +12 -0
- package/dist/keston-ui.js +2288 -1718
- package/package.json +4 -2
- package/src/components/Age/Age.vue +4 -2
- package/src/components/AppShell/AppShell.vue +4 -2
- package/src/components/AvatarGroup/AvatarGroup.vue +4 -2
- package/src/components/Breadcrumb/Breadcrumb.vue +3 -2
- package/src/components/Calendar/Calendar.vue +8 -6
- package/src/components/Card/Card.vue +3 -1
- package/src/components/Checkbox/Checkbox.stories.ts +3 -0
- package/src/components/Checkbox/Checkbox.vue +3 -1
- package/src/components/CheckboxGroup/CheckboxGroup.stories.ts +48 -0
- package/src/components/CheckboxGroup/CheckboxGroup.vue +96 -0
- package/src/components/Chip/Chip.vue +3 -2
- package/src/components/FormField/FormField.vue +3 -1
- package/src/components/Header/Header.vue +6 -5
- package/src/components/Input/Input.vue +4 -2
- package/src/components/InputCode/InputCode.vue +4 -2
- package/src/components/InputDate/InputDate.vue +4 -2
- package/src/components/InputPassword/InputPassword.vue +4 -2
- package/src/components/InputRichText/InputRichText.vue +6 -4
- package/src/components/InputTextArea/InputTextArea.stories.ts +53 -0
- package/src/components/InputTextArea/InputTextArea.vue +89 -0
- package/src/components/LanguageSwitcher/LanguageSwitcher.stories.ts +21 -0
- package/src/components/LanguageSwitcher/LanguageSwitcher.vue +57 -0
- package/src/components/Link/Link.vue +1 -0
- package/src/components/Notification/Notification.vue +3 -1
- package/src/components/Notification/NotificationPane.vue +10 -8
- package/src/components/Notification/Toaster.vue +9 -7
- package/src/components/PageHeader/PageHeader.stories.ts +29 -1
- package/src/components/PageHeader/PageHeader.vue +108 -22
- package/src/components/Progress/Progress.vue +3 -1
- package/src/components/RadioGroup/RadioGroup.vue +3 -1
- package/src/components/Select/Select.vue +6 -5
- package/src/components/SettingsRow/SettingsRow.stories.ts +59 -0
- package/src/components/SettingsRow/SettingsRow.vue +39 -0
- package/src/components/Sidebar/Sidebar.vue +5 -4
- package/src/components/Slideover/Slideover.vue +8 -7
- package/src/components/Spinner/Spinner.vue +4 -3
- package/src/components/StatTile/StatTile.vue +3 -1
- package/src/components/Steps/Steps.stories.ts +38 -0
- package/src/components/Steps/Steps.vue +38 -0
- package/src/components/SummaryList/SummaryList.vue +5 -4
- package/src/components/Switch/Switch.vue +3 -1
- package/src/components/Table/Table.stories.ts +34 -0
- package/src/components/Table/Table.vue +98 -8
- package/src/i18n/en.ts +127 -0
- package/src/i18n/i18n.test.ts +56 -0
- package/src/i18n/index.ts +89 -0
- package/src/index.ts +14 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
|
2
|
+
import { ref } from "vue";
|
|
3
|
+
import InputTextArea from "./InputTextArea.vue";
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: "Components/Form/InputTextArea",
|
|
7
|
+
component: InputTextArea,
|
|
8
|
+
tags: ["autodocs"],
|
|
9
|
+
argTypes: {
|
|
10
|
+
helperPlacement: { options: ["below", "icon"], control: { type: "inline-radio" } },
|
|
11
|
+
status: { options: [undefined, "error", "success", "loading"], control: { type: "inline-radio" } },
|
|
12
|
+
},
|
|
13
|
+
args: {
|
|
14
|
+
label: "Redirect addresses",
|
|
15
|
+
helper: "One address per line.",
|
|
16
|
+
helperPlacement: "below",
|
|
17
|
+
placeholder: "https://example.com/callback",
|
|
18
|
+
disabled: false,
|
|
19
|
+
},
|
|
20
|
+
decorators: [() => ({ template: '<div class="max-w-120"><story /></div>' })],
|
|
21
|
+
render: (args) => ({
|
|
22
|
+
components: { InputTextArea },
|
|
23
|
+
setup: () => ({ args, value: ref("") }),
|
|
24
|
+
template: '<InputTextArea v-bind="args" v-model="value" />',
|
|
25
|
+
}),
|
|
26
|
+
} satisfies Meta<typeof InputTextArea>;
|
|
27
|
+
|
|
28
|
+
export default meta;
|
|
29
|
+
type Story = StoryObj<typeof meta>;
|
|
30
|
+
|
|
31
|
+
/** Four lines tall to start with; it grows with the text up to 15 lines, then scrolls. */
|
|
32
|
+
export const Default: Story = {};
|
|
33
|
+
|
|
34
|
+
export const WithText: Story = {
|
|
35
|
+
render: (args) => ({
|
|
36
|
+
components: { InputTextArea },
|
|
37
|
+
setup: () => ({ args, value: ref("https://app.keston.co/callback\nhttps://staging.keston.co/callback") }),
|
|
38
|
+
template: '<InputTextArea v-bind="args" v-model="value" />',
|
|
39
|
+
}),
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** Too long shows as soon as the text passes `maxLength`. */
|
|
43
|
+
export const MaxLength: Story = {
|
|
44
|
+
args: { label: "Reason", helper: "", maxLength: 40, placeholder: "" },
|
|
45
|
+
render: (args) => ({
|
|
46
|
+
components: { InputTextArea },
|
|
47
|
+
setup: () => ({ args, value: ref("This reason is much longer than forty characters.") }),
|
|
48
|
+
template: '<InputTextArea v-bind="args" v-model="value" />',
|
|
49
|
+
}),
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const WithError: Story = { args: { errorText: "Enter at least one address" } };
|
|
53
|
+
export const Disabled: Story = { args: { disabled: true } };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, type HTMLAttributes } from 'vue'
|
|
3
|
+
import { useI18n } from 'vue-i18n'
|
|
4
|
+
import FormField, { type FormFieldStatus } from '../FormField/FormField.vue'
|
|
5
|
+
|
|
6
|
+
// Attributes like placeholder, name, autocomplete and spellcheck go to the
|
|
7
|
+
// <textarea>, not the wrapper.
|
|
8
|
+
defineOptions({ inheritAttrs: false })
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Several lines of plain text, e.g. a reason, an address or a list with one
|
|
12
|
+
* item per line. It starts four lines tall and grows with the text up to 15
|
|
13
|
+
* lines, then scrolls. For notes that need bold, italic or underline, use
|
|
14
|
+
* InputRichText; for one line, Input.
|
|
15
|
+
*/
|
|
16
|
+
export interface InputTextAreaProps {
|
|
17
|
+
/** Visible label. Always set it: it is also the field's accessible name. */
|
|
18
|
+
label: string
|
|
19
|
+
/** Extra guidance about what to enter. */
|
|
20
|
+
helper?: string
|
|
21
|
+
/** Show helper text under the label, or behind a `?` icon next to it. */
|
|
22
|
+
helperPlacement?: 'below' | 'icon'
|
|
23
|
+
/** Keep the label for screen readers only, e.g. in a table of fields with column headings. */
|
|
24
|
+
hideLabel?: boolean
|
|
25
|
+
/**
|
|
26
|
+
* Error message, e.g. from a Zod schema. Overrides `status`, `statusText`
|
|
27
|
+
* and the length check.
|
|
28
|
+
*/
|
|
29
|
+
errorText?: string
|
|
30
|
+
/** Colours the field and the status text. Overrides the length check. */
|
|
31
|
+
status?: FormFieldStatus
|
|
32
|
+
/** Message under the field. */
|
|
33
|
+
statusText?: string
|
|
34
|
+
/** Shown in the empty field, e.g. "One address per line". */
|
|
35
|
+
placeholder?: string
|
|
36
|
+
/** Shows an error as soon as the text is too long. Typing is not blocked. */
|
|
37
|
+
maxLength?: number
|
|
38
|
+
disabled?: boolean
|
|
39
|
+
class?: HTMLAttributes['class']
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const props = withDefaults(defineProps<InputTextAreaProps>(), {
|
|
43
|
+
helperPlacement: 'below'
|
|
44
|
+
})
|
|
45
|
+
const { t } = useI18n()
|
|
46
|
+
|
|
47
|
+
const model = defineModel<string>({ default: '' })
|
|
48
|
+
|
|
49
|
+
const lengthError = computed(() =>
|
|
50
|
+
props.maxLength !== undefined && model.value.length > props.maxLength
|
|
51
|
+
? t('ui.input.maxLength', { count: props.maxLength })
|
|
52
|
+
: undefined
|
|
53
|
+
)
|
|
54
|
+
const status = computed(() => props.status ?? (lengthError.value ? 'error' : undefined))
|
|
55
|
+
const statusText = computed(() => props.statusText ?? lengthError.value)
|
|
56
|
+
|
|
57
|
+
const area = ref<HTMLTextAreaElement>()
|
|
58
|
+
defineExpose({ focus: () => area.value?.focus() })
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
<template>
|
|
62
|
+
<FormField
|
|
63
|
+
:label="label"
|
|
64
|
+
:helper="helper"
|
|
65
|
+
:helper-placement="helperPlacement"
|
|
66
|
+
:hide-label="hideLabel"
|
|
67
|
+
:error-text="errorText"
|
|
68
|
+
:status="status"
|
|
69
|
+
:status-text="statusText"
|
|
70
|
+
:disabled="disabled"
|
|
71
|
+
:class="props.class"
|
|
72
|
+
>
|
|
73
|
+
<template #default="{ id, describedBy, invalid }">
|
|
74
|
+
<!-- field-sizing grows it with the text; 4 to 15 lines (96px to 320px),
|
|
75
|
+
like InputRichText. A drag handle would fight that, so there's none. -->
|
|
76
|
+
<textarea
|
|
77
|
+
:id="id"
|
|
78
|
+
ref="area"
|
|
79
|
+
v-model="model"
|
|
80
|
+
v-bind="$attrs"
|
|
81
|
+
:placeholder="placeholder"
|
|
82
|
+
:disabled="disabled"
|
|
83
|
+
:aria-invalid="invalid"
|
|
84
|
+
:aria-describedby="describedBy"
|
|
85
|
+
class="field-sizing-content -my-0.5 max-h-80 min-h-24 min-w-0 flex-1 resize-none bg-transparent text-sm leading-5 outline-none placeholder:text-black/55 disabled:cursor-not-allowed pointer-coarse:text-base"
|
|
86
|
+
/>
|
|
87
|
+
</template>
|
|
88
|
+
</FormField>
|
|
89
|
+
</template>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
|
2
|
+
import LanguageSwitcher from "./LanguageSwitcher.vue";
|
|
3
|
+
|
|
4
|
+
const meta = {
|
|
5
|
+
title: "Components/Form/LanguageSwitcher",
|
|
6
|
+
component: LanguageSwitcher,
|
|
7
|
+
tags: ["autodocs"],
|
|
8
|
+
args: { hideLabel: false, disabled: false },
|
|
9
|
+
decorators: [() => ({ template: '<div class="max-w-80"><story /></div>' })],
|
|
10
|
+
} satisfies Meta<typeof LanguageSwitcher>;
|
|
11
|
+
|
|
12
|
+
export default meta;
|
|
13
|
+
type Story = StoryObj<typeof meta>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Lists the languages the app has. Storybook has English only; an app with
|
|
17
|
+
* more shows each in its own name and changes language as soon as one is chosen.
|
|
18
|
+
*/
|
|
19
|
+
export const Default: Story = {};
|
|
20
|
+
|
|
21
|
+
export const HiddenLabel: Story = { args: { hideLabel: true } };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, type HTMLAttributes } from 'vue'
|
|
3
|
+
import { useI18n } from 'vue-i18n'
|
|
4
|
+
import { Languages } from '@lucide/vue'
|
|
5
|
+
import Select from '../Select/Select.vue'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Chooses the language the app is shown in, e.g. in the account menu, the
|
|
9
|
+
* footer or Settings. It lists the languages the app's vue-i18n has, each
|
|
10
|
+
* in its own name ("Cymraeg", "Español"), and changes the app's language as
|
|
11
|
+
* soon as one is chosen. With `createKestonI18n` the choice is remembered
|
|
12
|
+
* for next time.
|
|
13
|
+
*/
|
|
14
|
+
export interface LanguageSwitcherProps {
|
|
15
|
+
/** Visible label. Default "Language". */
|
|
16
|
+
label?: string
|
|
17
|
+
/** Keep the label for screen readers only, e.g. in a header or footer. */
|
|
18
|
+
hideLabel?: boolean
|
|
19
|
+
/**
|
|
20
|
+
* Names to show instead of the browser's own for a code, e.g.
|
|
21
|
+
* `{ 'en-GB': 'English (UK)' }`.
|
|
22
|
+
*/
|
|
23
|
+
names?: Record<string, string>
|
|
24
|
+
disabled?: boolean
|
|
25
|
+
class?: HTMLAttributes['class']
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const props = defineProps<LanguageSwitcherProps>()
|
|
29
|
+
const { t, locale, availableLocales } = useI18n()
|
|
30
|
+
|
|
31
|
+
// Each language in its own tongue, so someone can find theirs even when the
|
|
32
|
+
// page is in a language they can't read.
|
|
33
|
+
function nameOf(code: string) {
|
|
34
|
+
if (props.names?.[code]) return props.names[code]
|
|
35
|
+
try {
|
|
36
|
+
const name = new Intl.DisplayNames([code], { type: 'language' }).of(code)
|
|
37
|
+
return name ? name.charAt(0).toLocaleUpperCase(code) + name.slice(1) : code
|
|
38
|
+
} catch {
|
|
39
|
+
return code
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const options = computed(() => availableLocales.map((code) => ({ label: nameOf(code), value: code })))
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
<template>
|
|
47
|
+
<Select
|
|
48
|
+
v-model="locale"
|
|
49
|
+
:label="label ?? t('ui.languageSwitcher.label')"
|
|
50
|
+
:hide-label="hideLabel"
|
|
51
|
+
:options="options"
|
|
52
|
+
:disabled="disabled"
|
|
53
|
+
:class="props.class"
|
|
54
|
+
>
|
|
55
|
+
<template #leading><Languages aria-hidden="true" /></template>
|
|
56
|
+
</Select>
|
|
57
|
+
</template>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { useI18n } from 'vue-i18n'
|
|
2
3
|
import { computed, useId, type HTMLAttributes } from 'vue'
|
|
3
4
|
import { CircleCheck, CircleX, Info, TriangleAlert, X } from '@lucide/vue'
|
|
4
5
|
import { cn } from '../../lib/cn'
|
|
@@ -44,6 +45,7 @@ export interface NotificationProps {
|
|
|
44
45
|
class?: HTMLAttributes['class']
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
const { t } = useI18n()
|
|
47
49
|
const props = withDefaults(defineProps<NotificationProps>(), {
|
|
48
50
|
type: 'info',
|
|
49
51
|
appearance: 'card',
|
|
@@ -127,7 +129,7 @@ function runAction() {
|
|
|
127
129
|
square
|
|
128
130
|
:class="cn('shrink-0', !oneLine && '-mt-1 -mr-1.5')"
|
|
129
131
|
data-dismiss
|
|
130
|
-
:aria-label="dismissLabel ??
|
|
132
|
+
:aria-label="dismissLabel ?? t('ui.notifications.dismiss', { title })"
|
|
131
133
|
@click="emit('dismiss')"
|
|
132
134
|
>
|
|
133
135
|
<X />
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { useI18n } from 'vue-i18n'
|
|
2
3
|
import { computed, nextTick, ref, useId, watch, type HTMLAttributes } from 'vue'
|
|
3
4
|
import { Bell, BellOff } from '@lucide/vue'
|
|
4
5
|
import { cn } from '../../lib/cn'
|
|
@@ -27,10 +28,8 @@ export interface NotificationPaneProps {
|
|
|
27
28
|
ui?: { content?: HTMLAttributes['class']; trigger?: HTMLAttributes['class'] }
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
emptyText: "You're all caught up."
|
|
33
|
-
})
|
|
31
|
+
const { t } = useI18n()
|
|
32
|
+
const props = defineProps<NotificationPaneProps>()
|
|
34
33
|
|
|
35
34
|
const open = defineModel<boolean>('open', { default: false })
|
|
36
35
|
|
|
@@ -40,7 +39,10 @@ const unread = computed(() => store.value.unreadCount.value)
|
|
|
40
39
|
// The name uses the same text as the badge ("99+"), so voice control users
|
|
41
40
|
// can say what they see.
|
|
42
41
|
const countText = computed(() => (unread.value > 99 ? '99+' : String(unread.value)))
|
|
43
|
-
const
|
|
42
|
+
const title = computed(() => props.label ?? t('ui.notifications.title'))
|
|
43
|
+
const triggerLabel = computed(() =>
|
|
44
|
+
unread.value ? t('ui.notifications.withUnread', { label: title.value, count: countText.value }) : title.value
|
|
45
|
+
)
|
|
44
46
|
|
|
45
47
|
const headingId = `${useId()}-heading`
|
|
46
48
|
const heading = ref<HTMLElement>()
|
|
@@ -143,9 +145,9 @@ async function finishClear() {
|
|
|
143
145
|
<template #content="{ close }">
|
|
144
146
|
<section ref="pane" :aria-labelledby="headingId" class="flex min-h-0 flex-col">
|
|
145
147
|
<div class="flex h-11 shrink-0 items-center justify-between gap-2 border-b border-black/15 pr-2 pl-4">
|
|
146
|
-
<h2 :id="headingId" ref="heading" tabindex="-1" class="font-bold outline-none">{{
|
|
148
|
+
<h2 :id="headingId" ref="heading" tabindex="-1" class="font-bold outline-none">{{ title }}</h2>
|
|
147
149
|
<Button v-if="items.length" variant="ghost" size="sm" :disabled="clearing" @click="clearAll">
|
|
148
|
-
|
|
150
|
+
{{ t('ui.notifications.clearAll') }}
|
|
149
151
|
</Button>
|
|
150
152
|
</div>
|
|
151
153
|
|
|
@@ -176,7 +178,7 @@ async function finishClear() {
|
|
|
176
178
|
v-else
|
|
177
179
|
size="sm"
|
|
178
180
|
:icon="BellOff"
|
|
179
|
-
:description="emptyText"
|
|
181
|
+
:description="emptyText ?? t('ui.notifications.empty')"
|
|
180
182
|
:class="cn(emptied && 'motion-safe:animate-empty-in')"
|
|
181
183
|
:ui="{ icon: cn('origin-top', emptied && 'motion-safe:animate-bell-wobble') }"
|
|
182
184
|
/>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { useI18n } from 'vue-i18n'
|
|
2
3
|
import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref, watch, type ComponentPublicInstance, type HTMLAttributes } from 'vue'
|
|
3
4
|
import { ToastProvider, ToastRoot, ToastViewport } from 'reka-ui'
|
|
4
5
|
import { cn } from '../../lib/cn'
|
|
@@ -44,6 +45,7 @@ export interface ToasterProps {
|
|
|
44
45
|
class?: HTMLAttributes['class']
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
const { t } = useI18n()
|
|
47
49
|
const props = withDefaults(defineProps<ToasterProps>(), {
|
|
48
50
|
position: 'bottom-right',
|
|
49
51
|
maxHeight: 320,
|
|
@@ -345,7 +347,7 @@ const positions = {
|
|
|
345
347
|
|
|
346
348
|
<template>
|
|
347
349
|
<!-- label: said before each toast. The viewport's label names the area F8 jumps to. -->
|
|
348
|
-
<ToastProvider swipe-direction="right" label="
|
|
350
|
+
<ToastProvider swipe-direction="right" :label="t('ui.notifications.region')">
|
|
349
351
|
<ToastRoot
|
|
350
352
|
v-for="toast in rendered"
|
|
351
353
|
:key="toast.id"
|
|
@@ -379,14 +381,14 @@ const positions = {
|
|
|
379
381
|
:action="toast.item.action"
|
|
380
382
|
:compact="toast.item.compact"
|
|
381
383
|
class="shadow-md"
|
|
382
|
-
:dismiss-label="
|
|
384
|
+
:dismiss-label="t('ui.notifications.close', { title: toast.item.title })"
|
|
383
385
|
@dismiss="setOpen(toast.id, false)"
|
|
384
386
|
@action="setOpen(toast.id, false)"
|
|
385
387
|
/>
|
|
386
388
|
</ToastRoot>
|
|
387
389
|
|
|
388
390
|
<ToastViewport
|
|
389
|
-
label="
|
|
391
|
+
:label="t('ui.notifications.hotkeyRegion', { hotkey: '{hotkey}' })"
|
|
390
392
|
:style="viewportStyle"
|
|
391
393
|
:class="
|
|
392
394
|
cn(
|
|
@@ -434,11 +436,11 @@ const positions = {
|
|
|
434
436
|
@click="onMore"
|
|
435
437
|
>
|
|
436
438
|
<template v-if="hidden">
|
|
437
|
-
<span class="in-data-expanded:hidden"
|
|
438
|
-
<span class="hidden in-data-expanded:inline"
|
|
439
|
+
<span class="in-data-expanded:hidden">{{ t('ui.notifications.more', { count: layout.notInView }) }}</span>
|
|
440
|
+
<span class="hidden in-data-expanded:inline">{{ t('ui.notifications.more', { count: hidden }) }}</span>
|
|
439
441
|
</template>
|
|
440
|
-
<template v-else
|
|
441
|
-
<span class="sr-only"> notifications</span>
|
|
442
|
+
<template v-else>{{ t('ui.notifications.more', { count: layout.notInView }) }}</template>
|
|
443
|
+
<span class="sr-only"> {{ t('ui.notifications.notifications') }}</span>
|
|
442
444
|
</button>
|
|
443
445
|
</li>
|
|
444
446
|
</ToastViewport>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
|
2
|
-
import { Building2, CalendarCog, KeyRound, Layers, LockOpen, LogOut, Pencil, Trash2, UserPlus, Users } from "@lucide/vue";
|
|
2
|
+
import { Ban, Building2, CalendarCog, KeyRound, Layers, LockOpen, LogOut, Pencil, Trash2, UserPlus, Users, UsersRound, X } from "@lucide/vue";
|
|
3
3
|
import AvatarGroup from "../AvatarGroup/AvatarGroup.vue";
|
|
4
4
|
import Badge from "../Badge/Badge.vue";
|
|
5
5
|
import Button from "../Button/Button.vue";
|
|
@@ -109,3 +109,31 @@ export const WithToolbar: Story = {
|
|
|
109
109
|
</PageHeader>`,
|
|
110
110
|
}),
|
|
111
111
|
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Something before the buttons (`toolbar-start`), e.g. how many rows are
|
|
115
|
+
* ticked. Narrow the preview: actions that don't fit move into the "⋯" menu
|
|
116
|
+
* at the end, and come back as it widens.
|
|
117
|
+
*/
|
|
118
|
+
export const ToolbarWithSelection: Story = {
|
|
119
|
+
args: {
|
|
120
|
+
title: "Users",
|
|
121
|
+
description: undefined,
|
|
122
|
+
breadcrumb: undefined,
|
|
123
|
+
toolbar: [
|
|
124
|
+
{ label: "Reset password", icon: KeyRound, onSelect: () => {} },
|
|
125
|
+
{ label: "Change sign-in status", icon: Ban, onSelect: () => {} },
|
|
126
|
+
{ label: "Manage group memberships", icon: UsersRound, onSelect: () => {} },
|
|
127
|
+
{ label: "Delete users", icon: Trash2, onSelect: () => {} },
|
|
128
|
+
{ label: "Clear selection", icon: X, onSelect: () => {} },
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
render: (args) => ({
|
|
132
|
+
components: { PageHeader },
|
|
133
|
+
setup: () => ({ args }),
|
|
134
|
+
template: `
|
|
135
|
+
<PageHeader v-bind="args">
|
|
136
|
+
<template #toolbar-start>2 users selected</template>
|
|
137
|
+
</PageHeader>`,
|
|
138
|
+
}),
|
|
139
|
+
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import
|
|
2
|
+
import { useI18n } from 'vue-i18n'
|
|
3
|
+
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch, type Component, type HTMLAttributes } from 'vue'
|
|
3
4
|
import { cn } from '../../lib/cn'
|
|
4
5
|
import Breadcrumb, { type BreadcrumbItem } from '../Breadcrumb/Breadcrumb.vue'
|
|
5
6
|
import Button from '../Button/Button.vue'
|
|
7
|
+
import Menu, { type MenuItem } from '../Menu/Menu.vue'
|
|
6
8
|
|
|
7
9
|
/** One of the page's everyday actions, in the toolbar under the title. */
|
|
8
10
|
export interface PageHeaderAction {
|
|
@@ -24,12 +26,15 @@ export interface PageHeaderAction {
|
|
|
24
26
|
*
|
|
25
27
|
* `toolbar`: the everyday things people do to what the page is about (e.g.
|
|
26
28
|
* on a user: Reset password, Unblock sign-in, Delete user), as a row of quiet
|
|
27
|
-
* buttons under the title.
|
|
29
|
+
* buttons under the title. Those that don't fit go in a "⋯" Menu at its
|
|
30
|
+
* right-hand end (and come back as it widens). `toolbar-start` and `toolbar-end` slots put
|
|
31
|
+
* something before or after them, e.g. "2 users selected". Keep the one main action (Save, Add…) in the
|
|
28
32
|
* actions slot on the right; the toolbar is for the rest.
|
|
29
33
|
*
|
|
30
34
|
* Slots: badge (after the title, e.g. a Badge), description (instead of the
|
|
31
|
-
* prop, for links or formatting), actions (e.g. Buttons),
|
|
32
|
-
*
|
|
35
|
+
* prop, for links or formatting), actions (e.g. Buttons), toolbar-start and
|
|
36
|
+
* toolbar-end (in the toolbar, before and after its buttons), default
|
|
37
|
+
* (anything under, e.g. an alert or tabs).
|
|
33
38
|
*/
|
|
34
39
|
export interface PageHeaderProps {
|
|
35
40
|
/** The page's name: its h1. */
|
|
@@ -52,6 +57,7 @@ export interface PageHeaderProps {
|
|
|
52
57
|
}
|
|
53
58
|
}
|
|
54
59
|
|
|
60
|
+
const { t } = useI18n()
|
|
55
61
|
const props = withDefaults(defineProps<PageHeaderProps>(), { linkComponent: 'a' })
|
|
56
62
|
|
|
57
63
|
// Links render as links, the rest as buttons.
|
|
@@ -61,12 +67,68 @@ function as(item: PageHeaderAction) {
|
|
|
61
67
|
return 'button'
|
|
62
68
|
}
|
|
63
69
|
|
|
64
|
-
defineSlots<{
|
|
70
|
+
const slots = defineSlots<{
|
|
65
71
|
badge?(): unknown
|
|
66
72
|
description?(): unknown
|
|
67
73
|
actions?(): unknown
|
|
74
|
+
'toolbar-start'?(): unknown
|
|
75
|
+
'toolbar-end'?(): unknown
|
|
68
76
|
default?(): unknown
|
|
69
77
|
}>()
|
|
78
|
+
|
|
79
|
+
const hasToolbar = computed(() => !!props.toolbar?.length || !!slots['toolbar-start'] || !!slots['toolbar-end'])
|
|
80
|
+
|
|
81
|
+
// ── Toolbar overflow ────────────────────────────────────────────────────────
|
|
82
|
+
// A hidden copy of every button is measured; as many as fit are shown, and
|
|
83
|
+
// the rest go in the "⋯" Menu (whose width is kept free for it).
|
|
84
|
+
const fitArea = ref<HTMLElement>()
|
|
85
|
+
const measure = ref<HTMLElement>()
|
|
86
|
+
const shown = ref(Infinity)
|
|
87
|
+
|
|
88
|
+
function fit() {
|
|
89
|
+
const area = fitArea.value
|
|
90
|
+
const copy = measure.value
|
|
91
|
+
const items = props.toolbar ?? []
|
|
92
|
+
if (!area || !copy || !items.length) return
|
|
93
|
+
const buttons = Array.from(copy.children) as HTMLElement[]
|
|
94
|
+
const more = buttons.pop()! // the ⋯ button, last in the copy
|
|
95
|
+
const gap = parseFloat(getComputedStyle(copy).columnGap) || 0
|
|
96
|
+
const widths = buttons.map((b) => b.getBoundingClientRect().width)
|
|
97
|
+
const available = area.clientWidth
|
|
98
|
+
const all = widths.reduce((sum, w) => sum + w, 0) + gap * Math.max(widths.length - 1, 0)
|
|
99
|
+
if (all <= available) {
|
|
100
|
+
shown.value = items.length
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
let used = more.getBoundingClientRect().width
|
|
104
|
+
let n = 0
|
|
105
|
+
while (n < widths.length && used + gap + widths[n]! <= available) used += gap + widths[n++]!
|
|
106
|
+
shown.value = n
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Watched for size changes whenever it's there: the toolbar may only appear
|
|
110
|
+
// after the page has loaded (e.g. once its actions arrive).
|
|
111
|
+
let observer: ResizeObserver | undefined
|
|
112
|
+
onMounted(() => {
|
|
113
|
+
observer = new ResizeObserver(() => fit())
|
|
114
|
+
if (fitArea.value) observer.observe(fitArea.value)
|
|
115
|
+
fit()
|
|
116
|
+
})
|
|
117
|
+
watch(fitArea, (el, old) => {
|
|
118
|
+
if (old) observer?.unobserve(old)
|
|
119
|
+
if (el) {
|
|
120
|
+
observer?.observe(el)
|
|
121
|
+
nextTick(fit)
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
onBeforeUnmount(() => observer?.disconnect())
|
|
125
|
+
watch(
|
|
126
|
+
() => props.toolbar?.map((i) => `${i.label}${i.disabled ? '-' : ''}`).join('|'),
|
|
127
|
+
() => nextTick(fit),
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
const visible = computed(() => (props.toolbar ?? []).slice(0, shown.value))
|
|
131
|
+
const overflow = computed<MenuItem[]>(() => (props.toolbar ?? []).slice(shown.value))
|
|
70
132
|
</script>
|
|
71
133
|
|
|
72
134
|
<template>
|
|
@@ -90,26 +152,50 @@ defineSlots<{
|
|
|
90
152
|
</div>
|
|
91
153
|
</div>
|
|
92
154
|
|
|
93
|
-
<!-- Ghost buttons in a white bar, like a Card
|
|
155
|
+
<!-- Ghost buttons in a white bar, like a Card; those that don't fit go
|
|
156
|
+
in the ⋯ Menu at the end. -->
|
|
94
157
|
<div
|
|
95
|
-
v-if="
|
|
158
|
+
v-if="hasToolbar"
|
|
96
159
|
role="group"
|
|
97
|
-
:aria-label="
|
|
98
|
-
:class="cn('flex
|
|
160
|
+
:aria-label="t('ui.pageHeader.actions', { title })"
|
|
161
|
+
:class="cn('flex items-center gap-1 rounded-lg border border-black/15 bg-white p-1', ui?.toolbar)"
|
|
99
162
|
>
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
163
|
+
<!-- Text here reads as the toolbar's own: bold, spaced like a button. -->
|
|
164
|
+
<div v-if="$slots['toolbar-start']" class="flex shrink-0 items-center gap-2 px-3 text-sm font-bold" aria-live="polite">
|
|
165
|
+
<slot name="toolbar-start" />
|
|
166
|
+
</div>
|
|
167
|
+
<div ref="fitArea" class="relative flex min-w-0 flex-1 items-center gap-1">
|
|
168
|
+
<Button
|
|
169
|
+
v-for="item in visible"
|
|
170
|
+
:key="item.label"
|
|
171
|
+
:as="as(item)"
|
|
172
|
+
:to="item.to"
|
|
173
|
+
:href="item.href"
|
|
174
|
+
variant="ghost"
|
|
175
|
+
:disabled="item.disabled"
|
|
176
|
+
class="shrink-0"
|
|
177
|
+
@click="item.onSelect?.()"
|
|
178
|
+
>
|
|
179
|
+
<template v-if="item.icon" #leading><component :is="item.icon" aria-hidden="true" /></template>
|
|
180
|
+
{{ item.label }}
|
|
181
|
+
</Button>
|
|
182
|
+
<!-- Always at the right-hand end. -->
|
|
183
|
+
<Menu v-if="overflow.length" :items="overflow" :label="t('ui.pageHeader.moreActions')" :link-component="linkComponent" class="ml-auto shrink-0" />
|
|
184
|
+
|
|
185
|
+
<!-- For measuring only: every button, and the ⋯ one, at full width. -->
|
|
186
|
+
<div aria-hidden="true" inert class="invisible absolute top-0 left-0 size-0 overflow-hidden">
|
|
187
|
+
<div ref="measure" class="flex w-max gap-1">
|
|
188
|
+
<Button v-for="item in toolbar" :key="item.label" variant="ghost" tabindex="-1" class="shrink-0">
|
|
189
|
+
<template v-if="item.icon" #leading><component :is="item.icon" /></template>
|
|
190
|
+
{{ item.label }}
|
|
191
|
+
</Button>
|
|
192
|
+
<Button variant="ghost" square tabindex="-1" class="shrink-0"><span /></Button>
|
|
193
|
+
</div>
|
|
194
|
+
</div>
|
|
195
|
+
</div>
|
|
196
|
+
<div v-if="$slots['toolbar-end']" class="flex shrink-0 items-center gap-2 px-3 text-sm">
|
|
197
|
+
<slot name="toolbar-end" />
|
|
198
|
+
</div>
|
|
113
199
|
</div>
|
|
114
200
|
|
|
115
201
|
<slot />
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { useI18n } from 'vue-i18n'
|
|
2
3
|
import { computed, type HTMLAttributes } from 'vue'
|
|
3
4
|
import { ProgressIndicator, ProgressRoot } from 'reka-ui'
|
|
4
5
|
import { cn } from '../../lib/cn'
|
|
@@ -23,6 +24,7 @@ export interface ProgressProps {
|
|
|
23
24
|
class?: HTMLAttributes['class']
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
const { t } = useI18n()
|
|
26
28
|
const props = withDefaults(defineProps<ProgressProps>(), {
|
|
27
29
|
value: null,
|
|
28
30
|
max: 100
|
|
@@ -38,7 +40,7 @@ const valueText = () =>
|
|
|
38
40
|
indeterminate.value
|
|
39
41
|
? undefined
|
|
40
42
|
: props.segments
|
|
41
|
-
?
|
|
43
|
+
? t('ui.progress.stepOf', { current: clamped.value, total: props.max })
|
|
42
44
|
: `${Math.round(percent.value)}%`
|
|
43
45
|
|
|
44
46
|
const track = 'h-1.5 overflow-hidden rounded-full bg-black/10'
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { useI18n } from 'vue-i18n'
|
|
2
3
|
import { computed, useId, type HTMLAttributes } from 'vue'
|
|
3
4
|
import { RadioGroupIndicator, RadioGroupItem, RadioGroupRoot } from 'reka-ui'
|
|
4
5
|
import { cn } from '../../lib/cn'
|
|
@@ -37,6 +38,7 @@ export interface RadioGroupProps {
|
|
|
37
38
|
class?: HTMLAttributes['class']
|
|
38
39
|
}
|
|
39
40
|
|
|
41
|
+
const { t } = useI18n()
|
|
40
42
|
const props = withDefaults(defineProps<RadioGroupProps>(), {
|
|
41
43
|
helperPlacement: 'below'
|
|
42
44
|
})
|
|
@@ -78,7 +80,7 @@ const circle = [
|
|
|
78
80
|
<div class="flex flex-col gap-0.5">
|
|
79
81
|
<div class="flex items-center gap-1">
|
|
80
82
|
<span :id="labelId" class="text-sm">{{ label }}</span>
|
|
81
|
-
<InfoTip v-if="helper && helperPlacement === 'icon'" :text="helper" :label="
|
|
83
|
+
<InfoTip v-if="helper && helperPlacement === 'icon'" :text="helper" :label="t('ui.formField.about', { label })" />
|
|
82
84
|
</div>
|
|
83
85
|
<!-- Behind the ?: hidden, but still the group's description. -->
|
|
84
86
|
<p v-if="helper" :id="helperId" :hidden="helperPlacement === 'icon'" class="text-xs text-black/65">
|