@thekestongroup/ui 0.1.2 → 0.2.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.
@@ -1,53 +1,26 @@
1
1
  <script setup lang="ts">
2
- import {
3
- ToastAction,
4
- ToastClose,
5
- ToastDescription,
6
- ToastRoot,
7
- ToastTitle,
8
- ToastViewport,
9
- useToastManager,
10
- } from 'reka-ui'
11
- import CloseButton from './CloseButton.vue'
2
+ import { ToastViewport, useToastManager } from 'reka-ui'
3
+ import ToastItem from './ToastItem.vue'
12
4
 
13
5
  const { toasts } = useToastManager()
14
6
  </script>
15
7
 
16
8
  <template>
17
9
  <ToastViewport
18
- class="kui-toast-viewport fixed bottom-0 right-0 z-[100] w-full max-w-sm p-4 outline-none sm:bottom-4 sm:right-4"
10
+ class="kui-toast-viewport fixed left-0 top-0 z-[100] w-full max-w-sm p-4 outline-none sm:left-4 sm:top-4"
19
11
  >
20
- <ToastRoot
21
- v-for="toast in toasts"
22
- :key="toast.id"
23
- :toast="toast"
24
- class="kui-toast pointer-events-auto flex items-start gap-3 rounded-lg border border-neutral-200 bg-white p-4 shadow-lg"
25
- >
26
- <div class="flex min-w-0 flex-1 flex-col gap-1">
27
- <ToastTitle class="text-sm font-semibold text-neutral-900" />
28
- <ToastDescription class="text-sm text-neutral-500" />
29
- <ToastAction
30
- class="mt-1 inline-flex h-8 items-center justify-center gap-2 self-start rounded-md bg-neutral-100 px-3 text-xs font-medium text-neutral-900 outline-none transition-colors hover:bg-neutral-200 focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2"
31
- />
32
- </div>
33
- <ToastClose
34
- aria-label="Close"
35
- class="shrink-0 rounded-sm text-neutral-400 outline-none transition-colors hover:text-neutral-600 focus-visible:ring-2 focus-visible:ring-blue-500"
36
- >
37
- <CloseButton />
38
- </ToastClose>
39
- </ToastRoot>
12
+ <ToastItem v-for="toast in toasts" :key="toast.id" :toast="toast" />
40
13
  </ToastViewport>
41
14
  </template>
42
15
 
43
16
  <style>
44
17
  .kui-toast {
45
18
  position: absolute;
46
- bottom: 0;
47
- right: 0;
19
+ top: 0;
20
+ left: 0;
48
21
  width: 100%;
49
22
  height: var(--reka-toast-frontmost-height);
50
- transform: translateY(calc(var(--reka-toast-index) * -12px))
23
+ transform: translateY(calc(var(--reka-toast-index) * 12px))
51
24
  scale(calc(1 - var(--reka-toast-index) * 0.05));
52
25
  z-index: calc(1000 - var(--reka-toast-index));
53
26
  transition:
@@ -57,21 +30,21 @@ const { toasts } = useToastManager()
57
30
  transition-delay: 100ms;
58
31
  }
59
32
 
60
- /* Invisible hit-area that covers the gap above each toast, so the cursor
33
+ /* Invisible hit-area that covers the gap below each toast, so the cursor
61
34
  moving between toasts doesn't leave the viewport and collapse the stack. */
62
35
  .kui-toast::after {
63
36
  content: '';
64
37
  position: absolute;
65
38
  left: 0;
66
39
  right: 0;
67
- bottom: 100%;
40
+ top: 100%;
68
41
  height: 12px;
69
42
  }
70
43
 
71
44
  .kui-toast-viewport[data-expanded] .kui-toast {
72
45
  height: var(--reka-toast-height);
73
46
  transform: translateY(
74
- calc(var(--reka-toast-offset-y) * -1 - var(--reka-toast-index) * 12px)
47
+ calc(var(--reka-toast-offset-y) + var(--reka-toast-index) * 12px)
75
48
  );
76
49
  transition-delay: 0ms;
77
50
  }
