@thekestongroup/ui 0.4.0 → 0.6.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 (38) hide show
  1. package/dist/components/AppShell/AppShell.vue.d.ts +4 -2
  2. package/dist/components/FormField/FormField.vue.d.ts +5 -0
  3. package/dist/components/Header/Header.vue.d.ts +9 -1
  4. package/dist/components/Input/Input.vue.d.ts +2 -0
  5. package/dist/components/InputDate/InputDate.vue.d.ts +2 -0
  6. package/dist/components/InputNumber/InputNumber.vue.d.ts +2 -0
  7. package/dist/components/InputPassword/InputPassword.vue.d.ts +2 -0
  8. package/dist/components/InputRichText/InputRichText.vue.d.ts +2 -0
  9. package/dist/components/Menu/Menu.vue.d.ts +38 -0
  10. package/dist/components/PageHeader/PageHeader.vue.d.ts +23 -1
  11. package/dist/components/Select/Select.vue.d.ts +2 -0
  12. package/dist/components/Sidebar/Sidebar.vue.d.ts +1 -1
  13. package/dist/components/Table/Table.vue.d.ts +14 -1
  14. package/dist/components/Tabs/Tabs.vue.d.ts +42 -0
  15. package/dist/index.d.ts +5 -1
  16. package/dist/keston-ui.js +817 -589
  17. package/package.json +1 -1
  18. package/src/components/AppShell/AppShell.stories.ts +5 -0
  19. package/src/components/AppShell/AppShell.vue +6 -2
  20. package/src/components/FormField/FormField.vue +7 -2
  21. package/src/components/Header/Header.stories.ts +9 -0
  22. package/src/components/Header/Header.vue +27 -4
  23. package/src/components/Input/Input.stories.ts +21 -0
  24. package/src/components/Input/Input.vue +3 -0
  25. package/src/components/InputDate/InputDate.vue +3 -0
  26. package/src/components/InputNumber/InputNumber.vue +3 -0
  27. package/src/components/InputPassword/InputPassword.vue +3 -0
  28. package/src/components/InputRichText/InputRichText.vue +3 -0
  29. package/src/components/Menu/Menu.stories.ts +40 -0
  30. package/src/components/Menu/Menu.vue +104 -0
  31. package/src/components/PageHeader/PageHeader.stories.ts +33 -1
  32. package/src/components/PageHeader/PageHeader.vue +52 -1
  33. package/src/components/Select/Select.vue +3 -0
  34. package/src/components/Table/Table.stories.ts +59 -1
  35. package/src/components/Table/Table.vue +57 -4
  36. package/src/components/Tabs/Tabs.stories.ts +47 -0
  37. package/src/components/Tabs/Tabs.vue +69 -0
  38. package/src/index.ts +5 -1
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts" generic="Row extends Record<string, any>">
2
- import { computed, onBeforeUnmount, onMounted, ref, useId, type HTMLAttributes } from 'vue'
2
+ import { computed, onBeforeUnmount, onMounted, ref, useId, type Component, type HTMLAttributes } from 'vue'
3
3
  import { ArrowDown, ArrowUp, ChevronsUpDown } from '@lucide/vue'
4
4
  import { cn } from '../../lib/cn'
5
5
  import EmptyState from '../EmptyState/EmptyState.vue'
@@ -19,6 +19,11 @@ import { nextSort, sortRows, type TableColumn, type TableSort } from './table'
19
19
  * `manualSort` it only reports the sort (`v-model:sort`) so you can sort on
20
20
  * the server.
21
21
  *
22
+ * Clickable rows: `rowLink` gives each row a page to go to. The row-header
23
+ * cell (or the first column) becomes a real link, stretched over the whole
24
+ * row, so the row highlights on hover and a click anywhere on it follows the
25
+ * link. Buttons and links in other cells still work on their own.
26
+ *
22
27
  * Slots: cell-{key}, header-{key}, empty, footer (rows for a `<tfoot>`,
23
28
  * e.g. totals), caption.
24
29
  */
