@aleph-alpha/ui-library 2.2.0 → 2.4.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/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/UiToggle/UiToggle.vue.d.ts +5 -0
- package/dist/system/components/UiToggle/types.d.ts +13 -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/lib/heightTransition.d.ts +5 -0
- package/dist/system/lib/useDrag.d.ts +52 -0
- package/dist/system/lib.js +22198 -19966
- package/dist/system/patterns/UiDataTable/UiDataTable.vue.d.ts +22 -3
- package/dist/system/patterns/UiDataTable/UiDataTableColumnFilter.vue.d.ts +14 -0
- package/dist/system/patterns/UiDataTable/constants.d.ts +13 -0
- package/dist/system/patterns/UiDataTable/index.d.ts +2 -0
- package/dist/system/patterns/UiDataTable/types.d.ts +32 -1
- 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/package.json +2 -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/UiTable/__tests__/UiTableRow.test.ts +14 -5
- package/src/components/UiToggle/UiToggle.vue +18 -1
- package/src/components/UiToggle/__tests__/UiToggle.test.ts +33 -3
- package/src/components/UiToggle/types.ts +13 -0
- package/src/components/core/accordion/AccordionContent.vue +36 -1
- 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/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/core/table/TableRow.vue +1 -1
- package/src/components/core/toggle/index.ts +2 -2
- package/src/components/index.ts +1 -0
- package/src/lib/heightTransition.ts +27 -0
- package/src/lib/useDrag.stories.ts +295 -0
- package/src/lib/useDrag.ts +212 -0
- package/src/patterns/UiDataTable/UiDataTable.stories.ts +348 -0
- package/src/patterns/UiDataTable/UiDataTable.vue +558 -22
- package/src/patterns/UiDataTable/UiDataTableColumnFilter.vue +83 -0
- package/src/patterns/UiDataTable/UiDataTableColumnHeader.vue +4 -13
- package/src/patterns/UiDataTable/__tests__/UiDataTable.test.ts +329 -0
- package/src/patterns/UiDataTable/__tests__/UiDataTableColumnFilter.test.ts +194 -0
- package/src/patterns/UiDataTable/__tests__/UiDataTableColumnHeader.test.ts +11 -0
- package/src/patterns/UiDataTable/constants.ts +15 -0
- package/src/patterns/UiDataTable/index.ts +2 -0
- package/src/patterns/UiDataTable/types.ts +33 -0
- package/src/patterns/UiSidebar/UiSidebar.stories.ts +42 -1
- package/src/patterns/UiSidebar/UiSidebar.vue +20 -0
- package/src/patterns/UiSidebar/UiSidebarGroupContent.vue +13 -36
- package/src/patterns/UiSidebar/__tests__/UiSidebar.test.ts +204 -2
- package/src/patterns/UiSidebar/__tests__/UiSidebarRail.test.ts +14 -0
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import { ref } from 'vue';
|
|
3
|
+
import {
|
|
4
|
+
UiResizableHandle,
|
|
5
|
+
UiResizablePanel,
|
|
6
|
+
UiResizablePanelGroup,
|
|
7
|
+
} from './index';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* UiResizable creates split-panel layouts whose panels can be resized by dragging
|
|
11
|
+
* the handle between them.
|
|
12
|
+
*/
|
|
13
|
+
const meta: Meta<typeof UiResizablePanelGroup> = {
|
|
14
|
+
title: 'Components/UiResizable',
|
|
15
|
+
component: UiResizablePanelGroup,
|
|
16
|
+
tags: ['autodocs'],
|
|
17
|
+
argTypes: {
|
|
18
|
+
direction: {
|
|
19
|
+
control: 'select',
|
|
20
|
+
options: ['horizontal', 'vertical'],
|
|
21
|
+
description: 'The orientation of the resizable panel group.',
|
|
22
|
+
},
|
|
23
|
+
autoSaveId: {
|
|
24
|
+
control: 'text',
|
|
25
|
+
description:
|
|
26
|
+
'Optional id used to persist the panel layout in localStorage.',
|
|
27
|
+
},
|
|
28
|
+
keyboardResizeBy: {
|
|
29
|
+
control: 'number',
|
|
30
|
+
description: 'Step size used when resizing with the keyboard.',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
args: {
|
|
34
|
+
direction: 'horizontal',
|
|
35
|
+
keyboardResizeBy: 10,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default meta;
|
|
40
|
+
|
|
41
|
+
type Story = StoryObj<typeof UiResizablePanelGroup>;
|
|
42
|
+
|
|
43
|
+
const panelClasses =
|
|
44
|
+
'flex items-center justify-center rounded-md bg-background-surface-muted p-6 text-sm';
|
|
45
|
+
const sizeValueClasses = 'font-mono text-xs text-muted-foreground';
|
|
46
|
+
|
|
47
|
+
const defaultTemplateSource = `<script setup lang="ts">
|
|
48
|
+
import { ref } from 'vue'
|
|
49
|
+
import {
|
|
50
|
+
UiResizableHandle,
|
|
51
|
+
UiResizablePanel,
|
|
52
|
+
UiResizablePanelGroup,
|
|
53
|
+
} from '@aleph-alpha/ui-library'
|
|
54
|
+
|
|
55
|
+
const sidebarWidth = ref(30)
|
|
56
|
+
const contentWidth = ref(70)
|
|
57
|
+
|
|
58
|
+
function updateSidebarWidth(size: number) {
|
|
59
|
+
sidebarWidth.value = Math.round(size)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function updateContentWidth(size: number) {
|
|
63
|
+
contentWidth.value = Math.round(size)
|
|
64
|
+
}
|
|
65
|
+
</script>
|
|
66
|
+
|
|
67
|
+
<template>
|
|
68
|
+
<UiResizablePanelGroup direction="horizontal" class="min-h-64 rounded-lg">
|
|
69
|
+
<UiResizablePanel
|
|
70
|
+
:default-size="30"
|
|
71
|
+
:min-size="20"
|
|
72
|
+
@resize="updateSidebarWidth"
|
|
73
|
+
>
|
|
74
|
+
<div
|
|
75
|
+
class="flex h-full flex-col items-center justify-center gap-1 rounded-md bg-background-surface-muted p-6 text-sm"
|
|
76
|
+
>
|
|
77
|
+
<span>Sidebar</span>
|
|
78
|
+
<span class="font-mono text-xs text-muted-foreground">{{ sidebarWidth }}% wide</span>
|
|
79
|
+
</div>
|
|
80
|
+
</UiResizablePanel>
|
|
81
|
+
<UiResizableHandle with-handle />
|
|
82
|
+
<UiResizablePanel
|
|
83
|
+
:default-size="70"
|
|
84
|
+
:min-size="30"
|
|
85
|
+
@resize="updateContentWidth"
|
|
86
|
+
>
|
|
87
|
+
<div
|
|
88
|
+
class="flex h-full flex-col items-center justify-center gap-1 rounded-md bg-background-surface-muted p-6 text-sm"
|
|
89
|
+
>
|
|
90
|
+
<span>Content</span>
|
|
91
|
+
<span class="font-mono text-xs text-muted-foreground">{{ contentWidth }}% wide</span>
|
|
92
|
+
</div>
|
|
93
|
+
</UiResizablePanel>
|
|
94
|
+
</UiResizablePanelGroup>
|
|
95
|
+
</template>`;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Two horizontal panels with a visible drag handle.
|
|
99
|
+
*/
|
|
100
|
+
export const Default: Story = {
|
|
101
|
+
render: (args) => ({
|
|
102
|
+
components: {
|
|
103
|
+
UiResizableHandle,
|
|
104
|
+
UiResizablePanel,
|
|
105
|
+
UiResizablePanelGroup,
|
|
106
|
+
},
|
|
107
|
+
setup() {
|
|
108
|
+
const sidebarWidth = ref(30);
|
|
109
|
+
const contentWidth = ref(70);
|
|
110
|
+
|
|
111
|
+
function updateSidebarWidth(size: number) {
|
|
112
|
+
sidebarWidth.value = Math.round(size);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function updateContentWidth(size: number) {
|
|
116
|
+
contentWidth.value = Math.round(size);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
args,
|
|
121
|
+
contentWidth,
|
|
122
|
+
panelClasses,
|
|
123
|
+
sidebarWidth,
|
|
124
|
+
sizeValueClasses,
|
|
125
|
+
updateContentWidth,
|
|
126
|
+
updateSidebarWidth,
|
|
127
|
+
};
|
|
128
|
+
},
|
|
129
|
+
template: `
|
|
130
|
+
<UiResizablePanelGroup
|
|
131
|
+
v-bind="args"
|
|
132
|
+
class="min-h-64 border border-border-surface-focus-ring"
|
|
133
|
+
>
|
|
134
|
+
<UiResizablePanel
|
|
135
|
+
:default-size="30"
|
|
136
|
+
:min-size="20"
|
|
137
|
+
@resize="updateSidebarWidth"
|
|
138
|
+
>
|
|
139
|
+
<div
|
|
140
|
+
:class="[panelClasses, 'h-full flex-col gap-1']"
|
|
141
|
+
>
|
|
142
|
+
<span>Sidebar</span>
|
|
143
|
+
<span :class="sizeValueClasses">{{ sidebarWidth }}% wide</span>
|
|
144
|
+
</div>
|
|
145
|
+
</UiResizablePanel>
|
|
146
|
+
<UiResizableHandle with-handle />
|
|
147
|
+
<UiResizablePanel
|
|
148
|
+
:default-size="70"
|
|
149
|
+
:min-size="30"
|
|
150
|
+
@resize="updateContentWidth"
|
|
151
|
+
>
|
|
152
|
+
<div
|
|
153
|
+
:class="[panelClasses, 'h-full flex-col gap-1']"
|
|
154
|
+
>
|
|
155
|
+
<span>Content</span>
|
|
156
|
+
<span :class="sizeValueClasses">{{ contentWidth }}% wide</span>
|
|
157
|
+
</div>
|
|
158
|
+
</UiResizablePanel>
|
|
159
|
+
</UiResizablePanelGroup>
|
|
160
|
+
`,
|
|
161
|
+
}),
|
|
162
|
+
parameters: {
|
|
163
|
+
docs: {
|
|
164
|
+
source: {
|
|
165
|
+
code: defaultTemplateSource,
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const verticalTemplateSource = `<script setup lang="ts">
|
|
172
|
+
import { ref } from 'vue'
|
|
173
|
+
import {
|
|
174
|
+
UiResizableHandle,
|
|
175
|
+
UiResizablePanel,
|
|
176
|
+
UiResizablePanelGroup,
|
|
177
|
+
} from '@aleph-alpha/ui-library'
|
|
178
|
+
|
|
179
|
+
const previewHeight = ref(60)
|
|
180
|
+
const consoleHeight = ref(40)
|
|
181
|
+
|
|
182
|
+
function updatePreviewHeight(size: number) {
|
|
183
|
+
previewHeight.value = Math.round(size)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function updateConsoleHeight(size: number) {
|
|
187
|
+
consoleHeight.value = Math.round(size)
|
|
188
|
+
}
|
|
189
|
+
</script>
|
|
190
|
+
|
|
191
|
+
<template>
|
|
192
|
+
<UiResizablePanelGroup direction="vertical" class="min-h-96 rounded-lg bg-background-surface-secondary p-2 shadow-lg">
|
|
193
|
+
<UiResizablePanel
|
|
194
|
+
:default-size="60"
|
|
195
|
+
:min-size="30"
|
|
196
|
+
@resize="updatePreviewHeight"
|
|
197
|
+
>
|
|
198
|
+
<div
|
|
199
|
+
class="flex h-full flex-col items-center justify-center gap-1 rounded-md bg-background-surface-muted p-6 text-sm"
|
|
200
|
+
>
|
|
201
|
+
<span>Preview</span>
|
|
202
|
+
<span class="font-mono text-xs text-muted-foreground">{{ previewHeight }}% tall</span>
|
|
203
|
+
</div>
|
|
204
|
+
</UiResizablePanel>
|
|
205
|
+
<UiResizableHandle with-handle />
|
|
206
|
+
<UiResizablePanel
|
|
207
|
+
:default-size="40"
|
|
208
|
+
:min-size="20"
|
|
209
|
+
@resize="updateConsoleHeight"
|
|
210
|
+
>
|
|
211
|
+
<div
|
|
212
|
+
class="flex h-full flex-col items-center justify-center gap-1 rounded-md bg-background-surface-muted p-6 text-sm"
|
|
213
|
+
>
|
|
214
|
+
<span>Console</span>
|
|
215
|
+
<span class="font-mono text-xs text-muted-foreground">{{ consoleHeight }}% tall</span>
|
|
216
|
+
</div>
|
|
217
|
+
</UiResizablePanel>
|
|
218
|
+
</UiResizablePanelGroup>
|
|
219
|
+
</template>`;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Vertical resizing stacks panels from top to bottom.
|
|
223
|
+
*/
|
|
224
|
+
export const Vertical: Story = {
|
|
225
|
+
render: () => ({
|
|
226
|
+
components: {
|
|
227
|
+
UiResizableHandle,
|
|
228
|
+
UiResizablePanel,
|
|
229
|
+
UiResizablePanelGroup,
|
|
230
|
+
},
|
|
231
|
+
setup() {
|
|
232
|
+
const previewHeight = ref(60);
|
|
233
|
+
const consoleHeight = ref(40);
|
|
234
|
+
|
|
235
|
+
function updatePreviewHeight(size: number) {
|
|
236
|
+
previewHeight.value = Math.round(size);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function updateConsoleHeight(size: number) {
|
|
240
|
+
consoleHeight.value = Math.round(size);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return {
|
|
244
|
+
consoleHeight,
|
|
245
|
+
panelClasses,
|
|
246
|
+
previewHeight,
|
|
247
|
+
sizeValueClasses,
|
|
248
|
+
updateConsoleHeight,
|
|
249
|
+
updatePreviewHeight,
|
|
250
|
+
};
|
|
251
|
+
},
|
|
252
|
+
template: `
|
|
253
|
+
<UiResizablePanelGroup
|
|
254
|
+
direction="vertical"
|
|
255
|
+
class="min-h-96 rounded-lg bg-background-surface-secondary p-2 shadow-lg"
|
|
256
|
+
>
|
|
257
|
+
<UiResizablePanel
|
|
258
|
+
:default-size="60"
|
|
259
|
+
:min-size="30"
|
|
260
|
+
@resize="updatePreviewHeight"
|
|
261
|
+
>
|
|
262
|
+
<div
|
|
263
|
+
:class="[panelClasses, 'h-full flex-col gap-1']"
|
|
264
|
+
>
|
|
265
|
+
<span>Preview</span>
|
|
266
|
+
<span :class="sizeValueClasses">{{ previewHeight }}% tall</span>
|
|
267
|
+
</div>
|
|
268
|
+
</UiResizablePanel>
|
|
269
|
+
<UiResizableHandle with-handle />
|
|
270
|
+
<UiResizablePanel
|
|
271
|
+
:default-size="40"
|
|
272
|
+
:min-size="20"
|
|
273
|
+
@resize="updateConsoleHeight"
|
|
274
|
+
>
|
|
275
|
+
<div
|
|
276
|
+
:class="[panelClasses, 'h-full flex-col gap-1']"
|
|
277
|
+
>
|
|
278
|
+
<span>Console</span>
|
|
279
|
+
<span :class="sizeValueClasses">{{ consoleHeight }}% tall</span>
|
|
280
|
+
</div>
|
|
281
|
+
</UiResizablePanel>
|
|
282
|
+
</UiResizablePanelGroup>
|
|
283
|
+
`,
|
|
284
|
+
}),
|
|
285
|
+
parameters: {
|
|
286
|
+
docs: {
|
|
287
|
+
source: {
|
|
288
|
+
code: verticalTemplateSource,
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
const collapsibleTemplateSource = `<script setup lang="ts">
|
|
295
|
+
import {
|
|
296
|
+
UiResizableHandle,
|
|
297
|
+
UiResizablePanel,
|
|
298
|
+
UiResizablePanelGroup,
|
|
299
|
+
} from '@aleph-alpha/ui-library'
|
|
300
|
+
</script>
|
|
301
|
+
|
|
302
|
+
<template>
|
|
303
|
+
<UiResizablePanelGroup direction="horizontal" class="min-h-64 rounded-lg bg-background-surface-secondary p-2 shadow-lg">
|
|
304
|
+
<UiResizablePanel collapsible :collapsed-size="8" :default-size="25" :min-size="20">
|
|
305
|
+
<div class="flex h-full items-center justify-center rounded-md bg-background-surface-muted p-6 text-sm">
|
|
306
|
+
Collapsible
|
|
307
|
+
</div>
|
|
308
|
+
</UiResizablePanel>
|
|
309
|
+
<UiResizableHandle with-handle />
|
|
310
|
+
<UiResizablePanel :default-size="75" :min-size="30">
|
|
311
|
+
<div class="flex h-full items-center justify-center rounded-md bg-background-surface-muted p-6 text-sm">
|
|
312
|
+
Main panel
|
|
313
|
+
</div>
|
|
314
|
+
</UiResizablePanel>
|
|
315
|
+
</UiResizablePanelGroup>
|
|
316
|
+
</template>`;
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* A panel can collapse when resized below its minimum size.
|
|
320
|
+
*/
|
|
321
|
+
export const Collapsible: Story = {
|
|
322
|
+
render: () => ({
|
|
323
|
+
components: {
|
|
324
|
+
UiResizableHandle,
|
|
325
|
+
UiResizablePanel,
|
|
326
|
+
UiResizablePanelGroup,
|
|
327
|
+
},
|
|
328
|
+
setup() {
|
|
329
|
+
return { panelClasses };
|
|
330
|
+
},
|
|
331
|
+
template: `
|
|
332
|
+
<UiResizablePanelGroup
|
|
333
|
+
direction="horizontal"
|
|
334
|
+
class="min-h-64 rounded-lg bg-background-surface-secondary p-2 shadow-lg"
|
|
335
|
+
>
|
|
336
|
+
<UiResizablePanel
|
|
337
|
+
collapsible
|
|
338
|
+
:collapsed-size="8"
|
|
339
|
+
:default-size="25"
|
|
340
|
+
:min-size="20"
|
|
341
|
+
>
|
|
342
|
+
<div :class="[panelClasses, 'h-full']">Collapsible</div>
|
|
343
|
+
</UiResizablePanel>
|
|
344
|
+
<UiResizableHandle with-handle />
|
|
345
|
+
<UiResizablePanel :default-size="75" :min-size="30">
|
|
346
|
+
<div :class="[panelClasses, 'h-full']">Main panel</div>
|
|
347
|
+
</UiResizablePanel>
|
|
348
|
+
</UiResizablePanelGroup>
|
|
349
|
+
`,
|
|
350
|
+
}),
|
|
351
|
+
parameters: {
|
|
352
|
+
docs: {
|
|
353
|
+
source: {
|
|
354
|
+
code: collapsibleTemplateSource,
|
|
355
|
+
},
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
const pixelSizingTemplateSource = `<script setup lang="ts">
|
|
361
|
+
import {
|
|
362
|
+
UiResizableHandle,
|
|
363
|
+
UiResizablePanel,
|
|
364
|
+
UiResizablePanelGroup,
|
|
365
|
+
} from '@aleph-alpha/ui-library'
|
|
366
|
+
</script>
|
|
367
|
+
|
|
368
|
+
<template>
|
|
369
|
+
<UiResizablePanelGroup direction="horizontal" class="min-h-64 rounded-lg bg-background-surface-secondary p-2 shadow-lg">
|
|
370
|
+
<UiResizablePanel size-unit="px" :default-size="240" :min-size="160" :max-size="320">
|
|
371
|
+
<div class="flex h-full items-center justify-center rounded-md bg-background-surface-muted p-6 text-sm">
|
|
372
|
+
Fixed sidebar
|
|
373
|
+
</div>
|
|
374
|
+
</UiResizablePanel>
|
|
375
|
+
<UiResizableHandle with-handle />
|
|
376
|
+
<UiResizablePanel>
|
|
377
|
+
<div class="flex h-full items-center justify-center rounded-md bg-background-surface-muted p-6 text-sm">
|
|
378
|
+
Flexible content
|
|
379
|
+
</div>
|
|
380
|
+
</UiResizablePanel>
|
|
381
|
+
</UiResizablePanelGroup>
|
|
382
|
+
</template>`;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Pixel sizing keeps a panel at a fixed pixel width while the rest of the group stays flexible.
|
|
386
|
+
*/
|
|
387
|
+
export const PixelSizing: Story = {
|
|
388
|
+
render: () => ({
|
|
389
|
+
components: {
|
|
390
|
+
UiResizableHandle,
|
|
391
|
+
UiResizablePanel,
|
|
392
|
+
UiResizablePanelGroup,
|
|
393
|
+
},
|
|
394
|
+
setup() {
|
|
395
|
+
return { panelClasses };
|
|
396
|
+
},
|
|
397
|
+
template: `
|
|
398
|
+
<UiResizablePanelGroup
|
|
399
|
+
direction="horizontal"
|
|
400
|
+
class="min-h-64 rounded-lg bg-background-surface-secondary p-2 shadow-lg"
|
|
401
|
+
>
|
|
402
|
+
<UiResizablePanel
|
|
403
|
+
size-unit="px"
|
|
404
|
+
:default-size="240"
|
|
405
|
+
:min-size="160"
|
|
406
|
+
:max-size="320"
|
|
407
|
+
>
|
|
408
|
+
<div :class="[panelClasses, 'h-full']">Fixed sidebar</div>
|
|
409
|
+
</UiResizablePanel>
|
|
410
|
+
<UiResizableHandle with-handle />
|
|
411
|
+
<UiResizablePanel>
|
|
412
|
+
<div :class="[panelClasses, 'h-full']">Flexible content</div>
|
|
413
|
+
</UiResizablePanel>
|
|
414
|
+
</UiResizablePanelGroup>
|
|
415
|
+
`,
|
|
416
|
+
}),
|
|
417
|
+
parameters: {
|
|
418
|
+
docs: {
|
|
419
|
+
source: {
|
|
420
|
+
code: pixelSizingTemplateSource,
|
|
421
|
+
},
|
|
422
|
+
},
|
|
423
|
+
},
|
|
424
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ResizableHandle } from '@/components/core/resizable';
|
|
3
|
+
import type { UiResizableHandleEmits, UiResizableHandleProps } from './types';
|
|
4
|
+
|
|
5
|
+
defineOptions({
|
|
6
|
+
name: 'UiResizableHandle',
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const props = defineProps<UiResizableHandleProps>();
|
|
10
|
+
const emit = defineEmits<UiResizableHandleEmits>();
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<template>
|
|
14
|
+
<ResizableHandle v-bind="props" @dragging="emit('dragging', $event)">
|
|
15
|
+
<slot />
|
|
16
|
+
</ResizableHandle>
|
|
17
|
+
</template>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useForwardExpose } from 'reka-ui';
|
|
3
|
+
import { ResizablePanel } from '@/components/core/resizable';
|
|
4
|
+
import type { UiResizablePanelEmits, UiResizablePanelProps } from './types';
|
|
5
|
+
|
|
6
|
+
defineOptions({
|
|
7
|
+
name: 'UiResizablePanel',
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const props = defineProps<UiResizablePanelProps>();
|
|
11
|
+
const emit = defineEmits<UiResizablePanelEmits>();
|
|
12
|
+
const { forwardRef } = useForwardExpose();
|
|
13
|
+
|
|
14
|
+
function handleResize(size: number, prevSize: number | undefined) {
|
|
15
|
+
emit('resize', size, prevSize);
|
|
16
|
+
}
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<template>
|
|
20
|
+
<ResizablePanel
|
|
21
|
+
:ref="forwardRef"
|
|
22
|
+
v-slot="slotProps"
|
|
23
|
+
v-bind="props"
|
|
24
|
+
@collapse="emit('collapse')"
|
|
25
|
+
@expand="emit('expand')"
|
|
26
|
+
@resize="handleResize"
|
|
27
|
+
>
|
|
28
|
+
<slot v-bind="slotProps" />
|
|
29
|
+
</ResizablePanel>
|
|
30
|
+
</template>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useForwardExpose } from 'reka-ui';
|
|
3
|
+
import { ResizablePanelGroup } from '@/components/core/resizable';
|
|
4
|
+
import type {
|
|
5
|
+
UiResizablePanelGroupEmits,
|
|
6
|
+
UiResizablePanelGroupProps,
|
|
7
|
+
} from './types';
|
|
8
|
+
|
|
9
|
+
defineOptions({
|
|
10
|
+
name: 'UiResizablePanelGroup',
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const props = defineProps<UiResizablePanelGroupProps>();
|
|
14
|
+
const emit = defineEmits<UiResizablePanelGroupEmits>();
|
|
15
|
+
const { forwardRef } = useForwardExpose();
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<template>
|
|
19
|
+
<ResizablePanelGroup
|
|
20
|
+
:ref="forwardRef"
|
|
21
|
+
v-slot="slotProps"
|
|
22
|
+
v-bind="props"
|
|
23
|
+
@layout="emit('layout', $event)"
|
|
24
|
+
>
|
|
25
|
+
<slot v-bind="slotProps" />
|
|
26
|
+
</ResizablePanelGroup>
|
|
27
|
+
</template>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { render } from '@testing-library/vue';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { describe, expect, test, vi } from 'vitest';
|
|
4
|
+
import { defineComponent, h } from 'vue';
|
|
5
|
+
import UiResizableHandle from '../UiResizableHandle.vue';
|
|
6
|
+
|
|
7
|
+
vi.mock('@/components/core/resizable', () => ({
|
|
8
|
+
ResizableHandle: defineComponent({
|
|
9
|
+
name: 'ResizableHandleMock',
|
|
10
|
+
props: {
|
|
11
|
+
disabled: Boolean,
|
|
12
|
+
id: {
|
|
13
|
+
type: String,
|
|
14
|
+
default: undefined,
|
|
15
|
+
},
|
|
16
|
+
withHandle: Boolean,
|
|
17
|
+
},
|
|
18
|
+
emits: ['dragging'],
|
|
19
|
+
setup(props, { attrs, emit, slots }) {
|
|
20
|
+
return () =>
|
|
21
|
+
h(
|
|
22
|
+
'button',
|
|
23
|
+
{
|
|
24
|
+
...attrs,
|
|
25
|
+
'data-disabled': String(props.disabled),
|
|
26
|
+
'data-id': props.id,
|
|
27
|
+
'data-testid': 'resizable-handle',
|
|
28
|
+
'data-with-handle': String(props.withHandle),
|
|
29
|
+
type: 'button',
|
|
30
|
+
onClick: () => emit('dragging', true),
|
|
31
|
+
},
|
|
32
|
+
slots.default?.(),
|
|
33
|
+
);
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
describe('UiResizableHandle', () => {
|
|
39
|
+
test('renders default slot and forwards handle props', () => {
|
|
40
|
+
const { getByTestId, getByText } = render(UiResizableHandle, {
|
|
41
|
+
props: {
|
|
42
|
+
disabled: true,
|
|
43
|
+
id: 'resize-sidebar',
|
|
44
|
+
withHandle: true,
|
|
45
|
+
},
|
|
46
|
+
slots: { default: '<span>Grip</span>' },
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const handle = getByTestId('resizable-handle');
|
|
50
|
+
expect(handle).toHaveAttribute('data-disabled', 'true');
|
|
51
|
+
expect(handle).toHaveAttribute('data-id', 'resize-sidebar');
|
|
52
|
+
expect(handle).toHaveAttribute('data-with-handle', 'true');
|
|
53
|
+
expect(getByText('Grip')).toBeInTheDocument();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('re-emits dragging changes', async () => {
|
|
57
|
+
const user = userEvent.setup();
|
|
58
|
+
const { emitted, getByTestId } = render(UiResizableHandle);
|
|
59
|
+
|
|
60
|
+
await user.click(getByTestId('resizable-handle'));
|
|
61
|
+
|
|
62
|
+
expect(emitted('dragging')?.[0]).toEqual([true]);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { render } from '@testing-library/vue';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { describe, expect, test, vi } from 'vitest';
|
|
4
|
+
import { defineComponent, h } from 'vue';
|
|
5
|
+
import UiResizablePanel from '../UiResizablePanel.vue';
|
|
6
|
+
|
|
7
|
+
vi.mock('@/components/core/resizable', () => ({
|
|
8
|
+
ResizablePanel: defineComponent({
|
|
9
|
+
name: 'ResizablePanelMock',
|
|
10
|
+
props: {
|
|
11
|
+
defaultSize: {
|
|
12
|
+
type: Number,
|
|
13
|
+
default: undefined,
|
|
14
|
+
},
|
|
15
|
+
minSize: {
|
|
16
|
+
type: Number,
|
|
17
|
+
default: undefined,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
emits: ['collapse', 'expand', 'resize'],
|
|
21
|
+
setup(props, { attrs, emit, slots }) {
|
|
22
|
+
return () =>
|
|
23
|
+
h(
|
|
24
|
+
'button',
|
|
25
|
+
{
|
|
26
|
+
...attrs,
|
|
27
|
+
'data-default-size': props.defaultSize,
|
|
28
|
+
'data-min-size': props.minSize,
|
|
29
|
+
'data-testid': 'resizable-panel',
|
|
30
|
+
type: 'button',
|
|
31
|
+
onClick: () => {
|
|
32
|
+
emit('collapse');
|
|
33
|
+
emit('expand');
|
|
34
|
+
emit('resize', 40, 30);
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
slots.default?.({ isCollapsed: false, isExpanded: true }),
|
|
38
|
+
);
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
describe('UiResizablePanel', () => {
|
|
44
|
+
test('renders default slot and forwards size props', () => {
|
|
45
|
+
const { getByTestId, getByText } = render(UiResizablePanel, {
|
|
46
|
+
props: {
|
|
47
|
+
defaultSize: 60,
|
|
48
|
+
minSize: 20,
|
|
49
|
+
},
|
|
50
|
+
slots: { default: '<span>Panel content</span>' },
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const panel = getByTestId('resizable-panel');
|
|
54
|
+
expect(panel).toHaveAttribute('data-default-size', '60');
|
|
55
|
+
expect(panel).toHaveAttribute('data-min-size', '20');
|
|
56
|
+
expect(getByText('Panel content')).toBeInTheDocument();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('passes slot props through from the core panel', () => {
|
|
60
|
+
const { getByText } = render({
|
|
61
|
+
components: { UiResizablePanel },
|
|
62
|
+
template: `
|
|
63
|
+
<UiResizablePanel :default-size="50" v-slot="{ isCollapsed, isExpanded }">
|
|
64
|
+
Collapsed: {{ isCollapsed }}, expanded: {{ isExpanded }}
|
|
65
|
+
</UiResizablePanel>
|
|
66
|
+
`,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
expect(getByText('Collapsed: false, expanded: true')).toBeInTheDocument();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('re-emits panel lifecycle events', async () => {
|
|
73
|
+
const user = userEvent.setup();
|
|
74
|
+
const { emitted, getByTestId } = render(UiResizablePanel);
|
|
75
|
+
|
|
76
|
+
await user.click(getByTestId('resizable-panel'));
|
|
77
|
+
|
|
78
|
+
expect(emitted('collapse')?.[0]).toEqual([]);
|
|
79
|
+
expect(emitted('expand')?.[0]).toEqual([]);
|
|
80
|
+
expect(emitted('resize')?.[0]).toEqual([40, 30]);
|
|
81
|
+
});
|
|
82
|
+
});
|