@thekestongroup/ui 0.1.3 → 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.
@@ -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
+ }