@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
@@ -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 ? `Step ${step.value + 1} of ${stepCount.value}: ${props.steps[step.value]}` : ''))
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 ?? 'Steps'" segments :value="step + 1" :max="stepCount" />
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="Close" class="-my-1.5 -mr-3 shrink-0">
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 ? 'Cancel' : 'Previous' }}
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 : 'Next' }}
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: 'Up', down: 'Down', flat: 'No change' } as const
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) {
@@ -109,22 +161,31 @@ function linkFor(row: Row, index: number) {
109
161
  return props.linkComponent === 'a' ? { href: target as string } : { to: target }
110
162
  }
111
163
 
112
- // The link's ::after covers the row (the row is `relative`), so a click
113
- // anywhere follows it. Controls in other cells are lifted above it, so they
114
- // still get their own clicks. The focus ring is drawn on the ::after, round
115
- // the whole row, just inside its edge.
164
+ // A click anywhere on the row follows its link. Each cell is `relative` and
165
+ // holds its own overlay: the real link's ::after in its cell, and in the
166
+ // others a hidden twin (same target, out of the tab order and the
167
+ // accessibility tree). Not one overlay stretched across the row: Safari
168
+ // (WebKit) doesn't reliably make a <tr> the containing block for absolutely
169
+ // positioned children, so it grew to the whole table. Controls in other cells
170
+ // are lifted above the overlays, so they still get their own clicks. The focus
171
+ // ring is drawn on the real link's ::after, and the row is shaded to match.
116
172
  const rowLinkClass = [
117
173
  'text-inherit no-underline outline-none group-hover/row:underline underline-offset-2',
118
174
  'after:absolute after:inset-0 after:outline-2 after:-outline-offset-2 after:outline-transparent',
119
175
  'focus-visible:after:outline-focus forced-colors:not-focus-visible:after:outline-0'
120
176
  ]
121
177
  const linkedRowClass = [
122
- 'relative cursor-pointer hover:bg-black/5',
123
- '[&_:is(a,button,input,select,textarea,label,[tabindex]):not([data-row-link])]:relative',
124
- '[&_:is(a,button,input,select,textarea,label,[tabindex]):not([data-row-link])]:z-1'
178
+ 'cursor-pointer hover:bg-black/5 has-[[data-row-link]:focus-visible]:bg-black/5',
179
+ '[&_:is(a,button,input,select,textarea,label,[tabindex]):not([data-row-link],[data-row-overlay])]:relative',
180
+ '[&_:is(a,button,input,select,textarea,label,[tabindex]):not([data-row-link],[data-row-overlay])]:z-1'
125
181
  ]
182
+ const overlayClass = 'absolute inset-0 outline-none'
183
+
184
+ const cellPadding = computed(() => {
185
+ const base = props.size === 'sm' ? 'px-4 py-2' : 'px-4 py-3'
186
+ return props.inset ? `${base} sm:first:pl-6 sm:last:pr-6` : base
187
+ })
126
188
 
127
- const cellPadding = computed(() => (props.size === 'sm' ? 'px-4 py-2' : 'px-4 py-3'))
128
189
 
129
190
  function columnClasses(column: TableColumn<Row>) {
130
191
  return cn(column.align === 'end' && 'text-right', column.nowrap !== false && 'whitespace-nowrap', column.class)
@@ -164,18 +225,33 @@ onBeforeUnmount(() => observer?.disconnect())
164
225
  :tabindex="scrolls ? 0 : undefined"
165
226
  :role="scrolls ? 'region' : undefined"
166
227
  :aria-labelledby="scrolls && (caption || $slots.caption) ? captionId : undefined"
167
- :aria-label="scrolls && !caption && !$slots.caption ? 'Table' : undefined"
228
+ :aria-label="scrolls && !caption && !$slots.caption ? t('ui.table.table') : undefined"
168
229
  >
169
230
  <table
170
231
  :class="cn('w-full border-separate border-spacing-0 text-left text-sm text-black', ui?.table)"
171
232
  :aria-busy="loading || undefined"
172
233
  >
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'">
234
+ <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
235
  <slot name="caption">{{ caption }}</slot>
175
236
  </caption>
176
237
 
177
238
  <thead :class="cn(stickyHeader && 'sticky top-0 z-10 bg-white', ui?.header)">
178
239
  <tr>
240
+ <th
241
+ v-if="selectable"
242
+ scope="col"
243
+ :class="cn('border-b border-black/15', cellPadding, selectableKeys.length && selectCell)"
244
+ @click="onCellPress($event, () => selectableKeys.length && setAll(allState !== true))"
245
+ >
246
+ <Checkbox
247
+ v-if="selectableKeys.length"
248
+ :model-value="allState"
249
+ :label="t('ui.table.selectAll')"
250
+ hide-label
251
+ @update:model-value="setAll($event === true)"
252
+ />
253
+ <span v-else class="sr-only">{{ t('ui.table.select') }}</span>
254
+ </th>
179
255
  <th
180
256
  v-for="column in columns"
181
257
  :key="column.key"
@@ -211,13 +287,13 @@ onBeforeUnmount(() => observer?.disconnect())
211
287
 
212
288
  <tbody :class="cn(loading && shownRows.length && 'opacity-50 transition-opacity')">
213
289
  <tr v-if="!shownRows.length">
214
- <td :colspan="columns.length" class="px-4 py-8 text-center text-black/65">
290
+ <td :colspan="colspan" class="px-4 py-8 text-center text-black/65">
215
291
  <span v-if="loading" class="inline-flex items-center gap-2">
216
292
  <Spinner size="sm" />
217
293
  Loading…
218
294
  </span>
219
295
  <slot v-else name="empty">
220
- <EmptyState size="sm" :description="emptyText" class="p-0" />
296
+ <EmptyState size="sm" :description="emptyText ?? t('ui.table.empty')" class="p-0" />
221
297
  </slot>
222
298
  </td>
223
299
  </tr>
@@ -226,6 +302,19 @@ onBeforeUnmount(() => observer?.disconnect())
226
302
  :key="keyOf(row, index)"
227
303
  :class="cn('group/row', linkFor(row, index) && linkedRowClass, ui?.row)"
228
304
  >
305
+ <td
306
+ v-if="selectable"
307
+ :class="cn('border-b border-black/15 align-middle', !inset && 'group-last/row:border-b-0', cellPadding, canSelect(row) && selectCell)"
308
+ @click="canSelect(row) && onCellPress($event, () => setRow(row, index, !isSelected(row, index)))"
309
+ >
310
+ <Checkbox
311
+ v-if="canSelect(row)"
312
+ :model-value="isSelected(row, index)"
313
+ :label="rowLabel ? rowLabel(row, index) : t('ui.table.selectRow', { n: index + 1 })"
314
+ hide-label
315
+ @update:model-value="setRow(row, index, $event === true)"
316
+ />
317
+ </td>
229
318
  <component
230
319
  :is="column.rowHeader ? 'th' : 'td'"
231
320
  v-for="column in columns"
@@ -233,14 +322,24 @@ onBeforeUnmount(() => observer?.disconnect())
233
322
  :scope="column.rowHeader ? 'row' : undefined"
234
323
  :class="
235
324
  cn(
236
- 'border-b border-black/15 align-middle group-last/row:border-b-0',
325
+ 'border-b border-black/15 align-middle', !inset && 'group-last/row:border-b-0',
237
326
  column.rowHeader ? 'font-bold' : 'font-normal',
238
327
  column.align === 'end' && 'tabular-nums',
239
328
  cellPadding,
329
+ linkFor(row, index) && 'relative',
240
330
  columnClasses(column)
241
331
  )
242
332
  "
243
333
  >
334
+ <component
335
+ :is="linkComponent"
336
+ v-if="column.key !== linkColumn && linkFor(row, index)"
337
+ v-bind="linkFor(row, index)"
338
+ data-row-overlay
339
+ tabindex="-1"
340
+ aria-hidden="true"
341
+ :class="overlayClass"
342
+ />
244
343
  <component
245
344
  :is="linkComponent"
246
345
  v-if="column.key === linkColumn && linkFor(row, index)"
@@ -257,6 +356,11 @@ onBeforeUnmount(() => observer?.disconnect())
257
356
  </slot>
258
357
  </component>
259
358
  </tr>
359
+ <!-- inset: the last row keeps its line, then the space below it is its
360
+ own part, so a hovered last row isn't taller than the others. -->
361
+ <tr v-if="inset && shownRows.length && !$slots.footer" aria-hidden="true">
362
+ <td :colspan="colspan" class="h-2 p-0 sm:h-4"></td>
363
+ </tr>
260
364
  </tbody>
261
365
 
262
366
  <!-- Footer cells get the same padding and a top border, so totals line up. -->
@@ -265,7 +369,8 @@ onBeforeUnmount(() => observer?.disconnect())
265
369
  :class="
266
370
  cn(
267
371
  'font-bold *:*:border-t *:*:border-black/15',
268
- size === 'sm' ? '*:*:px-4 *:*:py-2' : '*:*:px-4 *:*:py-3'
372
+ size === 'sm' ? '*:*:px-4 *:*:py-2' : '*:*:px-4 *:*:py-3',
373
+ inset && '*:*:sm:first:pl-6 *:*:sm:last:pr-6'
269
374
  )
270
375
  "
271
376
  >