1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493---
title: Usage
description: All usage options available in Vue Split Panel
navigation:
icon: i-lucide-align-horizontal-justify-center
---
## Anatomy
The splitter component is rendered as a single Vue component with two slots, one for each panel.
::code-preview
:example-basic
#code
```vue
<script lang="ts" setup>
import { SplitPanel } from '@directus/vue-split-panel';
</script>
<template>
<SplitPanel>
<template #start>
<div class="h-16 bg-orange-100 dark:bg-orange-900 flex items-center justify-center">Panel A</div>
</template>
<template #end>
<div class="h-16 bg-blue-100 dark:bg-blue-900 flex items-center justify-center">Panel B</div>
</template>
</SplitPanel>
</template>
```
::
## API Reference
### Model
::field-group
::field{name="size" type="number"}
The current size of the start panel.
::
::field{name="collapsed" type="boolean"}
Whether the primary panel is currently collapsed.
::
::
### Props
::field-group
::field{name="orientation" type="'horizontal' | 'vertical'"}
Set the rendering orientation.
Defaults to `'horizontal'`
::
::field{name="direction" type="'ltr' | 'rtl'"}
Sets the panels text direction.
Defaults to `'ltr'`
::
::field{name="primary" type="'start' | 'end'"}
If no primary panel is designated, both panels will resize equally.
::
::field{name="dividerHitArea" type="string"}
A CSS size to define the hitbox area around the divider slot.
Defaults to `'12px'`
::
::field{name="sizeUnit" type="'%' | 'px'"}
Whether `size`, `minSize`, `maxSize`, and `collapseThreshold` are configured in percentages (0-100) or pixel values.
Defaults to `'%'`
::
::field{name="disabled" type="boolean"}
Disable the manual resizing/collapsing of the panels.
Defaults to `false`
::
::field{name="minSize" type="number"}
Minimum allowed size of the primary panel. Requires `primary` to be set.
Defaults to `false`
::
::field{name="maxSize" type="number"}
Maximum allowed size of the primary panel. Requires `primary` to be set.
Defaults to `false`
::
::field{name="collapsible" type="boolean"}
Whether to allow the primary panel to be collapsed on enter key on divider or when the collapse threshold is met.
Defaults to `false`
::
::field{name="collapseThreshold" type="number"}
How far to drag beyond the minSize to collapse/expand the primary panel.
::
::field{name="collapsedSize" type="number"}
How much of the collapsed panel is visible in its collapsed state.
::
::field{name="transitionDuration" type="number"}
Duration of the collapse/expand transition in ms.
Defaults to `0`
::
::field{name="transitionTimingFunctionExpand" type="string"}
CSS timing function for the expand transition.
Defaults to `"cubic-bezier(0, 0, 0.2, 1)"`
::
::field{name="transitionTimingFunctionCollapse" type="string"}
CSS timing function for the collapse transition.
Defaults to `"cubic-bezier(0.4, 0, 0.6, 1)"`
::
::field{name="snapPoints" type="number[]"}
Where to snap the primary panel to during dragging operations.
Defaults to `[]`
::
::field{name="snapThreshold" type="number"}
How close the divider must be to a snap point for snapping to occur.
Defaults to `12`
::
::field{name="ui" type="{ start?: string, divider?: string, end?: string }"}
Inject additional classes in the slot container elements.
::
::
## Examples
### % / Pixels
By setting `sizeUnit` to `px`, the component will use pixel values for `minSize`, `maxSize`, and `size`.
::tabs{.w-full}
::tabs-item{icon="i-lucide-percent" label="Percentages"}
::code-preview
:example-percentage
#code
```vue
<script lang="ts" setup>
import { SplitPanel } from '@directus/vue-split-panel';
</script>
<template>
<SplitPanel
size-unit="%"
:min-size="20"
:size="30"
:max-size="40"
>
<template #start>
<div class="h-16 bg-orange-100 dark:bg-orange-900 flex items-center justify-center">Panel A</div>
</template>
<template #end>
<div class="h-16 bg-blue-100 dark:bg-blue-900 flex items-center justify-center">Panel B</div>
</template>
</SplitPanel>
</template>
```
::
::
::tabs-item{icon="i-lucide-grid-2x2" label="Pixels"}
::code-preview
:example-px
#code
```vue
<script lang="ts" setup>
import { SplitPanel } from '@directus/vue-split-panel';
</script>
<template>
<SplitPanel
size-unit="px"
:min-size="300"
:size="400"
:max-size="500"
>
<template #start>
<div class="h-16 bg-orange-100 dark:bg-orange-900 flex items-center justify-center">Panel A</div>
</template>
<template #end>
<div class="h-16 bg-blue-100 dark:bg-blue-900 flex items-center justify-center">Panel B</div>
</template>
</SplitPanel>
</template>
```
::
::
::
### Collapsible
By setting `collapsible` to `true`, you can allow the primary panel to be collapsed by either dragging the divider the `collapseThreshold` beyond the `minSize` or using Enter when focussed on the divider.
Both `minSize` and `collapsibleThreshold` have to be defined.
::code-preview
:example-collapsible
#code
```vue
<script lang="ts" setup>
import { SplitPanel } from '@directus/vue-split-panel';
</script>
<template>
<SplitPanel
collapsible
size-unit="px"
:min-size="250"
:size="350"
:max-size="500"
:collapse-threshold="50"
>
<template #start>
<div class="h-16 bg-orange-100 dark:bg-orange-900 flex items-center justify-center">Panel A</div>
</template>
<template #end>
<div class="h-16 bg-blue-100 dark:bg-blue-900 flex items-center justify-center">Panel B</div>
</template>
</SplitPanel>
</template>
```
::
### Collapse / Expand Programmatically
To collapse or expand the primary panel programmatically, you can either use the `collapsed` model:
```vue
<script lang="ts" setup>
import { ref } from 'vue';
import { SplitPanel } from '@directus/vue-split-panel';
const collapsed = ref(false);
</script>
<template>
<SplitPanel v-model="collapsed">
<!-- ... -->
</SplitPanel>
</template>
```
or use the exposed `collapse`, `expand`, and `toggle` functions:
```vue
<script lang="ts" setup>
import { useTemplateRef } from 'vue';
import { SplitPanel } from '@directus/vue-split-panel';
const panelComponent = useTemplateRef('panel-component');
// panelComponent.value.expand();
// panelComponent.value.collapse();
// panelComponent.value.toggle();
</script>
<template>
<SplitPanel ref="panel-component">
<!-- ... -->
</SplitPanel>
</template>
```
### Customize Divider
Customize the divider element by passing any element into the divider slot:
::code-preview
:example-divider
#code
```vue
<script lang="ts" setup>
import { SplitPanel } from '@directus/vue-split-panel';
</script>
<template>
<SplitPanel
collapsible
size-unit="px"
:min-size="200"
:size="350"
:max-size="500"
>
<template #start>
<div class="h-16 bg-orange-100 dark:bg-orange-900 flex items-center justify-center">Panel A</div>
</template>
<template #divider>
<div class="h-full bg-muted hover:bg-primary w-4" />
</template>
<template #end>
<div class="h-16 bg-blue-100 dark:bg-blue-900 flex items-center justify-center">Panel B</div>
</template>
</SplitPanel>
</template>
```
::
### Vertical Split Orientation
The panels can be oriented vertically by setting the `orientation` prop to `"vertical"`. Make sure to add a height to the parent split component.
::code-preview
:example-vertical
#code
```vue
<script lang="ts" setup>
import { SplitPanel } from '@directus/vue-split-panel';
</script>
<template>
<SplitPanel
orientation="vertical"
class="h-128"
>
<template #start>
<div class="w-full h-full bg-orange-100 dark:bg-orange-900 flex items-center justify-center">Panel A</div>
</template>
<template #end>
<div class="w-full h-full bg-blue-100 dark:bg-blue-900 flex items-center justify-center">Panel B</div>
</template>
</SplitPanel>
</template>
```
::
### Nested Split Panels
While a `SplitPanel` only holds two panels at a time, you can nest multiple split panels to create rich layouts.
::code-preview
:example-nested
#code
```vue
<script lang="ts" setup>
import { SplitPanel } from '@directus/vue-split-panel';
</script>
<template>
<SplitPanel primary="start" class="h-128 w-full">
<template #start>
<div class="w-full h-full bg-orange-100 dark:bg-orange-900 flex items-center justify-center">Panel A</div>
</template>
<template #end>
<SplitPanel orientation="vertical" class="h-full">
<template #start>
<div class="w-full h-full bg-blue-100 dark:bg-blue-900 flex items-center justify-center">Panel B</div>
</template>
<template #end>
<div class="w-full h-full bg-green-100 dark:bg-green-100 flex items-center justify-center">Panel C</div>
</template>
</SplitPanel>
</template>
</SplitPanel>
</template>
```
::
### Primary Panel
By setting `primary` to either `start` or `end`, you can make sure that the primary panel doesn't resize when the parent container resizes. This is particularly helpful for layouts where you have a primary sidebar that you'd like to remain a fixed size, with a page view that takes up the remaining space.
::code-preview
:example-primary
#code
```vue
<script lang="ts" setup>
import { SplitPanel } from '@directus/vue-split-panel';
</script>
<template>
<SplitPanel class="w-full" primary="start" :size="350" size-unit="px">
<template #start>
<div class="w-full h-16 bg-orange-100 dark:bg-orange-900 flex items-center justify-center">Panel A</div>
</template>
<template #end>
<div class="w-full h-16 bg-blue-100 dark:bg-blue-900 flex items-center justify-center">Panel B</div>
</template>
</SplitPanel>
</template>
```
::
::callout{icon="i-lucide-info" color="primary"}
Resize your browser window to see primary in action.
::
### Transitions
By setting the `transitionDuration` prop, you can control the duration of the transition. Use the `transitionTimingFunctionExpand` and `transitionTimingFunctionCollapse` properties to fine-tune the timing functions of the expand and collapse transition respectively.
::code-preview
:example-transitions
#code
```vue
<script lang="ts" setup>
import { SplitPanel } from '@directus/vue-split-panel';
</script>
<template>
<SplitPanel
class="w-full"
collapsible
size-unit="px"
:min-size="250"
:size="350"
:max-size="500"
:collapse-threshold="50"
:transition-duration="150"
>
<template #start>
<div class="h-16 bg-orange-100 dark:bg-orange-900 flex items-center justify-center">Panel A</div>
</template>
<template #end>
<div class="h-16 bg-blue-100 dark:bg-blue-900 flex items-center justify-center">Panel B</div>
</template>
</SplitPanel>
</template>
```
::
### Snapping
To snap the divider to a given point while dragging, pass an array of points in the `snapPoints` property.
::code-preview
:example-snap
#code
```vue
<script lang="ts" setup>
import { SplitPanel } from '@directus/vue-split-panel';
</script>
<template>
<SplitPanel class="w-full" :snap-points="[25, 50]">
<template #start>
<div class="h-16 bg-orange-100 dark:bg-orange-900 flex items-center justify-center">Panel A</div>
</template>
<template #end>
<div class="h-16 bg-blue-100 dark:bg-blue-900 flex items-center justify-center">Panel B</div>
</template>
</SplitPanel>
</template>
```
::
## Accessibility
Uses the [Window Splitter WAI-ARIA pattern](https://www.w3.org/WAI/ARIA/apg/patterns/windowsplitter).
### Keyboard Interactions
| Key | Description |
|--------------------------|------------------------------------------------|
| :kbd{value="Enter"} | Toggles the collapse state of the primary pane |
| :kbd{value="ArrowDown"} | Moves a horizontal panel down |
| :kbd{value="ArrowUp"} | Moves a horizontal panel up |
| :kbd{value="ArrowRight"} | Moves a vertical splitter right |
| :kbd{value="ArrowLeft"} | Moves a vertical splitter left |
| :kbd{value="Home"} | Moves the splitter to the configured min-size |
| :kbd{value="End"} | Moves the splitter to the configured max-size |
::callout{icon="i-lucide-person-standing" color="warning"}
The divider by default has no styling. Please add your own divider element to handle focus styles.
::