@thekestongroup/ui 0.7.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/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 +2189 -1691
- 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.vue +13 -2
- 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
|
@@ -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 {
|
|
4
5
|
DialogClose,
|
|
@@ -86,6 +87,7 @@ export interface SlideoverProps {
|
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
|
|
90
|
+
const { t } = useI18n()
|
|
89
91
|
const props = withDefaults(defineProps<SlideoverProps>(), {
|
|
90
92
|
side: 'right',
|
|
91
93
|
overlay: true,
|
|
@@ -93,8 +95,7 @@ const props = withDefaults(defineProps<SlideoverProps>(), {
|
|
|
93
95
|
dismissible: true,
|
|
94
96
|
modal: true,
|
|
95
97
|
portal: true,
|
|
96
|
-
initialFocus: 'none'
|
|
97
|
-
finishLabel: 'Finish'
|
|
98
|
+
initialFocus: 'none'
|
|
98
99
|
})
|
|
99
100
|
|
|
100
101
|
const emit = defineEmits<{
|
|
@@ -144,7 +145,7 @@ const nextStatus = ref<ButtonStatus>('idle')
|
|
|
144
145
|
// - otherwise (Next / Previous buttons, touch screens): the same words are
|
|
145
146
|
// announced. Never both, so it isn't read twice.
|
|
146
147
|
const stepLabelId = `${useId()}-step`
|
|
147
|
-
const stepText = computed(() => (props.steps ?
|
|
148
|
+
const stepText = computed(() => (props.steps ? t('ui.slideover.stepOf', { current: step.value + 1, total: stepCount.value, name: props.steps[step.value] }) : ''))
|
|
148
149
|
const announcement = ref('')
|
|
149
150
|
const body = ref<HTMLElement>()
|
|
150
151
|
|
|
@@ -294,7 +295,7 @@ const panel = [
|
|
|
294
295
|
v-if="title || description || close || steps || $slots.header || $slots.title"
|
|
295
296
|
:class="cn('flex flex-col gap-4 border-b border-black/15 px-6 py-4', ui?.header)"
|
|
296
297
|
>
|
|
297
|
-
<Progress v-if="steps" :label="title ?? '
|
|
298
|
+
<Progress v-if="steps" :label="title ?? t('ui.slideover.steps')" segments :value="step + 1" :max="stepCount" />
|
|
298
299
|
<div class="flex items-start gap-4">
|
|
299
300
|
<slot name="header" :close="closePanel">
|
|
300
301
|
<div class="flex min-w-0 flex-1 flex-col gap-1">
|
|
@@ -318,7 +319,7 @@ const panel = [
|
|
|
318
319
|
<!-- A ghost icon Button; the negative margins keep it from making
|
|
319
320
|
the header taller and line its icon up with the panel edge. -->
|
|
320
321
|
<DialogClose v-if="close" as-child>
|
|
321
|
-
<Button variant="ghost" square aria-label="
|
|
322
|
+
<Button variant="ghost" square :aria-label="t('ui.slideover.close')" class="-my-1.5 -mr-3 shrink-0">
|
|
322
323
|
<X />
|
|
323
324
|
</Button>
|
|
324
325
|
</DialogClose>
|
|
@@ -350,10 +351,10 @@ const panel = [
|
|
|
350
351
|
@click="step === 0 ? closePanel() : goTo(step - 1)"
|
|
351
352
|
>
|
|
352
353
|
<template v-if="step > 0" #leading><ChevronLeft /></template>
|
|
353
|
-
{{ step === 0 ? '
|
|
354
|
+
{{ step === 0 ? t('ui.slideover.cancel') : t('ui.slideover.previous') }}
|
|
354
355
|
</Button>
|
|
355
356
|
<Button variant="primary" :status="nextStatus" @click="next">
|
|
356
|
-
{{ isLastStep ? finishLabel : '
|
|
357
|
+
{{ isLastStep ? (finishLabel ?? t('ui.slideover.finish')) : t('ui.slideover.next') }}
|
|
357
358
|
<template v-if="!isLastStep" #trailing><ChevronRight /></template>
|
|
358
359
|
</Button>
|
|
359
360
|
</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 { ProgressRoot } from 'reka-ui'
|
|
4
5
|
import { cn } from '../../lib/cn'
|
|
@@ -26,10 +27,10 @@ export interface SpinnerProps {
|
|
|
26
27
|
class?: HTMLAttributes['class']
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
const { t } = useI18n()
|
|
29
31
|
const props = withDefaults(defineProps<SpinnerProps>(), {
|
|
30
32
|
max: 100,
|
|
31
|
-
size: 'md'
|
|
32
|
-
label: 'Loading'
|
|
33
|
+
size: 'md'
|
|
33
34
|
})
|
|
34
35
|
|
|
35
36
|
const indeterminate = computed(() => props.value === null || props.value === undefined)
|
|
@@ -57,7 +58,7 @@ const sizes: Record<NonNullable<SpinnerProps['size']>, string> = {
|
|
|
57
58
|
as="span"
|
|
58
59
|
:model-value="indeterminate ? null : fraction * max"
|
|
59
60
|
:max="max"
|
|
60
|
-
:aria-label="label"
|
|
61
|
+
:aria-label="label ?? t('ui.spinner.loading')"
|
|
61
62
|
:class="cn('relative inline-flex shrink-0 items-center justify-center', sizes[size], props.class)"
|
|
62
63
|
>
|
|
63
64
|
<svg
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { useI18n } from 'vue-i18n'
|
|
2
3
|
import { computed, type Component, type HTMLAttributes } from 'vue'
|
|
3
4
|
import { ArrowDownRight, ArrowRight, ArrowUpRight } from '@lucide/vue'
|
|
4
5
|
import { cn } from '../../lib/cn'
|
|
@@ -36,6 +37,7 @@ export interface StatTileProps {
|
|
|
36
37
|
class?: HTMLAttributes['class']
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
const { t } = useI18n()
|
|
39
41
|
const props = defineProps<StatTileProps>()
|
|
40
42
|
|
|
41
43
|
defineSlots<{
|
|
@@ -56,7 +58,7 @@ const trendIcon = computed(() =>
|
|
|
56
58
|
props.trend === 'up' ? ArrowUpRight : props.trend === 'down' ? ArrowDownRight : props.trend === 'flat' ? ArrowRight : undefined
|
|
57
59
|
)
|
|
58
60
|
// The arrow is decorative, so say the direction in words for screen readers.
|
|
59
|
-
const trendWords = { up: '
|
|
61
|
+
const trendWords = computed(() => ({ up: t('ui.statTile.up'), down: t('ui.statTile.down'), flat: t('ui.statTile.flat') }))
|
|
60
62
|
</script>
|
|
61
63
|
|
|
62
64
|
<template>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
|
2
|
+
import { ref } from "vue";
|
|
3
|
+
import Steps from "./Steps.vue";
|
|
4
|
+
import Button from "../Button/Button.vue";
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: "Components/Navigation/Steps",
|
|
8
|
+
component: Steps,
|
|
9
|
+
tags: ["autodocs"],
|
|
10
|
+
args: {
|
|
11
|
+
label: "Add a user",
|
|
12
|
+
steps: ["User info", "Licences", "Confirmation"],
|
|
13
|
+
step: 1,
|
|
14
|
+
},
|
|
15
|
+
argTypes: { step: { control: { type: "number", min: 0, max: 2 } } },
|
|
16
|
+
decorators: [() => ({ template: '<div class="max-w-120"><story /></div>' })],
|
|
17
|
+
} satisfies Meta<typeof Steps>;
|
|
18
|
+
|
|
19
|
+
export default meta;
|
|
20
|
+
type Story = StoryObj<typeof meta>;
|
|
21
|
+
|
|
22
|
+
export const Default: Story = {};
|
|
23
|
+
|
|
24
|
+
/** Drive it from Previous and Next buttons. The words are announced as the step changes. */
|
|
25
|
+
export const WithButtons: Story = {
|
|
26
|
+
render: (args) => ({
|
|
27
|
+
components: { Steps, Button },
|
|
28
|
+
setup: () => ({ args, step: ref(0) }),
|
|
29
|
+
template: `
|
|
30
|
+
<div class="flex flex-col gap-6">
|
|
31
|
+
<Steps v-bind="args" :step="step" />
|
|
32
|
+
<div class="flex gap-2">
|
|
33
|
+
<Button :disabled="step === 0" @click="step--">Previous</Button>
|
|
34
|
+
<Button variant="primary" :disabled="step === args.steps.length - 1" @click="step++">Next</Button>
|
|
35
|
+
</div>
|
|
36
|
+
</div>`,
|
|
37
|
+
}),
|
|
38
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { HTMLAttributes } from 'vue'
|
|
3
|
+
import { I18nT } from 'vue-i18n'
|
|
4
|
+
import { cn } from '../../lib/cn'
|
|
5
|
+
import Progress from '../Progress/Progress.vue'
|
|
6
|
+
|
|
7
|
+
/**
|
|
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" under it. Put it at the top of
|
|
10
|
+
* a multi-step form. (Slideover's `steps` shows one for you; use this when
|
|
11
|
+
* the steps are on a page, or in a Slideover you drive yourself.) The words
|
|
12
|
+
* are announced when the step changes.
|
|
13
|
+
*/
|
|
14
|
+
export interface StepsProps {
|
|
15
|
+
/** The name of each step, in order, e.g. `['User info', 'Licences']`. */
|
|
16
|
+
steps: string[]
|
|
17
|
+
/** The current step, counting from 0. */
|
|
18
|
+
step: number
|
|
19
|
+
/** What the steps are for, e.g. "Add a user". The progress bar's accessible name; not shown. */
|
|
20
|
+
label: string
|
|
21
|
+
class?: HTMLAttributes['class']
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const props = defineProps<StepsProps>()
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<template>
|
|
28
|
+
<div :class="cn('flex flex-col gap-3', props.class)">
|
|
29
|
+
<Progress :label="label" segments :value="step + 1" :max="steps.length" />
|
|
30
|
+
<p class="text-sm text-black/65" aria-live="polite">
|
|
31
|
+
<I18nT keypath="ui.steps.stepOfNamed" scope="global" tag="span">
|
|
32
|
+
<template #current>{{ step + 1 }}</template>
|
|
33
|
+
<template #total>{{ steps.length }}</template>
|
|
34
|
+
<template #name><span class="text-black">{{ steps[step] }}</span></template>
|
|
35
|
+
</I18nT>
|
|
36
|
+
</p>
|
|
37
|
+
</div>
|
|
38
|
+
</template>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts" generic="Item extends SummaryListItem">
|
|
2
|
+
import { useI18n } from 'vue-i18n'
|
|
2
3
|
import type { HTMLAttributes } from 'vue'
|
|
3
4
|
import { cn } from '../../lib/cn'
|
|
4
5
|
|
|
@@ -38,10 +39,10 @@ export interface SummaryListProps<Item extends SummaryListItem = SummaryListItem
|
|
|
38
39
|
class?: HTMLAttributes['class']
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
const { t } = useI18n()
|
|
41
43
|
const props = withDefaults(defineProps<SummaryListProps<Item>>(), {
|
|
42
44
|
layout: 'rows',
|
|
43
|
-
labelWidth: 'md'
|
|
44
|
-
emptyLabel: 'Not set'
|
|
45
|
+
labelWidth: 'md'
|
|
45
46
|
})
|
|
46
47
|
|
|
47
48
|
defineSlots<{
|
|
@@ -86,7 +87,7 @@ const labelWidths = {
|
|
|
86
87
|
<dd :class="cn('min-w-0 break-words', item.emphasis && 'font-bold', !$slots.action && 'col-span-2')">
|
|
87
88
|
<slot name="value" :item="item" :index="index">
|
|
88
89
|
<template v-if="!isEmpty(item.value)">{{ item.value }}</template>
|
|
89
|
-
<template v-else><span class="text-black/40" aria-hidden="true">—</span><span class="sr-only">{{ emptyLabel }}</span></template>
|
|
90
|
+
<template v-else><span class="text-black/40" aria-hidden="true">—</span><span class="sr-only">{{ emptyLabel ?? t('ui.summaryList.notSet') }}</span></template>
|
|
90
91
|
</slot>
|
|
91
92
|
<span v-if="item.description" class="mt-0.5 block text-black/65">{{ item.description }}</span>
|
|
92
93
|
</dd>
|
|
@@ -115,7 +116,7 @@ const labelWidths = {
|
|
|
115
116
|
>
|
|
116
117
|
<slot name="value" :item="item" :index="index">
|
|
117
118
|
<template v-if="!isEmpty(item.value)">{{ item.value }}</template>
|
|
118
|
-
<template v-else><span class="text-black/40" aria-hidden="true">—</span><span class="sr-only">{{ emptyLabel }}</span></template>
|
|
119
|
+
<template v-else><span class="text-black/40" aria-hidden="true">—</span><span class="sr-only">{{ emptyLabel ?? t('ui.summaryList.notSet') }}</span></template>
|
|
119
120
|
</slot>
|
|
120
121
|
<span v-if="item.description" class="mt-0.5 block font-normal text-black/65">{{ item.description }}</span>
|
|
121
122
|
<span v-if="$slots.action" class="mt-1 block font-normal"><slot name="action" :item="item" :index="index" /></span>
|
|
@@ -26,6 +26,8 @@ export interface SwitchProps {
|
|
|
26
26
|
/** Name for native form submission. */
|
|
27
27
|
name?: string
|
|
28
28
|
disabled?: boolean
|
|
29
|
+
/** Keep the label (and description) for screen readers only, e.g. a switch in a SettingsRow. */
|
|
30
|
+
hideLabel?: boolean
|
|
29
31
|
class?: HTMLAttributes['class']
|
|
30
32
|
}
|
|
31
33
|
|
|
@@ -82,7 +84,7 @@ const thumb = 'size-4 rounded-full bg-white shadow-sm transition-transform data-
|
|
|
82
84
|
<SwitchThumb :class="thumb" />
|
|
83
85
|
</SwitchRoot>
|
|
84
86
|
<div
|
|
85
|
-
:class="cn('flex min-w-0 flex-col gap-0.5', disabled ? 'cursor-not-allowed' : 'cursor-pointer')"
|
|
87
|
+
:class="cn('flex min-w-0 flex-col gap-0.5', disabled ? 'cursor-not-allowed' : 'cursor-pointer', hideLabel && 'sr-only')"
|
|
86
88
|
@click="pressControl($event, controlId)"
|
|
87
89
|
>
|
|
88
90
|
<label :for="controlId" :class="cn('text-sm', disabled ? 'cursor-not-allowed' : 'cursor-pointer')">{{ label }}</label>
|
|
@@ -268,3 +268,37 @@ export const SomeRowsClickable: Story = {
|
|
|
268
268
|
},
|
|
269
269
|
render: ClickableRows.render,
|
|
270
270
|
};
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Ticking rows to act on several at once: `selectable` (here, everyone but
|
|
274
|
+
* declined applicants), `v-model:selected` for the ticked rows' keys, and
|
|
275
|
+
* `rowLabel` to name each box. Clicking anywhere in a checkbox's cell ticks
|
|
276
|
+
* it, without opening the row.
|
|
277
|
+
*/
|
|
278
|
+
export const SelectableRows: Story = {
|
|
279
|
+
args: {
|
|
280
|
+
rowLink: (row) => `/applicants/${row.id}`,
|
|
281
|
+
linkComponent: FakeRouterLink,
|
|
282
|
+
selectable: (row) => row.status !== "Declined",
|
|
283
|
+
rowLabel: (row) => `Select ${row.name}`,
|
|
284
|
+
},
|
|
285
|
+
render: (args) => ({
|
|
286
|
+
components: { Table, Card, Badge },
|
|
287
|
+
setup() {
|
|
288
|
+
const selected = ref<(string | number)[]>([2]);
|
|
289
|
+
opened.value = "";
|
|
290
|
+
return { args, statusColors, date, opened, selected };
|
|
291
|
+
},
|
|
292
|
+
template: `
|
|
293
|
+
<div class="flex flex-col gap-3">
|
|
294
|
+
<Card padding="none">
|
|
295
|
+
<Table v-bind="args" v-model:selected="selected">
|
|
296
|
+
<template #cell-applied="{ value }">{{ date(value) }}</template>
|
|
297
|
+
<template #cell-score="{ value }">{{ value ?? '—' }}</template>
|
|
298
|
+
<template #cell-status="{ value }"><Badge size="sm" :color="statusColors[value]">{{ value }}</Badge></template>
|
|
299
|
+
</Table>
|
|
300
|
+
</Card>
|
|
301
|
+
<p class="text-sm">Selected: <code>{{ selected.join(', ') || 'none' }}</code> · Opened: <code>{{ opened || 'none' }}</code></p>
|
|
302
|
+
</div>`,
|
|
303
|
+
}),
|
|
304
|
+
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
<script setup lang="ts" generic="Row extends Record<string, any>">
|
|
2
|
+
import { useI18n } from 'vue-i18n'
|
|
2
3
|
import { computed, onBeforeUnmount, onMounted, ref, useId, type Component, type HTMLAttributes } from 'vue'
|
|
3
4
|
import { ArrowDown, ArrowUp, ChevronsUpDown } from '@lucide/vue'
|
|
4
5
|
import { cn } from '../../lib/cn'
|
|
5
6
|
import EmptyState from '../EmptyState/EmptyState.vue'
|
|
7
|
+
import Checkbox from '../Checkbox/Checkbox.vue'
|
|
6
8
|
import Spinner from '../Spinner/Spinner.vue'
|
|
7
9
|
import { nextSort, sortRows, type TableColumn, type TableSort } from './table'
|
|
8
10
|
|
|
@@ -44,6 +46,14 @@ export interface TableProps<Row = Record<string, any>> {
|
|
|
44
46
|
loading?: boolean
|
|
45
47
|
/** md (default) 12px above and below each cell, sm 8px for dense tables. */
|
|
46
48
|
size?: 'sm' | 'md'
|
|
49
|
+
/**
|
|
50
|
+
* For a table that fills a `Card` with `padding="none"` and has a title
|
|
51
|
+
* above it (so the content lines up with the card's padding): the first and
|
|
52
|
+
* last columns have 24px at the table's outer edges (from sm), and there is
|
|
53
|
+
* the same space beneath the last row. The row lines still run edge to
|
|
54
|
+
* edge. Leave it off for a table that is the whole card.
|
|
55
|
+
*/
|
|
56
|
+
inset?: boolean
|
|
47
57
|
/** Keep the header row in view while the table scrolls. Give the table a max height (`class="max-h-96"`). */
|
|
48
58
|
stickyHeader?: boolean
|
|
49
59
|
/** Don't sort the rows: just update `sort`, e.g. to sort on the server. */
|
|
@@ -56,6 +66,15 @@ export interface TableProps<Row = Record<string, any>> {
|
|
|
56
66
|
rowLink?: (row: Row, index: number) => unknown
|
|
57
67
|
/** Component for row links, e.g. RouterLink. It receives `to`. Default a plain `<a href>`. */
|
|
58
68
|
linkComponent?: string | Component
|
|
69
|
+
/**
|
|
70
|
+
* A checkbox at the start of each row (and "select all" in the header), for
|
|
71
|
+
* acting on several rows. `true` for every row, or a function saying which
|
|
72
|
+
* rows can be ticked. The whole cell is the click target. Ticked rows'
|
|
73
|
+
* keys (`rowKey`) are in `v-model:selected`.
|
|
74
|
+
*/
|
|
75
|
+
selectable?: boolean | ((row: Row) => boolean)
|
|
76
|
+
/** Describes a row for its checkbox, e.g. its name: "Select Jo Bloggs". Default "Select row 2". */
|
|
77
|
+
rowLabel?: (row: Row, index: number) => string
|
|
59
78
|
class?: HTMLAttributes['class']
|
|
60
79
|
ui?: {
|
|
61
80
|
table?: HTMLAttributes['class']
|
|
@@ -64,13 +83,15 @@ export interface TableProps<Row = Record<string, any>> {
|
|
|
64
83
|
}
|
|
65
84
|
}
|
|
66
85
|
|
|
86
|
+
const { t } = useI18n()
|
|
67
87
|
const props = withDefaults(defineProps<TableProps<Row>>(), {
|
|
68
|
-
emptyText: 'Nothing to show.',
|
|
69
88
|
size: 'md',
|
|
70
89
|
linkComponent: 'a'
|
|
71
90
|
})
|
|
72
91
|
|
|
73
92
|
const sort = defineModel<TableSort | null>('sort', { default: null })
|
|
93
|
+
/** Ticked rows' keys (see `selectable`). */
|
|
94
|
+
const selected = defineModel<(string | number)[]>('selected', { default: () => [] })
|
|
74
95
|
|
|
75
96
|
defineSlots<
|
|
76
97
|
{
|
|
@@ -86,6 +107,37 @@ defineSlots<
|
|
|
86
107
|
|
|
87
108
|
const captionId = `${useId()}-caption`
|
|
88
109
|
|
|
110
|
+
// ── Selecting rows ──────────────────────────────────────────────────────────
|
|
111
|
+
const canSelect = (row: Row) => (typeof props.selectable === 'function' ? props.selectable(row) : !!props.selectable)
|
|
112
|
+
const selectableKeys = computed(() => shownRows.value.flatMap((row, i) => (canSelect(row) ? [keyOf(row, i)] : [])))
|
|
113
|
+
const isSelected = (row: Row, index: number) => selected.value.includes(keyOf(row, index))
|
|
114
|
+
function setRow(row: Row, index: number, on: boolean) {
|
|
115
|
+
const key = keyOf(row, index)
|
|
116
|
+
selected.value = on ? [...selected.value.filter((k) => k !== key), key] : selected.value.filter((k) => k !== key)
|
|
117
|
+
}
|
|
118
|
+
/** Header box: ticked when every row is, a dash when some are. */
|
|
119
|
+
const allState = computed<boolean | 'indeterminate'>(() => {
|
|
120
|
+
const n = selectableKeys.value.filter((k) => selected.value.includes(k)).length
|
|
121
|
+
return n === 0 ? false : n === selectableKeys.value.length ? true : 'indeterminate'
|
|
122
|
+
})
|
|
123
|
+
function setAll(on: boolean) {
|
|
124
|
+
const keys = selectableKeys.value
|
|
125
|
+
selected.value = on ? [...new Set([...selected.value, ...keys])] : selected.value.filter((k) => !keys.includes(k))
|
|
126
|
+
}
|
|
127
|
+
// The checkbox cell is above a row's link, so clicking anywhere in it ticks
|
|
128
|
+
// the box rather than opening the row.
|
|
129
|
+
const selectCell = 'relative z-1 w-0 cursor-pointer'
|
|
130
|
+
/**
|
|
131
|
+
* Pressing anywhere in the cell ticks the box: the cell's padding and the gap
|
|
132
|
+
* around the box, not only the box. The box and its (hidden) label do their
|
|
133
|
+
* own ticking, so they're left alone, or it would tick twice.
|
|
134
|
+
*/
|
|
135
|
+
function onCellPress(event: MouseEvent, toggle: () => void) {
|
|
136
|
+
if ((event.target as HTMLElement).closest('button, label, .sr-only')) return
|
|
137
|
+
toggle()
|
|
138
|
+
}
|
|
139
|
+
const colspan = computed(() => props.columns.length + (props.selectable ? 1 : 0))
|
|
140
|
+
|
|
89
141
|
const shownRows = computed(() => (props.manualSort ? props.rows : sortRows(props.rows, props.columns, sort.value)))
|
|
90
142
|
|
|
91
143
|
function keyOf(row: Row, index: number) {
|
|
@@ -124,7 +176,11 @@ const linkedRowClass = [
|
|
|
124
176
|
'[&_:is(a,button,input,select,textarea,label,[tabindex]):not([data-row-link])]:z-1'
|
|
125
177
|
]
|
|
126
178
|
|
|
127
|
-
const cellPadding = computed(() =>
|
|
179
|
+
const cellPadding = computed(() => {
|
|
180
|
+
const base = props.size === 'sm' ? 'px-4 py-2' : 'px-4 py-3'
|
|
181
|
+
return props.inset ? `${base} sm:first:pl-6 sm:last:pr-6` : base
|
|
182
|
+
})
|
|
183
|
+
|
|
128
184
|
|
|
129
185
|
function columnClasses(column: TableColumn<Row>) {
|
|
130
186
|
return cn(column.align === 'end' && 'text-right', column.nowrap !== false && 'whitespace-nowrap', column.class)
|
|
@@ -164,18 +220,33 @@ onBeforeUnmount(() => observer?.disconnect())
|
|
|
164
220
|
:tabindex="scrolls ? 0 : undefined"
|
|
165
221
|
:role="scrolls ? 'region' : undefined"
|
|
166
222
|
:aria-labelledby="scrolls && (caption || $slots.caption) ? captionId : undefined"
|
|
167
|
-
:aria-label="scrolls && !caption && !$slots.caption ? '
|
|
223
|
+
:aria-label="scrolls && !caption && !$slots.caption ? t('ui.table.table') : undefined"
|
|
168
224
|
>
|
|
169
225
|
<table
|
|
170
226
|
:class="cn('w-full border-separate border-spacing-0 text-left text-sm text-black', ui?.table)"
|
|
171
227
|
:aria-busy="loading || undefined"
|
|
172
228
|
>
|
|
173
|
-
<caption v-if="caption || $slots.caption" :id="captionId" :class="showCaption ? 'px-4 pt-4 pb-2 text-left text-base font-bold' : 'sr-only'">
|
|
229
|
+
<caption v-if="caption || $slots.caption" :id="captionId" :class="showCaption ? cn('px-4 pt-4 pb-2 text-left text-base font-bold', inset && 'sm:px-6') : 'sr-only'">
|
|
174
230
|
<slot name="caption">{{ caption }}</slot>
|
|
175
231
|
</caption>
|
|
176
232
|
|
|
177
233
|
<thead :class="cn(stickyHeader && 'sticky top-0 z-10 bg-white', ui?.header)">
|
|
178
234
|
<tr>
|
|
235
|
+
<th
|
|
236
|
+
v-if="selectable"
|
|
237
|
+
scope="col"
|
|
238
|
+
:class="cn('border-b border-black/15', cellPadding, selectableKeys.length && selectCell)"
|
|
239
|
+
@click="onCellPress($event, () => selectableKeys.length && setAll(allState !== true))"
|
|
240
|
+
>
|
|
241
|
+
<Checkbox
|
|
242
|
+
v-if="selectableKeys.length"
|
|
243
|
+
:model-value="allState"
|
|
244
|
+
:label="t('ui.table.selectAll')"
|
|
245
|
+
hide-label
|
|
246
|
+
@update:model-value="setAll($event === true)"
|
|
247
|
+
/>
|
|
248
|
+
<span v-else class="sr-only">{{ t('ui.table.select') }}</span>
|
|
249
|
+
</th>
|
|
179
250
|
<th
|
|
180
251
|
v-for="column in columns"
|
|
181
252
|
:key="column.key"
|
|
@@ -211,13 +282,13 @@ onBeforeUnmount(() => observer?.disconnect())
|
|
|
211
282
|
|
|
212
283
|
<tbody :class="cn(loading && shownRows.length && 'opacity-50 transition-opacity')">
|
|
213
284
|
<tr v-if="!shownRows.length">
|
|
214
|
-
<td :colspan="
|
|
285
|
+
<td :colspan="colspan" class="px-4 py-8 text-center text-black/65">
|
|
215
286
|
<span v-if="loading" class="inline-flex items-center gap-2">
|
|
216
287
|
<Spinner size="sm" />
|
|
217
288
|
Loading…
|
|
218
289
|
</span>
|
|
219
290
|
<slot v-else name="empty">
|
|
220
|
-
<EmptyState size="sm" :description="emptyText" class="p-0" />
|
|
291
|
+
<EmptyState size="sm" :description="emptyText ?? t('ui.table.empty')" class="p-0" />
|
|
221
292
|
</slot>
|
|
222
293
|
</td>
|
|
223
294
|
</tr>
|
|
@@ -226,6 +297,19 @@ onBeforeUnmount(() => observer?.disconnect())
|
|
|
226
297
|
:key="keyOf(row, index)"
|
|
227
298
|
:class="cn('group/row', linkFor(row, index) && linkedRowClass, ui?.row)"
|
|
228
299
|
>
|
|
300
|
+
<td
|
|
301
|
+
v-if="selectable"
|
|
302
|
+
:class="cn('border-b border-black/15 align-middle', !inset && 'group-last/row:border-b-0', cellPadding, canSelect(row) && selectCell)"
|
|
303
|
+
@click="canSelect(row) && onCellPress($event, () => setRow(row, index, !isSelected(row, index)))"
|
|
304
|
+
>
|
|
305
|
+
<Checkbox
|
|
306
|
+
v-if="canSelect(row)"
|
|
307
|
+
:model-value="isSelected(row, index)"
|
|
308
|
+
:label="rowLabel ? rowLabel(row, index) : t('ui.table.selectRow', { n: index + 1 })"
|
|
309
|
+
hide-label
|
|
310
|
+
@update:model-value="setRow(row, index, $event === true)"
|
|
311
|
+
/>
|
|
312
|
+
</td>
|
|
229
313
|
<component
|
|
230
314
|
:is="column.rowHeader ? 'th' : 'td'"
|
|
231
315
|
v-for="column in columns"
|
|
@@ -233,7 +317,7 @@ onBeforeUnmount(() => observer?.disconnect())
|
|
|
233
317
|
:scope="column.rowHeader ? 'row' : undefined"
|
|
234
318
|
:class="
|
|
235
319
|
cn(
|
|
236
|
-
'border-b border-black/15 align-middle group-last/row:border-b-0',
|
|
320
|
+
'border-b border-black/15 align-middle', !inset && 'group-last/row:border-b-0',
|
|
237
321
|
column.rowHeader ? 'font-bold' : 'font-normal',
|
|
238
322
|
column.align === 'end' && 'tabular-nums',
|
|
239
323
|
cellPadding,
|
|
@@ -257,6 +341,11 @@ onBeforeUnmount(() => observer?.disconnect())
|
|
|
257
341
|
</slot>
|
|
258
342
|
</component>
|
|
259
343
|
</tr>
|
|
344
|
+
<!-- inset: the last row keeps its line, then the space below it is its
|
|
345
|
+
own part, so a hovered last row isn't taller than the others. -->
|
|
346
|
+
<tr v-if="inset && shownRows.length && !$slots.footer" aria-hidden="true">
|
|
347
|
+
<td :colspan="colspan" class="h-2 p-0 sm:h-4"></td>
|
|
348
|
+
</tr>
|
|
260
349
|
</tbody>
|
|
261
350
|
|
|
262
351
|
<!-- Footer cells get the same padding and a top border, so totals line up. -->
|
|
@@ -265,7 +354,8 @@ onBeforeUnmount(() => observer?.disconnect())
|
|
|
265
354
|
:class="
|
|
266
355
|
cn(
|
|
267
356
|
'font-bold *:*:border-t *:*:border-black/15',
|
|
268
|
-
size === 'sm' ? '*:*:px-4 *:*:py-2' : '*:*:px-4 *:*:py-3'
|
|
357
|
+
size === 'sm' ? '*:*:px-4 *:*:py-2' : '*:*:px-4 *:*:py-3',
|
|
358
|
+
inset && '*:*:sm:first:pl-6 *:*:sm:last:pr-6'
|
|
269
359
|
)
|
|
270
360
|
"
|
|
271
361
|
>
|
package/src/i18n/en.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keston UI's own words in English: what its components say and announce
|
|
3
|
+
* (button names, screen reader text, empty and error messages). Apps add
|
|
4
|
+
* these to their vue-i18n messages (see `createKestonI18n`) and keep their
|
|
5
|
+
* own under other keys.
|
|
6
|
+
*
|
|
7
|
+
* To add a language, copy this object, translate the values and give it to
|
|
8
|
+
* `createKestonI18n` under its code, e.g. `{ en, cy }`. Keep the keys and
|
|
9
|
+
* the `{placeholders}` as they are.
|
|
10
|
+
*/
|
|
11
|
+
export const en = {
|
|
12
|
+
ui: {
|
|
13
|
+
age: {
|
|
14
|
+
born: 'Born {date}',
|
|
15
|
+
birthdayToday: 'Birthday today',
|
|
16
|
+
birthdayTomorrow: 'Birthday tomorrow',
|
|
17
|
+
birthdayInDays: 'Birthday in {days} days'
|
|
18
|
+
},
|
|
19
|
+
appShell: {
|
|
20
|
+
menu: 'Menu',
|
|
21
|
+
expandSidebar: 'Expand sidebar',
|
|
22
|
+
collapseSidebar: 'Collapse sidebar'
|
|
23
|
+
},
|
|
24
|
+
avatar: {
|
|
25
|
+
account: 'Account: {name}',
|
|
26
|
+
accountWithInitials: '{initials}, account: {name}'
|
|
27
|
+
},
|
|
28
|
+
avatarGroup: {
|
|
29
|
+
people: 'no people | 1 person | {count} people',
|
|
30
|
+
more: '{count} more: {names}'
|
|
31
|
+
},
|
|
32
|
+
breadcrumb: { label: 'Breadcrumb' },
|
|
33
|
+
calendar: {
|
|
34
|
+
previousMonth: 'Previous month',
|
|
35
|
+
nextMonth: 'Next month',
|
|
36
|
+
previousYear: 'Previous year',
|
|
37
|
+
nextYear: 'Next year',
|
|
38
|
+
previousYears: 'Previous years',
|
|
39
|
+
nextYears: 'Next years',
|
|
40
|
+
chooseMonth: 'Choose month',
|
|
41
|
+
chooseYear: 'Choose year'
|
|
42
|
+
},
|
|
43
|
+
chip: { remove: 'Remove' },
|
|
44
|
+
formField: { about: 'About {label}' },
|
|
45
|
+
header: {
|
|
46
|
+
menu: 'Menu',
|
|
47
|
+
signIn: 'Sign in',
|
|
48
|
+
account: 'Account: {name}',
|
|
49
|
+
accountWithInitials: '{initials}, account: {name}'
|
|
50
|
+
},
|
|
51
|
+
input: {
|
|
52
|
+
maxLength: 'Must be {count} characters or fewer',
|
|
53
|
+
minLength: 'Must be at least {count} characters'
|
|
54
|
+
},
|
|
55
|
+
inputCode: { character: 'Character {n} of {total}' },
|
|
56
|
+
inputDate: {
|
|
57
|
+
openCalendar: 'Open calendar',
|
|
58
|
+
enterDate: 'Enter a date like {example}'
|
|
59
|
+
},
|
|
60
|
+
inputPassword: {
|
|
61
|
+
capsLock: 'Caps Lock is on',
|
|
62
|
+
show: 'Show password'
|
|
63
|
+
},
|
|
64
|
+
inputRichText: {
|
|
65
|
+
formattingFor: 'Formatting for {label}',
|
|
66
|
+
bold: 'Bold',
|
|
67
|
+
italic: 'Italic',
|
|
68
|
+
underline: 'Underline'
|
|
69
|
+
},
|
|
70
|
+
languageSwitcher: { label: 'Language' },
|
|
71
|
+
notifications: {
|
|
72
|
+
title: 'Notifications',
|
|
73
|
+
region: 'Notification',
|
|
74
|
+
hotkeyRegion: 'Notifications ({hotkey})',
|
|
75
|
+
notifications: 'notifications',
|
|
76
|
+
empty: 'You’re all caught up.',
|
|
77
|
+
withUnread: '{label}, {count} unread',
|
|
78
|
+
dismiss: 'Dismiss: {title}',
|
|
79
|
+
close: 'Close: {title}',
|
|
80
|
+
clearAll: 'Clear all',
|
|
81
|
+
more: '+{count} more'
|
|
82
|
+
},
|
|
83
|
+
pageHeader: {
|
|
84
|
+
actions: '{title} actions',
|
|
85
|
+
moreActions: 'More actions'
|
|
86
|
+
},
|
|
87
|
+
progress: { stepOf: 'Step {current} of {total}' },
|
|
88
|
+
select: {
|
|
89
|
+
choose: 'Choose…',
|
|
90
|
+
search: 'Search…',
|
|
91
|
+
noMatches: 'No matches',
|
|
92
|
+
showOptions: 'Show options',
|
|
93
|
+
remove: 'Remove {name}'
|
|
94
|
+
},
|
|
95
|
+
sidebar: {
|
|
96
|
+
main: 'Main',
|
|
97
|
+
backFrom: 'Back from {name}',
|
|
98
|
+
expand: 'Expand sidebar',
|
|
99
|
+
collapse: 'Collapse sidebar'
|
|
100
|
+
},
|
|
101
|
+
slideover: {
|
|
102
|
+
close: 'Close',
|
|
103
|
+
cancel: 'Cancel',
|
|
104
|
+
previous: 'Previous',
|
|
105
|
+
next: 'Next',
|
|
106
|
+
finish: 'Finish',
|
|
107
|
+
steps: 'Steps',
|
|
108
|
+
stepOf: 'Step {current} of {total}: {name}'
|
|
109
|
+
},
|
|
110
|
+
spinner: { loading: 'Loading' },
|
|
111
|
+
statTile: { up: 'Up', down: 'Down', flat: 'No change' },
|
|
112
|
+
steps: {
|
|
113
|
+
stepOf: 'Step {current} of {total}',
|
|
114
|
+
stepOfNamed: 'Step {current} of {total}: {name}'
|
|
115
|
+
},
|
|
116
|
+
summaryList: { notSet: 'Not set' },
|
|
117
|
+
table: {
|
|
118
|
+
table: 'Table',
|
|
119
|
+
empty: 'Nothing to show.',
|
|
120
|
+
selectAll: 'Select all rows',
|
|
121
|
+
selectRow: 'Select row {n}',
|
|
122
|
+
select: 'Select'
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export type UiMessages = typeof en
|