Vue Splitter 컴포넌트
Splitter는 패널을 분리하고 크기를 조절할 때 사용하는 컴포넌트예요. IDE 레이아웃처럼 경계선을 드래그해 패널 폭과 높이를 바꿀 수 있게 해 줘요.
출처: 문서
본문
Vue Splitter Component
Splitter is utilized to separate and resize panels.
Import
import Splitter from 'primevue/splitter';
import SplitterPanel from 'primevue/splitterpanel';
Accessibility
Screen Reader Splitter 바는 separator를 role로 정의하고 aria-orientation을 horizontal 또는 vertical로 설정해요. Keyboard Support Key Function tab splitter 바를 통해 포커스를 이동해요. down arrow 세로 splitter를 아래로 이동해요. up arrow 세로 splitter를 위로 이동해요. left arrow 가로 splitter를 왼쪽으로 이동해요. right arrow 가로 splitter를 오른쪽으로 이동해요.
Horizontal
Splitter는 자식으로 두 개의 SplitterPanel 컴포넌트를 필요로 하고, 기본적으로 가로로 표시돼요.
<Splitter style="height: 300px">
<SplitterPanel class="flex items-center justify-center"> Panel 1 </SplitterPanel>
<SplitterPanel class="flex items-center justify-center"> Panel 2 </SplitterPanel>
</Splitter>
Composition API Example
<template>
<div class="card">
<Splitter style="height: 300px">
<SplitterPanel class="flex items-center justify-center"> Panel 1 </SplitterPanel>
<SplitterPanel class="flex items-center justify-center"> Panel 2 </SplitterPanel>
</Splitter>
</div>
</template>
<script setup>
<\/script>
Nested
Splitter를 조합하면 고급 레이아웃을 만들 수 있어요.
<Splitter style="height: 300px">
<SplitterPanel class="flex items-center justify-center" :size="20" :minSize="10"> Panel 1 </SplitterPanel>
<SplitterPanel :size="80">
<Splitter layout="vertical">
<SplitterPanel class="flex items-center justify-center" :size="15"> Panel 2 </SplitterPanel>
<SplitterPanel :size="85">
<Splitter>
<SplitterPanel class="flex items-center justify-center" :size="20"> Panel 3 </SplitterPanel>
<SplitterPanel class="flex items-center justify-center" :size="80"> Panel 4 </SplitterPanel>
</Splitter>
</SplitterPanel>
</Splitter>
</SplitterPanel>
</Splitter>
Composition API Example
<template>
<div class="card">
<Splitter style="height: 300px">
<SplitterPanel class="flex items-center justify-center" :size="20" :minSize="10"> Panel 1 </SplitterPanel>
<SplitterPanel :size="80">
<Splitter layout="vertical">
<SplitterPanel class="flex items-center justify-center" :size="15"> Panel 2 </SplitterPanel>
<SplitterPanel :size="85">
<Splitter>
<SplitterPanel class="flex items-center justify-center" :size="20"> Panel 3 </SplitterPanel>
<SplitterPanel class="flex items-center justify-center" :size="80"> Panel 4 </SplitterPanel>
</Splitter>
</SplitterPanel>
</Splitter>
</SplitterPanel>
</Splitter>
</div>
</template>
<script setup>
<\/script>
Size
패널의 초기 크기는 백분율 기반이고 size 프로퍼티로 정의해요. 또한 리사이즈 중 최솟값을 설정하기 위한 minSize도 제공돼요.
<Splitter style="height: 300px">
<SplitterPanel class="flex items-center justify-center" :size="25" :minSize="10"> Panel 1 </SplitterPanel>
<SplitterPanel class="flex items-center justify-center" :size="75"> Panel 2 </SplitterPanel>
</Splitter>
Composition API Example
<template>
<div class="card">
<Splitter style="height: 300px">
<SplitterPanel class="flex items-center justify-center" :size="25" :minSize="10"> Panel 1 </SplitterPanel>
<SplitterPanel class="flex items-center justify-center" :size="75"> Panel 2 </SplitterPanel>
</Splitter>
</div>
</template>
<script setup>
<\/script>
Vertical
layout을 vertical로 설정하면 패널이 쌓인 형태로 표시돼요.
<Splitter style="height: 300px" layout="vertical">
<SplitterPanel class="flex items-center justify-center"> Panel 1 </SplitterPanel>
<SplitterPanel class="flex items-center justify-center"> Panel 2 </SplitterPanel>
</Splitter>
Composition API Example
<template>
<div class="card">
<Splitter style="height: 300px" layout="vertical">
<SplitterPanel class="flex items-center justify-center"> Panel 1 </SplitterPanel>
<SplitterPanel class="flex items-center justify-center"> Panel 2 </SplitterPanel>
</Splitter>
</div>
</template>
<script setup>
<\/script>
Splitter
Props
| Name | Type | Default | Description |
|---|---|---|---|
| layout | HintedString<"horizontal" | "vertical"> | horizontal | Orientation of the panels. |
| gutterSize | number | 4 | Size of the divider in pixels. |
| stateKey | string | - | Storage identifier of a stateful Splitter. |
| stateStorage | HintedString<"session" | "local"> | session | Defines where a stateful splitter keeps its state, valid values are 'session' for sessionStorage and 'local' for localStorage. |
| step | number | 5 | Step factor to increment/decrement the size of the panels while pressing the arrow keys. |
| dt | any | - | It generates scoped CSS variables using design tokens for the component. |
| pt | PassThrough | - | Used to pass attributes to DOM elements inside the component. |
| ptOptions | any | - | Used to configure passthrough(pt) options of the component. |
| unstyled | boolean | false | When enabled, it removes component related styles in the core. |
Pass Through Options
| Name | Type | Description |
|---|---|---|
| root | SplitterPassThroughOptionType | Used to pass attributes to the root's DOM element. |
| gutter | SplitterPassThroughOptionType | Used to pass attributes to the gutter's DOM element. |
| gutterHandle | SplitterPassThroughOptionType | Used to pass attributes to the gutter handle's DOM element. |
| hooks | any | Used to manage all lifecycle hooks. |
Theming
CSS Classes
| Class | Description |
|---|---|
| p-splitter | Class name of the root element |
| p-splitter-gutter | Class name of the gutter element |
| p-splitter-gutter-handle | Class name of the gutter handle element |
Design Tokens
| Token | CSS Variable | Description |
|---|---|---|
| splitter.background | --p-splitter-background | Background of root |
| splitter.border.color | --p-splitter-border-color | Border color of root |
| splitter.color | --p-splitter-color | Color of root |
| splitter.transition.duration | --p-splitter-transition-duration | Transition duration of root |
| splitter.gutter.background | --p-splitter-gutter-background | Background of gutter |
| splitter.handle.size | --p-splitter-handle-size | Size of handle |
| splitter.handle.background | --p-splitter-handle-background | Background of handle |
| splitter.handle.border.radius | --p-splitter-handle-border-radius | Border radius of handle |
| splitter.handle.focus.ring.width | --p-splitter-handle-focus-ring-width | Focus ring width of handle |
| splitter.handle.focus.ring.style | --p-splitter-handle-focus-ring-style | Focus ring style of handle |
| splitter.handle.focus.ring.color | --p-splitter-handle-focus-ring-color | Focus ring color of handle |
| splitter.handle.focus.ring.offset | --p-splitter-handle-focus-ring-offset | Focus ring offset of handle |
| splitter.handle.focus.ring.shadow | --p-splitter-handle-focus-ring-shadow | Focus ring shadow of handle |