@humanonlyweb/ui 0.0.0-stage → 0.1.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.
Files changed (144) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +45 -2
  3. package/dist/components/accordion/Accordion.js +60 -0
  4. package/dist/components/accordion/Accordion.vue.d.ts +28 -0
  5. package/dist/components/accordion/AccordionItem.js +102 -0
  6. package/dist/components/accordion/AccordionItem.vue.d.ts +33 -0
  7. package/dist/components/avatar/Avatar.js +52 -0
  8. package/dist/components/avatar/Avatar.vue.d.ts +26 -0
  9. package/dist/components/avatar/AvatarGroup.js +48 -0
  10. package/dist/components/avatar/AvatarGroup.vue.d.ts +16 -0
  11. package/dist/components/button/Button.js +95 -0
  12. package/dist/components/button/Button.vue.d.ts +74 -0
  13. package/dist/components/button/IconButton.js +47 -0
  14. package/dist/components/button/IconButton.vue.d.ts +115 -0
  15. package/dist/components/checkbox/Checkbox.js +93 -0
  16. package/dist/components/checkbox/Checkbox.vue.d.ts +43 -0
  17. package/dist/components/combobox/Combobox.js +294 -0
  18. package/dist/components/combobox/Combobox.vue.d.ts +80 -0
  19. package/dist/components/context-menu/ContextMenu.js +170 -0
  20. package/dist/components/context-menu/ContextMenu.vue.d.ts +38 -0
  21. package/dist/components/dialog/ConfirmDialog.js +103 -0
  22. package/dist/components/dialog/ConfirmDialog.vue.d.ts +46 -0
  23. package/dist/components/dialog/Dialog.js +160 -0
  24. package/dist/components/dialog/Dialog.vue.d.ts +54 -0
  25. package/dist/components/field/FieldMessage.js +31 -0
  26. package/dist/components/input/Input.js +111 -0
  27. package/dist/components/input/Input.vue.d.ts +50 -0
  28. package/dist/components/kbd/Kbd.js +48 -0
  29. package/dist/components/kbd/Kbd.vue.d.ts +24 -0
  30. package/dist/components/menu/Menu.js +124 -0
  31. package/dist/components/menu/Menu.vue.d.ts +41 -0
  32. package/dist/components/otp-input/OtpInput.js +179 -0
  33. package/dist/components/otp-input/OtpInput.vue.d.ts +48 -0
  34. package/dist/components/popover/Popover.js +83 -0
  35. package/dist/components/popover/Popover.vue.d.ts +37 -0
  36. package/dist/components/radio-group/RadioGroup.js +125 -0
  37. package/dist/components/radio-group/RadioGroup.vue.d.ts +45 -0
  38. package/dist/components/segmented/Segmented.js +110 -0
  39. package/dist/components/segmented/Segmented.vue.d.ts +41 -0
  40. package/dist/components/select/Select.js +231 -0
  41. package/dist/components/select/Select.vue.d.ts +59 -0
  42. package/dist/components/slider/Slider.js +196 -0
  43. package/dist/components/slider/Slider.vue.d.ts +49 -0
  44. package/dist/components/spin-button/SpinButton.js +231 -0
  45. package/dist/components/spin-button/SpinButton.vue.d.ts +48 -0
  46. package/dist/components/split-button/SplitButton.js +69 -0
  47. package/dist/components/split-button/SplitButton.vue.d.ts +38 -0
  48. package/dist/components/switch/Switch.js +95 -0
  49. package/dist/components/switch/Switch.vue.d.ts +42 -0
  50. package/dist/components/table/Table.js +173 -0
  51. package/dist/components/table/Table.vue.d.ts +45 -0
  52. package/dist/components/tabs/Tabs.js +99 -0
  53. package/dist/components/tabs/Tabs.vue.d.ts +39 -0
  54. package/dist/components/textarea/Textarea.js +118 -0
  55. package/dist/components/textarea/Textarea.vue.d.ts +34 -0
  56. package/dist/components/toast/ToastItem.js +91 -0
  57. package/dist/components/toast/ToastItem.vue.d.ts +29 -0
  58. package/dist/components/toast/ToastViewport.js +56 -0
  59. package/dist/components/toast/ToastViewport.vue.d.ts +25 -0
  60. package/dist/components/toolbar/Toolbar.js +91 -0
  61. package/dist/components/toolbar/Toolbar.vue.d.ts +21 -0
  62. package/dist/components/tooltip/Tooltip.js +85 -0
  63. package/dist/components/tooltip/Tooltip.vue.d.ts +25 -0
  64. package/dist/composables/internal/env.js +5 -0
  65. package/dist/composables/internal/is-equal.js +14 -0
  66. package/dist/composables/internal/on-click-outside.js +18 -0
  67. package/dist/composables/internal/standard-schema.d.ts +38 -0
  68. package/dist/composables/internal/use-document-visibility.js +16 -0
  69. package/dist/composables/internal/use-event-listener.js +24 -0
  70. package/dist/composables/internal/use-interval-fn.js +21 -0
  71. package/dist/composables/internal/use-resize-observer.js +21 -0
  72. package/dist/composables/internal/use-timeout-fn.js +25 -0
  73. package/dist/composables/use-accordion.d.ts +9 -0
  74. package/dist/composables/use-accordion.js +10 -0
  75. package/dist/composables/use-combobox.d.ts +44 -0
  76. package/dist/composables/use-combobox.js +185 -0
  77. package/dist/composables/use-field.d.ts +17 -0
  78. package/dist/composables/use-field.js +27 -0
  79. package/dist/composables/use-form.d.ts +44 -0
  80. package/dist/composables/use-form.js +146 -0
  81. package/dist/composables/use-menu.d.ts +26 -0
  82. package/dist/composables/use-menu.js +117 -0
  83. package/dist/composables/use-platform.d.ts +17 -0
  84. package/dist/composables/use-platform.js +126 -0
  85. package/dist/composables/use-popover.d.ts +35 -0
  86. package/dist/composables/use-popover.js +49 -0
  87. package/dist/composables/use-roving-selection.d.ts +22 -0
  88. package/dist/composables/use-roving-selection.js +65 -0
  89. package/dist/composables/use-select.d.ts +31 -0
  90. package/dist/composables/use-select.js +169 -0
  91. package/dist/composables/use-slide-indicator.d.ts +24 -0
  92. package/dist/composables/use-slide-indicator.js +52 -0
  93. package/dist/composables/use-toast.d.ts +23 -0
  94. package/dist/composables/use-toast.js +51 -0
  95. package/dist/config.d.ts +40 -0
  96. package/dist/config.js +35 -0
  97. package/dist/docs/README.md +44 -0
  98. package/dist/docs/changelog.md +14 -0
  99. package/dist/docs/components/accordion.md +100 -0
  100. package/dist/docs/components/avatar-group.md +58 -0
  101. package/dist/docs/components/avatar.md +40 -0
  102. package/dist/docs/components/button.md +109 -0
  103. package/dist/docs/components/checkbox.md +123 -0
  104. package/dist/docs/components/combobox.md +207 -0
  105. package/dist/docs/components/confirm-dialog.md +107 -0
  106. package/dist/docs/components/context-menu.md +98 -0
  107. package/dist/docs/components/dialog.md +127 -0
  108. package/dist/docs/components/icon-button.md +47 -0
  109. package/dist/docs/components/input.md +89 -0
  110. package/dist/docs/components/kbd.md +41 -0
  111. package/dist/docs/components/menu.md +112 -0
  112. package/dist/docs/components/otp-input.md +92 -0
  113. package/dist/docs/components/popover.md +72 -0
  114. package/dist/docs/components/radio-group.md +114 -0
  115. package/dist/docs/components/segmented.md +96 -0
  116. package/dist/docs/components/select.md +129 -0
  117. package/dist/docs/components/slider.md +105 -0
  118. package/dist/docs/components/spin-button.md +73 -0
  119. package/dist/docs/components/split-button.md +64 -0
  120. package/dist/docs/components/switch.md +71 -0
  121. package/dist/docs/components/table.md +241 -0
  122. package/dist/docs/components/tabs.md +106 -0
  123. package/dist/docs/components/textarea.md +46 -0
  124. package/dist/docs/components/toast.md +135 -0
  125. package/dist/docs/components/toolbar.md +71 -0
  126. package/dist/docs/components/tooltip.md +57 -0
  127. package/dist/docs/forms.md +182 -0
  128. package/dist/docs/index.md +11 -0
  129. package/dist/docs/installation.md +73 -0
  130. package/dist/docs/localisation.md +40 -0
  131. package/dist/docs/ssr.md +24 -0
  132. package/dist/docs/styling.md +66 -0
  133. package/dist/index.d.ts +46 -0
  134. package/dist/index.js +44 -0
  135. package/dist/nuxt/module.d.ts +15 -0
  136. package/dist/nuxt/module.js +72 -0
  137. package/dist/nuxt/runtime/plugin.d.ts +4 -0
  138. package/dist/nuxt/runtime/plugin.js +24 -0
  139. package/dist/package.js +4 -0
  140. package/dist/styles/core.css +284 -0
  141. package/dist/translations.d.ts +71 -0
  142. package/dist/translations.js +55 -0
  143. package/dist/types.d.ts +61 -0
  144. package/package.json +93 -4
