@fibrae/semi-ui-svelte 0.9.1 → 0.10.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/README.md +8 -4
- package/README.zh-CN.md +8 -4
- package/dist/components/anchor/interface.d.ts +14 -0
- package/dist/components/audio-player/interface.d.ts +5 -0
- package/dist/components/auto-complete/interface.d.ts +29 -0
- package/dist/components/avatar/interface.d.ts +24 -0
- package/dist/components/backtop/interface.d.ts +2 -0
- package/dist/components/badge/interface.d.ts +7 -0
- package/dist/components/banner/interface.d.ts +7 -0
- package/dist/components/breadcrumb/interface.d.ts +10 -0
- package/dist/components/button/interface.d.ts +18 -0
- package/dist/components/calendar/interface.d.ts +16 -0
- package/dist/components/card/interface.d.ts +18 -0
- package/dist/components/carousel/interface.d.ts +16 -0
- package/dist/components/cascader/interface.d.ts +57 -0
- package/dist/components/checkbox/interface.d.ts +19 -0
- package/dist/components/code-highlight/interface.d.ts +3 -0
- package/dist/components/collapse/interface.d.ts +16 -0
- package/dist/components/collapsible/interface.d.ts +10 -0
- package/dist/components/color-picker/interface.d.ts +10 -0
- package/dist/components/config-provider/interface.d.ts +7 -0
- package/dist/components/cropper/interface.d.ts +11 -0
- package/dist/components/date-picker/interface.d.ts +47 -0
- package/dist/components/descriptions/interface.d.ts +6 -0
- package/dist/components/divider/interface.d.ts +4 -0
- package/dist/components/dropdown/interface.d.ts +8 -0
- package/dist/components/empty/interface.d.ts +7 -0
- package/dist/components/feedback/interface.d.ts +16 -0
- package/dist/components/float-button/interface.d.ts +14 -0
- package/dist/components/form/interface.d.ts +47 -0
- package/dist/components/grid/interface.d.ts +13 -0
- package/dist/components/highlight/interface.d.ts +7 -0
- package/dist/components/hot-keys/interface.d.ts +3 -0
- package/dist/components/image/interface.d.ts +59 -0
- package/dist/components/input/interface.d.ts +67 -0
- package/dist/components/input-number/interface.d.ts +24 -0
- package/dist/components/json-viewer/interface.d.ts +7 -0
- package/dist/components/layout/interface.d.ts +3 -0
- package/dist/components/list/interface.d.ts +18 -0
- package/dist/components/locale/interface.d.ts +4 -0
- package/dist/components/lottie/interface.d.ts +2 -0
- package/dist/components/markdown-render/interface.d.ts +5 -0
- package/dist/components/modal/interface.d.ts +29 -0
- package/dist/components/navigation/interface.d.ts +47 -0
- package/dist/components/overflow-list/interface.d.ts +11 -0
- package/dist/components/pagination/interface.d.ts +12 -0
- package/dist/components/pincode/interface.d.ts +8 -0
- package/dist/components/popconfirm/interface.d.ts +12 -0
- package/dist/components/popover/interface.d.ts +30 -0
- package/dist/components/progress/interface.d.ts +13 -0
- package/dist/components/radio/interface.d.ts +22 -0
- package/dist/components/rating/interface.d.ts +12 -0
- package/dist/components/resizable/interface.d.ts +30 -0
- package/dist/components/scroll-list/interface.d.ts +6 -0
- package/dist/components/select/interface.d.ts +63 -0
- package/dist/components/side-sheet/interface.d.ts +19 -0
- package/dist/components/skeleton/interface.d.ts +7 -0
- package/dist/components/slider/interface.d.ts +23 -0
- package/dist/components/space/interface.d.ts +4 -0
- package/dist/components/spin/interface.d.ts +7 -0
- package/dist/components/steps/interface.d.ts +9 -0
- package/dist/components/switch/interface.d.ts +7 -0
- package/dist/components/table/interface.d.ts +48 -0
- package/dist/components/tabs/interface.d.ts +29 -0
- package/dist/components/tag/interface.d.ts +22 -0
- package/dist/components/tag-input/interface.d.ts +29 -0
- package/dist/components/time-picker/interface.d.ts +31 -0
- package/dist/components/timeline/interface.d.ts +5 -0
- package/dist/components/tooltip/interface.d.ts +20 -0
- package/dist/components/transfer/interface.d.ts +18 -0
- package/dist/components/tree/interface.d.ts +45 -0
- package/dist/components/tree-select/interface.d.ts +55 -0
- package/dist/components/typography/interface.d.ts +33 -0
- package/dist/components/upload/interface.d.ts +64 -0
- package/dist/components/user-guide/interface.d.ts +15 -0
- package/dist/components/video-player/interface.d.ts +22 -0
- package/docs/advanced/dark-mode.md +288 -0
- package/docs/basic/button.md +605 -0
- package/docs/basic/divider.md +103 -0
- package/docs/basic/float-button.md +246 -0
- package/docs/basic/grid.md +427 -0
- package/docs/basic/layout.md +459 -0
- package/docs/basic/resizable.md +584 -0
- package/docs/basic/space.md +163 -0
- package/docs/basic/tokens.md +425 -0
- package/docs/basic/typography.md +615 -0
- package/docs/changes-from-semi.md +105 -0
- package/docs/ecosystem/tailwind.md +210 -0
- package/docs/experience/accessibility.md +82 -0
- package/docs/experience/content-guidelines.md +819 -0
- package/docs/experience/internationalization.md +7 -0
- package/docs/feedback/banner.md +198 -0
- package/docs/feedback/feedback.md +294 -0
- package/docs/feedback/notification.md +401 -0
- package/docs/feedback/popconfirm.md +243 -0
- package/docs/feedback/progress.md +389 -0
- package/docs/feedback/skeleton.md +388 -0
- package/docs/feedback/spin.md +172 -0
- package/docs/feedback/toast.md +393 -0
- package/docs/input/auto-complete.md +399 -0
- package/docs/input/cascader.md +1558 -0
- package/docs/input/checkbox.md +408 -0
- package/docs/input/color-picker.md +175 -0
- package/docs/input/date-picker.md +942 -0
- package/docs/input/form.md +2550 -0
- package/docs/input/input-number.md +451 -0
- package/docs/input/input.md +640 -0
- package/docs/input/pincode.md +191 -0
- package/docs/input/radio.md +337 -0
- package/docs/input/rating.md +214 -0
- package/docs/input/select.md +1230 -0
- package/docs/input/slider.md +347 -0
- package/docs/input/switch.md +206 -0
- package/docs/input/tag-input.md +465 -0
- package/docs/input/time-picker.md +358 -0
- package/docs/input/transfer.md +1061 -0
- package/docs/input/tree-select.md +1300 -0
- package/docs/input/upload.md +1811 -0
- package/docs/llms.txt +147 -0
- package/docs/navigation/anchor.md +377 -0
- package/docs/navigation/backtop.md +100 -0
- package/docs/navigation/breadcrumb.md +284 -0
- package/docs/navigation/navigation.md +851 -0
- package/docs/navigation/pagination.md +217 -0
- package/docs/navigation/steps.md +315 -0
- package/docs/navigation/tabs.md +754 -0
- package/docs/navigation/tree.md +1956 -0
- package/docs/other/config-provider.md +599 -0
- package/docs/other/locale.md +353 -0
- package/docs/plus/audio-player.md +155 -0
- package/docs/plus/code-highlight.md +150 -0
- package/docs/plus/drag-move.md +214 -0
- package/docs/plus/hot-keys.md +174 -0
- package/docs/plus/json-viewer.md +392 -0
- package/docs/plus/lottie.md +176 -0
- package/docs/plus/markdown-render.md +240 -0
- package/docs/plus/video-player.md +325 -0
- package/docs/show/avatar.md +475 -0
- package/docs/show/badge.md +276 -0
- package/docs/show/calendar.md +352 -0
- package/docs/show/card.md +485 -0
- package/docs/show/carousel.md +592 -0
- package/docs/show/collapse.md +289 -0
- package/docs/show/collapsible.md +216 -0
- package/docs/show/cropper.md +285 -0
- package/docs/show/descriptions.md +325 -0
- package/docs/show/dropdown.md +466 -0
- package/docs/show/empty.md +225 -0
- package/docs/show/highlight.md +144 -0
- package/docs/show/image.md +433 -0
- package/docs/show/list.md +927 -0
- package/docs/show/modal.md +517 -0
- package/docs/show/overflow-list.md +272 -0
- package/docs/show/popover.md +534 -0
- package/docs/show/scroll-list.md +156 -0
- package/docs/show/side-sheet.md +274 -0
- package/docs/show/table.md +5437 -0
- package/docs/show/tag.md +428 -0
- package/docs/show/timeline.md +277 -0
- package/docs/show/tooltip.md +442 -0
- package/docs/show/user-guide.md +419 -0
- package/docs/start/getting-started.md +234 -0
- package/docs/start/introduction.md +57 -0
- package/docs/start/overview.md +21 -0
- package/package.json +5 -4
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
# Collapse
|
|
2
|
+
|
|
3
|
+
> Display content areas can be expanded or folded.
|
|
4
|
+
|
|
5
|
+
Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/show/collapse/
|
|
6
|
+
|
|
7
|
+
## Demos
|
|
8
|
+
|
|
9
|
+
### How to import
|
|
10
|
+
|
|
11
|
+
```svelte
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { Collapse, CollapsePanel } from '@fibrae/semi-ui-svelte';
|
|
14
|
+
</script>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
In Svelte, write the panel as `Collapse.Panel` or the named export `CollapsePanel`, which are the same component. The `header` and `extra` of a Panel are snippets. A Panel can only be used inside Collapse, otherwise it throws a descriptive error.
|
|
18
|
+
|
|
19
|
+
### Basic Usage
|
|
20
|
+
|
|
21
|
+
You can expand multiple panels at the same time, and use `defaultActiveKey` to set the panel to expand by default.
|
|
22
|
+
|
|
23
|
+
Svelte has no `defaultActiveKey`: a plain `activeKey` is the initially expanded panel; use `bind:activeKey` to read and write the expanded state.
|
|
24
|
+
|
|
25
|
+
```svelte
|
|
26
|
+
<script lang="ts">
|
|
27
|
+
import { Collapse } from '@fibrae/semi-ui-svelte';
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<Collapse>
|
|
31
|
+
<Collapse.Panel itemKey="1">
|
|
32
|
+
{#snippet header()}This is panel header 1{/snippet}
|
|
33
|
+
<p>Hi, this is the docsite of Semi Design Next.</p>
|
|
34
|
+
</Collapse.Panel>
|
|
35
|
+
<Collapse.Panel itemKey="2">
|
|
36
|
+
{#snippet header()}This is panel header 2{/snippet}
|
|
37
|
+
<p>Hi, this is the docsite of Semi Design Next.</p>
|
|
38
|
+
</Collapse.Panel>
|
|
39
|
+
<Collapse.Panel itemKey="3">
|
|
40
|
+
{#snippet header()}This is panel header 3{/snippet}
|
|
41
|
+
<p>Hi, this is the docsite of Semi Design Next.</p>
|
|
42
|
+
</Collapse.Panel>
|
|
43
|
+
</Collapse>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Accordion
|
|
47
|
+
|
|
48
|
+
Use `accordion` to restrict one panel only to be expanded at one time.
|
|
49
|
+
|
|
50
|
+
```svelte
|
|
51
|
+
<script lang="ts">
|
|
52
|
+
import { Collapse } from '@fibrae/semi-ui-svelte';
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<Collapse accordion>
|
|
56
|
+
<Collapse.Panel itemKey="1">
|
|
57
|
+
{#snippet header()}This is panel header 1{/snippet}
|
|
58
|
+
<p>Hi, this is the docsite of Semi Design Next.</p>
|
|
59
|
+
</Collapse.Panel>
|
|
60
|
+
<Collapse.Panel itemKey="2">
|
|
61
|
+
{#snippet header()}This is panel header 2{/snippet}
|
|
62
|
+
<p>Hi, this is the docsite of Semi Design Next.</p>
|
|
63
|
+
</Collapse.Panel>
|
|
64
|
+
<Collapse.Panel itemKey="3">
|
|
65
|
+
{#snippet header()}This is panel header 3{/snippet}
|
|
66
|
+
<p>Hi, this is the docsite of Semi Design Next.</p>
|
|
67
|
+
</Collapse.Panel>
|
|
68
|
+
</Collapse>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Disable Panel
|
|
72
|
+
|
|
73
|
+
Use `disabled` to disabled panel.
|
|
74
|
+
|
|
75
|
+
```svelte
|
|
76
|
+
<script lang="ts">
|
|
77
|
+
import { Collapse } from '@fibrae/semi-ui-svelte';
|
|
78
|
+
</script>
|
|
79
|
+
|
|
80
|
+
<Collapse accordion>
|
|
81
|
+
<Collapse.Panel disabled itemKey="1">
|
|
82
|
+
{#snippet header()}This is panel header 1{/snippet}
|
|
83
|
+
<p>Hi, this is the docsite of Semi Design Next.</p>
|
|
84
|
+
</Collapse.Panel>
|
|
85
|
+
<Collapse.Panel itemKey="2">
|
|
86
|
+
{#snippet header()}This is panel header 2{/snippet}
|
|
87
|
+
<p>Hi, this is the docsite of Semi Design Next.</p>
|
|
88
|
+
</Collapse.Panel>
|
|
89
|
+
<Collapse.Panel itemKey="3">
|
|
90
|
+
{#snippet header()}This is panel header 3{/snippet}
|
|
91
|
+
<p>Hi, this is the docsite of Semi Design Next.</p>
|
|
92
|
+
</Collapse.Panel>
|
|
93
|
+
</Collapse>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Hide The Panel Icon
|
|
97
|
+
|
|
98
|
+
Use `showArrow` to hide the panel icon.
|
|
99
|
+
|
|
100
|
+
```svelte
|
|
101
|
+
<script lang="ts">
|
|
102
|
+
import { Collapse } from '@fibrae/semi-ui-svelte';
|
|
103
|
+
</script>
|
|
104
|
+
|
|
105
|
+
<Collapse accordion>
|
|
106
|
+
<Collapse.Panel itemKey="1" showArrow={false}>
|
|
107
|
+
{#snippet header()}This is panel header 1{/snippet}
|
|
108
|
+
<p>Hi, this is the docsite of Semi Design Next.</p>
|
|
109
|
+
</Collapse.Panel>
|
|
110
|
+
<Collapse.Panel itemKey="2">
|
|
111
|
+
{#snippet header()}This is panel header 2{/snippet}
|
|
112
|
+
<p>Hi, this is the docsite of Semi Design Next.</p>
|
|
113
|
+
</Collapse.Panel>
|
|
114
|
+
<Collapse.Panel itemKey="3">
|
|
115
|
+
{#snippet header()}This is panel header 3{/snippet}
|
|
116
|
+
<p>Hi, this is the docsite of Semi Design Next.</p>
|
|
117
|
+
</Collapse.Panel>
|
|
118
|
+
</Collapse>
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Custom Icon
|
|
122
|
+
|
|
123
|
+
Use the `expandIcon` snippet of Collapse to set the expanding icon and the `collapseIcon` snippet for the folded icon, written as `{#snippet expandIcon()}...{/snippet}` inside the Collapse tag.
|
|
124
|
+
|
|
125
|
+
The expanding icon is shown while a panel is collapsed (it can be expanded), the folded icon while it is expanded.
|
|
126
|
+
|
|
127
|
+
```svelte
|
|
128
|
+
<script lang="ts">
|
|
129
|
+
import { IconMinus, IconPlus } from '@fibrae/semi-icons-svelte';
|
|
130
|
+
import { Collapse } from '@fibrae/semi-ui-svelte';
|
|
131
|
+
</script>
|
|
132
|
+
|
|
133
|
+
<Collapse>
|
|
134
|
+
{#snippet expandIcon()}
|
|
135
|
+
<IconPlus />
|
|
136
|
+
{/snippet}
|
|
137
|
+
{#snippet collapseIcon()}
|
|
138
|
+
<IconMinus />
|
|
139
|
+
{/snippet}
|
|
140
|
+
<Collapse.Panel itemKey="1">
|
|
141
|
+
{#snippet header()}This is panel header 1{/snippet}
|
|
142
|
+
<p>Hi, this is the docsite of Semi Design Next.</p>
|
|
143
|
+
</Collapse.Panel>
|
|
144
|
+
<Collapse.Panel itemKey="2">
|
|
145
|
+
{#snippet header()}This is panel header 2{/snippet}
|
|
146
|
+
<p>Hi, this is the docsite of Semi Design Next.</p>
|
|
147
|
+
</Collapse.Panel>
|
|
148
|
+
<Collapse.Panel itemKey="3">
|
|
149
|
+
{#snippet header()}This is panel header 3{/snippet}
|
|
150
|
+
<p>Hi, this is the docsite of Semi Design Next.</p>
|
|
151
|
+
</Collapse.Panel>
|
|
152
|
+
</Collapse>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Custom Extra Content on the Right-upper Corner
|
|
156
|
+
|
|
157
|
+
Use the `extra` snippet to set extra content on the right-upper corner.
|
|
158
|
+
|
|
159
|
+
`header` is rendered inside the panel's toggle button, so it may only hold text, icons and other non-interactive content. `extra` sits beside the button in the same row and may hold controls such as buttons or inputs.
|
|
160
|
+
|
|
161
|
+
```svelte
|
|
162
|
+
<script lang="ts">
|
|
163
|
+
import { IconCopy } from '@fibrae/semi-icons-svelte';
|
|
164
|
+
import { Collapse, Tag } from '@fibrae/semi-ui-svelte';
|
|
165
|
+
</script>
|
|
166
|
+
|
|
167
|
+
<Collapse>
|
|
168
|
+
<Collapse.Panel itemKey="1">
|
|
169
|
+
{#snippet header()}This is panel header 1{/snippet}
|
|
170
|
+
{#snippet extra()}1234{/snippet}
|
|
171
|
+
<p>Hi, this is the docsite of Semi Design Next.</p>
|
|
172
|
+
</Collapse.Panel>
|
|
173
|
+
<Collapse.Panel itemKey="2">
|
|
174
|
+
{#snippet header()}This is panel header 2{/snippet}
|
|
175
|
+
{#snippet extra()}
|
|
176
|
+
<IconCopy />
|
|
177
|
+
{/snippet}
|
|
178
|
+
<p>Hi, this is the docsite of Semi Design Next.</p>
|
|
179
|
+
</Collapse.Panel>
|
|
180
|
+
<Collapse.Panel itemKey="3">
|
|
181
|
+
{#snippet header()}This is panel header 3{/snippet}
|
|
182
|
+
{#snippet extra()}
|
|
183
|
+
<Tag color="violet" style="margin: 0">Recommended</Tag>
|
|
184
|
+
{/snippet}
|
|
185
|
+
<p>Hi, this is the docsite of Semi Design Next.</p>
|
|
186
|
+
</Collapse.Panel>
|
|
187
|
+
</Collapse>
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## API reference
|
|
191
|
+
|
|
192
|
+
### Collapse
|
|
193
|
+
|
|
194
|
+
**Props**
|
|
195
|
+
|
|
196
|
+
| Property | Description | Type | Default |
|
|
197
|
+
| - | - | - | - |
|
|
198
|
+
| accordion | Accordion mode. | `boolean` | `false` |
|
|
199
|
+
| activeKey | Key of the currently expanded panel; bind it with `bind:activeKey`. null and the empty string mean all panels are collapsed. `bind:activeKey={get, set}` makes it fully controlled; a plain `activeKey` is the initial value and a click overrides it inside the component. | `string \| string[] \| null` | - |
|
|
200
|
+
| children | Snippet for the CollapsePanel panels. | `Snippet` | - |
|
|
201
|
+
| clickHeaderToExpand | Clicking anywhere in the header row toggles the panel; when false only the toggle button and the arrow respond. | `boolean` | `true` |
|
|
202
|
+
| collapseIcon | Snippet for the icon shown while a panel is expanded, IconChevronUp by default. | `Snippet` | - |
|
|
203
|
+
| expandIcon | Snippet for the icon shown while a panel is collapsed, IconChevronDown by default. | `Snippet` | - |
|
|
204
|
+
| expandIconPosition | Position of the expand icon: left or right. | `'left' \| 'right'` | `"right"` |
|
|
205
|
+
| keepDOM | Whether to keep the DOM tree of hidden panels; destroyed by default. When omitted it reads the global default of Collapse, then that of Collapsible. | `boolean` | - |
|
|
206
|
+
| lazyRender | Used with keepDOM; when true, panel content is not rendered until the panel is first expanded. | `boolean` | `false` |
|
|
207
|
+
| motion | Whether to enable the animation; enabled by default. When omitted it reads the global default of Collapse, then that of Collapsible. | `boolean` | - |
|
|
208
|
+
| onChange | Called when a panel is toggled, with the array of expanded keys and the native MouseEvent (keyboard use also produces a click through the native button). | `(activeKey: string[], event: MouseEvent) => void` | - |
|
|
209
|
+
|
|
210
|
+
`class`, `style` and native attributes and events (such as `id` and `aria-*`) land on the root element of Collapse (`.semi-collapse`). The first argument of `onChange` is always a `string[]`, even when `activeKey` is passed as a string.
|
|
211
|
+
|
|
212
|
+
### Collapse.Panel
|
|
213
|
+
|
|
214
|
+
**Props**
|
|
215
|
+
|
|
216
|
+
| Property | Description | Type | Default |
|
|
217
|
+
| - | - | - | - |
|
|
218
|
+
| children | Snippet for the panel content; a panel counts as having content only when children is given. | `Snippet` | - |
|
|
219
|
+
| disabled | Whether the panel is disabled. | `boolean` | `false` |
|
|
220
|
+
| extra | Snippet for the auxiliary content on the right of the panel header, outside the toggle button; may hold controls. | `Snippet` | - |
|
|
221
|
+
| header | Snippet for the panel header content, rendered inside the toggle button; must not contain interactive elements. | `Snippet` | - |
|
|
222
|
+
| itemKey | Required and unique, matched against activeKey. | `string` | - |
|
|
223
|
+
| onMotionEnd | Called when the expand or collapse animation ends. | `() => void` | - |
|
|
224
|
+
| showArrow | Whether to show the arrow icon. | `boolean` | `true` |
|
|
225
|
+
|
|
226
|
+
`class`, `style` and native attributes and events land on the root element of the Panel (`.semi-collapse-item`). Panel does not read global defaults, and counts as having content only when `children` is given.
|
|
227
|
+
|
|
228
|
+
## Accessibility
|
|
229
|
+
|
|
230
|
+
### ARIA
|
|
231
|
+
|
|
232
|
+
- Each panel header follows the WAI-ARIA Accordion pattern: a native `button` wrapped in an element with `role="heading"` and `aria-level="3"`. The button's accessible name is the `header` content.
|
|
233
|
+
- The button carries `aria-expanded`, and `aria-controls` pointing at the panel content whenever that content is still in the DOM: always when open, and when closed once `keepDOM` is in effect (including when `keepDOM` is only set in the global defaults of Collapsible) and the content has been rendered, for example a panel opened once and closed again with `keepDOM` and `lazyRender`. A closed panel that `lazyRender` has not rendered yet has no content and no `aria-controls`.
|
|
234
|
+
- The panel content has `role="region"` and is labelled by the button through `aria-labelledby`; closed content kept by `keepDOM` is `inert`.
|
|
235
|
+
- The expand icon is decorative and has `aria-hidden="true"`; `extra` is outside the button.
|
|
236
|
+
- A `disabled` panel uses the button's native `disabled` attribute.
|
|
237
|
+
|
|
238
|
+
### Keyboard and Focus
|
|
239
|
+
|
|
240
|
+
- Each panel header button is one Tab stop; disabled panels are skipped.
|
|
241
|
+
- `Enter` or `Space` on the focused button expands or collapses the panel, also when `clickHeaderToExpand` is `false`.
|
|
242
|
+
- Controls inside `extra` are Tab stops of their own.
|
|
243
|
+
|
|
244
|
+
## Content Guidelines
|
|
245
|
+
|
|
246
|
+
The essence of the folding panel is that the card container adds the function of folding and unfolding, so the copywriting specification of the folding panel needs to be the same as the [Card copywriting specification](../show/card.md#content-guidelines)
|
|
247
|
+
|
|
248
|
+
## Design Tokens
|
|
249
|
+
|
|
250
|
+
The design token table of this component is on the web page: <https://semi-design-next.pages.dev/en-US/svelte/show/collapse/>
|
|
251
|
+
|
|
252
|
+
## FAQ
|
|
253
|
+
|
|
254
|
+
- ### Why is the data in Form cleared when using Collapse?
|
|
255
|
+
|
|
256
|
+
When Collapse is collapsed, the related DOM is destroyed and so are the fields data stored in Form. You could set `keepDOM` of Collapse to true to keep the DOM from being destroyed.
|
|
257
|
+
|
|
258
|
+
- ### The whole header row is a click hot zone for folding and expanding. If a control (such as Input) is placed in the row, clicking it collapses/expands the panel. How to avoid it?
|
|
259
|
+
Put the control in `extra`, not in `header`: `header` is inside the toggle button and must not contain controls. With `clickHeaderToExpand` set to false only the toggle button and the icon respond to clicks; otherwise stop the click from bubbling to the header row in the control's click handler, or in a wrapping element's click handler if the control does not provide the event object, as in the example below.
|
|
260
|
+
|
|
261
|
+
```svelte
|
|
262
|
+
<script lang="ts">
|
|
263
|
+
import { Collapse, CollapsePanel, Input } from '@fibrae/semi-ui-svelte';
|
|
264
|
+
</script>
|
|
265
|
+
|
|
266
|
+
<Collapse>
|
|
267
|
+
<CollapsePanel itemKey="1">
|
|
268
|
+
{#snippet header()}Panel header{/snippet}
|
|
269
|
+
{#snippet extra()}
|
|
270
|
+
<span onclick={(e) => e.stopPropagation()}>
|
|
271
|
+
<Input aria-label="Panel note" />
|
|
272
|
+
</span>
|
|
273
|
+
{/snippet}
|
|
274
|
+
<p>Hi, this is the docsite of Semi Design Next.</p>
|
|
275
|
+
</CollapsePanel>
|
|
276
|
+
</Collapse>
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## Changes from Semi Design
|
|
280
|
+
|
|
281
|
+
From the project release notes (written in Chinese). Your knowledge of Semi Design does not cover these.
|
|
282
|
+
|
|
283
|
+
- 破坏性:删除 `reCalcKey`(Collapsible、Collapse.Panel)与静态方法 `Collapsible.getEntryInfo`;`onChange` 事件类型收窄为 `MouseEvent`,`activeKey` 类型加入 `null`(受控空值,`''` 与 `null` 收起全部面板);Collapsible 的高度过渡改用 `calc-size(auto, size)`,外层不再有内联 `height`,改由 `--semi-collapsible-height` 写入。不支持 `calc-size()` 的浏览器(Firefox、Safari)同样播放高度动画,时长与曲线不变,`onMotionEnd` 在动画结束时调用。
|
|
284
|
+
- 面板头部按 APG accordion 改为原生 `<button class="semi-collapse-header-button">`,`extra` 与展开箭头在按钮之外;`clickHeaderToExpand={false}` 时点击标题与箭头展开,点击 `extra` 不展开;收起内容带 `inert`。Vue:受控用 `v-model:activeKey`,`change` 载荷总是 `string[]`;`expandIcon`、`collapseIcon`、Panel 的 `header`、`extra` 改为插槽;`onMotionEnd` 改为 `motionEnd` 事件;Collapsible 的 `className` 改为 `class`。
|
|
285
|
+
- Collapsible 使用方传入的 `onTransitionEnd` 不再被内部处理覆盖。
|
|
286
|
+
- 面板较窄时 `extra` 不再收缩,标题更早截断。
|
|
287
|
+
- `keepDOM` 加 `lazyRender` 时,面板内容消失后「展开过」的记录随之复位,内容在收起状态下恢复时不渲染、头部不带 `aria-controls`,重新展开后才渲染。
|
|
288
|
+
- Svelte:受控值用 `bind:activeKey`,没有 `defaultActiveKey`;`expandIcon`、`collapseIcon` 与 Panel 的 `header`、`extra` 是 snippet;`onMotionEnd` 是 Panel 与 Collapsible 的回调 prop;Panel 写在 Collapse 外抛错;导出为 `Collapse` 与 `CollapsePanel`,`Collapse.Panel` 与 `CollapsePanel` 是同一组件;Panel 按是否传入 `children` 判断有无内容。
|
|
289
|
+
- Collapsible:在 `display: none` 下切换时立即结束并触发 `onMotionEnd`。
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# Collapsible
|
|
2
|
+
|
|
3
|
+
> The collapsible component is a container component used to put long sections of information under a block that can be expanded or collapsed.
|
|
4
|
+
|
|
5
|
+
Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/show/collapsible/
|
|
6
|
+
|
|
7
|
+
## When to use
|
|
8
|
+
|
|
9
|
+
- `Collapsible`is a behavior component with animation effect by default. It is used in various components in Semi Components, including: `Navigation`, `Collapse`, `Tree`, `TreeSelect`, and `Typography`.
|
|
10
|
+
- When the above components do not meet requirements or customized collapsed behavior, you can use `Collapsible` to put in contents that need to be expanded or folded.
|
|
11
|
+
|
|
12
|
+
## Demos
|
|
13
|
+
|
|
14
|
+
### How to import
|
|
15
|
+
|
|
16
|
+
```svelte
|
|
17
|
+
<script lang="ts">
|
|
18
|
+
import { Collapsible } from '@fibrae/semi-ui-svelte';
|
|
19
|
+
</script>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Basic Usage
|
|
23
|
+
|
|
24
|
+
Use `isOpen` to control the expansion or folding of the content.
|
|
25
|
+
|
|
26
|
+
```svelte
|
|
27
|
+
<script lang="ts">
|
|
28
|
+
import { Button, Collapsible } from '@fibrae/semi-ui-svelte';
|
|
29
|
+
|
|
30
|
+
let isOpen = $state(false);
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<div>
|
|
34
|
+
<Button aria-controls="collapsible-basic" aria-expanded={isOpen} onclick={() => (isOpen = !isOpen)}>Toggle</Button>
|
|
35
|
+
<Collapsible id="collapsible-basic" {isOpen}>
|
|
36
|
+
<ul>
|
|
37
|
+
<li>
|
|
38
|
+
<p>Semi Design 以内容优先进行设计。</p>
|
|
39
|
+
</li>
|
|
40
|
+
<li>
|
|
41
|
+
<p>更容易地自定义主题。</p>
|
|
42
|
+
</li>
|
|
43
|
+
<li>
|
|
44
|
+
<p>适用国际化场景。</p>
|
|
45
|
+
</li>
|
|
46
|
+
<li>
|
|
47
|
+
<p>效率场景加入人性化关怀。</p>
|
|
48
|
+
</li>
|
|
49
|
+
</ul>
|
|
50
|
+
</Collapsible>
|
|
51
|
+
</div>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Custom Animation Duration
|
|
55
|
+
|
|
56
|
+
You can use `duration` to set animation duration or turn off animation by setting `motion` to false.
|
|
57
|
+
|
|
58
|
+
```svelte
|
|
59
|
+
<script lang="ts">
|
|
60
|
+
import { Button, Collapsible, InputNumber } from '@fibrae/semi-ui-svelte';
|
|
61
|
+
|
|
62
|
+
let isOpen = $state(false);
|
|
63
|
+
let duration = $state(250);
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<div>
|
|
67
|
+
<span id="collapsible-duration-label">设置动画时间:</span>
|
|
68
|
+
<InputNumber aria-labelledby="collapsible-duration-label" min={0} onChange={(value) => (duration = Number(value))} step={10} style="width: 120px" value={250} />
|
|
69
|
+
<br />
|
|
70
|
+
<Button aria-controls="collapsible-duration" aria-expanded={isOpen} onclick={() => (isOpen = !isOpen)}>Toggle</Button>
|
|
71
|
+
<Collapsible {duration} id="collapsible-duration" {isOpen}>
|
|
72
|
+
<ul>
|
|
73
|
+
<li>
|
|
74
|
+
<p>Semi Design 以内容优先进行设计。</p>
|
|
75
|
+
</li>
|
|
76
|
+
<li>
|
|
77
|
+
<p>更容易地自定义主题。</p>
|
|
78
|
+
</li>
|
|
79
|
+
<li>
|
|
80
|
+
<p>适用国际化场景。</p>
|
|
81
|
+
</li>
|
|
82
|
+
<li>
|
|
83
|
+
<p>效率场景加入人性化关怀。</p>
|
|
84
|
+
</li>
|
|
85
|
+
</ul>
|
|
86
|
+
</Collapsible>
|
|
87
|
+
</div>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Nested use
|
|
91
|
+
|
|
92
|
+
```svelte
|
|
93
|
+
<script lang="ts">
|
|
94
|
+
import { Button, Collapsible } from '@fibrae/semi-ui-svelte';
|
|
95
|
+
|
|
96
|
+
let isOpen = $state(false);
|
|
97
|
+
let isChildOpen = $state(false);
|
|
98
|
+
</script>
|
|
99
|
+
|
|
100
|
+
<div>
|
|
101
|
+
<Button aria-controls="collapsible-nested" aria-expanded={isOpen} onclick={() => (isOpen = !isOpen)}>Toggle</Button>
|
|
102
|
+
<br />
|
|
103
|
+
<Collapsible id="collapsible-nested" {isOpen}>
|
|
104
|
+
<div>
|
|
105
|
+
<span>Semi Design的设计原则包括:</span>
|
|
106
|
+
<Button aria-controls="collapsible-nested-list" aria-expanded={isChildOpen} onclick={() => (isChildOpen = !isChildOpen)}>Toggle List</Button>
|
|
107
|
+
</div>
|
|
108
|
+
<Collapsible id="collapsible-nested-list" isOpen={isChildOpen}>
|
|
109
|
+
<ul>
|
|
110
|
+
<li>
|
|
111
|
+
<p>Semi Design 以内容优先进行设计。</p>
|
|
112
|
+
</li>
|
|
113
|
+
<li>
|
|
114
|
+
<p>更容易地自定义主题。</p>
|
|
115
|
+
</li>
|
|
116
|
+
<li>
|
|
117
|
+
<p>适用国际化场景。</p>
|
|
118
|
+
</li>
|
|
119
|
+
<li>
|
|
120
|
+
<p>效率场景加入人性化关怀。</p>
|
|
121
|
+
</li>
|
|
122
|
+
</ul>
|
|
123
|
+
</Collapsible>
|
|
124
|
+
</Collapsible>
|
|
125
|
+
</div>
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Custom CollapseHeight
|
|
129
|
+
|
|
130
|
+
You could use `collapseHeight` to customize collapsed height.
|
|
131
|
+
|
|
132
|
+
```svelte
|
|
133
|
+
<script lang="ts">
|
|
134
|
+
import { Button, Collapsible } from '@fibrae/semi-ui-svelte';
|
|
135
|
+
|
|
136
|
+
let isOpen = $state(false);
|
|
137
|
+
|
|
138
|
+
const maskStyle = $derived(isOpen ? undefined : '-webkit-mask-image: linear-gradient(to bottom, black 0%, rgba(0, 0, 0, 1) 60%, rgba(0, 0, 0, 0.2) 80%, transparent 100%)');
|
|
139
|
+
const linkStyle = 'position: absolute; left: 0; right: 0; width: 100%; padding: 0; border: none; background: none; font-size: inherit; font-family: inherit; line-height: inherit; text-align: center; bottom: -10px; font-weight: 700; cursor: pointer; color: var(--semi-color-link)';
|
|
140
|
+
</script>
|
|
141
|
+
|
|
142
|
+
<Button aria-controls="collapsible-height" aria-expanded={isOpen} onclick={() => (isOpen = !isOpen)}>Toggle</Button>
|
|
143
|
+
<div style="position: relative">
|
|
144
|
+
<Collapsible collapseHeight={60} id="collapsible-height" {isOpen} style={maskStyle}>
|
|
145
|
+
<ul>
|
|
146
|
+
<li>
|
|
147
|
+
<p>Semi Design 以内容优先进行设计。</p>
|
|
148
|
+
</li>
|
|
149
|
+
<li>
|
|
150
|
+
<p>更容易地自定义主题。</p>
|
|
151
|
+
</li>
|
|
152
|
+
<li>
|
|
153
|
+
<p>适用国际化场景。</p>
|
|
154
|
+
</li>
|
|
155
|
+
<li>
|
|
156
|
+
<p>效率场景加入人性化关怀。</p>
|
|
157
|
+
</li>
|
|
158
|
+
</ul>
|
|
159
|
+
</Collapsible>
|
|
160
|
+
{#if !isOpen}
|
|
161
|
+
<button aria-controls="collapsible-height" aria-expanded={isOpen} style={linkStyle} type="button" onclick={() => (isOpen = !isOpen)}>+ Show More</button>
|
|
162
|
+
{/if}
|
|
163
|
+
</div>
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## API reference
|
|
167
|
+
|
|
168
|
+
**Props**
|
|
169
|
+
|
|
170
|
+
| Property | Description | Type | Default |
|
|
171
|
+
| - | - | - | - |
|
|
172
|
+
| children | Snippet for the content to expand or collapse. | `Snippet` | - |
|
|
173
|
+
| collapseHeight | Height in pixels when collapsed. | `number` | `0` |
|
|
174
|
+
| collapseHeightAdaptive | Whether the collapsed height follows the content when it is shorter than collapseHeight. | `boolean` | `false` |
|
|
175
|
+
| duration | Animation duration in milliseconds. | `number` | `250` |
|
|
176
|
+
| fade | Whether to fade in and out. | `boolean` | `false` |
|
|
177
|
+
| id | id of the inner content element, for the trigger's aria-controls; it does not read the global default. | `string` | - |
|
|
178
|
+
| isOpen | Whether the content area is expanded. | `boolean` | `false` |
|
|
179
|
+
| keepDOM | Whether to keep the DOM tree of the hidden content; it is destroyed by default. | `boolean` | `false` |
|
|
180
|
+
| lazyRender | Used with keepDOM; when true, the content is not rendered on mount but after the first expansion. | `boolean` | `false` |
|
|
181
|
+
| motion | Whether to enable the animation. | `boolean` | `true` |
|
|
182
|
+
| onMotionEnd | Called when the expand or collapse animation ends. | `() => void` | - |
|
|
183
|
+
|
|
184
|
+
`class`, `style` and other native attributes and events land on the outer wrapper; `id` is a declared prop and lands on the inner content element, and it does not read the global default. An `ontransitionend` from the caller runs together with the component's own handler.
|
|
185
|
+
|
|
186
|
+
## Accessibility
|
|
187
|
+
|
|
188
|
+
### ARIA
|
|
189
|
+
|
|
190
|
+
- Collapsible has `id` props, the value passed in will be set as the id of the inner content element (not the outer wrapper). The trigger button points at it with `aria-controls` and reports whether it is open with `aria-expanded`, see the usage example below.
|
|
191
|
+
|
|
192
|
+
```svelte
|
|
193
|
+
<script lang="ts">
|
|
194
|
+
import { Button, Collapsible } from '@fibrae/semi-ui-svelte';
|
|
195
|
+
|
|
196
|
+
const collapseId = 'myCollapsible';
|
|
197
|
+
let visible = $state(false);
|
|
198
|
+
</script>
|
|
199
|
+
|
|
200
|
+
<Button aria-controls={collapseId} aria-expanded={visible} onclick={() => (visible = !visible)}>
|
|
201
|
+
{visible ? 'hide' : 'show'}
|
|
202
|
+
</Button>
|
|
203
|
+
<Collapsible id={collapseId} isOpen={visible}>
|
|
204
|
+
<div>hide content</div>
|
|
205
|
+
</Collapsible>
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Focus
|
|
209
|
+
|
|
210
|
+
- With `collapseHeight` of 0, the collapsed content is `inert`: screen readers skip it and Tab cannot reach it.
|
|
211
|
+
- With `collapseHeight` above 0, the visible preview and the clipped part are the same element, and the clipped part cannot be hidden on its own, so the whole content stays readable and focusable and screen reader users get the full text. Do not put links, buttons or other focusable elements in the clipped part, or keyboard focus lands where it cannot be seen.
|
|
212
|
+
|
|
213
|
+
## FAQ
|
|
214
|
+
|
|
215
|
+
- Why Collapsible does not expand as expected?\
|
|
216
|
+
The expanded height of `Collapsible` is computed by CSS and does not depend on measuring the node, so toggling `isOpen` under a parent with `display: none` still gives the correct expanded height. First check that `isOpen` follows your state; with `collapseHeight` above 0, part of the content is visible while collapsed by design.
|