@thekestongroup/ui 0.7.0 → 0.9.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.
Files changed (68) hide show
  1. package/dist/components/Breadcrumb/Breadcrumb.vue.d.ts +0 -1
  2. package/dist/components/Checkbox/Checkbox.vue.d.ts +2 -0
  3. package/dist/components/CheckboxGroup/CheckboxGroup.vue.d.ts +45 -0
  4. package/dist/components/Chip/Chip.vue.d.ts +0 -1
  5. package/dist/components/Header/Header.vue.d.ts +0 -1
  6. package/dist/components/InputDate/InputDate.vue.d.ts +1 -1
  7. package/dist/components/InputTextArea/InputTextArea.vue.d.ts +49 -0
  8. package/dist/components/LanguageSwitcher/LanguageSwitcher.vue.d.ts +24 -0
  9. package/dist/components/Notification/NotificationPane.vue.d.ts +1 -4
  10. package/dist/components/Select/Select.vue.d.ts +0 -1
  11. package/dist/components/SettingsRow/SettingsRow.vue.d.ts +28 -0
  12. package/dist/components/Sidebar/Sidebar.vue.d.ts +0 -1
  13. package/dist/components/Slideover/Slideover.vue.d.ts +0 -1
  14. package/dist/components/Spinner/Spinner.vue.d.ts +0 -1
  15. package/dist/components/Steps/Steps.vue.d.ts +20 -0
  16. package/dist/components/Switch/Switch.vue.d.ts +2 -0
  17. package/dist/components/Table/Table.vue.d.ts +21 -1
  18. package/dist/i18n/en.d.ts +146 -0
  19. package/dist/i18n/index.d.ts +32 -0
  20. package/dist/index.d.ts +12 -0
  21. package/dist/keston-ui.js +2200 -1694
  22. package/package.json +4 -2
  23. package/src/components/Age/Age.vue +4 -2
  24. package/src/components/AppShell/AppShell.vue +4 -2
  25. package/src/components/AvatarGroup/AvatarGroup.vue +4 -2
  26. package/src/components/Breadcrumb/Breadcrumb.vue +3 -2
  27. package/src/components/Calendar/Calendar.vue +8 -6
  28. package/src/components/Card/Card.vue +3 -1
  29. package/src/components/Checkbox/Checkbox.stories.ts +3 -0
  30. package/src/components/Checkbox/Checkbox.vue +3 -1
  31. package/src/components/CheckboxGroup/CheckboxGroup.stories.ts +48 -0
  32. package/src/components/CheckboxGroup/CheckboxGroup.vue +96 -0
  33. package/src/components/Chip/Chip.vue +3 -2
  34. package/src/components/FormField/FormField.vue +3 -1
  35. package/src/components/Header/Header.vue +6 -5
  36. package/src/components/Input/Input.vue +4 -2
  37. package/src/components/InputCode/InputCode.vue +4 -2
  38. package/src/components/InputDate/InputDate.vue +4 -2
  39. package/src/components/InputPassword/InputPassword.vue +4 -2
  40. package/src/components/InputRichText/InputRichText.vue +6 -4
  41. package/src/components/InputTextArea/InputTextArea.stories.ts +53 -0
  42. package/src/components/InputTextArea/InputTextArea.vue +89 -0
  43. package/src/components/LanguageSwitcher/LanguageSwitcher.stories.ts +21 -0
  44. package/src/components/LanguageSwitcher/LanguageSwitcher.vue +57 -0
  45. package/src/components/Link/Link.vue +1 -0
  46. package/src/components/Notification/Notification.vue +3 -1
  47. package/src/components/Notification/NotificationPane.vue +10 -8
  48. package/src/components/Notification/Toaster.vue +9 -7
  49. package/src/components/PageHeader/PageHeader.vue +13 -2
  50. package/src/components/Progress/Progress.vue +3 -1
  51. package/src/components/RadioGroup/RadioGroup.vue +3 -1
  52. package/src/components/Select/Select.vue +6 -5
  53. package/src/components/SettingsRow/SettingsRow.stories.ts +59 -0
  54. package/src/components/SettingsRow/SettingsRow.vue +39 -0
  55. package/src/components/Sidebar/Sidebar.vue +5 -4
  56. package/src/components/Slideover/Slideover.vue +8 -7
  57. package/src/components/Spinner/Spinner.vue +4 -3
  58. package/src/components/StatTile/StatTile.vue +3 -1
  59. package/src/components/Steps/Steps.stories.ts +38 -0
  60. package/src/components/Steps/Steps.vue +38 -0
  61. package/src/components/SummaryList/SummaryList.vue +5 -4
  62. package/src/components/Switch/Switch.vue +3 -1
  63. package/src/components/Table/Table.stories.ts +34 -0
  64. package/src/components/Table/Table.vue +120 -15
  65. package/src/i18n/en.ts +127 -0
  66. package/src/i18n/i18n.test.ts +56 -0
  67. package/src/i18n/index.ts +89 -0
  68. 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>
