@aleph-alpha/ui-library 2.3.0 → 2.4.1
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/components/UiAlert/UiAlert.vue.d.ts +1 -0
- package/dist/system/components/UiAlert/constants.d.ts +16 -2
- package/dist/system/components/UiResizable/UiResizableHandle.vue.d.ts +22 -0
- package/dist/system/components/UiResizable/UiResizablePanel.vue.d.ts +31 -0
- package/dist/system/components/UiResizable/UiResizablePanelGroup.vue.d.ts +23 -0
- package/dist/system/components/UiResizable/index.d.ts +4 -0
- package/dist/system/components/UiResizable/types.d.ts +37 -0
- package/dist/system/components/core/resizable/ResizableHandle.vue.d.ts +27 -0
- package/dist/system/components/core/resizable/ResizablePanel.vue.d.ts +32 -0
- package/dist/system/components/core/resizable/ResizablePanelGroup.vue.d.ts +28 -0
- package/dist/system/components/core/resizable/index.d.ts +3 -0
- package/dist/system/components/core/sidebar/Sidebar.vue.d.ts +7 -0
- package/dist/system/components/core/sidebar/SidebarResizeHandle.vue.d.ts +16 -0
- package/dist/system/components/core/sidebar/index.d.ts +16 -0
- package/dist/system/components/core/sidebar/utils.d.ts +4 -0
- package/dist/system/components/index.d.ts +1 -0
- package/dist/system/favicon.ico +0 -0
- package/dist/system/lib.js +21879 -20151
- package/dist/system/patterns/UiSidebar/UiSidebar.vue.d.ts +1 -0
- package/dist/system/patterns/UiSidebar/__tests__/sidebar-test-helpers.d.ts +6 -0
- package/dist/system/storybook-config.json +9 -0
- package/package.json +3 -2
- package/src/components/UiAlert/UiAlert.stories.ts +3 -15
- package/src/components/UiAlert/UiAlert.vue +16 -10
- package/src/components/UiAlert/constants.ts +21 -2
- package/src/components/UiResizable/UiResizable.stories.ts +424 -0
- package/src/components/UiResizable/UiResizableHandle.vue +17 -0
- package/src/components/UiResizable/UiResizablePanel.vue +30 -0
- package/src/components/UiResizable/UiResizablePanelGroup.vue +27 -0
- package/src/components/UiResizable/__tests__/UiResizableHandle.test.ts +64 -0
- package/src/components/UiResizable/__tests__/UiResizablePanel.test.ts +82 -0
- package/src/components/UiResizable/__tests__/UiResizablePanelGroup.test.ts +79 -0
- package/src/components/UiResizable/index.ts +4 -0
- package/src/components/UiResizable/types.ts +50 -0
- package/src/components/core/resizable/ResizableHandle.vue +45 -0
- package/src/components/core/resizable/ResizablePanel.vue +21 -0
- package/src/components/core/resizable/ResizablePanelGroup.vue +31 -0
- package/src/components/core/resizable/index.ts +3 -0
- package/src/components/core/sidebar/Sidebar.vue +208 -2
- package/src/components/core/sidebar/SidebarMenuButton.vue +5 -1
- package/src/components/core/sidebar/SidebarRail.vue +1 -2
- package/src/components/core/sidebar/SidebarResizeHandle.vue +46 -0
- package/src/components/core/sidebar/index.ts +17 -0
- package/src/components/core/sidebar/utils.ts +4 -0
- package/src/components/index.ts +1 -0
- package/src/patterns/UiSidebar/UiSidebar.stories.ts +42 -1
- package/src/patterns/UiSidebar/UiSidebar.vue +20 -0
- package/src/patterns/UiSidebar/__tests__/UiSidebar.test.ts +204 -2
- package/src/patterns/UiSidebar/__tests__/UiSidebarMenuButton.test.ts +31 -0
- package/src/patterns/UiSidebar/__tests__/UiSidebarRail.test.ts +14 -0
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { SidebarProps } from '.';
|
|
3
|
+
import { defaultWindow } from '@vueuse/core';
|
|
4
|
+
import { computed, onBeforeUnmount, ref, watch } from 'vue';
|
|
3
5
|
import { cn } from '@/lib/utils';
|
|
4
6
|
import { Sheet, SheetContent } from '@/components/core/sheet';
|
|
5
7
|
import SheetDescription from '@/components/core/sheet/SheetDescription.vue';
|
|
6
8
|
import SheetHeader from '@/components/core/sheet/SheetHeader.vue';
|
|
7
9
|
import SheetTitle from '@/components/core/sheet/SheetTitle.vue';
|
|
8
|
-
import
|
|
10
|
+
import SidebarResizeHandle from './SidebarResizeHandle.vue';
|
|
11
|
+
import {
|
|
12
|
+
SIDEBAR_WIDTH_DEFAULT,
|
|
13
|
+
SIDEBAR_WIDTH_MAX,
|
|
14
|
+
SIDEBAR_WIDTH_MIN,
|
|
15
|
+
SIDEBAR_WIDTH_MOBILE,
|
|
16
|
+
SIDEBAR_WIDTH_STORAGE_KEY,
|
|
17
|
+
useSidebar,
|
|
18
|
+
} from './utils';
|
|
9
19
|
|
|
10
20
|
defineOptions({
|
|
11
21
|
inheritAttrs: false,
|
|
@@ -15,24 +25,206 @@ const props = withDefaults(defineProps<SidebarProps>(), {
|
|
|
15
25
|
side: 'left',
|
|
16
26
|
variant: 'sidebar',
|
|
17
27
|
collapsible: 'offcanvas',
|
|
28
|
+
resizable: false,
|
|
29
|
+
defaultWidth: SIDEBAR_WIDTH_DEFAULT,
|
|
30
|
+
minWidth: SIDEBAR_WIDTH_MIN,
|
|
31
|
+
maxWidth: SIDEBAR_WIDTH_MAX,
|
|
32
|
+
widthStorageKey: SIDEBAR_WIDTH_STORAGE_KEY,
|
|
33
|
+
resizeAriaLabel: 'Resize sidebar',
|
|
34
|
+
keyboardResizeBy: 10,
|
|
18
35
|
});
|
|
19
36
|
|
|
20
37
|
const { isMobile, state, openMobile, setOpenMobile } = useSidebar();
|
|
38
|
+
|
|
39
|
+
const resolvedResizable = computed(
|
|
40
|
+
() => props.resizeOptions !== undefined || props.resizable,
|
|
41
|
+
);
|
|
42
|
+
const minWidth = computed(() =>
|
|
43
|
+
Math.min(
|
|
44
|
+
props.resizeOptions?.minWidth ?? props.minWidth,
|
|
45
|
+
props.resizeOptions?.maxWidth ?? props.maxWidth,
|
|
46
|
+
),
|
|
47
|
+
);
|
|
48
|
+
const maxWidth = computed(() =>
|
|
49
|
+
Math.max(
|
|
50
|
+
props.resizeOptions?.minWidth ?? props.minWidth,
|
|
51
|
+
props.resizeOptions?.maxWidth ?? props.maxWidth,
|
|
52
|
+
),
|
|
53
|
+
);
|
|
54
|
+
const resolvedDefaultWidth = computed(
|
|
55
|
+
() => props.resizeOptions?.defaultWidth ?? props.defaultWidth,
|
|
56
|
+
);
|
|
57
|
+
const resolvedWidthStorageKey = computed(
|
|
58
|
+
() => props.resizeOptions?.widthStorageKey ?? props.widthStorageKey,
|
|
59
|
+
);
|
|
60
|
+
const resolvedResizeAriaLabel = computed(
|
|
61
|
+
() => props.resizeOptions?.resizeAriaLabel ?? props.resizeAriaLabel,
|
|
62
|
+
);
|
|
63
|
+
const resolvedKeyboardResizeBy = computed(
|
|
64
|
+
() => props.resizeOptions?.keyboardResizeBy ?? props.keyboardResizeBy,
|
|
65
|
+
);
|
|
66
|
+
const sidebarWidth = ref(getInitialSidebarWidth());
|
|
67
|
+
const isResizing = ref(false);
|
|
68
|
+
let resizeStartX = 0;
|
|
69
|
+
let resizeStartWidth = 0;
|
|
70
|
+
|
|
71
|
+
const canResize = computed(
|
|
72
|
+
() =>
|
|
73
|
+
resolvedResizable.value &&
|
|
74
|
+
!isMobile.value &&
|
|
75
|
+
(props.collapsible === 'none' || state.value === 'expanded'),
|
|
76
|
+
);
|
|
77
|
+
const sidebarStyle = computed(() => ({
|
|
78
|
+
...(resolvedResizable.value
|
|
79
|
+
? {
|
|
80
|
+
'--sidebar-width': `${sidebarWidth.value}px`,
|
|
81
|
+
}
|
|
82
|
+
: {}),
|
|
83
|
+
}));
|
|
84
|
+
|
|
85
|
+
function clampWidth(width: number) {
|
|
86
|
+
return Math.min(Math.max(width, minWidth.value), maxWidth.value);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function getStoredSidebarWidth() {
|
|
90
|
+
if (!resolvedWidthStorageKey.value || !defaultWindow?.localStorage)
|
|
91
|
+
return null;
|
|
92
|
+
|
|
93
|
+
let stored: string | null;
|
|
94
|
+
try {
|
|
95
|
+
stored = defaultWindow.localStorage.getItem(resolvedWidthStorageKey.value);
|
|
96
|
+
} catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (!stored) return null;
|
|
101
|
+
const parsed = Number.parseFloat(stored);
|
|
102
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function getInitialSidebarWidth() {
|
|
106
|
+
return clampWidth(getStoredSidebarWidth() ?? resolvedDefaultWidth.value);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function persistSidebarWidth(width: number) {
|
|
110
|
+
if (!resolvedWidthStorageKey.value || !defaultWindow?.localStorage) return;
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
defaultWindow.localStorage.setItem(
|
|
114
|
+
resolvedWidthStorageKey.value,
|
|
115
|
+
String(width),
|
|
116
|
+
);
|
|
117
|
+
} catch {
|
|
118
|
+
// Ignore unavailable storage; resizing should still work for the session.
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function setSidebarWidth(width: number, persist = true) {
|
|
123
|
+
const nextWidth = clampWidth(width);
|
|
124
|
+
sidebarWidth.value = nextWidth;
|
|
125
|
+
|
|
126
|
+
if (persist) {
|
|
127
|
+
persistSidebarWidth(nextWidth);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function getNextWidth(clientX: number) {
|
|
132
|
+
const delta = clientX - resizeStartX;
|
|
133
|
+
return props.side === 'right'
|
|
134
|
+
? resizeStartWidth - delta
|
|
135
|
+
: resizeStartWidth + delta;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function stopResize() {
|
|
139
|
+
isResizing.value = false;
|
|
140
|
+
defaultWindow?.removeEventListener('pointermove', handlePointerMove);
|
|
141
|
+
defaultWindow?.removeEventListener('pointerup', stopResize);
|
|
142
|
+
defaultWindow?.removeEventListener('pointercancel', stopResize);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function handlePointerMove(event: PointerEvent) {
|
|
146
|
+
if (!isResizing.value) return;
|
|
147
|
+
event.preventDefault();
|
|
148
|
+
setSidebarWidth(getNextWidth(event.clientX));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function startResize(event: PointerEvent) {
|
|
152
|
+
if (!canResize.value) return;
|
|
153
|
+
|
|
154
|
+
event.preventDefault();
|
|
155
|
+
isResizing.value = true;
|
|
156
|
+
resizeStartX = event.clientX;
|
|
157
|
+
resizeStartWidth = sidebarWidth.value;
|
|
158
|
+
defaultWindow?.addEventListener('pointermove', handlePointerMove);
|
|
159
|
+
defaultWindow?.addEventListener('pointerup', stopResize);
|
|
160
|
+
defaultWindow?.addEventListener('pointercancel', stopResize);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function resizeBy(delta: number) {
|
|
164
|
+
const directionalDelta = props.side === 'right' ? -delta : delta;
|
|
165
|
+
setSidebarWidth(sidebarWidth.value + directionalDelta);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function handleResizeKeydown(event: KeyboardEvent) {
|
|
169
|
+
if (!canResize.value) return;
|
|
170
|
+
|
|
171
|
+
if (event.key === 'ArrowLeft') {
|
|
172
|
+
event.preventDefault();
|
|
173
|
+
resizeBy(-resolvedKeyboardResizeBy.value);
|
|
174
|
+
} else if (event.key === 'ArrowRight') {
|
|
175
|
+
event.preventDefault();
|
|
176
|
+
resizeBy(resolvedKeyboardResizeBy.value);
|
|
177
|
+
} else if (event.key === 'Home') {
|
|
178
|
+
event.preventDefault();
|
|
179
|
+
setSidebarWidth(minWidth.value);
|
|
180
|
+
} else if (event.key === 'End') {
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
setSidebarWidth(maxWidth.value);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
watch(
|
|
187
|
+
() => [
|
|
188
|
+
props.defaultWidth,
|
|
189
|
+
props.minWidth,
|
|
190
|
+
props.maxWidth,
|
|
191
|
+
props.resizeOptions?.defaultWidth,
|
|
192
|
+
props.resizeOptions?.minWidth,
|
|
193
|
+
props.resizeOptions?.maxWidth,
|
|
194
|
+
],
|
|
195
|
+
// Clamp config-driven changes without overwriting the user's stored width preference.
|
|
196
|
+
() => setSidebarWidth(sidebarWidth.value, false),
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
onBeforeUnmount(stopResize);
|
|
21
200
|
</script>
|
|
22
201
|
|
|
23
202
|
<template>
|
|
24
203
|
<div
|
|
25
204
|
v-if="collapsible === 'none'"
|
|
26
205
|
data-slot="sidebar"
|
|
206
|
+
:data-resizable="resolvedResizable ? '' : undefined"
|
|
207
|
+
:style="sidebarStyle"
|
|
27
208
|
:class="
|
|
28
209
|
cn(
|
|
29
|
-
'bg-sidebar text-sidebar-foreground flex h-full w-(--sidebar-width) flex-col',
|
|
210
|
+
'bg-sidebar text-sidebar-foreground relative flex h-full w-(--sidebar-width) flex-col',
|
|
30
211
|
$attrs.class ?? '',
|
|
31
212
|
)
|
|
32
213
|
"
|
|
33
214
|
v-bind="$attrs"
|
|
34
215
|
>
|
|
35
216
|
<slot />
|
|
217
|
+
<SidebarResizeHandle
|
|
218
|
+
v-if="canResize"
|
|
219
|
+
:accessible-label="resolvedResizeAriaLabel"
|
|
220
|
+
:is-resizing="isResizing"
|
|
221
|
+
:side="props.side"
|
|
222
|
+
:value-min="minWidth"
|
|
223
|
+
:value-max="maxWidth"
|
|
224
|
+
:value-now="sidebarWidth"
|
|
225
|
+
@keydown="handleResizeKeydown"
|
|
226
|
+
@pointerdown="startResize"
|
|
227
|
+
/>
|
|
36
228
|
</div>
|
|
37
229
|
|
|
38
230
|
<Sheet
|
|
@@ -69,6 +261,8 @@ const { isMobile, state, openMobile, setOpenMobile } = useSidebar();
|
|
|
69
261
|
:data-collapsible="state === 'collapsed' ? collapsible : ''"
|
|
70
262
|
:data-variant="variant"
|
|
71
263
|
:data-side="side"
|
|
264
|
+
:data-resizable="resolvedResizable ? '' : undefined"
|
|
265
|
+
:style="sidebarStyle"
|
|
72
266
|
>
|
|
73
267
|
<!-- This is what handles the sidebar gap on desktop -->
|
|
74
268
|
<div
|
|
@@ -87,6 +281,7 @@ const { isMobile, state, openMobile, setOpenMobile } = useSidebar();
|
|
|
87
281
|
:class="
|
|
88
282
|
cn(
|
|
89
283
|
'fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear md:flex',
|
|
284
|
+
isResizing && 'transition-none',
|
|
90
285
|
side === 'left'
|
|
91
286
|
? 'left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]'
|
|
92
287
|
: 'right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]',
|
|
@@ -105,6 +300,17 @@ const { isMobile, state, openMobile, setOpenMobile } = useSidebar();
|
|
|
105
300
|
>
|
|
106
301
|
<slot />
|
|
107
302
|
</div>
|
|
303
|
+
<SidebarResizeHandle
|
|
304
|
+
v-if="canResize"
|
|
305
|
+
:accessible-label="resolvedResizeAriaLabel"
|
|
306
|
+
:is-resizing="isResizing"
|
|
307
|
+
:side="props.side"
|
|
308
|
+
:value-min="minWidth"
|
|
309
|
+
:value-max="maxWidth"
|
|
310
|
+
:value-now="sidebarWidth"
|
|
311
|
+
@keydown="handleResizeKeydown"
|
|
312
|
+
@pointerdown="startResize"
|
|
313
|
+
/>
|
|
108
314
|
</div>
|
|
109
315
|
</div>
|
|
110
316
|
</template>
|
|
@@ -40,7 +40,11 @@ const delegatedProps = reactiveOmit(props, 'tooltip');
|
|
|
40
40
|
<slot />
|
|
41
41
|
</SidebarMenuButtonChild>
|
|
42
42
|
|
|
43
|
-
<Tooltip
|
|
43
|
+
<Tooltip
|
|
44
|
+
v-else
|
|
45
|
+
:disabled="state !== 'collapsed' || isMobile"
|
|
46
|
+
:delay-duration="0"
|
|
47
|
+
>
|
|
44
48
|
<TooltipTrigger as-child>
|
|
45
49
|
<SidebarMenuButtonChild v-bind="{ ...delegatedProps, ...$attrs }">
|
|
46
50
|
<slot />
|
|
@@ -18,8 +18,7 @@ const { toggleSidebar } = useSidebar();
|
|
|
18
18
|
:class="
|
|
19
19
|
cn(
|
|
20
20
|
'hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] sm:flex',
|
|
21
|
-
'
|
|
22
|
-
'[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize',
|
|
21
|
+
'cursor-pointer',
|
|
23
22
|
'hover:group-data-[collapsible=offcanvas]:bg-sidebar group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full',
|
|
24
23
|
'[[data-side=left][data-collapsible=offcanvas]_&]:-right-2',
|
|
25
24
|
'[[data-side=right][data-collapsible=offcanvas]_&]:-left-2',
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { cn } from '@/lib/utils';
|
|
3
|
+
|
|
4
|
+
defineProps<{
|
|
5
|
+
accessibleLabel: string;
|
|
6
|
+
isResizing: boolean;
|
|
7
|
+
side: 'left' | 'right';
|
|
8
|
+
valueMin: number;
|
|
9
|
+
valueMax: number;
|
|
10
|
+
valueNow: number;
|
|
11
|
+
}>();
|
|
12
|
+
|
|
13
|
+
defineEmits<{
|
|
14
|
+
keydown: [event: KeyboardEvent];
|
|
15
|
+
pointerdown: [event: PointerEvent];
|
|
16
|
+
}>();
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<template>
|
|
20
|
+
<button
|
|
21
|
+
type="button"
|
|
22
|
+
data-slot="sidebar-resize-handle"
|
|
23
|
+
data-sidebar="resize-handle"
|
|
24
|
+
:data-state="isResizing ? 'drag' : undefined"
|
|
25
|
+
role="separator"
|
|
26
|
+
aria-orientation="vertical"
|
|
27
|
+
:aria-label="accessibleLabel"
|
|
28
|
+
:aria-valuemin="valueMin"
|
|
29
|
+
:aria-valuemax="valueMax"
|
|
30
|
+
:aria-valuenow="valueNow"
|
|
31
|
+
:class="
|
|
32
|
+
cn(
|
|
33
|
+
'absolute inset-y-0 z-30 hidden w-4 cursor-col-resize bg-transparent p-0 outline-none after:absolute after:inset-y-0 after:left-1/2 after:w-0 after:-translate-x-1/2 after:border-l-2 after:border-l-transparent hover:after:border-l-accent-default focus-visible:after:border-l-accent-default data-[state=drag]:after:border-l-accent-default sm:flex',
|
|
34
|
+
side === 'left' ? '-right-2' : '-left-2',
|
|
35
|
+
)
|
|
36
|
+
"
|
|
37
|
+
@keydown="$emit('keydown', $event)"
|
|
38
|
+
@pointerdown="$emit('pointerdown', $event)"
|
|
39
|
+
/>
|
|
40
|
+
</template>
|
|
41
|
+
|
|
42
|
+
<style scoped>
|
|
43
|
+
[data-slot='sidebar-resize-handle']::after {
|
|
44
|
+
content: '';
|
|
45
|
+
}
|
|
46
|
+
</style>
|
|
@@ -5,6 +5,23 @@ export interface SidebarProps {
|
|
|
5
5
|
side?: 'left' | 'right';
|
|
6
6
|
variant?: 'sidebar' | 'floating' | 'inset';
|
|
7
7
|
collapsible?: 'offcanvas' | 'icon' | 'none';
|
|
8
|
+
resizeOptions?: SidebarResizeOptions;
|
|
9
|
+
resizable?: boolean;
|
|
10
|
+
defaultWidth?: number;
|
|
11
|
+
minWidth?: number;
|
|
12
|
+
maxWidth?: number;
|
|
13
|
+
widthStorageKey?: string;
|
|
14
|
+
resizeAriaLabel?: string;
|
|
15
|
+
keyboardResizeBy?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface SidebarResizeOptions {
|
|
19
|
+
defaultWidth?: number;
|
|
20
|
+
minWidth?: number;
|
|
21
|
+
maxWidth?: number;
|
|
22
|
+
widthStorageKey?: string;
|
|
23
|
+
resizeAriaLabel?: string;
|
|
24
|
+
keyboardResizeBy?: number;
|
|
8
25
|
}
|
|
9
26
|
|
|
10
27
|
export { default as Sidebar } from './Sidebar.vue';
|
|
@@ -4,9 +4,13 @@ import { createContext } from 'reka-ui';
|
|
|
4
4
|
export const SIDEBAR_COOKIE_NAME = 'sidebar_state';
|
|
5
5
|
export const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
|
|
6
6
|
export const SIDEBAR_WIDTH = '16rem';
|
|
7
|
+
export const SIDEBAR_WIDTH_DEFAULT = 256;
|
|
8
|
+
export const SIDEBAR_WIDTH_MIN = 240;
|
|
9
|
+
export const SIDEBAR_WIDTH_MAX = 480;
|
|
7
10
|
export const SIDEBAR_WIDTH_MOBILE = '18rem';
|
|
8
11
|
export const SIDEBAR_WIDTH_ICON = '3rem';
|
|
9
12
|
export const SIDEBAR_KEYBOARD_SHORTCUT = 'b';
|
|
13
|
+
export const SIDEBAR_WIDTH_STORAGE_KEY = 'sidebar_width';
|
|
10
14
|
|
|
11
15
|
export type SidebarContextValue = {
|
|
12
16
|
state: ComputedRef<'expanded' | 'collapsed'>;
|
package/src/components/index.ts
CHANGED
|
@@ -31,6 +31,7 @@ export * from './UiPopover';
|
|
|
31
31
|
export * from './UiProgress';
|
|
32
32
|
export * from './UiRadioGroup';
|
|
33
33
|
export * from './UiRangeCalendar';
|
|
34
|
+
export * from './UiResizable';
|
|
34
35
|
export * from './UiSelect';
|
|
35
36
|
export * from './UiSeparator';
|
|
36
37
|
export * from './UiSheet';
|
|
@@ -28,6 +28,10 @@ const meta: Meta<typeof UiSidebar> = {
|
|
|
28
28
|
side: 'left',
|
|
29
29
|
variant: 'sidebar',
|
|
30
30
|
collapsible: 'icon',
|
|
31
|
+
resizable: false,
|
|
32
|
+
minWidth: 240,
|
|
33
|
+
maxWidth: 480,
|
|
34
|
+
defaultWidth: 256,
|
|
31
35
|
},
|
|
32
36
|
parameters: {
|
|
33
37
|
layout: 'fullscreen',
|
|
@@ -56,6 +60,24 @@ const meta: Meta<typeof UiSidebar> = {
|
|
|
56
60
|
description:
|
|
57
61
|
'Collapse behavior: slide off-canvas, collapse to icon width, or non-collapsing.',
|
|
58
62
|
},
|
|
63
|
+
resizable: {
|
|
64
|
+
control: 'boolean',
|
|
65
|
+
description:
|
|
66
|
+
'Allows resizing the desktop sidebar by dragging its outer border.',
|
|
67
|
+
},
|
|
68
|
+
minWidth: {
|
|
69
|
+
control: { type: 'number', min: 160, max: 480, step: 8 },
|
|
70
|
+
description: 'Minimum resizable sidebar width in pixels.',
|
|
71
|
+
},
|
|
72
|
+
maxWidth: {
|
|
73
|
+
control: { type: 'number', min: 240, max: 720, step: 8 },
|
|
74
|
+
description: 'Maximum resizable sidebar width in pixels.',
|
|
75
|
+
},
|
|
76
|
+
defaultWidth: {
|
|
77
|
+
control: { type: 'number', min: 160, max: 720, step: 8 },
|
|
78
|
+
description:
|
|
79
|
+
'Initial sidebar width in pixels when no persisted width exists.',
|
|
80
|
+
},
|
|
59
81
|
},
|
|
60
82
|
};
|
|
61
83
|
|
|
@@ -146,7 +168,15 @@ const renderStory = (args: Story['args']) => ({
|
|
|
146
168
|
},
|
|
147
169
|
template: `
|
|
148
170
|
<UiSidebarProvider :default-open="true">
|
|
149
|
-
<UiSidebar
|
|
171
|
+
<UiSidebar
|
|
172
|
+
:side="args.side"
|
|
173
|
+
:variant="args.variant"
|
|
174
|
+
:collapsible="args.collapsible"
|
|
175
|
+
:resizable="args.resizable"
|
|
176
|
+
:default-width="args.defaultWidth"
|
|
177
|
+
:min-width="args.minWidth"
|
|
178
|
+
:max-width="args.maxWidth"
|
|
179
|
+
>
|
|
150
180
|
<UiSidebarHeader tooltip="Assistant" aria-label="Assistant sidebar trigger">
|
|
151
181
|
<template #logo>
|
|
152
182
|
<svg
|
|
@@ -352,6 +382,17 @@ export const Default: Story = {
|
|
|
352
382
|
render: renderStory,
|
|
353
383
|
};
|
|
354
384
|
|
|
385
|
+
export const Resizable: Story = {
|
|
386
|
+
render: renderStory,
|
|
387
|
+
args: {
|
|
388
|
+
resizable: true,
|
|
389
|
+
collapsible: 'icon',
|
|
390
|
+
defaultWidth: 280,
|
|
391
|
+
minWidth: 240,
|
|
392
|
+
maxWidth: 480,
|
|
393
|
+
},
|
|
394
|
+
};
|
|
395
|
+
|
|
355
396
|
export const Inset: Story = {
|
|
356
397
|
args: {
|
|
357
398
|
variant: 'inset',
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue';
|
|
2
3
|
import { Sidebar } from '@/components/core/sidebar';
|
|
3
4
|
import type { UiSidebarProps } from './types';
|
|
4
5
|
|
|
@@ -11,6 +12,24 @@ const props = withDefaults(defineProps<UiSidebarProps>(), {
|
|
|
11
12
|
side: 'left',
|
|
12
13
|
variant: 'sidebar',
|
|
13
14
|
collapsible: 'offcanvas',
|
|
15
|
+
resizable: false,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const resizeOptions = computed(() => {
|
|
19
|
+
const isResizable = props.resizeOptions !== undefined || props.resizable;
|
|
20
|
+
if (!isResizable) return undefined;
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
defaultWidth: props.resizeOptions?.defaultWidth ?? props.defaultWidth,
|
|
24
|
+
minWidth: props.resizeOptions?.minWidth ?? props.minWidth,
|
|
25
|
+
maxWidth: props.resizeOptions?.maxWidth ?? props.maxWidth,
|
|
26
|
+
widthStorageKey:
|
|
27
|
+
props.resizeOptions?.widthStorageKey ?? props.widthStorageKey,
|
|
28
|
+
resizeAriaLabel:
|
|
29
|
+
props.resizeOptions?.resizeAriaLabel ?? props.resizeAriaLabel,
|
|
30
|
+
keyboardResizeBy:
|
|
31
|
+
props.resizeOptions?.keyboardResizeBy ?? props.keyboardResizeBy,
|
|
32
|
+
};
|
|
14
33
|
});
|
|
15
34
|
</script>
|
|
16
35
|
|
|
@@ -19,6 +38,7 @@ const props = withDefaults(defineProps<UiSidebarProps>(), {
|
|
|
19
38
|
:side="props.side"
|
|
20
39
|
:variant="props.variant"
|
|
21
40
|
:collapsible="props.collapsible"
|
|
41
|
+
:resize-options="resizeOptions"
|
|
22
42
|
v-bind="$attrs"
|
|
23
43
|
>
|
|
24
44
|
<slot />
|