Collapse
Collapse (접이식 패널)
여러 개의 접히는 패널에 콘텐츠를 나눠 담는 컴포넌트예요. 패널 제목을 클릭하면 내용이 펼쳐지거나 접혀요. 아코디언 모드로 하나만 펼치게 만들 수도 있어요.
출처: 문서
본문
소개 (Intro)
콘텐츠를 여러 개의 접히는 패널에 넣고, 패널 제목을 클릭해 내용을 펼치거나 접을 수 있어요.
설치 (Install)
import { createApp } from 'vue'
import { Collapse, CollapseItem } from '@nutui/nutui'
const app = createApp()
app.use(Collapse)
app.use(CollapseItem)
기본 사용법 (Basic Usage)
CollapseItem 컴포넌트에는 고유 식별자로 name 속성을 반드시 설정해야 해요.
demo: collapse basic
v-model & onChange
펼쳐진 CollapseItem은 v-model로 제어할 수 있어요. 기본은 배열 타입이고, 값은 해당 CollapseItem의 name 속성이에요.
demo: collapse data
아코디언 (手风琴)
accordion으로 아코디언 모드를 설정할 수 있고, 최대 한 개의 패널만 펼칠 수 있어요. 이때 v-model은 단일 name이에요.
demo: collapse accordion
커스텀 접기 아이콘 (自定义折叠图标)
slots.icon 또는 props.icon 속성으로 커스텀 아이콘을 설정해요.
demo: collapse custom
비활성 상태 (禁用状态)
demo: collapse disabled
고정 콘텐츠 설정(접히지 않음, 设置固定内容(不折叠))
demo: collapse extra
API
Collapse Props
| Attribute | Description | Type | Default |
|---|---|---|---|
| v-model | name of the currently expanded panel |
accordion-mode: string | number non-accordion-mode: (string | number)[] |
- |
| accordion | Whether to enable accordion mode | boolean | false |
CollapseItem Props
| Attribute | Description | Type | Default |
|---|---|---|---|
| name | unique identifier, required | string | number | -1 |
| title | The content on the left side of the title bar, supports slot input (props input has a higher priority) |
string | - |
| value | The content on the right side of the title bar, support slot input (props input has a higher priority) |
string | - |
| icon | The icon component on the left side of the title bar, equivalent to the nutui-icon component |
- | - |
| label | title bar description | number | string | - |
| rotate | Click the rotation angle of folding and unfolding, effective in the custom icon mode | string | number | 180 |
| disabled | whether the title bar is disabled | boolean | false |
| border | Whether to display borders | boolean | true |
CollapseItem Slots
| Name | Description |
|---|---|
| title | Content slot on the left side of the title bar |
| alue | Right content slot of the title bar |
| extra | Set fixed content under the title (no folding) |
icon4.2.0 |
Set a custom icon |
Events
| Event | Description | Callback parameter |
|---|---|---|
| change | Triggered when switching panels | (modelValue, currName, status) |
Types v4.3.1
컴포넌트는 다음 타입 정의를 export해요:
import type {
CollapseValue,
CollapseProps,
CollapseInstance,
CollapseItemProps,
CollapseItemInstance
} from '@nutui/nutui';
Theming
CSS Variables
The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.
| Name | Default Value |
|---|---|
| --nut-collapse-item-padding | 13px 36px 13px 26px |
| --nut-collapse-item-color | #666666 |
| --nut-collapse-item-disabled-color | #c8c9cc |
| --nut-collapse-item-icon-color | #666666 |
| --nut-collapse-item-font-size | var(--nut-font-size-2) |
| --nut-collapse-item-line-height | 24px |
| --nut-collapse-item-sub-title-color | #666666 |
| --nut-collapse-wrapper-content-padding | 12px 26px |
| --nut-collapse-wrapper-empty-content-padding | 0 26px |
| --nut-collapse-wrapper-content-color | #666666 |
| --nut-collapse-wrapper-content-font-size | var(--nut-font-size-2) |
| --nut-collapse-wrapper-content-line-height | 1.5 |
| --nut-collapse-wrapper-content-background-color | var(--nut-white) |
더 알아보기 (Learn more)
- 원문 문서: Collapse — NutUI v4 영문 문서
- NutUI 저장소: jd-opensource/nutui