@aleph-alpha/ui-library 1.22.0 → 1.23.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 (71) hide show
  1. package/dist/system/index.d.ts +545 -329
  2. package/dist/system/lib.js +18800 -18015
  3. package/package.json +1 -1
  4. package/src/components/UiIconButton/UiIconButton.vue +5 -1
  5. package/src/components/UiIconButton/types.ts +1 -1
  6. package/src/components/core/button/index.ts +6 -4
  7. package/src/components/core/sidebar/SidebarContent.vue +11 -3
  8. package/src/components/core/sidebar/SidebarFooter.vue +10 -2
  9. package/src/components/core/sidebar/SidebarGroup.vue +10 -2
  10. package/src/components/core/sidebar/SidebarGroupLabel.vue +1 -1
  11. package/src/components/core/sidebar/SidebarHeader.vue +10 -2
  12. package/src/components/core/sidebar/SidebarMenu.vue +12 -2
  13. package/src/components/core/sidebar/SidebarMenuButton.vue +2 -2
  14. package/src/components/core/sidebar/SidebarSeparator.vue +10 -2
  15. package/src/components/core/sidebar/SidebarTrigger.vue +2 -2
  16. package/src/components/core/sidebar/index.ts +1 -1
  17. package/src/components/core/sidebar/utils.ts +11 -2
  18. package/src/components/index.ts +0 -1
  19. package/src/directives/index.ts +1 -0
  20. package/src/directives/vOverlay.ts +94 -0
  21. package/src/patterns/UiSidebar/UiSidebar.stories.ts +346 -0
  22. package/src/{components → patterns}/UiSidebar/UiSidebar.vue +9 -3
  23. package/src/patterns/UiSidebar/UiSidebarChatHistory.stories.ts +77 -0
  24. package/src/patterns/UiSidebar/UiSidebarChatHistory.vue +35 -0
  25. package/src/patterns/UiSidebar/UiSidebarChatHistoryItem.stories.ts +85 -0
  26. package/src/patterns/UiSidebar/UiSidebarChatHistoryItem.vue +139 -0
  27. package/src/patterns/UiSidebar/UiSidebarContent.vue +11 -0
  28. package/src/patterns/UiSidebar/UiSidebarFooter.vue +11 -0
  29. package/src/patterns/UiSidebar/UiSidebarGroup.stories.ts +91 -0
  30. package/src/patterns/UiSidebar/UiSidebarGroup.vue +42 -0
  31. package/src/patterns/UiSidebar/UiSidebarGroupContent.vue +15 -0
  32. package/src/patterns/UiSidebar/UiSidebarGroupLabel.stories.ts +163 -0
  33. package/src/patterns/UiSidebar/UiSidebarGroupLabel.vue +131 -0
  34. package/src/patterns/UiSidebar/UiSidebarHeader.vue +48 -0
  35. package/src/patterns/UiSidebar/UiSidebarInset.vue +11 -0
  36. package/src/patterns/UiSidebar/UiSidebarMenu.vue +11 -0
  37. package/src/patterns/UiSidebar/UiSidebarMenuButton.stories.ts +205 -0
  38. package/src/patterns/UiSidebar/UiSidebarMenuButton.vue +121 -0
  39. package/src/patterns/UiSidebar/UiSidebarMenuItem.stories.ts +67 -0
  40. package/src/patterns/UiSidebar/UiSidebarMenuItem.vue +11 -0
  41. package/src/patterns/UiSidebar/UiSidebarMenuSub.vue +38 -0
  42. package/src/patterns/UiSidebar/UiSidebarMenuSubItem.stories.ts +66 -0
  43. package/src/patterns/UiSidebar/UiSidebarMenuSubItem.vue +67 -0
  44. package/src/patterns/UiSidebar/UiSidebarPopover.vue +43 -0
  45. package/src/patterns/UiSidebar/UiSidebarPopoverMenu.stories.ts +56 -0
  46. package/src/patterns/UiSidebar/UiSidebarPopoverMenu.vue +56 -0
  47. package/src/patterns/UiSidebar/UiSidebarPopoverMenuItem.stories.ts +42 -0
  48. package/src/patterns/UiSidebar/UiSidebarPopoverMenuItem.vue +79 -0
  49. package/src/patterns/UiSidebar/UiSidebarPopoverTrigger.stories.ts +61 -0
  50. package/src/patterns/UiSidebar/UiSidebarPopoverTrigger.vue +81 -0
  51. package/src/patterns/UiSidebar/UiSidebarProvider.vue +11 -0
  52. package/src/patterns/UiSidebar/UiSidebarRail.vue +9 -0
  53. package/src/patterns/UiSidebar/UiSidebarTrigger.vue +35 -0
  54. package/src/patterns/UiSidebar/groupContext.ts +9 -0
  55. package/src/patterns/UiSidebar/index.ts +42 -0
  56. package/src/patterns/UiSidebar/types.ts +375 -0
  57. package/src/patterns/index.ts +1 -0
  58. package/src/components/UiSidebar/UiSidebar.stories.ts +0 -1188
  59. package/src/components/UiSidebar/UiSidebarGroupAction.vue +0 -18
  60. package/src/components/UiSidebar/UiSidebarGroupLabel.vue +0 -18
  61. package/src/components/UiSidebar/UiSidebarHeaderTrigger.vue +0 -53
  62. package/src/components/UiSidebar/UiSidebarInput.vue +0 -14
  63. package/src/components/UiSidebar/UiSidebarMenuAction.vue +0 -19
  64. package/src/components/UiSidebar/UiSidebarMenuButton.vue +0 -27
  65. package/src/components/UiSidebar/UiSidebarMenuSkeleton.vue +0 -16
  66. package/src/components/UiSidebar/UiSidebarMenuSubButton.vue +0 -24
  67. package/src/components/UiSidebar/UiSidebarProvider.vue +0 -16
  68. package/src/components/UiSidebar/UiSidebarSeparator.vue +0 -13
  69. package/src/components/UiSidebar/__tests__/UiSidebar.test.ts +0 -221
  70. package/src/components/UiSidebar/index.ts +0 -34
  71. package/src/components/UiSidebar/types.ts +0 -165