@@ -0,0 +1,105 @@
1
+ # Slider
2
+
3
+ > Pick a number, or a range, by dragging or with the keyboard.
4
+
5
+ ## Examples
6
+
7
+ ### Basic
8
+
9
+ ```vue
10
+ <script setup lang="ts">
11
+ const volume = ref(60);
12
+ </script>
13
+
14
+ <template>
15
+ <UiSlider v-model="volume" label="Volume" :format-value="(v) => `${v}%`" />
16
+ </template>
17
+ ```
18
+
19
+ ### Range
20
+
21
+ Bind a `[start, end]` array for two thumbs. `commit` fires when a drag ends, for anything expensive.
22
+
23
+ ```vue
24
+ <script setup lang="ts">
25
+ const price = ref<[number, number]>([200, 800]);
26
+ const toast = useToast();
27
+ </script>
28
+
29
+ <template>
30
+ <div class="demo-stack">
31
+ <UiSlider
32
+ v-model="price"
33
+ label="Price"
34
+ :min="0"
35
+ :max="1000"
36
+ :step="10"
37
+ :format-value="(v) => `$${v}`"
38
+ @commit="([low, high]) => toast.info(`Filtering $${low}–$${high}`)"
39
+ />
40
+ <p class="demo-note">${{ price[0] }} – ${{ price[1] }}</p>
41
+ </div>
42
+ </template>
43
+ ```
44
+
45
+ ### Vertical
46
+
47
+ ```vue
48
+ <script setup lang="ts">
49
+ const bass = ref(4);
50
+ const treble = ref(-2);
51
+ </script>
52
+
53
+ <template>
54
+ <div class="demo-row">
55
+ <UiSlider v-model="bass" orientation="vertical" label="Bass" :min="-12" :max="12" />
56
+ <UiSlider v-model="treble" orientation="vertical" label="Treble" :min="-12" :max="12" />
57
+ </div>
58
+ </template>
59
+ ```
60
+
61
+ ## API
62
+
63
+ | Prop | Type | Default | Description |
64
+ | --- | --- | --- | --- |
65
+ | `min` | `number` | `0` | Lowest value. |
66
+ | `max` | `number` | `100` | Highest value. |
67
+ | `step` | `number` | `1` | Arrow-key increment. Values snap to it. |
68
+ | `largeStep` | `number` | — | PageUp/PageDown increment. Defaults to ten steps. |
69
+ | `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | Layout hook, exposed as `data-orientation` and `aria-orientation`. |
70
+ | `disabled` | `boolean` | `false` | Disables the slider. |
71
+ | `label` | `string` | — | Visible label, which names the thumb(s). |
72
+ | `thumbLabels` | `[string, string]` | — | Accessible names for the two thumbs of a range. Default to `rangeStart` / `rangeEnd`. |
73
+ | `formatValue` | `((value: number) => string)` | — | Text for `aria-valuetext`, e.g. `(v) => \`${v}%\``. |
74
+ | `name` | `string` | — | Form field name; renders a hidden input per value. |
75
+ | `modelValue` | `T` | — | A number, or `[start, end]` for a range. Empty starts at `min`. |
76
+
77
+ | Event | Payload | Description |
78
+ | --- | --- | --- |
79
+ | `commit` | `[value: T]` | A drag ended, or a key changed the value. Use it for expensive work. |
80
+ | `update:modelValue` | `[value: T \| undefined]` | `v-model:modelValue` update. |
81
+
82
+ | Slot | Props | Description |
83
+ | --- | --- | --- |
84
+ | `thumb` | `{ value: number; index: number; }` | Thumb content, e.g. a value bubble. |
85
+
86
+ ## Styling
87
+
88
+ The range and thumbs are placed with `--ui-slider-start`, `--ui-slider-end` and `--ui-slider-value` (percentages).
89
+
90
+ - Parts (`[data-part="…"]`): `slider`, `slider-label`, `slider-control`, `slider-track`, `slider-range`, `slider-thumb`
91
+ - State attributes: `data-orientation`, `data-slider-disabled`, `data-slider-thumb`
92
+
93
+ ## Keyboard
94
+
95
+ | Keys | Action |
96
+ | ----------------------- | ---------------------------------- |
97
+ | `←` / `→`, `↓` / `↑` | One step |
98
+ | `Page Up` / `Page Down` | `largeStep` (ten steps by default) |
99
+ | `Home` / `End` | Minimum / maximum |
100
+
101
+ ## Accessibility
102
+
103
+ - Each thumb is named by `label`; a range's thumbs also get `thumb-labels` (“Minimum”, “Maximum”).
104
+ - Use `format-value` so screen readers hear units, e.g. “60%”.
105
+ - In right-to-left layouts, `←` / `→` follow the visual direction.
@@ -0,0 +1,73 @@
1
+ # Spin Button
2
+
3
+ > A number input with step buttons.
4
+
5
+ ## Examples
6
+
7
+ ### Basic
8
+
9
+ ```vue
10
+ <script setup lang="ts">
11
+ const seats = ref(3);
12
+ </script>
13
+
14
+ <template>
15
+ <UiSpinButton v-model="seats" label="Seats" :min="1" :max="50" hint="Between 1 and 50." />
16
+ </template>
17
+ ```
18
+
19
+ ### Decimal step
20
+
21
+ Values round to the step's precision.
22
+
23
+ ```vue
24
+ <script setup lang="ts">
25
+ const opacity = ref(0.8);
26
+ </script>
27
+
28
+ <template>
29
+ <UiSpinButton v-model="opacity" label="Opacity" :min="0" :max="1" :step="0.05" />
30
+ </template>
31
+ ```
32
+
33
+ ## API
34
+
35
+ | Prop | Type | Default | Description |
36
+ | --- | --- | --- | --- |
37
+ | `id` | `string` | — | Id for the control; generated with `useId()` when omitted. |
38
+ | `min` | `number` | `Number.NEGATIVE_INFINITY` | Lowest value. Home jumps here. |
39
+ | `max` | `number` | `Number.POSITIVE_INFINITY` | Highest value. End jumps here. |
40
+ | `step` | `number` | `1` | Arrow-key and button increment; PageUp/PageDown move ten steps. Its decimals set the rounding. |
41
+ | `hint` | `string` | — | Help text under the control, announced as its description. |
42
+ | `label` | `string` | — | Visible label, linked to the control. |
43
+ | `optional` | `boolean` | `false` | Appends the `optional` translation to the label. |
44
+ | `disabled` | `boolean` | `false` | Disables the control. |
45
+ | `error` | `string \| boolean` | — | `true` marks the control invalid; a string also shows it as the message, replacing the hint. |
46
+ | `modelValue` | `number` | — | The value. `undefined` while the input is empty. |
47
+
48
+ | Event | Payload | Description |
49
+ | --- | --- | --- |
50
+ | `update:modelValue` | `[value: number \| undefined]` | `v-model:modelValue` update. |
51
+
52
+ | Slot | Props | Description |
53
+ | --- | --- | --- |
54
+ | `decrement` | — | Decrease button icon. |
55
+ | `increment` | — | Increase button icon. |
56
+
57
+ ## Styling
58
+
59
+ - Parts (`[data-part="…"]`): `field`, `field-label`, `field-optional`, `spinbutton`, `spinbutton-decrement`, `spinbutton-input`, `spinbutton-increment`, `field-message`
60
+ - State attributes: `data-field-error`, `data-spinbutton-error`, `data-spinbutton-disabled`, `data-field-tone`
61
+
62
+ ## Keyboard
63
+
64
+ | Keys | Action |
65
+ | ----------------------- | ----------------- |
66
+ | `↑` / `↓` | Step up / down |
67
+ | `Page Up` / `Page Down` | Ten steps |
68
+ | `Home` / `End` | Minimum / maximum |
69
+
70
+ ## Accessibility
71
+
72
+ - The buttons repeat while held and are skipped by Tab.
73
+ - Values are clamped and rounded on blur.
@@ -0,0 +1,64 @@
1
+ # Split Button
2
+
3
+ > A main action with a menu of alternatives.
4
+
5
+ ## Examples
6
+
7
+ ### With a menu
8
+
9
+ Pass the menu's trigger `attrs` to `trigger-attrs`.
10
+
11
+ ```vue
12
+ <script setup lang="ts">
13
+ const toast = useToast();
14
+ const options = [
15
+ { label: "Save as draft", value: "draft" },
16
+ { label: "Save and publish", value: "publish" },
17
+ { label: "Save a copy", value: "copy" },
18
+ ];
19
+ </script>
20
+
21
+ <template>
22
+ <UiMenu :items="options" align="end" @select="(value) => toast.success(`Saved (${value})`)">
23
+ <template #trigger="{ attrs }">
24
+ <UiSplitButton
25
+ variant="primary"
26
+ menu-label="More save options"
27
+ :trigger-attrs="attrs"
28
+ @action="toast.success('Saved')"
29
+ >
30
+ Save
31
+ </UiSplitButton>
32
+ </template>
33
+ </UiMenu>
34
+ </template>
35
+ ```
36
+
37
+ ## API
38
+
39
+ | Prop | Type | Default | Description |
40
+ | --- | --- | --- | --- |
41
+ | `menuLabel` (required) | `string` | — | Accessible name for the toggle half, e.g. "More save options". |
42
+ | `triggerAttrs` | `Record<string, unknown>` | — | The `attrs` from a `<Menu>` or `<Popover>` trigger slot, bound to the toggle half. |
43
+ | `variant` | `"danger" \| "ghost" \| "primary" \| "secondary" \| "solid"` | `"secondary"` | Style hook, exposed as `data-button-variant` on both halves. |
44
+ | `size` | `"medium" \| "small"` | `"medium"` | Size hook, exposed as `data-button-size` on both halves. |
45
+ | `disabled` | `boolean` | `false` | Disables both halves. |
46
+
47
+ | Event | Payload | Description |
48
+ | --- | --- | --- |
49
+ | `action` | `[]` | The main half was pressed. |
50
+ | `toggle` | `[]` | The toggle half was pressed. |
51
+
52
+ | Slot | Props | Description |
53
+ | --- | --- | --- |
54
+ | `default` | — | Main action label. |
55
+ | `caret` | `{ open: boolean; }` | Replaces the toggle's chevron. |
56
+
57
+ ## Styling
58
+
59
+ - Parts (`[data-part="…"]`): `split-button`, `button-label`
60
+ - State attributes: `data-split-variant`, `data-split-part`, `data-split-open`
61
+
62
+ ## Accessibility
63
+
64
+ - Name the toggle with `menu-label`.
@@ -0,0 +1,71 @@
1
+ # Switch
2
+
3
+ > An on/off toggle.
4
+
5
+ ## Examples
6
+
7
+ ### Basic
8
+
9
+ ```vue
10
+ <script setup lang="ts">
11
+ const notifications = ref(true);
12
+ const marketing = ref(false);
13
+ </script>
14
+
15
+ <template>
16
+ <div class="demo-stack">
17
+ <UiSwitch v-model="notifications" label="Push notifications" />
18
+ <UiSwitch v-model="marketing" label="Product updates" size="small" />
19
+ <UiSwitch :model-value="true" label="Required" disabled />
20
+ </div>
21
+ </template>
22
+ ```
23
+
24
+ ### Hint
25
+
26
+ Like other fields, `hint` and `error` show under the label and are read as its description.
27
+
28
+ ```vue
29
+ <script setup lang="ts">
30
+ const digest = ref(true);
31
+ </script>
32
+
33
+ <template>
34
+ <div class="demo-stack">
35
+ <UiSwitch v-model="digest" label="Weekly digest" hint="A summary every Monday morning." />
36
+ </div>
37
+ </template>
38
+ ```
39
+
40
+ ## API
41
+
42
+ | Prop | Type | Default | Description |
43
+ | --- | --- | --- | --- |
44
+ | `disabled` | `boolean` | `false` | Disables the switch. |
45
+ | `label` | `string` | — | Text next to the switch. The default slot overrides it. |
46
+ | `size` | `"medium" \| "small"` | `"medium"` | Size hook, exposed as `data-switch-size`. |
47
+ | `hint` | `string` | — | Help text under the switch, announced as its description. |
48
+ | `error` | `string \| boolean` | — | `true` marks it invalid; a string also shows it as the message, replacing the hint. |
49
+ | `name` | `string` | — | Form field name: while on, a native form submits `value` under it. |
50
+ | `value` | `string` | `"on"` | What a native form submits while on, as a checkbox would. |
51
+ | `id` | `string` | — | Id for the switch; generated with `useId()` when omitted. |
52
+ | `modelValue` | `boolean` | `false` | On or off. |
53
+
54
+ | Event | Payload | Description |
55
+ | --- | --- | --- |
56
+ | `update:modelValue` | `[value: boolean]` | `v-model:modelValue` update. |
57
+
58
+ | Slot | Props | Description |
59
+ | --- | --- | --- |
60
+ | `default` | — | Label content, replacing `label`. |
61
+
62
+ ## Styling
63
+
64
+ - Parts (`[data-part="…"]`): `switch`, `switch-track`, `switch-thumb`, `switch-label`, `field-message`
65
+ - State attributes: `data-switch-size`, `data-switch-checked`, `data-switch-error`, `data-field-name`, `data-field-tone`
66
+
67
+ ## Keyboard
68
+
69
+ | Keys | Action |
70
+ | ----------------- | ------ |
71
+ | `Space` / `Enter` | Toggle |
@@ -0,0 +1,241 @@
1
+ # Table
2
+
3
+ > A data table with custom cells.
4
+
5
+ ## Examples
6
+
7
+ ### Basic
8
+
9
+ ```vue
10
+ <script setup lang="ts">
11
+ const columns = [
12
+ { key: "name", header: "Member" },
13
+ { key: "role", header: "Role" },
14
+ { key: "commits", header: "Commits", numeric: true },
15
+ ];
16
+
17
+ const rows = [
18
+ {
19
+ id: 1,
20
+ name: "Ada Lovelace",
21
+ email: "ada@example.com",
22
+ avatar: "/avatars/ada.svg",
23
+ role: "Maintainer",
24
+ commits: 1243,
25
+ },
26
+ {
27
+ id: 2,
28
+ name: "Grace Hopper",
29
+ email: "grace@example.com",
30
+ avatar: "/avatars/grace.svg",
31
+ role: "Reviewer",
32
+ commits: 812,
33
+ },
34
+ { id: 3, name: "Alan Turing", email: "alan@example.com", role: "Contributor", commits: 97 },
35
+ ];
36
+ </script>
37
+
38
+ <template>
39
+ <UiTable :columns="columns" :rows="rows" row-key="id" caption="Contributors">
40
+ <template #name-cell="{ row }">
41
+ <span class="person">
42
+ <UiAvatar :name="row.name" :src="row.avatar" size="small" />
43
+ <span>
44
+ {{ row.name }}
45
+ <small>{{ row.email }}</small>
46
+ </span>
47
+ </span>
48
+ </template>
49
+ <template #role-cell="{ value }">
50
+ <span class="badge" :data-tone="value === 'Maintainer' ? 'accent' : undefined">{{
51
+ value
52
+ }}</span>
53
+ </template>
54
+ <template #commits-cell="{ value }">{{ (value as number).toLocaleString("en-US") }}</template>
55
+ </UiTable>
56
+ </template>
57
+ ```
58
+
59
+ ### Custom cells
60
+
61
+ Replace any cell, header or footer with the `<key>-cell`, `<key>-header` and `<key>-footer` slots.
62
+
63
+ ```vue
64
+ <script setup lang="ts">
65
+ interface Invoice {
66
+ id: string;
67
+ customer: string;
68
+ status: "paid" | "due" | "overdue";
69
+ amount: number;
70
+ }
71
+
72
+ const columns = [
73
+ { key: "id", header: "Invoice" },
74
+ { key: "status", header: "Status" },
75
+ { key: "amount", header: "Amount", numeric: true },
76
+ { key: "actions", header: "", align: "right" as const, width: "64px" as const },
77
+ ];
78
+
79
+ const rows: Invoice[] = [
80
+ { id: "INV-001", customer: "Acme Inc.", status: "paid", amount: 1200 },
81
+ { id: "INV-002", customer: "Globex", status: "due", amount: 860 },
82
+ { id: "INV-003", customer: "Initech", status: "overdue", amount: 2400 },
83
+ ];
84
+
85
+ const tones = { paid: "success", due: "warning", overdue: "danger" } as const;
86
+ const total = rows.reduce((sum, row) => sum + row.amount, 0);
87
+ const money = (value: number) => `$${value.toLocaleString("en-US")}`;
88
+
89
+ const toast = useToast();
90
+ const actions = [
91
+ { label: "View", value: "view" },
92
+ { label: "Download PDF", value: "download" },
93
+ { label: "Void", value: "void" },
94
+ ];
95
+ </script>
96
+
97
+ <template>
98
+ <UiTable :columns="columns" :rows="rows" row-key="id">
99
+ <template #id-cell="{ row }">
100
+ <span class="stacked">
101
+ {{ row.id }}
102
+ <small>{{ row.customer }}</small>
103
+ </span>
104
+ </template>
105
+ <template #status-cell="{ row }">
106
+ <span class="badge" :data-tone="tones[row.status]">{{ row.status }}</span>
107
+ </template>
108
+ <template #amount-cell="{ row }">{{ money(row.amount) }}</template>
109
+ <template #amount-footer>{{ money(total) }}</template>
110
+ <template #actions-cell="{ row }">
111
+ <UiMenu :items="actions" align="end" @select="(action) => toast.info(`${action} ${row.id}`)">
112
+ <template #trigger="{ attrs }">
113
+ <UiIconButton :label="`Actions for ${row.id}`" size="small" v-bind="attrs">
114
+ <Icon name="more" :size="14" />
115
+ </UiIconButton>
116
+ </template>
117
+ </UiMenu>
118
+ </template>
119
+ </UiTable>
120
+ </template>
121
+ ```
122
+
123
+ ### Sorting
124
+
125
+ Mark a column `sortable` and its header becomes a button that sets `v-model:sort`. The table doesn't reorder rows: sort them yourself, or on the server.
126
+
127
+ ```vue
128
+ <script setup lang="ts">
129
+ import type { TableSort } from "@humanonlyweb/ui";
130
+
131
+ const columns = [
132
+ { key: "name", header: "Package", sortable: true },
133
+ { key: "size", header: "Size (kB)", numeric: true, sortable: true },
134
+ { key: "downloads", header: "Weekly downloads", numeric: true, sortable: true },
135
+ ];
136
+
137
+ const packages = [
138
+ { name: "vue", size: 112, downloads: 7_100_000 },
139
+ { name: "nuxt", size: 820, downloads: 1_050_000 },
140
+ { name: "vite", size: 3_900, downloads: 31_000_000 },
141
+ { name: "zod", size: 590, downloads: 26_000_000 },
142
+ ];
143
+
144
+ const sort = ref<TableSort>({ key: "downloads", direction: "descending" });
145
+
146
+ // The table only reports the sort; ordering the rows (here, or on a server) is yours.
147
+ const rows = computed(() => {
148
+ const { key, direction } = sort.value;
149
+ const sign = direction === "ascending" ? 1 : -1;
150
+ return packages.toSorted((a, b) => {
151
+ const x = a[key as keyof typeof a];
152
+ const y = b[key as keyof typeof b];
153
+ return (
154
+ (typeof x === "number" && typeof y === "number"
155
+ ? x - y
156
+ : String(x).localeCompare(String(y))) * sign
157
+ );
158
+ });
159
+ });
160
+ </script>
161
+
162
+ <template>
163
+ <UiTable v-model:sort="sort" :columns="columns" :rows="rows" row-key="name" caption="Packages">
164
+ <template #downloads-cell="{ value }">{{ Number(value).toLocaleString("en-US") }}</template>
165
+ </UiTable>
166
+ </template>
167
+ ```
168
+
169
+ ### Empty
170
+
171
+ ```vue
172
+ <script setup lang="ts">
173
+ const columns = [
174
+ { key: "name", header: "Name" },
175
+ { key: "email", header: "Email" },
176
+ ];
177
+ </script>
178
+
179
+ <template>
180
+ <UiTable :columns="columns" :rows="[]" caption="Members">
181
+ <template #empty>
182
+ <div class="empty">
183
+ <p>No members yet</p>
184
+ <UiButton size="small" variant="secondary">
185
+ <template #leading><Icon name="plus" :size="14" /></template>
186
+ Invite someone
187
+ </UiButton>
188
+ </div>
189
+ </template>
190
+ </UiTable>
191
+ </template>
192
+ ```
193
+
194
+ ## API
195
+
196
+ | Prop | Type | Default | Description |
197
+ | --- | --- | --- | --- |
198
+ | `columns` (required) | `TableColumn<T>[]` | — | Column definitions: `key`, `header`, and optional `accessor`, `align`, `numeric`, `width`. |
199
+ | `rows` (required) | `T[]` | — | Row data. |
200
+ | `rowKey` | `((row: T, index: number) => PropertyKey) \| keyof T` | — | Stable key per row: a property name or a function. Defaults to the index. |
201
+ | `caption` | `string` | — | Visible caption. Also names the scroll region. |
202
+ | `sort` | `TableSort` | — | The sorted column and direction, set by `sortable` columns' headers. Rows aren't reordered for you. |
203
+
204
+ | Event | Payload | Description |
205
+ | --- | --- | --- |
206
+ | `update:sort` | `[value: TableSort \| undefined]` | `v-model:sort` update. |
207
+
208
+ | Slot | Props | Description |
209
+ | --- | --- | --- |
210
+ | `empty` | — | Shown when there are no rows. |
211
+ | `sort-indicator` | `{ direction: "ascending" \| "descending" \| undefined; }` | Replaces a sortable header's direction arrow. |
212
+
213
+ Types:
214
+
215
+ ```ts
216
+ export interface TableColumn<T> {
217
+ key: string;
218
+ header: string;
219
+ accessor?: (row: T) => unknown;
220
+ align?: TdHTMLAttributes["align"];
221
+ numeric?: boolean;
222
+ width?: `${number}px` | `${number}%`;
223
+ /** Its header becomes a button that sets the table's `v-model:sort`. */
224
+ sortable?: boolean;
225
+ }
226
+
227
+ /** A table's sort: which column, which way. Sorting the rows is up to you. */
228
+ export interface TableSort {
229
+ key: string;
230
+ direction: "ascending" | "descending";
231
+ }
232
+ ```
233
+
234
+ ## Styling
235
+
236
+ - Parts (`[data-part="…"]`): `table-scroll`, `table`, `table-caption`, `table-header`, `table-row`, `table-cell`, `table-sort`, `table-sort-indicator`, `table-empty`, `table-footer`
237
+ - State attributes: `data-table-overflow`, `data-table-align`, `data-table-numeric`, `data-table-sort`
238
+
239
+ ## Accessibility
240
+
241
+ - A table wider than its container scrolls in a region named by `caption`, focusable so the keyboard can scroll it.
@@ -0,0 +1,106 @@
1
+ # Tabs
2
+
3
+ > Panels switched by tabs.
4
+
5
+ ## Examples
6
+
7
+ ### Basic
8
+
9
+ ```vue
10
+ <script setup lang="ts">
11
+ const tab = ref("overview");
12
+ const tabs = [
13
+ { label: "Overview", value: "overview" },
14
+ { label: "Activity", value: "activity" },
15
+ { label: "Settings", value: "settings" },
16
+ { label: "Billing", value: "billing", disabled: true },
17
+ ];
18
+ </script>
19
+
20
+ <template>
21
+ <UiTabs v-model="tab" :items="tabs" label="Project" class="demo-wide" v-slot="{ value }">
22
+ <p v-if="value === 'overview'">A summary of the project.</p>
23
+ <p v-else-if="value === 'activity'">Recent commits and comments.</p>
24
+ <p v-else>Name, visibility and danger zone.</p>
25
+ </UiTabs>
26
+ </template>
27
+ ```
28
+
29
+ ### Counts
30
+
31
+ The `tab` slot replaces each tab's text, e.g. to add a count.
32
+
33
+ ```vue
34
+ <script setup lang="ts">
35
+ const tab = ref("open");
36
+ const tabs = [
37
+ { label: "Open", value: "open", count: 12 },
38
+ { label: "In review", value: "review", count: 3 },
39
+ { label: "Closed", value: "closed", count: 148 },
40
+ ];
41
+ const countOf = (value?: string) => tabs.find((t) => t.value === value)?.count;
42
+ </script>
43
+
44
+ <template>
45
+ <UiTabs v-model="tab" :items="tabs" label="Issues" class="demo-wide">
46
+ <template #tab="{ item, selected }">
47
+ {{ item.label }}
48
+ <span class="tab-count" :data-selected="selected || undefined">{{
49
+ countOf(item.value)
50
+ }}</span>
51
+ </template>
52
+ <template #default="{ value }">
53
+ <p>{{ countOf(value) }} issues.</p>
54
+ </template>
55
+ </UiTabs>
56
+ </template>
57
+ ```
58
+
59
+ ## API
60
+
61
+ | Prop | Type | Default | Description |
62
+ | --- | --- | --- | --- |
63
+ | `items` | `SelectOption<T>[]` | `[]` | Tabs to render, in order. |
64
+ | `label` | `string` | — | Accessible name for the tablist. |
65
+ | `disabled` | `boolean` | `false` | Disables every tab. |
66
+ | `modelValue` | `T` | — | The selected tab's value. |
67
+
68
+ | Event | Payload | Description |
69
+ | --- | --- | --- |
70
+ | `update:modelValue` | `[value: T \| undefined]` | `v-model:modelValue` update. |
71
+
72
+ | Slot | Props | Description |
73
+ | --- | --- | --- |
74
+ | `default` | `{ value: T \| undefined; }` | Panel content for the selected tab. |
75
+ | `tab` | `{ item: SelectOption<T>; selected: boolean; }` | Tab content. |
76
+
77
+ Types:
78
+
79
+ ```ts
80
+ export interface SelectOption<T extends SelectValue = SelectValue> {
81
+ label: string;
82
+ value: T;
83
+ disabled?: boolean;
84
+ }
85
+
86
+ export type SelectValue = string | number;
87
+ ```
88
+
89
+ ## Styling
90
+
91
+ `--ui-indicator-x`, `--ui-indicator-width`, `--ui-indicator-top` and `--ui-indicator-height` place the indicator on the selected item.
92
+
93
+ - Parts (`[data-part="…"]`): `tabs`, `tablist`, `tab-indicator`, `tab`, `tabpanel`
94
+ - State attributes: `data-tabs-sliding`, `data-tabs-animate`, `data-tab-selected`
95
+
96
+ ## Keyboard
97
+
98
+ | Keys | Action |
99
+ | -------------- | -------------------------------------- |
100
+ | `Tab` | Focus the selected tab, then the panel |
101
+ | `←` / `→` | Select the previous / next tab |
102
+ | `Home` / `End` | Select the first / last tab |
103
+
104
+ ## Accessibility
105
+
106
+ - In right-to-left layouts, `←` / `→` follow the visual direction.