@@ -43,6 +48,14 @@ export interface TableProps<Row = Record<string, any>> {
43
48
  stickyHeader?: boolean
44
49
  /** Don't sort the rows: just update `sort`, e.g. to sort on the server. */
45
50
  manualSort?: boolean
51
+ /**
52
+ * Where each row goes when clicked: passed as `to` to `linkComponent`
53
+ * (e.g. a route), or as `href` without one. Return undefined for rows that
54
+ * don't go anywhere.
55
+ */
56
+ rowLink?: (row: Row, index: number) => unknown
57
+ /** Component for row links, e.g. RouterLink. It receives `to`. Default a plain `<a href>`. */
58
+ linkComponent?: string | Component
46
59
  class?: HTMLAttributes['class']
47
60
  ui?: {
48
61
  table?: HTMLAttributes['class']
@@ -53,7 +66,8 @@ export interface TableProps<Row = Record<string, any>> {
53
66
 
54
67
  const props = withDefaults(defineProps<TableProps<Row>>(), {
55
68
  emptyText: 'Nothing to show.',
56
- size: 'md'
69
+ size: 'md',
70
+ linkComponent: 'a'
57
71
  })
58
72
 
59
73
  const sort = defineModel<TableSort | null>('sort', { default: null })
@@ -86,6 +100,30 @@ function ariaSort(column: TableColumn<Row>) {
86
100
  return sort.value.direction === 'asc' ? 'ascending' : 'descending'
87
101
  }
88
102
 
103
+ // The column whose cell holds the row's link: the row header, else the first.
104
+ const linkColumn = computed(() => (props.columns.find((c) => c.rowHeader) ?? props.columns[0])?.key)
105
+
106
+ function linkFor(row: Row, index: number) {
107
+ const target = props.rowLink?.(row, index)
108
+ if (target === undefined || target === null || target === '') return undefined
109
+ return props.linkComponent === 'a' ? { href: target as string } : { to: target }
110
+ }
111
+
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.
116
+ const rowLinkClass = [
117
+ 'text-inherit no-underline outline-none group-hover/row:underline underline-offset-2',
118
+ 'after:absolute after:inset-0 after:outline-2 after:-outline-offset-2 after:outline-transparent',
119
+ 'focus-visible:after:outline-focus forced-colors:not-focus-visible:after:outline-0'
120
+ ]
121
+ 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'
125
+ ]
126
+
89
127
  const cellPadding = computed(() => (props.size === 'sm' ? 'px-4 py-2' : 'px-4 py-3'))
90
128
 
91
129
  function columnClasses(column: TableColumn<Row>) {
@@ -183,7 +221,11 @@ onBeforeUnmount(() => observer?.disconnect())
183
221
  </slot>
184
222
  </td>
185
223
  </tr>
186
- <tr v-for="(row, index) in shownRows" :key="keyOf(row, index)" :class="cn('group/row', ui?.row)">
224
+ <tr
225
+ v-for="(row, index) in shownRows"
226
+ :key="keyOf(row, index)"
227
+ :class="cn('group/row', linkFor(row, index) && linkedRowClass, ui?.row)"
228
+ >
187
229
  <component
188
230
  :is="column.rowHeader ? 'th' : 'td'"
189
231
  v-for="column in columns"
@@ -199,7 +241,18 @@ onBeforeUnmount(() => observer?.disconnect())
199
241
  )
200
242
  "
201
243
  >
202
- <slot :name="`cell-${column.key}`" :row="row" :value="row[column.key]" :index="index">
244
+ <component
245
+ :is="linkComponent"
246
+ v-if="column.key === linkColumn && linkFor(row, index)"
247
+ v-bind="linkFor(row, index)"
248
+ data-row-link
249
+ :class="rowLinkClass"
250
+ >
251
+ <slot :name="`cell-${column.key}`" :row="row" :value="row[column.key]" :index="index">
252
+ {{ row[column.key] ?? '' }}
253
+ </slot>
254
+ </component>
255
+ <slot v-else :name="`cell-${column.key}`" :row="row" :value="row[column.key]" :index="index">
203
256
  {{ row[column.key] ?? '' }}
204
257
  </slot>
205
258
  </component>
@@ -0,0 +1,47 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import { AppWindow, UserRound } from "@lucide/vue";
3
+ import { ref } from "vue";
4
+ import Card from "../Card/Card.vue";
5
+ import Tabs from "./Tabs.vue";
6
+
7
+ const meta = {
8
+ title: "Components/Navigation/Tabs",
9
+ component: Tabs,
10
+ tags: ["autodocs"],
11
+ parameters: { layout: "padded" },
12
+ args: {
13
+ label: "User details",
14
+ tabs: [
15
+ { value: "account", label: "Account", icon: UserRound },
16
+ { value: "licences", label: "Licences & Apps", icon: AppWindow },
17
+ ],
18
+ },
19
+ render: (args) => ({
20
+ components: { Tabs, Card },
21
+ setup: () => ({ args, tab: ref("account") }),
22
+ template: `
23
+ <Tabs v-bind="args" v-model="tab">
24
+ <template #account><Card title="Profile">Name, email, password and MFA.</Card></template>
25
+ <template #licences><Card title="Licences">Keston Work, and which apps they have.</Card></template>
26
+ </Tabs>`,
27
+ }),
28
+ } satisfies Meta<typeof Tabs>;
29
+
30
+ export default meta;
31
+ type Story = StoryObj<typeof meta>;
32
+
33
+ /** A user's page: Account, and Licences & Apps. Arrow keys move between tabs. */
34
+ export const Default: Story = {};
35
+
36
+ /** Without icons, with more tabs, one turned off. Narrow the preview to see the list scroll. */
37
+ export const Plain: Story = {
38
+ args: {
39
+ label: "Organisation",
40
+ tabs: [
41
+ { value: "account", label: "Overview" },
42
+ { value: "licences", label: "Users" },
43
+ { value: "groups", label: "Groups" },
44
+ { value: "billing", label: "Billing", disabled: true },
45
+ ],
46
+ },
47
+ };
@@ -0,0 +1,69 @@
1
+ <script setup lang="ts">
2
+ import type { Component, HTMLAttributes } from 'vue'
3
+ import { TabsContent, TabsIndicator, TabsList, TabsRoot, TabsTrigger } from 'reka-ui'
4
+ import { cn } from '../../lib/cn'
5
+
6
+ export interface Tab {
7
+ /** Identifies the tab: v-model's value, and the name of its content slot. */
8
+ value: string
9
+ label: string
10
+ /** A Lucide (or any) icon component, shown before the label. */
11
+ icon?: Component
12
+ disabled?: boolean
13
+ }
14
+
15
+ /**
16
+ * Sections of one page, one shown at a time, e.g. a user's Account and
17
+ * Licences & Apps. Built on Reka UI's Tabs: a tab list (arrow keys move
18
+ * between tabs, Home / End jump), each tab's content in a slot named after
19
+ * its value. Use v-model to know or set the open tab (e.g. to keep it in
20
+ * the URL).
21
+ */
22
+ export interface TabsProps {
23
+ tabs: Tab[]
24
+ /** The tab list's accessible name, e.g. "User details". */
25
+ label: string
26
+ class?: HTMLAttributes['class']
27
+ }
28
+
29
+ const props = defineProps<TabsProps>()
30
+ /** The open tab's value. Defaults to the first tab. */
31
+ const model = defineModel<string>()
32
+
33
+ defineSlots<Record<string, () => unknown>>()
34
+
35
+ // Like Sidebar's items: muted until hovered or chosen; the chosen one is
36
+ // primary, with a bar under it that slides between tabs.
37
+ const trigger = [
38
+ 'relative inline-flex h-10 items-center gap-2 px-3 text-sm whitespace-nowrap text-black/65 outline-none',
39
+ '[&_svg]:size-4 [&_svg]:shrink-0',
40
+ 'not-data-disabled:hover:text-black',
41
+ 'data-[state=active]:font-bold data-[state=active]:text-primary',
42
+ 'focus-visible:rounded focus-visible:ring-2 focus-visible:ring-primary',
43
+ 'data-disabled:cursor-not-allowed data-disabled:opacity-40'
44
+ ]
45
+ </script>
46
+
47
+ <template>
48
+ <TabsRoot
49
+ :model-value="model ?? tabs[0]?.value"
50
+ :class="cn('flex flex-col gap-6', props.class)"
51
+ @update:model-value="model = String($event)"
52
+ >
53
+ <!-- Scrolls sideways on narrow screens rather than wrapping. -->
54
+ <TabsList :aria-label="label" class="relative flex overflow-x-auto overflow-y-hidden border-b border-black/15">
55
+ <TabsTrigger v-for="t in tabs" :key="t.value" :value="t.value" :disabled="t.disabled" :class="trigger">
56
+ <component :is="t.icon" v-if="t.icon" aria-hidden="true" />
57
+ {{ t.label }}
58
+ </TabsTrigger>
59
+ <TabsIndicator
60
+ class="absolute bottom-0 left-0 h-0.5 w-(--reka-tabs-indicator-size) translate-x-(--reka-tabs-indicator-position) rounded-full transition-[width,translate] duration-200 motion-reduce:transition-none"
61
+ >
62
+ <span class="block size-full rounded-full bg-primary" />
63
+ </TabsIndicator>
64
+ </TabsList>
65
+ <TabsContent v-for="t in tabs" :key="t.value" :value="t.value" class="outline-none">
66
+ <slot :name="t.value" />
67
+ </TabsContent>
68
+ </TabsRoot>
69
+ </template>
package/src/index.ts CHANGED
@@ -11,7 +11,7 @@ export type { AppShellProps } from './components/AppShell/AppShell.vue'
11
11
  export { default as Header } from './components/Header/Header.vue'
12
12
  export type { HeaderProps, HeaderUser, HeaderUserAction } from './components/Header/Header.vue'
13
13
  export { default as PageHeader } from './components/PageHeader/PageHeader.vue'
14
- export type { PageHeaderProps } from './components/PageHeader/PageHeader.vue'
14
+ export type { PageHeaderAction, PageHeaderProps } from './components/PageHeader/PageHeader.vue'
15
15
 
16
16
  // Element
17
17
  export { default as Avatar } from './components/Avatar/Avatar.vue'
@@ -89,6 +89,10 @@ export type { LinkProps } from './components/Link/Link.vue'
89
89
  // Overlay
90
90
  export { default as Popover } from './components/Popover/Popover.vue'
91
91
  export type { PopoverProps } from './components/Popover/Popover.vue'
92
+ export { default as Menu } from './components/Menu/Menu.vue'
93
+ export type { MenuItem, MenuProps } from './components/Menu/Menu.vue'
94
+ export { default as Tabs } from './components/Tabs/Tabs.vue'
95
+ export type { Tab, TabsProps } from './components/Tabs/Tabs.vue'
92
96
  export { default as Slideover } from './components/Slideover/Slideover.vue'
93
97
  export type { SlideoverProps } from './components/Slideover/Slideover.vue'
94
98
  export { default as Tooltip } from './components/Tooltip/Tooltip.vue'