@@ -42,6 +42,7 @@ const base = [
42
42
  <Primitive
43
43
  :as="as"
44
44
  :href="href"
45
+ :type="as === 'button' ? 'button' : undefined"
45
46
  :target="newTab ? '_blank' : undefined"
46
47
  :rel="newTab ? 'noopener noreferrer' : undefined"
47
48
  :class="cn(base, props.class)"
@@ -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 ?? `Dismiss: ${title}`"
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 props = withDefaults(defineProps<NotificationPaneProps>(), {
31
- label: 'Notifications',
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 triggerLabel = computed(() => (unread.value ? `${props.label}, ${countText.value} unread` : props.label))
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">{{ label }}</h2>
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
- Clear all
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="Notification">
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="`Close: ${toast.item.title}`"
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="Notifications ({hotkey})"
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">+{{ layout.notInView }} more</span>
438
- <span class="hidden in-data-expanded:inline">+{{ hidden }} more</span>
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>+{{ layout.notInView }} more</template>
441
- <span class="sr-only">&nbsp;notifications</span>
442
+ <template v-else>{{ t('ui.notifications.more', { count: layout.notInView }) }}</template>
443
+ <span class="sr-only">&nbsp;{{ t('ui.notifications.notifications') }}</span>
442
444
  </button>
443
445
  </li>
444
446
  </ToastViewport>
@@ -1,4 +1,5 @@
1
1
  <script setup lang="ts">
2
+ import { useI18n } from 'vue-i18n'
2
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'
@@ -56,6 +57,7 @@ export interface PageHeaderProps {
56
57
  }
57
58
  }
58
59
 
60
+ const { t } = useI18n()
59
61
  const props = withDefaults(defineProps<PageHeaderProps>(), { linkComponent: 'a' })
60
62
 
61
63
  // Links render as links, the rest as buttons.
@@ -104,12 +106,21 @@ function fit() {
104
106
  shown.value = n
105
107
  }
106
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).
107
111
  let observer: ResizeObserver | undefined
108
112
  onMounted(() => {
109
113
  observer = new ResizeObserver(() => fit())
110
114
  if (fitArea.value) observer.observe(fitArea.value)
111
115
  fit()
112
116
  })
117
+ watch(fitArea, (el, old) => {
118
+ if (old) observer?.unobserve(old)
119
+ if (el) {
120
+ observer?.observe(el)
121
+ nextTick(fit)
122
+ }
123
+ })
113
124
  onBeforeUnmount(() => observer?.disconnect())
114
125
  watch(
115
126
  () => props.toolbar?.map((i) => `${i.label}${i.disabled ? '-' : ''}`).join('|'),
@@ -146,7 +157,7 @@ const overflow = computed<MenuItem[]>(() => (props.toolbar ?? []).slice(shown.va
146
157
  <div
147
158
  v-if="hasToolbar"
148
159
  role="group"
149
- :aria-label="`${title} actions`"
160
+ :aria-label="t('ui.pageHeader.actions', { title })"
150
161
  :class="cn('flex items-center gap-1 rounded-lg border border-black/15 bg-white p-1', ui?.toolbar)"
151
162
  >
152
163
  <!-- Text here reads as the toolbar's own: bold, spaced like a button. -->
@@ -169,7 +180,7 @@ const overflow = computed<MenuItem[]>(() => (props.toolbar ?? []).slice(shown.va
169
180
  {{ item.label }}
170
181
  </Button>
171
182
  <!-- Always at the right-hand end. -->
172
- <Menu v-if="overflow.length" :items="overflow" label="More actions" :link-component="linkComponent" class="ml-auto shrink-0" />
183
+ <Menu v-if="overflow.length" :items="overflow" :label="t('ui.pageHeader.moreActions')" :link-component="linkComponent" class="ml-auto shrink-0" />
173
184
 
174
185
  <!-- For measuring only: every button, and the ⋯ one, at full width. -->
175
186
  <div aria-hidden="true" inert class="invisible absolute top-0 left-0 size-0 overflow-hidden">
@@ -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
- ? `Step ${clamped.value} of ${props.max}`
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="`About ${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">
@@ -1,4 +1,5 @@
1
1
  <script setup lang="ts">
2
+ import { useI18n } from 'vue-i18n'
2
3
  import { computed, nextTick, onBeforeUnmount, onMounted, ref, useId, type Component, type HTMLAttributes } from 'vue'
3
4
  import {
4
5
  ComboboxAnchor,
@@ -119,10 +120,10 @@ export interface SelectProps {
119
120
  class?: HTMLAttributes['class']
120
121
  }
121
122
 
123
+ const { t } = useI18n()
122
124
  const props = withDefaults(defineProps<SelectProps>(), {
123
125
  options: () => [],
124
126
  groups: () => [],
125
- emptyText: 'No matches',
126
127
  helperPlacement: 'below'
127
128
  })
128
129
 
@@ -162,7 +163,7 @@ function setValue(next: unknown) {
162
163
  if (props.searchable) nextTick(() => searchInput.value?.$el?.select?.())
163
164
  }
164
165
 
165
- const placeholderText = computed(() => props.placeholder ?? (props.searchable ? 'Search…' : 'Choose…'))
166
+ const placeholderText = computed(() => props.placeholder ?? (props.searchable ? t('ui.select.search') : t('ui.select.choose')))
166
167
 
167
168
  const toOption = (option: SelectOption | string): SelectOption =>
168
169
  typeof option === 'string' ? { label: option, value: option } : { ...option, value: option.value ?? option.label }
@@ -477,7 +478,7 @@ const chevron = 'transition-transform duration-150 in-data-[state=open]:rotate-1
477
478
  :key="String(option.value)"
478
479
  size="sm"
479
480
  removable
480
- :remove-label="`Remove ${option.label}`"
481
+ :remove-label="t('ui.select.remove', { name: option.label })"
481
482
  :remove-focusable="false"
482
483
  :disabled="disabled"
483
484
  @pointerdown.stop
@@ -503,7 +504,7 @@ const chevron = 'transition-transform duration-150 in-data-[state=open]:rotate-1
503
504
  @keydown.backspace="onSearchBackspace"
504
505
  />
505
506
  </span>
506
- <ComboboxTrigger tabindex="-1" aria-label="Show options" class="flex cursor-pointer disabled:cursor-not-allowed">
507
+ <ComboboxTrigger tabindex="-1" :aria-label="t('ui.select.showOptions')" class="flex cursor-pointer disabled:cursor-not-allowed">
507
508
  <ChevronDown aria-hidden="true" :class="chevron" />
508
509
  </ComboboxTrigger>
509
510
  </ComboboxAnchor>
@@ -555,7 +556,7 @@ const chevron = 'transition-transform duration-150 in-data-[state=open]:rotate-1
555
556
  class="flex flex-col gap-0.5 p-1 [scrollbar-width:thin]! [&::-webkit-scrollbar]:block!"
556
557
  >
557
558
  <ComboboxEmpty v-if="searchable" class="px-2 py-1.5 text-sm text-black/65">
558
- {{ emptyText }}
559
+ {{ emptyText ?? t('ui.select.noMatches') }}
559
560
  </ComboboxEmpty>
560
561
 
561
562
  <!-- Inside a nested option: back to the level above. -->
@@ -0,0 +1,59 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import { ref } from "vue";
3
+ import SettingsRow from "./SettingsRow.vue";
4
+ import Card from "../Card/Card.vue";
5
+ import Select from "../Select/Select.vue";
6
+ import InputNumber from "../InputNumber/InputNumber.vue";
7
+ import Switch from "../Switch/Switch.vue";
8
+ import Divider from "../Divider/Divider.vue";
9
+
10
+ const meta = {
11
+ title: "Components/Layout/SettingsRow",
12
+ component: SettingsRow,
13
+ tags: ["autodocs"],
14
+ args: {
15
+ label: "Multi-factor authentication",
16
+ description: "Recommended for security. All users must verify with a second factor when they sign in.",
17
+ },
18
+ decorators: [() => ({ template: '<div class="max-w-3xl"><story /></div>' })],
19
+ render: (args) => ({
20
+ components: { SettingsRow, Select },
21
+ setup: () => ({ args, mode: ref("required") }),
22
+ template: `
23
+ <SettingsRow v-bind="args">
24
+ <Select v-model="mode" :label="args.label" hide-label :options="[
25
+ { label: 'Off', value: 'off' },
26
+ { label: 'Require MFA', value: 'required' },
27
+ { label: 'Custom rules', value: 'custom' },
28
+ ]" />
29
+ </SettingsRow>`,
30
+ }),
31
+ } satisfies Meta<typeof SettingsRow>;
32
+
33
+ export default meta;
34
+ type Story = StoryObj<typeof meta>;
35
+
36
+ /** Label and description on the left, the control on the right. It stacks on narrow screens. */
37
+ export const Default: Story = {};
38
+
39
+ /** Several settings in a Card, with a Divider between them. */
40
+ export const InACard: Story = {
41
+ render: () => ({
42
+ components: { SettingsRow, Select, InputNumber, Switch, Card, Divider },
43
+ setup: () => ({ mode: ref("required"), days: ref(14), everyone: ref(true) }),
44
+ template: `
45
+ <Card class="flex flex-col gap-6 p-6">
46
+ <SettingsRow label="Multi-factor authentication" description="All users must verify with a second factor when they sign in.">
47
+ <Select v-model="mode" label="Multi-factor authentication" hide-label :options="[{ label: 'Off', value: 'off' }, { label: 'Require MFA', value: 'required' }]" />
48
+ </SettingsRow>
49
+ <Divider />
50
+ <SettingsRow label="Grace period" description="How many days people have to set it up before it's enforced.">
51
+ <InputNumber v-model="days" label="Grace period" hide-label :min="0" :max="90" />
52
+ </SettingsRow>
53
+ <Divider />
54
+ <SettingsRow label="Remind people" description="Show a reminder each time they sign in during the grace period.">
55
+ <Switch v-model="everyone" label="Remind people" hide-label />
56
+ </SettingsRow>
57
+ </Card>`,
58
+ }),
59
+ };
@@ -0,0 +1,39 @@
1
+ <script setup lang="ts">
2
+ import type { HTMLAttributes } from 'vue'
3
+ import { cn } from '../../lib/cn'
4
+
5
+ /**
6
+ * One setting on a settings page: what it is and what it does on the left,
7
+ * the control that changes it on the right (it stacks, label first, on narrow
8
+ * screens). Put a Select, InputNumber, Switch, Input… in the default slot and
9
+ * give it the same label with `hide-label`, so the label is only said once.
10
+ * Stack rows inside a Card, with a Divider between them if there are several.
11
+ */
12
+ export interface SettingsRowProps {
13
+ /** What the setting is called, e.g. "Multi-factor authentication". */
14
+ label: string
15
+ /** What it does, in smaller text under the label. */
16
+ description?: string
17
+ class?: HTMLAttributes['class']
18
+ }
19
+
20
+ const props = defineProps<SettingsRowProps>()
21
+
22
+ defineSlots<{
23
+ /** The control. */
24
+ default(): unknown
25
+ }>()
26
+ </script>
27
+
28
+ <template>
29
+ <div :class="cn('flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between sm:gap-6', props.class)">
30
+ <div class="flex min-w-0 flex-col gap-0.5">
31
+ <!-- The control has this name too (hide-label), so it isn't read twice. -->
32
+ <p class="text-sm" aria-hidden="true">{{ label }}</p>
33
+ <p v-if="description" class="text-xs text-black/65">{{ description }}</p>
34
+ </div>
35
+ <div class="w-full shrink-0 sm:w-80">
36
+ <slot />
37
+ </div>
38
+ </div>
39
+ </template>
@@ -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 Component, type HTMLAttributes } from 'vue'
3
4
  import { ChevronLeft, ChevronRight, PanelLeftClose, PanelLeftOpen } from '@lucide/vue'
4
5
  import { cn } from '../../lib/cn'
@@ -73,10 +74,10 @@ export interface SidebarProps {
73
74
  }
74
75
  }
75
76
 
77
+ const { t } = useI18n()
76
78
  const props = withDefaults(defineProps<SidebarProps>(), {
77
79
  items: () => [],
78
80
  sections: () => [],
79
- label: 'Main',
80
81
  collapsible: false,
81
82
  linkComponent: 'a'
82
83
  })
@@ -276,7 +277,7 @@ const itemActiveParent = 'font-bold text-primary'
276
277
 
277
278
  <nav
278
279
  ref="navRef"
279
- :aria-label="label"
280
+ :aria-label="label ?? t('ui.sidebar.main')"
280
281
  :class="cn(
281
282
  'relative flex-1 overflow-x-hidden overflow-y-auto p-2 [scrollbar-width:thin]',
282
283
  // Collapsed, a scrollbar would take a third of the 40px strip and cut
@@ -293,7 +294,7 @@ const itemActiveParent = 'font-bold text-primary'
293
294
  <button
294
295
  type="button"
295
296
  data-back
296
- :title="collapsed ? `Back from ${current.label}` : undefined"
297
+ :title="collapsed ? t('ui.sidebar.backFrom', { name: current.label }) : undefined"
297
298
  :class="cn(itemBase, 'font-bold', ui?.item)"
298
299
  @click="goBack"
299
300
  >
@@ -369,7 +370,7 @@ const itemActiveParent = 'font-bold text-primary'
369
370
  v-if="collapsible"
370
371
  variant="ghost"
371
372
  square
372
- :aria-label="collapsed ? 'Expand sidebar' : 'Collapse sidebar'"
373
+ :aria-label="collapsed ? t('ui.sidebar.expand') : t('ui.sidebar.collapse')"
373
374
  :aria-expanded="!collapsed"
374
375
  class="self-start"
375
376
  @click="collapsed = !collapsed"