@thekestongroup/ui 0.10.0 → 0.11.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thekestongroup/ui",
3
- "version": "0.10.0",
3
+ "version": "0.11.1",
4
4
  "description": "Keston UI — Vue 3 + Reka UI + Tailwind CSS component library",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {
@@ -29,7 +29,7 @@ import Slideover from '../Slideover/Slideover.vue'
29
29
  * account-settings, switch-account, log-out (and sign-in when signed out).
30
30
  *
31
31
  * Slots: default (the page), header-leading, header-middle, header-trailing,
32
- * account, account-menu (passed to Header), sidebar-header and sidebar-footer (passed to Sidebar;
32
+ * account, account-menu and organisation (passed to Header), sidebar-header and sidebar-footer (passed to Sidebar;
33
33
  * sidebar-header is only shown on wide screens, as the Slideover has its own
34
34
  * title).
35
35
  */
@@ -86,6 +86,7 @@ defineSlots<{
86
86
  'header-trailing'?(): unknown
87
87
  account?(): unknown
88
88
  'account-menu'?(props: { close: () => void }): unknown
89
+ organisation?(props: { close: () => void }): unknown
89
90
  'sidebar-header'?(props: { collapsed: boolean }): unknown
90
91
  'sidebar-footer'?(props: { collapsed: boolean; mobile: boolean }): unknown
91
92
  }>()
@@ -166,6 +167,7 @@ const sidebarId = `${uid}-sidebar`
166
167
  <template v-if="$slots['header-trailing']" #trailing><slot name="header-trailing" /></template>
167
168
  <template v-if="$slots.account" #account><slot name="account" /></template>
168
169
  <template v-if="$slots['account-menu']" #account-menu="slotProps"><slot name="account-menu" v-bind="slotProps" /></template>
170
+ <template v-if="$slots.organisation" #organisation="slotProps"><slot name="organisation" v-bind="slotProps" /></template>
169
171
  </Header>
170
172
 
171
173
  <div class="flex flex-1">
@@ -94,6 +94,35 @@ export const CustomUserMenu: Story = {
94
94
  }),
95
95
  };
96
96
 
97
+ /**
98
+ * The organisation slot replaces the organisation heading at the top of the
99
+ * account menu, e.g. with a row that switches organisation. A divider sits
100
+ * under it.
101
+ */
102
+ export const OrganisationSwitcher: Story = {
103
+ render: (args) => ({
104
+ components: { Header, Building2, ChevronRight },
105
+ setup: () => ({ args }),
106
+ template: `
107
+ <Header v-bind="args">
108
+ <template #organisation="{ close }">
109
+ <button
110
+ type="button"
111
+ class="flex w-full items-center gap-2 px-4 py-3 text-left text-sm hover:bg-black/5 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus"
112
+ @click="close"
113
+ >
114
+ <Building2 class="size-4 shrink-0" aria-hidden="true" />
115
+ <span class="flex min-w-0 flex-1 flex-col">
116
+ <span class="truncate font-bold">The Keston School</span>
117
+ <span class="text-xs text-black/65">Switch organisation</span>
118
+ </span>
119
+ <ChevronRight class="size-4 shrink-0" aria-hidden="true" />
120
+ </button>
121
+ </template>
122
+ </Header>`,
123
+ }),
124
+ };
125
+
97
126
  /** The whole account area replaced with the account slot. */
