@thekestongroup/ui 0.19.0 → 0.21.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thekestongroup/ui",
3
- "version": "0.19.0",
3
+ "version": "0.21.0",
4
4
  "description": "Keston UI — Vue 3 + Reka UI + Tailwind CSS component library",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {
@@ -120,7 +120,7 @@ function linkAttrs(link: FooterLink) {
120
120
  side by side), labelled for screen readers. -->
121
121
  <div v-if="showLanguages || themeSwitcher" class="flex flex-wrap items-center gap-2">
122
122
  <LanguageSwitcher v-if="showLanguages" hide-label class="w-44" />
123
- <ThemeSwitcher v-if="themeSwitcher" hide-label appearance="segmented" />
123
+ <ThemeSwitcher v-if="themeSwitcher" hide-label appearance="icons" />
124
124
  </div>
125
125
  <p v-if="appName || version || build" class="flex flex-wrap items-baseline gap-x-1.5">
126
126
  <span v-if="appName" class="font-bold text-ink/80">{{ appName }}</span>
@@ -223,6 +223,26 @@ export const WithLockup: Story = {
223
223
  args: { lockup: sampleLockup, titleTo: "#home" },
224
224
  };
225
225
 
226
+ const sampleOrgLogo = (colour: string) =>
227
+ "data:image/svg+xml," +
228
+ encodeURIComponent(
229
+ `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 180 24"><path d="M12 1 2 5v7c0 6 4.5 9.5 10 11 5.5-1.5 10-5 10-11V5Z" fill="${colour}"/><text x="30" y="17" font-family="Georgia, serif" font-weight="700" font-size="15" fill="${colour}">The Keston School</text></svg>`,
230
+ );
231
+
232
+ /**
233
+ * organisationLogo: the organisation's logo at the top of the account menu
234
+ * (open it) instead of its name. Pass `{ light, dark }` for a dark-mode
235
+ * version; its alt text is the organisation's name.
236
+ */
237
+ export const WithOrganisationLogo: Story = {
238
+ args: {
239
+ user: {
240
+ ...user,
241
+ organisationLogo: { light: sampleOrgLogo("#023750"), dark: sampleOrgLogo("#ffffff") },
242
+ },
243
+ },
244
+ };
245
+
226
246
  /** Stays at the top while the page scrolls (the default). Scroll the box below. */
227
247
  export const Sticky: Story = {
228
248
  render: (args) => ({
@@ -13,6 +13,11 @@ export interface HeaderUser {
13
13
  email?: string
14
14
  /** Organisation or school the account belongs to, shown at the top of the account menu. */
15
15
  organisation?: string
16
+ /**
17
+ * The organisation's logo (e.g. a wordmark), shown at the top of the
18
+ * account menu instead of its name. Its alt text is the organisation's name.
19
+ */
20
+ organisationLogo?: HeaderImage
16
21
  /** Picture URL. Initials are shown without one. */
17
22
  avatar?: string
18
23
  }
@@ -157,6 +162,7 @@ const titleLinkClass = [
157
162
 
158
163
  const image = (i: HeaderImage | undefined) => (typeof i === 'string' ? { light: i, dark: undefined } : i)
159
164
  const logoImage = computed(() => image(props.logo))
165
+ const organisationLogo = computed(() => image(props.user?.organisationLogo))
160
166
  const lockupImage = computed(() => image(props.lockup))
161
167
 
162
168
  function runAction(action: HeaderUserAction, close: () => void) {
@@ -239,11 +245,25 @@ function runAction(action: HeaderUserAction, close: () => void) {
239
245
 
240
246
  <template #content="{ close }">
241
247
  <div class="flex flex-col">
242
- <!-- The organisation at the top, with a divider under it. The
243
- organisation slot replaces the plain heading. -->
244
- <div v-if="user.organisation || $slots.organisation" class="border-b border-ink/10">
248
+ <!-- The organisation at the top, with a divider under it: its
249
+ logo if it has one, otherwise its name. The organisation
250
+ slot replaces both. -->
251
+ <div v-if="user.organisation || organisationLogo || $slots.organisation" class="border-b border-ink/10">
245
252
  <slot name="organisation" :close="close">
246
- <p class="truncate px-4 py-3 text-xs font-bold text-ink/65 uppercase" :title="user.organisation">
253
+ <div v-if="organisationLogo" class="p-3">
254
+ <img
255
+ :src="organisationLogo.light"
256
+ :alt="user.organisation ?? ''"
257
+ :class="cn('h-6 w-auto max-w-full object-contain object-left', organisationLogo.dark && 'dark:hidden')"
258
+ />
259
+ <img
260
+ v-if="organisationLogo.dark"
261
+ :src="organisationLogo.dark"
262
+ :alt="user.organisation ?? ''"
263
+ class="hidden h-6 w-auto max-w-full object-contain object-left dark:block"
264
+ />
265
+ </div>
266
+ <p v-else class="truncate p-3 text-xs font-bold text-ink/65 uppercase" :title="user.organisation">
247
267
  {{ user.organisation }}
248
268
  </p>
249
269
  </slot>
@@ -251,7 +271,7 @@ function runAction(action: HeaderUserAction, close: () => void) {
251
271
  <!-- Two columns: the avatar at the top left, beside the name and
252
272
  email; Account settings sits under them in the text column,
253
273
  without moving the avatar. -->
254
- <div class="grid grid-cols-[auto_minmax(0,1fr)] items-start gap-x-3 gap-y-2 px-4 py-3">
274
+ <div class="grid grid-cols-[auto_minmax(0,1fr)] items-start gap-x-3 gap-y-2 p-3">
255
275
  <Avatar :user="user" size="lg" decorative />
256
276
  <div class="flex min-w-0 flex-col">
257
277
  <span class="truncate font-bold" :title="user.name">{{ user.name }}</span>
@@ -270,18 +290,24 @@ function runAction(action: HeaderUserAction, close: () => void) {
270
290
 
271
291
  <slot name="account-menu" :close="close" />
272
292
 
273
- <!-- Switch account on the left, Log out on the right. -->
293
+ <!-- Switch account and Log out fill the row, each growing from its
294
+ own text width (so Switch account stays the wider), with the
295
+ same 12px around them on every side, like the rest of the menu. -->
274
296
  <div
275
297
  v-if="userActions.includes('switch-account') || userActions.includes('log-out')"
276
- class="flex items-center gap-2 border-t border-ink/10 px-4 py-3"
298
+ class="flex items-center gap-2 border-t border-ink/10 p-3"
277
299
  >
278
- <Button v-if="userActions.includes('switch-account')" @click="runAction('switch-account', close)">
300
+ <Button
301
+ v-if="userActions.includes('switch-account')"
302
+ class="flex-auto"
303
+ @click="runAction('switch-account', close)"
304
+ >
279
305
  <template #leading><ArrowLeftRight /></template>
280
306
  Switch account
281
307
  </Button>
282
308
  <Button
283
309
  v-if="userActions.includes('log-out')"
284
- class="ml-auto"
310
+ class="flex-auto"
285
311
  @click="runAction('log-out', close)"
286
312
  >
287
313
  <template #leading><LogOut /></template>
@@ -3,12 +3,12 @@
3
3
  * Reka's popper (e.g. InputDate's calendar), so they all match.
4
4
  *
5
5
  * An elevated panel (white; a step lighter than the page in dark mode) with
6
- * the same border and radius as a basic Button, a shadow,
6
+ * the same border as a basic Button, 8px corners like a Card or dialog, a shadow,
7
7
  * and the theme's fade in / out (Reka waits for the fade-out to finish
8
8
  * before removing the panel).
9
9
  */
10
10
  export const popoverContent = [
11
- 'z-50 rounded border border-ink/10 bg-surface-elevated text-ink shadow-md outline-none',
11
+ 'z-50 rounded-lg border border-ink/10 bg-surface-elevated text-ink shadow-md outline-none',
12
12
  'data-[state=open]:animate-fade-in data-[state=closed]:animate-fade-out'
13
13
  ]
14
14
 
@@ -2,6 +2,7 @@
2
2
  import { computed, useId, type Component, type HTMLAttributes } from 'vue'
3
3
  import { RadioGroupItem, RadioGroupRoot } from 'reka-ui'
4
4
  import { cn } from '../../lib/cn'
5
+ import Tooltip from '../Tooltip/Tooltip.vue'
5
6
 
6
7
  /**
7
8
  * One choice from two to four short options, shown as a row of tab-like
@@ -30,7 +31,7 @@ export interface SegmentedControlProps {
30
31
  options: SegmentedOption[]
31
32
  /**
32
33
  * Icons only: each option's label becomes its accessible name and shows
33
- * as a tooltip-style title. Every option needs an icon.
34
+ * in a Tooltip on hover or keyboard focus. Every option needs an icon.
34
35
  */
35
36
  iconOnly?: boolean
36
37
  size?: 'sm' | 'md'
@@ -67,27 +68,29 @@ const itemSize = computed(() => (props.iconOnly ? `${sizes[props.size].icon} jus
67
68
  class="inline-flex w-max max-w-full gap-0.5 rounded-lg bg-ink/5 p-0.5"
68
69
  >
69
70
  <!-- The chosen one is raised like a basic button (control colours: a
70
- step above the track in light and dark). -->
71
- <RadioGroupItem
72
- v-for="option in options"
73
- :key="option.value"
74
- :value="option.value"
75
- :disabled="option.disabled"
76
- :aria-label="iconOnly ? option.label : undefined"
77
- :title="iconOnly ? option.label : undefined"
78
- :class="
79
- cn(
80
- 'inline-flex shrink-0 cursor-pointer items-center rounded-md font-bold whitespace-nowrap text-ink/65 outline-2 outline-offset-1 outline-transparent transition-colors duration-150 motion-reduce:transition-none',
81
- 'not-disabled:hover:text-ink focus-visible:outline-focus',
82
- 'data-[state=checked]:bg-control data-[state=checked]:text-ink data-[state=checked]:shadow-xs',
83
- 'disabled:cursor-not-allowed disabled:opacity-40',
84
- itemSize
85
- )
86
- "
87
- >
88
- <component :is="option.icon" v-if="option.icon" aria-hidden="true" />
89
- <span v-if="!iconOnly">{{ option.label }}</span>
90
- </RadioGroupItem>
71
+ step above the track in light and dark). Keyed off aria-checked,
72
+ not data-state, which the Tooltip's trigger sets to its own. -->
73
+ <!-- Icons only: the name in a tooltip (on hover and keyboard focus),
74
+ as well as for screen readers. -->
75
+ <Tooltip v-for="option in options" :key="option.value" :text="option.label" :disabled="!iconOnly" side="top">
76
+ <RadioGroupItem
77
+ :value="option.value"
78
+ :disabled="option.disabled"
79
+ :aria-label="iconOnly ? option.label : undefined"
80
+ :class="
81
+ cn(
82
+ 'inline-flex shrink-0 cursor-pointer items-center rounded-md font-bold whitespace-nowrap text-ink/65 outline-2 outline-offset-1 outline-transparent transition-colors duration-150 motion-reduce:transition-none',
83
+ 'not-disabled:hover:text-ink focus-visible:outline-focus',
84
+ 'aria-checked:bg-control aria-checked:text-ink aria-checked:shadow-xs',
85
+ 'disabled:cursor-not-allowed disabled:opacity-40',
86
+ itemSize
87
+ )
88
+ "
89
+ >
90
+ <component :is="option.icon" v-if="option.icon" aria-hidden="true" />
91
+ <span v-if="!iconOnly">{{ option.label }}</span>
92
+ </RadioGroupItem>
93
+ </Tooltip>
91
94
  </RadioGroupRoot>
92
95
  </div>
93
96
  </template>
@@ -20,3 +20,12 @@ type Story = StoryObj<typeof meta>;
20
20
  export const Default: Story = {};
21
21
 
22
22
  export const HiddenLabel: Story = { args: { hideLabel: true } };
23
+
24
+ /** Light / Dark / System side by side, with labels. */
25
+ export const Segmented: Story = { args: { appearance: "segmented", hideLabel: true } };
26
+
27
+ /**
28
+ * Only the icons, each named in a tooltip on hover or keyboard focus (and
29
+ * for screen readers): the smallest, as in the Footer.
30
+ */
31
+ export const Icons: Story = { args: { appearance: "icons", hideLabel: true } };
@@ -20,9 +20,10 @@ export interface ThemeSwitcherProps {
20
20
  disabled?: boolean
21
21
  /**
22
22
  * select: a dropdown (Settings, the account menu). segmented: Light / Dark
23
- * / System side by side with icons, small: for the footer.
23
+ * / System side by side with icons, small. icons: the same with only the
24
+ * sun, moon and monitor, each named in a tooltip: for the footer.
24
25
  */
25
- appearance?: 'select' | 'segmented'
26
+ appearance?: 'select' | 'segmented' | 'icons'
26
27
  class?: HTMLAttributes['class']
27
28
  }
28
29
 
@@ -34,7 +35,8 @@ const options = computed(() => [
34
35
  { label: t('ui.themeSwitcher.light'), value: 'light', icon: Sun },
35
36
  { label: t('ui.themeSwitcher.dark'), value: 'dark', icon: Moon },
36
37
  {
37
- // "System" fits the row; the dropdown has room for "Match device".
38
+ // "System" fits the row; the dropdown and the tooltip have room for
39
+ // "Match device".
38
40
  label: props.appearance === 'segmented' ? t('ui.themeSwitcher.systemShort') : t('ui.themeSwitcher.system'),
39
41
  value: 'system',
40
42
  icon: Monitor
@@ -49,9 +51,10 @@ const model = computed({
49
51
 
50
52
  <template>
51
53
  <SegmentedControl
52
- v-if="appearance === 'segmented'"
54
+ v-if="appearance !== 'select'"
53
55
  v-model="model"
54
56
  size="sm"
57
+ :icon-only="appearance === 'icons'"
55
58
  :label="label ?? t('ui.themeSwitcher.label')"
56
59
  :hide-label="hideLabel"
57
60
  :options="options"
@@ -72,7 +72,7 @@ const MaybeProvider: FunctionalComponent = (_, { slots }) =>
72
72
  :collision-padding="8"
73
73
  :class="
74
74
  cn(
75
- 'z-100 max-w-72 rounded-md bg-neutral-900 dark:bg-neutral-700 px-2.5 py-1.5 text-xs/4 text-white shadow-lg ring-1 ring-white/10',
75
+ 'z-100 max-w-72 rounded-lg bg-neutral-900 dark:bg-neutral-700 px-2.5 py-1.5 text-xs/4 text-white shadow-lg ring-1 ring-white/10',
76
76
  'data-[state=closed]:animate-fade-out data-[state=delayed-open]:animate-fade-in data-[state=instant-open]:animate-fade-in',
77
77
  props.class
78
78
  )