@aleph-alpha/ui-library 1.21.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.
- package/dist/system/index.d.ts +1520 -674
- package/dist/system/lib.js +21142 -19505
- package/package.json +3 -3
- package/src/components/UiAlertDialog/UiAlertDialog.stories.ts +135 -13
- package/src/components/UiAlertDialog/UiAlertDialog.vue +8 -7
- package/src/components/UiAlertDialog/UiAlertDialogHeader.vue +1 -1
- package/src/components/UiAlertDialog/__tests__/UiAlertDialog.test.ts +16 -16
- package/src/components/UiAlertDialog/types.ts +18 -0
- package/src/components/UiDialog/UiDialog.stories.ts +717 -0
- package/src/components/UiDialog/UiDialog.vue +19 -0
- package/src/components/UiDialog/UiDialogClose.vue +16 -0
- package/src/components/UiDialog/UiDialogContent.vue +108 -0
- package/src/components/UiDialog/UiDialogDescription.vue +16 -0
- package/src/components/UiDialog/UiDialogFooter.vue +16 -0
- package/src/components/UiDialog/UiDialogHeader.vue +16 -0
- package/src/components/UiDialog/UiDialogTitle.vue +16 -0
- package/src/components/UiDialog/UiDialogTrigger.vue +16 -0
- package/src/components/UiDialog/__tests__/UiDialog.test.ts +328 -0
- package/src/components/UiDialog/index.ts +13 -0
- package/src/components/UiDialog/types.ts +136 -0
- package/src/components/UiFileItem/UiFileItem.stories.ts +268 -0
- package/src/components/UiFileItem/UiFileItem.vue +119 -0
- package/src/components/UiFileItem/__tests__/UiFileItem.test.ts +66 -0
- package/src/components/UiFileItem/index.ts +2 -0
- package/src/components/UiFileItem/types.ts +27 -0
- package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +117 -0
- package/src/components/UiFileUploadBox/UiFileUploadBox.vue +230 -0
- package/src/components/UiFileUploadBox/__tests__/file-validation.test.ts +46 -0
- package/src/components/UiFileUploadBox/file-validation.ts +73 -0
- package/src/components/UiFileUploadBox/index.ts +7 -0
- package/src/components/UiFileUploadBox/types.ts +96 -0
- package/src/components/UiIconButton/UiIconButton.vue +5 -1
- package/src/components/UiIconButton/types.ts +1 -1
- package/src/components/UiItem/UiItem.vue +7 -1
- package/src/components/UiItem/types.ts +7 -0
- package/src/components/core/alert-dialog/AlertDialog.vue +1 -1
- package/src/components/core/alert-dialog/AlertDialogAction.vue +2 -6
- package/src/components/core/alert-dialog/AlertDialogCancel.vue +3 -7
- package/src/components/core/alert-dialog/AlertDialogContent.vue +15 -7
- package/src/components/core/alert-dialog/AlertDialogDescription.vue +3 -7
- package/src/components/core/alert-dialog/AlertDialogFooter.vue +1 -6
- package/src/components/core/alert-dialog/AlertDialogHeader.vue +1 -9
- package/src/components/core/alert-dialog/AlertDialogTitle.vue +3 -7
- package/src/components/core/button/index.ts +6 -4
- package/src/components/core/dialog/Dialog.vue +15 -0
- package/src/components/core/dialog/DialogClose.vue +12 -0
- package/src/components/core/dialog/DialogContent.vue +48 -0
- package/src/components/core/dialog/DialogDescription.vue +17 -0
- package/src/components/core/dialog/DialogFooter.vue +12 -0
- package/src/components/core/dialog/DialogHeader.vue +9 -0
- package/src/components/core/dialog/DialogOverlay.vue +23 -0
- package/src/components/core/dialog/DialogTitle.vue +17 -0
- package/src/components/core/dialog/DialogTrigger.vue +12 -0
- package/src/components/core/dialog/index.ts +9 -0
- package/src/components/core/drawer/DrawerContent.vue +1 -1
- package/src/components/core/item/Item.vue +7 -4
- package/src/components/core/progress/Progress.vue +7 -2
- package/src/components/core/sheet/SheetOverlay.vue +1 -1
- package/src/components/core/sidebar/SidebarContent.vue +11 -3
- package/src/components/core/sidebar/SidebarFooter.vue +10 -2
- package/src/components/core/sidebar/SidebarGroup.vue +10 -2
- package/src/components/core/sidebar/SidebarGroupLabel.vue +1 -1
- package/src/components/core/sidebar/SidebarHeader.vue +10 -2
- package/src/components/core/sidebar/SidebarMenu.vue +12 -2
- package/src/components/core/sidebar/SidebarMenuButton.vue +2 -2
- package/src/components/core/sidebar/SidebarSeparator.vue +10 -2
- package/src/components/core/sidebar/SidebarTrigger.vue +2 -2
- package/src/components/core/sidebar/index.ts +1 -1
- package/src/components/core/sidebar/utils.ts +11 -2
- package/src/components/index.ts +3 -1
- package/src/directives/index.ts +1 -0
- package/src/directives/vOverlay.ts +94 -0
- package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +768 -0
- package/src/patterns/UiFileUpload/UiFileUpload.vue +46 -0
- package/src/patterns/UiFileUpload/__tests__/UiFileUpload.test.ts +123 -0
- package/src/patterns/UiFileUpload/index.ts +8 -0
- package/src/patterns/UiFileUpload/types.ts +12 -0
- package/src/patterns/UiSidebar/UiSidebar.stories.ts +346 -0
- package/src/{components → patterns}/UiSidebar/UiSidebar.vue +9 -3
- package/src/patterns/UiSidebar/UiSidebarChatHistory.stories.ts +77 -0
- package/src/patterns/UiSidebar/UiSidebarChatHistory.vue +35 -0
- package/src/patterns/UiSidebar/UiSidebarChatHistoryItem.stories.ts +85 -0
- package/src/patterns/UiSidebar/UiSidebarChatHistoryItem.vue +139 -0
- package/src/patterns/UiSidebar/UiSidebarContent.vue +11 -0
- package/src/patterns/UiSidebar/UiSidebarFooter.vue +11 -0
- package/src/patterns/UiSidebar/UiSidebarGroup.stories.ts +91 -0
- package/src/patterns/UiSidebar/UiSidebarGroup.vue +42 -0
- package/src/patterns/UiSidebar/UiSidebarGroupContent.vue +15 -0
- package/src/patterns/UiSidebar/UiSidebarGroupLabel.stories.ts +163 -0
- package/src/patterns/UiSidebar/UiSidebarGroupLabel.vue +131 -0
- package/src/patterns/UiSidebar/UiSidebarHeader.vue +48 -0
- package/src/patterns/UiSidebar/UiSidebarInset.vue +11 -0
- package/src/patterns/UiSidebar/UiSidebarMenu.vue +11 -0
- package/src/patterns/UiSidebar/UiSidebarMenuButton.stories.ts +205 -0
- package/src/patterns/UiSidebar/UiSidebarMenuButton.vue +121 -0
- package/src/patterns/UiSidebar/UiSidebarMenuItem.stories.ts +67 -0
- package/src/patterns/UiSidebar/UiSidebarMenuItem.vue +11 -0
- package/src/patterns/UiSidebar/UiSidebarMenuSub.vue +38 -0
- package/src/patterns/UiSidebar/UiSidebarMenuSubItem.stories.ts +66 -0
- package/src/patterns/UiSidebar/UiSidebarMenuSubItem.vue +67 -0
- package/src/patterns/UiSidebar/UiSidebarPopover.vue +43 -0
- package/src/patterns/UiSidebar/UiSidebarPopoverMenu.stories.ts +56 -0
- package/src/patterns/UiSidebar/UiSidebarPopoverMenu.vue +56 -0
- package/src/patterns/UiSidebar/UiSidebarPopoverMenuItem.stories.ts +42 -0
- package/src/patterns/UiSidebar/UiSidebarPopoverMenuItem.vue +79 -0
- package/src/patterns/UiSidebar/UiSidebarPopoverTrigger.stories.ts +61 -0
- package/src/patterns/UiSidebar/UiSidebarPopoverTrigger.vue +81 -0
- package/src/patterns/UiSidebar/UiSidebarProvider.vue +11 -0
- package/src/patterns/UiSidebar/UiSidebarRail.vue +9 -0
- package/src/patterns/UiSidebar/UiSidebarTrigger.vue +35 -0
- package/src/patterns/UiSidebar/groupContext.ts +9 -0
- package/src/patterns/UiSidebar/index.ts +42 -0
- package/src/patterns/UiSidebar/types.ts +375 -0
- package/src/patterns/index.ts +2 -0
- package/src/components/UiSidebar/UiSidebar.stories.ts +0 -1188
- package/src/components/UiSidebar/UiSidebarGroupAction.vue +0 -18
- package/src/components/UiSidebar/UiSidebarGroupLabel.vue +0 -18
- package/src/components/UiSidebar/UiSidebarHeaderTrigger.vue +0 -53
- package/src/components/UiSidebar/UiSidebarInput.vue +0 -14
- package/src/components/UiSidebar/UiSidebarMenuAction.vue +0 -19
- package/src/components/UiSidebar/UiSidebarMenuButton.vue +0 -27
- package/src/components/UiSidebar/UiSidebarMenuSkeleton.vue +0 -16
- package/src/components/UiSidebar/UiSidebarMenuSubButton.vue +0 -24
- package/src/components/UiSidebar/UiSidebarProvider.vue +0 -16
- package/src/components/UiSidebar/UiSidebarSeparator.vue +0 -13
- package/src/components/UiSidebar/__tests__/UiSidebar.test.ts +0 -221
- package/src/components/UiSidebar/index.ts +0 -34
- package/src/components/UiSidebar/types.ts +0 -165
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import { ref } from 'vue';
|
|
3
|
+
import { MoreHorizontal } from 'lucide-vue-next';
|
|
4
|
+
import UiSidebar from './UiSidebar.vue';
|
|
5
|
+
import UiSidebarContent from './UiSidebarContent.vue';
|
|
6
|
+
import UiSidebarChatHistoryItem from './UiSidebarChatHistoryItem.vue';
|
|
7
|
+
import UiSidebarHeader from './UiSidebarHeader.vue';
|
|
8
|
+
import UiSidebarProvider from './UiSidebarProvider.vue';
|
|
9
|
+
|
|
10
|
+
const meta: Meta<typeof UiSidebarChatHistoryItem> = {
|
|
11
|
+
title: 'Patterns/UiSidebar/UiSidebarChatHistoryItem',
|
|
12
|
+
component: UiSidebarChatHistoryItem,
|
|
13
|
+
tags: ['autodocs'],
|
|
14
|
+
args: {
|
|
15
|
+
title: 'Project Proposal Overview',
|
|
16
|
+
metaStart: 'Today',
|
|
17
|
+
metaEnd: 'Innsbruck',
|
|
18
|
+
actionTooltip: 'More actions',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default meta;
|
|
23
|
+
|
|
24
|
+
type Story = StoryObj<typeof UiSidebarChatHistoryItem>;
|
|
25
|
+
|
|
26
|
+
const renderStory = (args: Story['args']) => ({
|
|
27
|
+
components: {
|
|
28
|
+
MoreHorizontal,
|
|
29
|
+
UiSidebar,
|
|
30
|
+
UiSidebarContent,
|
|
31
|
+
UiSidebarChatHistoryItem,
|
|
32
|
+
UiSidebarHeader,
|
|
33
|
+
UiSidebarProvider,
|
|
34
|
+
},
|
|
35
|
+
setup() {
|
|
36
|
+
const actionCount = ref(0);
|
|
37
|
+
|
|
38
|
+
function handleActionClick() {
|
|
39
|
+
actionCount.value += 1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return { actionCount, args, handleActionClick };
|
|
43
|
+
},
|
|
44
|
+
template: `
|
|
45
|
+
<UiSidebarProvider :default-open="true">
|
|
46
|
+
<div class="max-w-sm bg-background-surface-primary p-4">
|
|
47
|
+
<UiSidebar class="w-[22rem]" collapsible="icon">
|
|
48
|
+
<UiSidebarHeader tooltip="Toggle sidebar">Preview</UiSidebarHeader>
|
|
49
|
+
<UiSidebarContent class="p-2">
|
|
50
|
+
<UiSidebarChatHistoryItem v-bind="args" @action-click="handleActionClick" />
|
|
51
|
+
</UiSidebarContent>
|
|
52
|
+
</UiSidebar>
|
|
53
|
+
<p class="mt-3 text-xs text-content-on-surface-muted">
|
|
54
|
+
Action clicks: {{ actionCount }}
|
|
55
|
+
</p>
|
|
56
|
+
</div>
|
|
57
|
+
</UiSidebarProvider>
|
|
58
|
+
`,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export const Default: Story = {
|
|
62
|
+
render: renderStory,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const Active: Story = {
|
|
66
|
+
args: {
|
|
67
|
+
isActive: true,
|
|
68
|
+
},
|
|
69
|
+
render: renderStory,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const AlwaysShowAction: Story = {
|
|
73
|
+
args: {
|
|
74
|
+
showActionOnHover: false,
|
|
75
|
+
},
|
|
76
|
+
render: renderStory,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const NoMeta: Story = {
|
|
80
|
+
args: {
|
|
81
|
+
metaStart: '',
|
|
82
|
+
metaEnd: '',
|
|
83
|
+
},
|
|
84
|
+
render: renderStory,
|
|
85
|
+
};
|
|
@@ -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,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>
|