@@ -100,7 +73,7 @@ const { toasts } = useToastManager()
100
73
 
101
74
  @keyframes kui-toast-in {
102
75
  from {
103
- translate: 100% 0;
76
+ translate: -100% 0;
104
77
  opacity: 0;
105
78
  }
106
79
  to {
@@ -110,7 +83,7 @@ const { toasts } = useToastManager()
110
83
  }
111
84
  @keyframes kui-toast-out {
112
85
  to {
113
- translate: 100% 0;
86
+ translate: -100% 0;
114
87
  opacity: 0;
115
88
  }
116
89
  }
@@ -119,7 +92,7 @@ const { toasts } = useToastManager()
119
92
  transform: translateX(var(--reka-toast-swipe-end-x));
120
93
  }
121
94
  to {
122
- transform: translateX(calc(100% + 1rem));
95
+ transform: translateX(calc(-100% - 1rem));
123
96
  }
124
97
  }
125
98
 
@@ -0,0 +1,52 @@
1
+ <script setup lang="ts">
2
+ import AppLauncher from './AppLauncher.vue'
3
+ import type { AppLink } from '../lib/types'
4
+
5
+ withDefaults(
6
+ defineProps<{
7
+ appName: string
8
+ apps?: AppLink[]
9
+ current?: string
10
+ showMenu?: boolean
11
+ }>(),
12
+ {
13
+ apps: () => [],
14
+ current: '',
15
+ showMenu: false,
16
+ },
17
+ )
18
+
19
+ defineEmits<{
20
+ (e: 'menu'): void
21
+ }>()
22
+ </script>
23
+
24
+ <template>
25
+ <header class="flex h-16 items-center gap-2 border-b border-neutral-200 bg-white px-3 sm:px-4">
26
+ <AppLauncher :apps="apps" :current="current" />
27
+
28
+ <button
29
+ v-if="showMenu"
30
+ type="button"
31
+ aria-label="Toggle navigation"
32
+ class="inline-flex h-9 w-9 items-center justify-center rounded-md text-neutral-600 outline-none transition-colors hover:bg-neutral-100 focus-visible:ring-2 focus-visible:ring-blue-500"
33
+ @click="$emit('menu')"
34
+ >
35
+ <svg class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" aria-hidden="true">
36
+ <path stroke-linecap="round" stroke-linejoin="round" d="M4 6h16M4 12h16M4 18h16" />
37
+ </svg>
38
+ </button>
39
+
40
+ <span class="ml-1 truncate text-base font-semibold text-neutral-900">{{ appName }}</span>
41
+
42
+ <div class="ml-2 min-w-0 flex-1">
43
+ <slot name="search" />
44
+ </div>
45
+
46
+ <div class="flex shrink-0 items-center gap-1">
47
+ <slot name="actions" />
48
+ <slot name="notifications" />
49
+ <slot name="profile" />
50
+ </div>
51
+ </header>
52
+ </template>
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export { default as Avatar } from './components/Avatar.vue'
2
+ export { default as AppLauncher } from './components/AppLauncher.vue'
1
3
  export { default as Button } from './components/Button.vue'
2
4
  export { default as Checkbox } from './components/Checkbox.vue'
3
5
  export { default as CloseButton } from './components/CloseButton.vue'
@@ -8,14 +10,26 @@ export { default as Input } from './components/Input.vue'
8
10
  export { default as Label } from './components/Label.vue'
9
11
  export { default as DropdownMenuItem } from './components/DropdownMenuItem.vue'
10
12
  export { default as DropdownMenuSeparator } from './components/DropdownMenuSeparator.vue'
13
+ export { default as NotificationsMenu } from './components/NotificationsMenu.vue'
11
14
  export { default as Popover } from './components/Popover.vue'
15
+ export { default as ProfileSwitcher } from './components/ProfileSwitcher.vue'
12
16
  export { default as Select } from './components/Select.vue'
13
17
  export type { SelectOption } from './components/Select.vue'
14
18
  export { default as Separator } from './components/Separator.vue'
15
19
  export { default as Tooltip } from './components/Tooltip.vue'
16
20
  export { default as Toaster } from './components/Toaster.vue'