@@ -0,0 +1,139 @@
1
+ <script setup lang="ts">
2
+ import { computed, useAttrs, useSlots } from 'vue';
3
+ import { MoreVertical } from 'lucide-vue-next';
4
+ import { Primitive } from 'reka-ui';
5
+ import { vOverlay } from '@/directives';
6
+ import { UiTooltip } from '@/components/UiTooltip';
7
+ import { cn } from '@/lib/utils';
8
+ import type { UiSidebarChatHistoryItemEmits, UiSidebarChatHistoryItemProps } from './types';
9
+
10
+ defineOptions({
11
+ name: 'UiSidebarChatHistoryItem',
12
+ inheritAttrs: false,
13
+ });
14
+
15
+ const emit = defineEmits<UiSidebarChatHistoryItemEmits>();
16
+
17
+ const props = withDefaults(defineProps<UiSidebarChatHistoryItemProps>(), {
18
+ as: 'button',
19
+ isActive: false,
20
+ showAction: true,
21
+ showActionOnHover: true,
22
+ actionTooltip: '',
23
+ actionAriaLabel: 'History item action',
24
+ });
25
+
26
+ const attrs = useAttrs();
27
+ const slots = useSlots();
28
+
29
+ const resolvedActionIcon = computed(() => props.actionIcon ?? MoreVertical);
30
+ const hasMeta = computed(() => Boolean(props.metaStart || props.metaEnd || slots.meta));
31
+
32
+ const containerClass = computed(() =>
33
+ cn(
34
+ 'group/sidebar-chat-history-item relative flex w-full min-w-0 items-center gap-2 rounded-md border border-transparent px-2 py-1.5 group-data-[collapsible=icon]:hidden',
35
+ hasMeta.value ? 'h-12' : 'h-10',
36
+ 'focus-within:border-border-surface-focus-ring focus-within:ring-[3px] focus-within:ring-ring/50',
37
+ 'data-[active=true]:before:absolute data-[active=true]:before:z-10 data-[active=true]:before:top-1/2 data-[active=true]:before:left-0 data-[active=true]:before:h-4 data-[active=true]:before:w-0.5 data-[active=true]:before:-translate-y-1/2 data-[active=true]:before:rounded-full data-[active=true]:before:bg-background-accent-default data-[active=true]:before:content-[""]',
38
+ ),
39
+ );
40
+
41
+ const itemClass = computed(() =>
42
+ cn(
43
+ 'text-left outline-hidden transition-colors',
44
+ 'body-14-normal font-normal text-content-on-surface-primary',
45
+ '!hover:bg-transparent !active:bg-transparent',
46
+ 'focus-visible:ring-0',
47
+ 'data-[active=true]:text-content-on-surface-primary',
48
+ attrs.class as string | undefined,
49
+ ),
50
+ );
51
+
52
+ const actionClass = computed(() =>
53
+ cn(
54
+ 'ml-auto shrink-0',
55
+ props.showActionOnHover &&
56
+ 'opacity-0 transition-opacity group-hover/sidebar-chat-history-item:opacity-100 group-focus-within/sidebar-chat-history-item:opacity-100',
57
+ ),
58
+ );
59
+
60
+ const actionButtonClass = computed(() =>
61
+ cn(
62
+ 'flex size-4 items-center justify-center rounded-sm text-content-on-surface-primary outline-hidden',
63
+ 'focus-visible:ring-0',
64
+ '!hover:bg-transparent !active:bg-transparent',
65
+ '[&>svg]:size-4',
66
+ ),
67
+ );
68
+
69
+ const passthroughAttrs = computed(() => {
70
+ const { class: _class, ...rest } = attrs as Record<string, unknown>;
71
+ return rest;
72
+ });
73
+
74
+ function onActionClick(event: MouseEvent) {
75
+ event.stopPropagation();
76
+ emit('action-click', event);
77
+ }
78
+ </script>
79
+
80
+ <template>
81
+ <div
82
+ v-overlay="{ variant: 'default', active: props.isActive, hover: true }"
83
+ :data-active="props.isActive"
84
+ :class="containerClass"
85
+ >
86
+ <Primitive
87
+ v-bind="passthroughAttrs"
88
+ :as="props.as"
89
+ :as-child="props.asChild"
90
+ :data-active="props.isActive"
91
+ :class="cn(itemClass, 'min-w-0 flex-1')"
92
+ >
93
+ <div class="min-w-0 flex-1">
94
+ <div class="truncate body-14-normal font-normal text-content-on-surface-primary">
95
+ {{ props.title }}
96
+ </div>
97
+
98
+ <div
99
+ v-if="props.metaStart || props.metaEnd || $slots.meta"
100
+ class="mt-0.5 flex min-w-0 items-center gap-1 label-12-medium text-content-on-surface-muted"
101
+ >
102
+ <slot name="meta">
103
+ <span v-if="props.metaStart" class="truncate">{{ props.metaStart }}</span>
104
+ <span v-if="props.metaStart && props.metaEnd" aria-hidden="true">|</span>
105
+ <span v-if="props.metaEnd" class="truncate">{{ props.metaEnd }}</span>
106
+ </slot>
107
+ </div>
108
+ </div>
109
+ </Primitive>
110
+
111
+ <UiTooltip
112
+ v-if="props.showAction && props.actionTooltip"
113
+ :content="props.actionTooltip"
114
+ side="right"
115
+ align="center"
116
+ >
117
+ <div :class="actionClass">
118
+ <button
119
+ type="button"
120
+ :aria-label="props.actionAriaLabel"
121
+ :class="actionButtonClass"
122
+ @click="onActionClick"
123
+ >
124
+ <component :is="resolvedActionIcon" :size="16" />
125
+ </button>
126
+ </div>
127
+ </UiTooltip>
128
+ <div v-else-if="props.showAction" :class="actionClass">
129
+ <button
130
+ type="button"
131
+ :aria-label="props.actionAriaLabel"
132
+ :class="actionButtonClass"
133
+ @click="onActionClick"
134
+ >
135
+ <component :is="resolvedActionIcon" :size="16" />
136
+ </button>
137
+ </div>
138
+ </div>
139
+ </template>
@@ -0,0 +1,11 @@
1
+ <script setup lang="ts">
2
+ import { SidebarContent } from '@/components/core/sidebar';
3
+
4
+ defineOptions({ name: 'UiSidebarContent' });
5
+ </script>
6
+
7
+ <template>
8
+ <SidebarContent v-bind="$attrs">
9
+ <slot />
10
+ </SidebarContent>
11
+ </template>
@@ -0,0 +1,11 @@
1
+ <script setup lang="ts">
2
+ import { SidebarFooter } from '@/components/core/sidebar';
3
+
4
+ defineOptions({ name: 'UiSidebarFooter' });
5
+ </script>
6
+
7
+ <template>
8
+ <SidebarFooter v-bind="$attrs">
9
+ <slot />
10
+ </SidebarFooter>
11
+ </template>
@@ -0,0 +1,91 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
+ import { Bot, Folder, Plus } from 'lucide-vue-next';
3
+ import UiSidebar from './UiSidebar.vue';
4
+ import UiSidebarContent from './UiSidebarContent.vue';
5
+ import UiSidebarGroup from './UiSidebarGroup.vue';
6
+ import UiSidebarGroupContent from './UiSidebarGroupContent.vue';
7
+ import UiSidebarGroupLabel from './UiSidebarGroupLabel.vue';
8
+ import UiSidebarHeader from './UiSidebarHeader.vue';
9
+ import UiSidebarMenu from './UiSidebarMenu.vue';
10
+ import UiSidebarMenuButton from './UiSidebarMenuButton.vue';
11
+ import UiSidebarMenuItem from './UiSidebarMenuItem.vue';
12
+ import UiSidebarProvider from './UiSidebarProvider.vue';
13
+
14
+ const meta: Meta<typeof UiSidebarGroup> = {
15
+ title: 'Patterns/UiSidebar/UiSidebarGroup',
16
+ component: UiSidebarGroup,
17
+ tags: ['autodocs'],
18
+ };
19
+
20
+ export default meta;
21
+
22
+ type Story = StoryObj<typeof UiSidebarGroup>;
23
+
24
+ const renderStory = (defaultOpen = true) => ({
25
+ components: {
26
+ Bot,
27
+ Folder,
28
+ Plus,
29
+ UiSidebar,
30
+ UiSidebarContent,
31
+ UiSidebarGroup,
32
+ UiSidebarGroupContent,
33
+ UiSidebarGroupLabel,
34
+ UiSidebarHeader,
35
+ UiSidebarMenu,
36
+ UiSidebarMenuButton,
37
+ UiSidebarMenuItem,
38
+ UiSidebarProvider,
39
+ },
40
+ setup() {
41
+ const items = [
42
+ { title: 'Playground', icon: Bot },
43
+ { title: 'Projects', icon: Folder },
44
+ { title: 'New item', icon: Plus },
45
+ ];
46
+
47
+ return { defaultOpen, items };
48
+ },
49
+ template: `
50
+ <UiSidebarProvider :default-open="true">
51
+ <div class="bg-background-surface-primary p-4">
52
+ <div class="w-80">
53
+ <UiSidebar collapsible="icon">
54
+ <UiSidebarHeader tooltip="Toggle sidebar">Preview</UiSidebarHeader>
55
+ <UiSidebarContent class="p-0">
56
+ <UiSidebarGroup :default-open="defaultOpen">
57
+ <UiSidebarGroupLabel
58
+ collapse-tooltip="Collapse group"
59
+ action-tooltip="Add item"
60
+ >
61
+ Group title
62
+ </UiSidebarGroupLabel>
63
+
64
+ <UiSidebarGroupContent>
65
+ <UiSidebarMenu class="mt-2">
66
+ <UiSidebarMenuItem v-for="item in items" :key="item.title">
67
+ <UiSidebarMenuButton :tooltip="item.title">
68
+ <template #start-icon>
69
+ <component :is="item.icon" :size="16" />
70
+ </template>
71
+ {{ item.title }}
72
+ </UiSidebarMenuButton>
73
+ </UiSidebarMenuItem>
74
+ </UiSidebarMenu>
75
+ </UiSidebarGroupContent>
76
+ </UiSidebarGroup>
77
+ </UiSidebarContent>
78
+ </UiSidebar>
79
+ </div>
80
+ </div>
81
+ </UiSidebarProvider>
82
+ `,
83
+ });
84
+
85
+ export const Default: Story = {
86
+ render: () => renderStory(true),
87
+ };
88
+
89
+ export const CollapsedByDefault: Story = {
90
+ render: () => renderStory(false),
91
+ };
@@ -0,0 +1,42 @@
1
+ <script setup lang="ts">
2
+ import { computed, provide, ref, useAttrs } from 'vue';
3
+ import { SidebarGroup } from '@/components/core/sidebar';
4
+ import { cn } from '@/lib/utils';
5
+ import { uiSidebarGroupContextKey } from './groupContext';
6
+ import type { UiSidebarGroupProps } from './types';
7
+
8
+ defineOptions({
9
+ name: 'UiSidebarGroup',
10
+ inheritAttrs: false,
11
+ });
12
+
13
+ const props = withDefaults(defineProps<UiSidebarGroupProps>(), {
14
+ defaultOpen: true,
15
+ });
16
+
17
+ const open = ref(props.defaultOpen);
18
+
19
+ function toggle() {
20
+ open.value = !open.value;
21
+ }
22
+
23
+ const attrs = useAttrs();
24
+
25
+ const groupClass = computed(() => cn('!p-2', attrs.class as string | undefined));
26
+
27
+ const passthroughAttrs = computed(() => {
28
+ const { class: _class, ...rest } = attrs as Record<string, unknown>;
29
+ return rest;
30
+ });
31
+
32
+ provide(uiSidebarGroupContextKey, {
33
+ open,
34
+ toggle,
35
+ });
36
+ </script>
37
+
38
+ <template>
39
+ <SidebarGroup v-bind="passthroughAttrs" :class="groupClass">
40
+ <slot />
41
+ </SidebarGroup>
42
+ </template>
@@ -0,0 +1,15 @@
1
+ <script setup lang="ts">
2
+ import { inject } from 'vue';
3
+ import { SidebarGroupContent } from '@/components/core/sidebar';
4
+ import { uiSidebarGroupContextKey } from './groupContext';
5
+
6
+ defineOptions({ name: 'UiSidebarGroupContent' });
7
+
8
+ const group = inject(uiSidebarGroupContextKey, null);
9
+ </script>
10
+
11
+ <template>
12
+ <SidebarGroupContent v-if="!group || group.open.value" v-bind="$attrs">
13
+ <slot />
14
+ </SidebarGroupContent>
15
+ </template>
@@ -0,0 +1,163 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
+ import { ref } from 'vue';
3
+ import { ChevronRight, MoreHorizontal, Plus } from 'lucide-vue-next';
4
+ import UiSidebar from './UiSidebar.vue';
5
+ import UiSidebarContent from './UiSidebarContent.vue';
6
+ import UiSidebarGroup from './UiSidebarGroup.vue';
7
+ import UiSidebarGroupLabel from './UiSidebarGroupLabel.vue';
8
+ import UiSidebarGroupContent from './UiSidebarGroupContent.vue';
9
+ import UiSidebarHeader from './UiSidebarHeader.vue';
10
+ import UiSidebarProvider from './UiSidebarProvider.vue';
11
+
12
+ const meta: Meta<typeof UiSidebarGroupLabel> = {
13
+ title: 'Patterns/UiSidebar/UiSidebarGroupLabel',
14
+ component: UiSidebarGroupLabel,
15
+ tags: ['autodocs'],
16
+ argTypes: {
17
+ size: {
18
+ control: 'select',
19
+ options: ['sm', 'xs'],
20
+ },
21
+ collapseIcon: {
22
+ control: false,
23
+ },
24
+ actionIcon: {
25
+ control: false,
26
+ },
27
+ },
28
+ args: {
29
+ size: 'sm',
30
+ collapseTooltip: 'Collapse group',
31
+ actionTooltip: 'Add item',
32
+ },
33
+ };
34
+
35
+ export default meta;
36
+
37
+ type Story = StoryObj<typeof UiSidebarGroupLabel>;
38
+
39
+ const renderStory = (args: Story['args']) => ({
40
+ components: {
41
+ Plus,
42
+ ChevronRight,
43
+ MoreHorizontal,
44
+ UiSidebar,
45
+ UiSidebarContent,
46
+ UiSidebarGroup,
47
+ UiSidebarGroupContent,
48
+ UiSidebarHeader,
49
+ UiSidebarProvider,
50
+ UiSidebarGroupLabel,
51
+ },
52
+ setup() {
53
+ const open = ref(true);
54
+
55
+ function toggleGroup() {
56
+ open.value = !open.value;
57
+ }
58
+
59
+ return { args, ChevronRight, MoreHorizontal, open, toggleGroup };
60
+ },
61
+ template: `
62
+ <UiSidebarProvider :default-open="true">
63
+ <div class="max-w-xs bg-background-surface-primary p-4">
64
+ <UiSidebar collapsible="icon">
65
+ <UiSidebarHeader tooltip="Toggle sidebar">Preview</UiSidebarHeader>
66
+ <UiSidebarContent class="p-0">
67
+ <UiSidebarGroup>
68
+ <UiSidebarGroupLabel v-bind="args" @collapse-click="toggleGroup">
69
+ Projects
70
+ </UiSidebarGroupLabel>
71
+ <UiSidebarGroupContent v-if="open">
72
+ <div class="px-2 py-2 text-sm text-content-on-surface-muted">Group content</div>
73
+ </UiSidebarGroupContent>
74
+ </UiSidebarGroup>
75
+ </UiSidebarContent>
76
+ </UiSidebar>
77
+ </div>
78
+ </UiSidebarProvider>
79
+ `,
80
+ });
81
+
82
+ export const Default: Story = {
83
+ render: renderStory,
84
+ };
85
+
86
+ export const ExtraSmall: Story = {
87
+ args: {
88
+ size: 'xs',
89
+ },
90
+ render: renderStory,
91
+ };
92
+
93
+ export const CustomIcons: Story = {
94
+ render: () => ({
95
+ components: {
96
+ ChevronRight,
97
+ MoreHorizontal,
98
+ UiSidebar,
99
+ UiSidebarContent,
100
+ UiSidebarGroup,
101
+ UiSidebarGroupContent,
102
+ UiSidebarHeader,
103
+ UiSidebarProvider,
104
+ UiSidebarGroupLabel,
105
+ },
106
+ setup() {
107
+ const open = ref(true);
108
+
109
+ function toggleGroup() {
110
+ open.value = !open.value;
111
+ }
112
+
113
+ return { ChevronRight, MoreHorizontal, open, toggleGroup };
114
+ },
115
+ template: `
116
+ <UiSidebarProvider :default-open="true">
117
+ <div class="max-w-xs bg-background-surface-primary p-4">
118
+ <UiSidebar collapsible="icon">
119
+ <UiSidebarHeader tooltip="Toggle sidebar">Preview</UiSidebarHeader>
120
+ <UiSidebarContent class="p-0">
121
+ <UiSidebarGroup>
122
+ <UiSidebarGroupLabel
123
+ :collapse-icon="ChevronRight"
124
+ :action-icon="MoreHorizontal"
125
+ collapse-tooltip="Open group"
126
+ action-tooltip="More actions"
127
+ @collapse-click="toggleGroup"
128
+ >
129
+ Projects
130
+ </UiSidebarGroupLabel>
131
+ <UiSidebarGroupContent v-if="open">
132
+ <div class="px-2 py-2 text-sm text-content-on-surface-muted">Group content</div>
133
+ </UiSidebarGroupContent>
134
+ </UiSidebarGroup>
135
+ </UiSidebarContent>
136
+ </UiSidebar>
137
+ </div>
138
+ </UiSidebarProvider>
139
+ `,
140
+ }),
141
+ };
142
+
143
+ export const NoAction: Story = {
144
+ args: {
145
+ showAction: false,
146
+ },
147
+ render: renderStory,
148
+ };
149
+
150
+ export const AlwaysShowAction: Story = {
151
+ args: {
152
+ showActionOnHover: false,
153
+ },
154
+ render: renderStory,
155
+ };
156
+
157
+ export const NoTooltips: Story = {
158
+ args: {
159
+ collapseTooltip: '',
160
+ actionTooltip: '',
161
+ },
162
+ render: renderStory,
163
+ };
@@ -0,0 +1,131 @@
1
+ <script setup lang="ts">
2
+ import { computed, inject } from 'vue';
3
+ import { ChevronUp, Plus } from 'lucide-vue-next';
4
+ import { SidebarGroupLabel } from '@/components/core/sidebar';
5
+ import { UiIconButton } from '@/components/UiIconButton';
6
+ import { UiTooltip } from '@/components/UiTooltip';
7
+ import { cn } from '@/lib/utils';
8
+ import { uiSidebarGroupContextKey } from './groupContext';
9
+ import type { UiSidebarGroupLabelEmits, UiSidebarGroupLabelProps } from './types';
10
+
11
+ defineOptions({
12
+ name: 'UiSidebarGroupLabel',
13
+ inheritAttrs: false,
14
+ });
15
+
16
+ const emit = defineEmits<UiSidebarGroupLabelEmits>();
17
+
18
+ const props = withDefaults(defineProps<UiSidebarGroupLabelProps>(), {
19
+ collapseTooltip: '',
20
+ collapseAriaLabel: 'Collapse group',
21
+ actionTooltip: '',
22
+ actionAriaLabel: 'Group action',
23
+ showAction: true,
24
+ showActionOnHover: true,
25
+ showCollapse: true,
26
+ });
27
+
28
+ const group = inject(uiSidebarGroupContextKey, null);
29
+
30
+ const labelClass = computed(() =>
31
+ props.size === 'xs'
32
+ ? 'label-12-medium text-content-on-surface-primary'
33
+ : 'body-14-medium text-content-on-surface-primary',
34
+ );
35
+
36
+ const resolvedCollapseIcon = computed(() => props.collapseIcon ?? ChevronUp);
37
+ const resolvedActionIcon = computed(() => props.actionIcon ?? Plus);
38
+ const collapseRotationClass = computed(() => {
39
+ if (!group) return 'rotate-0';
40
+ return group.open.value ? 'rotate-0' : 'rotate-180';
41
+ });
42
+
43
+ const collapseIconClass = computed(() =>
44
+ cn('transition-transform duration-200', collapseRotationClass.value),
45
+ );
46
+ const actionClass = computed(() =>
47
+ cn(
48
+ 'ml-auto',
49
+ props.showActionOnHover &&
50
+ 'opacity-0 transition-opacity group-hover/sidebar-group-label:opacity-100 group-focus-within/sidebar-group-label:opacity-100',
51
+ ),
52
+ );
53
+
54
+ function onCollapseClick(event: MouseEvent) {
55
+ group?.toggle();
56
+ emit('collapse-click', event);
57
+ }
58
+
59
+ function onActionClick(event: MouseEvent) {
60
+ emit('action-click', event);
61
+ }
62
+ </script>
63
+
64
+ <template>
65
+ <SidebarGroupLabel
66
+ v-bind="$attrs"
67
+ :class="
68
+ cn(
69
+ '!h-auto !rounded-md !border !border-transparent !px-2 !py-0 text-content-on-surface-primary',
70
+ 'focus-within:!border-border-surface-focus-ring focus-within:!ring-[3px] focus-within:!ring-ring/50',
71
+ 'group/sidebar-group-label',
72
+ $attrs.class ?? '',
73
+ )
74
+ "
75
+ >
76
+ <div class="flex min-w-0 w-full items-center">
77
+ <span :class="cn('min-w-0 truncate', labelClass)">
78
+ <slot />
79
+ </span>
80
+
81
+ <UiTooltip
82
+ v-if="props.showCollapse && props.collapseTooltip"
83
+ :content="props.collapseTooltip"
84
+ >
85
+ <UiIconButton
86
+ variant="ghost"
87
+ size="icon-sm-no-padding"
88
+ :ariaLabel="props.collapseAriaLabel"
89
+ :aria-expanded="group?.open.value"
90
+ class="ml-1"
91
+ @click="onCollapseClick"
92
+ >
93
+ <component :is="resolvedCollapseIcon" :size="16" :class="collapseIconClass" />
94
+ </UiIconButton>
95
+ </UiTooltip>
96
+ <UiIconButton
97
+ v-else-if="props.showCollapse"
98
+ variant="ghost"
99
+ size="icon-sm-no-padding"
100
+ :ariaLabel="props.collapseAriaLabel"
101
+ :aria-expanded="group?.open.value"
102
+ class="ml-1"
103
+ @click="onCollapseClick"
104
+ >
105
+ <component :is="resolvedCollapseIcon" :size="16" :class="collapseIconClass" />
106
+ </UiIconButton>
107
+
108
+ <UiTooltip v-if="props.showAction && props.actionTooltip" :content="props.actionTooltip">
109
+ <UiIconButton
110
+ variant="ghost"
111
+ size="icon-sm-no-padding"
112
+ :ariaLabel="props.actionAriaLabel"
113
+ :class="actionClass"
114
+ @click="onActionClick"
115
+ >
116
+ <component :is="resolvedActionIcon" :size="16" />
117
+ </UiIconButton>
118
+ </UiTooltip>
119
+ <UiIconButton
120
+ v-else-if="props.showAction"
121
+ variant="ghost"
122
+ size="icon-sm-no-padding"
123
+ :ariaLabel="props.actionAriaLabel"
124
+ :class="actionClass"
125
+ @click="onActionClick"
126
+ >
127
+ <component :is="resolvedActionIcon" :size="16" />
128
+ </UiIconButton>
129
+ </div>
130
+ </SidebarGroupLabel>
131
+ </template>
@@ -0,0 +1,48 @@
1
+ <script setup lang="ts">
2
+ import { computed, useAttrs } from 'vue';
3
+ import { PanelLeft } from 'lucide-vue-next';
4
+ import { SidebarHeader } from '@/components/core/sidebar';
5
+ import { cn } from '@/lib/utils';
6
+ import UiSidebarTrigger from './UiSidebarTrigger.vue';
7
+ import type { UiSidebarHeaderProps } from './types';
8
+
9
+ defineOptions({
10
+ name: 'UiSidebarHeader',
11
+ inheritAttrs: false,
12
+ });
13
+
14
+ const props = withDefaults(defineProps<UiSidebarHeaderProps>(), {
15
+ tooltip: '',
16
+ ariaLabel: 'Toggle sidebar',
17
+ });
18
+
19
+ const attrs = useAttrs();
20
+
21
+ const headerClass = computed(() => cn(attrs.class as string | undefined));
22
+
23
+ const passthroughAttrs = computed(() => {
24
+ const { class: _class, ...rest } = attrs as Record<string, unknown>;
25
+ return rest;
26
+ });
27
+ </script>
28
+
29
+ <template>
30
+ <SidebarHeader v-bind="passthroughAttrs" :class="headerClass">
31
+ <div
32
+ class="flex w-full items-center rounded-sm p-2 text-content-on-surface-primary group-data-[collapsible=icon]:justify-center"
33
+ >
34
+ <div class="flex shrink-0 grow items-center gap-2 group-data-[collapsible=icon]:hidden">
35
+ <slot name="logo"> </slot>
36
+ <span v-if="$slots.default" class="min-w-0 truncate text-base leading-normal font-semibold">
37
+ <slot />
38
+ </span>
39
+ </div>
40
+
41
+ <UiSidebarTrigger
42
+ class="ml-auto group-data-[collapsible=icon]:ml-0"
43
+ :tooltip="props.tooltip"
44
+ :aria-label="props.ariaLabel"
45
+ />
46
+ </div>
47
+ </SidebarHeader>
48
+ </template>
@@ -0,0 +1,11 @@
1
+ <script setup lang="ts">
2
+ import { SidebarInset } from '@/components/core/sidebar';
3
+
4
+ defineOptions({ name: 'UiSidebarInset' });
5
+ </script>
6
+
7
+ <template>
8
+ <SidebarInset v-bind="$attrs">
9
+ <slot />
10
+ </SidebarInset>
11
+ </template>
@@ -0,0 +1,11 @@
1
+ <script setup lang="ts">
2
+ import { SidebarMenu } from '@/components/core/sidebar';
3
+
4
+ defineOptions({ name: 'UiSidebarMenu' });
5
+ </script>
6
+
7
+ <template>
8
+ <SidebarMenu v-bind="$attrs">
9
+ <slot />
10
+ </SidebarMenu>
11
+ </template>