98
127
  export const CustomUser: Story = {
99
128
  render: (args) => ({
@@ -30,7 +30,9 @@ export type HeaderUserAction = 'account-settings' | 'switch-account' | 'log-out'
30
30
  * fills the space between title and trailing), trailing (actions before the
31
31
  * account menu), account (replaces the account menu, or the Sign in button),
32
32
  * account-menu (extra content in the account menu, above Switch account /
33
- * Log out: `{ close }`).
33
+ * Log out: `{ close }`), organisation (replaces the organisation heading at the
34
+ * very top of the account menu, e.g. with a row that switches organisation:
35
+ * `{ close }`).
34
36
  */
35
37
  export interface HeaderProps {
36
38
  /** Name of the app or area, shown next to the menu button. */
@@ -108,6 +110,7 @@ defineSlots<{
108
110
  trailing?(): unknown
109
111
  account?(): unknown
110
112
  'account-menu'?(props: { close: () => void }): unknown
113
+ organisation?(props: { close: () => void }): unknown
111
114
  }>()
112
115
 
113
116
  // "Ben Smith" → "BS", "Ben" → "B".
@@ -192,20 +195,22 @@ function runAction(action: HeaderUserAction, close: () => void) {
192
195
  <slot name="account">
193
196
  <!-- Account menu: the user's avatar opens a panel with who is signed
194
197
  in and the account actions. -->
195
- <Popover v-if="user" :content="{ align: 'end' }" :ui="{ content: cn('w-72', ui?.userMenu) }">
198
+ <Popover v-if="user" :content="{ align: 'end' }" :ui="{ content: cn('w-80', ui?.userMenu) }">
196
199
  <Button variant="ghost" square :aria-label="accountLabel" class="-mr-1.5 rounded-full">
197
200
  <Avatar :user="user" size="sm" decorative />
198
201
  </Button>
199
202
 
200
203
  <template #content="{ close }">
201
204
  <div class="flex flex-col">
202
- <p
203
- v-if="user.organisation"
204
- class="truncate px-4 pt-3 text-xs font-bold text-black/65 uppercase"
205
- :title="user.organisation"
206
- >
207
- {{ user.organisation }}
208
- </p>
205
+ <!-- The organisation at the top, with a divider under it. The
206
+ organisation slot replaces the plain heading. -->
207
+ <div v-if="user.organisation || $slots.organisation" class="border-b border-black/15">
208
+ <slot name="organisation" :close="close">
209
+ <p class="truncate px-4 py-3 text-xs font-bold text-black/65 uppercase" :title="user.organisation">
210
+ {{ user.organisation }}
211
+ </p>
212
+ </slot>
213
+ </div>
209
214
  <!-- Two columns: the avatar at the top left, beside the name and
210
215
  email; Account settings sits under them in the text column,
211
216
  without moving the avatar. -->
@@ -45,12 +45,21 @@ export const Grid: Story = {
45
45
  <div class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4">
46
46
  <StatTile label="Students on roll" value="1,204" :icon="Users" change="+38" change-label="since September" trend="up" />
47
47
  <StatTile label="Open applications" value="48" :icon="FileText" change="+12%" change-label="on last year" trend="up" />
48
- <StatTile label="Attendance" value="95.8%" :icon="CalendarCheck" change="0.0 pts" change-label="on last week" trend="flat" />
48
+ <StatTile label="Attendance" value="95.8%" :icon="CalendarCheck" change="0.0 pts" change-label="on last week" trend="flat" href="#attendance" />
49
49
  <StatTile label="Persistent absence" value="7.4%" :icon="UserX" change="+0.9 pts" change-label="this term" trend="up" sentiment="negative" />
50
50
  </div>`,
51
51
  }),
52
52
  };
53
53
 
54
+ /**
55
+ * With an `href` (or `as` for a router link) the whole tile is one link: an
56
+ * arrow in the corner shows it's clickable, the border darkens on hover and
57
+ * the background on press. Tab to it to see the focus ring.
58
+ */
59
+ export const Clickable: Story = {
60
+ args: { href: "#open-applications", icon: FileText, description: "Waiting for an interview or a decision." },
61
+ };
62
+
54
63
  /** With a description and a footer link. */
55
64
  export const WithDescriptionAndFooter: Story = {
56
65
  args: { description: "Waiting for an interview or a decision.", change: undefined, changeLabel: undefined, trend: undefined },
@@ -1,6 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { useI18n } from 'vue-i18n'
3
- import { computed, type Component, type HTMLAttributes } from 'vue'
3
+ import { computed, watchEffect, type Component, type HTMLAttributes } from 'vue'
4
+ import { Primitive, type PrimitiveProps } from 'reka-ui'
4
5
  import { ArrowDownRight, ArrowRight, ArrowUpRight } from '@lucide/vue'
5
6
  import { cn } from '../../lib/cn'
6
7
  import Card from '../Card/Card.vue'
@@ -10,8 +11,12 @@ import Card from '../Card/Card.vue'
10
11
  * Put several in a grid. Optionally with how it's changed ("+12% on last
11
12
  * year") and a short description.
12
13
  *
14
+ * Give it an `href` (or `as`, e.g. a router link, with its own `to`) and the
15
+ * whole tile becomes one link: an arrow in the corner shows it's clickable,
16
+ * and it darkens its border on hover and its background when pressed.
17
+ *
13
18
  * Slots: value (e.g. a value with a unit in smaller text), description,
14
- * footer (e.g. a "View all" link).
19
+ * footer (e.g. a "View all" link; not in a tile that is itself a link).
15
20
  */
16
21
  export interface StatTileProps {
17
22
  /** What the number is, e.g. "Open applications". */
@@ -34,18 +39,30 @@ export interface StatTileProps {
34
39
  sentiment?: 'positive' | 'negative' | 'neutral'
35
40
  /** Grey text under the value. */
36
41
  description?: string
42
+ /** Makes the whole tile a link to here. */
43
+ href?: string
44
+ /** Element or component to render the link as, e.g. RouterLink (then pass its `to`). Makes the tile a link. */
45
+ as?: PrimitiveProps['as']
37
46
  class?: HTMLAttributes['class']
38
47
  }
39
48
 
40
49
  const { t } = useI18n()
41
50
  const props = defineProps<StatTileProps>()
42
51
 
43
- defineSlots<{
52
+ const slots = defineSlots<{
44
53
  value?(): unknown
45
54
  description?(): unknown
46
55
  footer?(): unknown
47
56
  }>()
48
57
 
58
+ const isLink = computed(() => Boolean(props.href || props.as))
59
+ // A link can't hold another link or button, so the footer is for static tiles.
60
+ watchEffect(() => {
61
+ if (import.meta.env.DEV && isLink.value && slots.footer) {
62
+ console.warn('[StatTile] The footer slot is ignored when the tile is a link (href or as).')
63
+ }
64
+ })
65
+
49
66
  const tone = computed(() => {
50
67
  if (props.sentiment) return props.sentiment
51
68
  if (props.trend === 'up') return 'positive'
@@ -62,8 +79,27 @@ const trendWords = computed(() => ({ up: t('ui.statTile.up'), down: t('ui.statTi
62
79
  </script>
63
80
 
64
81
  <template>
65
- <Card padding="sm" :class="props.class" :ui="{ body: 'gap-1' }">
66
- <p class="flex items-center gap-2 text-sm text-black/65">
82
+ <!-- A link wraps the card; a static tile is just the card (as="template" hands the attributes to it). -->
83
+ <Primitive
84
+ :as="isLink ? (as ?? 'a') : 'template'"
85
+ :href="isLink ? href : undefined"
86
+ :class="isLink && 'group block h-full cursor-pointer rounded-lg outline-2 outline-offset-2 outline-transparent focus-visible:outline-focus'"
87
+ >
88
+ <Card
89
+ padding="sm"
90
+ :class="
91
+ cn(
92
+ isLink &&
93
+ 'relative h-full transition-[border-color,box-shadow,background-color] duration-150 motion-reduce:transition-none group-hover:border-black/40 group-hover:shadow-md group-active:bg-black/1',
94
+ props.class
95
+ )
96
+ "
97
+ :ui="{ body: 'gap-1' }"
98
+ >
99
+ <!-- Still, decorative: the link role is what screen readers get. -->
100
+ <ArrowUpRight v-if="isLink" class="absolute end-4 top-4 size-4 text-black/65" aria-hidden="true" />
101
+
102
+ <p :class="cn('flex items-center gap-2 text-sm text-black/65', isLink && 'pe-6')">
67
103
  <component :is="icon" v-if="icon" class="size-4 shrink-0" aria-hidden="true" />
68
104
  {{ label }}
69
105
  </p>
@@ -84,8 +120,9 @@ const trendWords = computed(() => ({ up: t('ui.statTile.up'), down: t('ui.statTi
84
120
  <slot name="description">{{ description }}</slot>
85
121
  </p>
86
122
 
87
- <div v-if="$slots.footer" class="mt-2 text-sm">
123
+ <div v-if="$slots.footer && !isLink" class="mt-2 text-sm">
88
124
  <slot name="footer" />
89
125
  </div>
90
126
  </Card>
127
+ </Primitive>
91
128
  </template>