21
+ export { default as TopBar } from './components/TopBar.vue'
17
22
  export { toast, toastManager } from './lib/toast'
23
+ export {
24
+ clearNotifications,
25
+ markNotificationsRead,
26
+ removeNotification,
27
+ toastNotifications,
28
+ } from './lib/toast'
29
+ export type { AppLink } from './lib/types'
18
30
  export type {
31
+ ToastStatus,
32
+ ToastNotification,
19
33
  ToastObject,
20
34
  ToastAddOptions,
21
35
  ToastUpdateOptions,
package/src/lib/toast.ts CHANGED
@@ -1,12 +1,88 @@
1
1
  import { createToastManager } from 'reka-ui'
2
+ import type { ToastAddOptions } from 'reka-ui'
3
+ import { reactive } from 'vue'
2
4
 
3
5
  const manager = createToastManager()
4
6
 
7
+ export type ToastStatus = 'success' | 'warning' | 'error' | 'info' | 'plain'
8
+
9
+ export interface ToastNotification {
10
+ id: string
11
+ title: string
12
+ description: string
13
+ status: ToastStatus
14
+ at: number
15
+ read: boolean
16
+ }
17
+
18
+ const MAX_NOTIFICATIONS = 100
19
+
20
+ export const toastNotifications = reactive<ToastNotification[]>([])
21
+
22
+ function toText(value: unknown): string {
23
+ if (typeof value === 'string') return value
24
+ if (typeof value === 'number') return String(value)
25
+ return ''
26
+ }
27
+
28
+ function record(id: string, options: ToastAddOptions, status: ToastStatus) {
29
+ toastNotifications.unshift({
30
+ id,
31
+ title: toText(options.title),
32
+ description: toText(options.description),
33
+ status,
34
+ at: Date.now(),
35
+ read: false,
36
+ })
37
+ if (toastNotifications.length > MAX_NOTIFICATIONS) {
38
+ toastNotifications.length = MAX_NOTIFICATIONS
39
+ }
40
+ }
41
+
42
+ function add(options: ToastAddOptions) {
43
+ const status = (options.status as ToastStatus) ?? 'plain'
44
+ const id = manager.add(options)
45
+ record(id, options, status)
46
+ return id
47
+ }
48
+
49
+ function update(id: string, options: Partial<ToastAddOptions>) {
50
+ const existing = toastNotifications.find((n) => n.id === id)
51
+ if (existing) {
52
+ if (options.title !== undefined) existing.title = toText(options.title)
53
+ if (options.description !== undefined) existing.description = toText(options.description)
54
+ if (options.status !== undefined) existing.status = options.status as ToastStatus
55
+ }
56
+ return manager.update(id, options)
57
+ }
58
+
59
+ function addWithStatus(status: ToastStatus) {
60
+ return (options: ToastAddOptions) => add({ ...options, status })
61
+ }
62
+
5
63
  export const toast = {
6
- add: manager.add,
7
- update: manager.update,
64
+ add,
65
+ update,
8
66
  close: manager.close,
9
67
  promise: manager.promise,
68
+ success: addWithStatus('success'),
69
+ warning: addWithStatus('warning'),
70
+ error: addWithStatus('error'),
71
+ info: addWithStatus('info'),
72
+ plain: addWithStatus('plain'),
73
+ }
74
+
75
+ export function markNotificationsRead() {
76
+ for (const n of toastNotifications) n.read = true
77
+ }
78
+
79
+ export function clearNotifications() {
80
+ toastNotifications.length = 0
81
+ }
82
+
83
+ export function removeNotification(id: string) {
84
+ const index = toastNotifications.findIndex((n) => n.id === id)
85
+ if (index !== -1) toastNotifications.splice(index, 1)
10
86
  }
11
87
 
12
88
  export const toastManager = manager
@@ -0,0 +1,5 @@
1
+ export interface AppLink {
2
+ name: string
3
+ href: string
4
+ description?: string
5
+ }
@@ -1 +0,0 @@
1
- .kui-drawer-content{outline:none;transition:transform .3s ease-in-out}.kui-drawer-content[data-swiping]{transition-duration:0ms}.kui-drawer-right,.kui-drawer-left{transform:translate(var(--drawer-swipe-movement-x, 0px))}.kui-drawer-top,.kui-drawer-bottom{transform:translateY(var(--drawer-swipe-movement-y, 0px))}.kui-drawer-right[data-state=open]{animation:kui-drawer-in-right .3s ease-in-out}.kui-drawer-right[data-state=closed]{animation:kui-drawer-out-right .3s ease-in-out}.kui-drawer-left[data-state=open]{animation:kui-drawer-in-left .3s ease-in-out}.kui-drawer-left[data-state=closed]{animation:kui-drawer-out-left .3s ease-in-out}.kui-drawer-top[data-state=open]{animation:kui-drawer-in-top .3s ease-in-out}.kui-drawer-top[data-state=closed]{animation:kui-drawer-out-top .3s ease-in-out}.kui-drawer-bottom[data-state=open]{animation:kui-drawer-in-bottom .3s ease-in-out}.kui-drawer-bottom[data-state=closed]{animation:kui-drawer-out-bottom .3s ease-in-out}.kui-drawer-overlay[data-state=open]{animation:kui-drawer-overlay-in .3s ease-in-out}.kui-drawer-overlay[data-state=closed]{animation:kui-drawer-overlay-out .3s ease-in-out}@keyframes kui-drawer-in-right{0%{translate:100% 0}}@keyframes kui-drawer-out-right{to{translate:100% 0}}@keyframes kui-drawer-in-left{0%{translate:-100% 0}}@keyframes kui-drawer-out-left{to{translate:-100% 0}}@keyframes kui-drawer-in-top{0%{translate:0 -100%}}@keyframes kui-drawer-out-top{to{translate:0 -100%}}@keyframes kui-drawer-in-bottom{0%{translate:0 100%}}@keyframes kui-drawer-out-bottom{to{translate:0 100%}}@keyframes kui-drawer-overlay-in{0%{opacity:0}to{opacity:1}}@keyframes kui-drawer-overlay-out{0%{opacity:1}to{opacity:0}}.kui-toast{position:absolute;bottom:0;right:0;width:100%;height:var(--reka-toast-frontmost-height);transform:translateY(calc(var(--reka-toast-index) * -12px)) scale(calc(1 - var(--reka-toast-index) * .05));z-index:calc(1000 - var(--reka-toast-index));transition:transform .3s cubic-bezier(.21,1.02,.73,1),opacity .3s ease,height .3s ease;transition-delay:.1s}.kui-toast:after{content:"";position:absolute;left:0;right:0;bottom:100%;height:12px}.kui-toast-viewport[data-expanded] .kui-toast{height:var(--reka-toast-height);transform:translateY(calc(var(--reka-toast-offset-y) * -1 - var(--reka-toast-index) * 12px));transition-delay:0ms}.kui-toast[data-limited]{opacity:0}.kui-toast[data-state=open]{animation:kui-toast-in .3s cubic-bezier(.21,1.02,.73,1)}.kui-toast[data-state=closed]{animation:kui-toast-out .2s ease-in forwards}.kui-toast[data-swipe=move]{transform:translate(var(--reka-toast-swipe-move-x))}.kui-toast[data-swipe=cancel]{transform:translate(0);transition:transform .2s ease-out}.kui-toast[data-swipe=end]{animation:kui-toast-swipe-out .1s ease-out forwards}@keyframes kui-toast-in{0%{translate:100% 0;opacity:0}to{translate:0 0;opacity:1}}@keyframes kui-toast-out{to{translate:100% 0;opacity:0}}@keyframes kui-toast-swipe-out{0%{transform:translate(var(--reka-toast-swipe-end-x))}to{transform:translate(calc(100% + 1rem))}}@media(prefers-reduced-motion:reduce){.kui-toast{transition:none}.kui-toast[data-state=open],.kui-toast[data-state=closed],.kui-toast[data-swipe=end]{animation:none}.kui-toast[data-swipe=move],.kui-toast[data-swipe=cancel]{transform:none}}