@kubex/zinc 1.0.25 → 1.0.99
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/.claude/project.md +556 -0
- package/.github/workflows/js_build_and_deploy.yaml +9 -10
- package/dist/custom-elements.json +13575 -8856
- package/dist/vscode.html-custom-data.json +583 -48
- package/dist/web-types.json +1441 -181
- package/dist/zn.d.ts +1645 -660
- package/dist/zn.min.css +1 -1
- package/dist/zn.min.js +1412 -893
- package/docs/_utilities/code-previews.cjs +10 -1
- package/docs/assets/scripts/docs.js +42 -18
- package/docs/data/data-table.json +229 -66
- package/docs/data/empty.json +6 -0
- package/docs/data/products-table.json +41 -193
- package/docs/pages/components/action-bar.md +121 -6
- package/docs/pages/components/alert.md +118 -15
- package/docs/pages/components/animated-button.md +299 -0
- package/docs/pages/components/audio-select.md +534 -0
- package/docs/pages/components/bulk-actions.md +79 -5
- package/docs/pages/components/button-group.md +235 -27
- package/docs/pages/components/button.md +139 -1
- package/docs/pages/components/chart.md +365 -9
- package/docs/pages/components/checkbox.md +387 -58
- package/docs/pages/components/chip.md +253 -33
- package/docs/pages/components/collapsible.md +393 -46
- package/docs/pages/components/cols.md +152 -30
- package/docs/pages/components/confirm.md +182 -16
- package/docs/pages/components/copy-button.md +169 -6
- package/docs/pages/components/data-select.md +194 -15
- package/docs/pages/components/data-table-filter.md +96 -5
- package/docs/pages/components/data-table-search.md +451 -0
- package/docs/pages/components/data-table-sort.md +66 -5
- package/docs/pages/components/data-table.md +727 -66
- package/docs/pages/components/datepicker.md +402 -7
- package/docs/pages/components/defined-label.md +120 -5
- package/docs/pages/components/dialog.md +339 -59
- package/docs/pages/components/dropdown.md +366 -11
- package/docs/pages/components/editor.md +604 -7
- package/docs/pages/components/empty-state.md +315 -16
- package/docs/pages/components/expanding-action.md +212 -28
- package/docs/pages/components/file.md +421 -12
- package/docs/pages/components/filter-container.md +158 -5
- package/docs/pages/components/filter-wrapper.md +167 -6
- package/docs/pages/components/form-group.md +383 -6
- package/docs/pages/components/hover-container.md +237 -6
- package/docs/pages/components/icon-picker.md +121 -0
- package/docs/pages/components/icon.md +454 -48
- package/docs/pages/components/inline-edit.md +787 -19
- package/docs/pages/components/input-group.md +207 -13
- package/docs/pages/components/input.md +194 -0
- package/docs/pages/components/item.md +18 -0
- package/docs/pages/components/key-container.md +115 -0
- package/docs/pages/components/key.md +101 -0
- package/docs/pages/components/menu.md +512 -6
- package/docs/pages/components/note.md +239 -36
- package/docs/pages/components/opt-group.md +107 -0
- package/docs/pages/components/pagination.md +332 -6
- package/docs/pages/components/pane.md +222 -6
- package/docs/pages/components/panel.md +213 -26
- package/docs/pages/components/popup.md +1354 -6
- package/docs/pages/components/priority-list.md +233 -0
- package/docs/pages/components/progress-bar.md +387 -6
- package/docs/pages/components/radio-group.md +242 -5
- package/docs/pages/components/radio.md +474 -6
- package/docs/pages/components/rating.md +331 -7
- package/docs/pages/components/reveal.md +524 -6
- package/docs/pages/components/scroll-container.md +552 -6
- package/docs/pages/components/select.md +762 -160
- package/docs/pages/components/skeleton.md +473 -30
- package/docs/pages/components/slideout.md +261 -5
- package/docs/pages/components/sp.md +99 -41
- package/docs/pages/components/split-button.md +347 -9
- package/docs/pages/components/split-pane.md +445 -6
- package/docs/pages/components/stat.md +549 -9
- package/docs/pages/components/status-indicator.md +230 -1
- package/docs/pages/components/stepper.md +563 -6
- package/docs/pages/components/tabs.md +439 -13
- package/docs/pages/components/textarea.md +415 -17
- package/docs/pages/components/tile.md +385 -26
- package/docs/pages/components/toggle.md +424 -6
- package/docs/pages/components/tooltip.md +367 -0
- package/docs/pages/components/translation-group.md +210 -0
- package/docs/pages/components/translations.md +319 -19
- package/docs/pages/components/vertical-stepper.md +401 -8
- package/docs/pages/components/well.md +300 -3
- package/docs/pages/getting-started/form-controls.md +162 -0
- package/docs/pages/index.md +116 -15
- package/package.json +5 -6
- package/scss/_global-spacing.scss +4 -0
- package/scss/_root.scss +2 -2
- package/scss/boot.scss +19 -0
- package/scss/shared/layout.scss +5 -0
- package/scss/themes/_light.scss +3 -3
- package/src/components/alert/alert.scss +1 -0
- package/src/components/animated-button/README.md +306 -0
- package/src/components/animated-button/animated-button.component.ts +229 -0
- package/src/components/animated-button/animated-button.scss +228 -0
- package/src/components/animated-button/animated-button.test.ts +143 -0
- package/src/components/animated-button/index.ts +12 -0
- package/src/components/button/button.component.ts +5 -0
- package/src/components/button-group/button-group.component.ts +25 -13
- package/src/components/button-group/button-group.scss +6 -0
- package/src/components/checkbox/checkbox.component.ts +4 -0
- package/src/components/checkbox/checkbox.scss +7 -4
- package/src/components/checkbox-group/checkbox-group.scss +7 -0
- package/src/components/chip/chip.component.ts +7 -2
- package/src/components/chip/chip.scss +16 -2
- package/src/components/collapsible/collapsible.component.ts +27 -20
- package/src/components/cols/cols.component.ts +14 -2
- package/src/components/cols/cols.scss +6 -12
- package/src/components/confirm/confirm.component.ts +7 -0
- package/src/components/copy-button/copy-button.component.ts +12 -11
- package/src/components/data-select/data-select.component.ts +215 -44
- package/src/components/data-select/data-select.scss +66 -6
- package/src/components/data-select/providers/currency-data-provider.ts +20 -6
- package/src/components/data-select/providers/provider.ts +1 -0
- package/src/components/data-select/providers/us-state-data-provider.ts +68 -0
- package/src/components/data-table/data-table.component.ts +81 -22
- package/src/components/data-table-search/data-table-search.component.ts +184 -0
- package/src/components/data-table-search/data-table-search.scss +17 -0
- package/src/components/data-table-search/data-table-search.test.ts +11 -0
- package/src/components/data-table-search/index.ts +12 -0
- package/src/components/datepicker/datepicker.component.ts +347 -13
- package/src/components/dialog/dialog.component.ts +1 -1
- package/src/components/empty-state/empty-state.scss +6 -1
- package/src/components/header/header.scss +3 -3
- package/src/components/icon/icon.component.ts +23 -1
- package/src/components/icon/icon.scss +23 -0
- package/src/components/icon-picker/brand-icons.ts +24 -0
- package/src/components/icon-picker/icon-picker.component.ts +407 -0
- package/src/components/icon-picker/icon-picker.scss +205 -0
- package/src/components/icon-picker/index.ts +12 -0
- package/src/components/icon-picker/line-icons.ts +612 -0
- package/src/components/icon-picker/material-icons.ts +14543 -0
- package/src/components/inline-edit/inline-edit.component.ts +190 -46
- package/src/components/inline-edit/inline-edit.scss +29 -0
- package/src/components/inline-edit/inline-edit.test.ts +314 -1
- package/src/components/input/input.component.ts +324 -5
- package/src/components/input/input.scss +87 -0
- package/src/components/input-group/input-group.component.ts +28 -7
- package/src/components/input-group/input-group.scss +48 -10
- package/src/components/item/item.component.ts +24 -3
- package/src/components/item/item.scss +18 -0
- package/src/components/key/index.ts +12 -0
- package/src/components/key/key.component.ts +47 -0
- package/src/components/key/key.scss +38 -0
- package/src/components/key-container/index.ts +12 -0
- package/src/components/key-container/key-container.component.ts +142 -0
- package/src/components/key-container/key-container.scss +33 -0
- package/src/components/menu-item/menu-item.component.ts +20 -0
- package/src/components/menu-item/menu-item.scss +69 -2
- package/src/components/navbar/navbar.component.ts +103 -11
- package/src/components/navbar/navbar.scss +6 -1
- package/src/components/opt-group/index.ts +12 -0
- package/src/components/opt-group/opt-group.component.ts +74 -0
- package/src/components/opt-group/opt-group.scss +37 -0
- package/src/components/opt-group/opt-group.test.ts +27 -0
- package/src/components/option/option.component.ts +1 -16
- package/src/components/option/option.scss +4 -0
- package/src/components/panel/panel.component.ts +10 -8
- package/src/components/panel/panel.scss +20 -0
- package/src/components/priority-list/index.ts +12 -0
- package/src/components/priority-list/priority-list.component.ts +611 -0
- package/src/components/priority-list/priority-list.scss +185 -0
- package/src/components/priority-list/priority-list.test.ts +139 -0
- package/src/components/progress-bar/progress-bar.component.ts +22 -16
- package/src/components/radio/radio.scss +10 -3
- package/src/components/select/select.component.ts +812 -72
- package/src/components/select/select.scss +108 -2
- package/src/components/select/select.test.ts +147 -2
- package/src/components/settings-container/settings-container.component.ts +44 -19
- package/src/components/settings-container/settings-container.scss +1 -1
- package/src/components/skeleton/skeleton.component.ts +6 -1
- package/src/components/slideout/slideout.scss +8 -3
- package/src/components/sp/sp.component.ts +3 -1
- package/src/components/sp/sp.scss +19 -0
- package/src/components/stepper/stepper.component.ts +16 -10
- package/src/components/textarea/textarea.scss +0 -4
- package/src/components/tile/tile.component.ts +12 -3
- package/src/components/tile/tile.scss +1 -1
- package/src/components/timer/timer.component.ts +15 -2
- package/src/components/toggle/toggle.component.ts +29 -26
- package/src/components/toggle/toggle.scss +13 -1
- package/src/components/translation-group/index.ts +12 -0
- package/src/components/translation-group/translation-group.component.ts +207 -0
- package/src/components/translation-group/translation-group.scss +8 -0
- package/src/components/translations/translations.component.ts +90 -44
- package/src/components/translations/translations.scss +4 -0
- package/src/components/vertical-stepper/vertical-stepper.component.ts +14 -9
- package/src/events/events.ts +12 -7
- package/src/events/zn-language-change.ts +7 -0
- package/src/events/zn-purchase.ts +11 -0
- package/src/events/zn-redirect.ts +7 -0
- package/src/events/zn-reorder.ts +7 -0
- package/src/events/zn-search-change.ts +11 -0
- package/src/events/zn-submit.ts +1 -1
- package/src/form-control.scss +4 -0
- package/src/internal/form-navigation.ts +510 -0
- package/src/internal/form.ts +6 -0
- package/src/zinc.ts +91 -83
|
@@ -1,92 +1,439 @@
|
|
|
1
1
|
---
|
|
2
2
|
meta:
|
|
3
3
|
title: Collapsible
|
|
4
|
-
description:
|
|
4
|
+
description: Collapsibles toggle between showing and hiding content when clicked, useful for organizing information in a compact, expandable format.
|
|
5
5
|
layout: component
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
+
Collapsibles provide an interactive way to show and hide content. They're ideal for accordion-style interfaces, settings panels, and any scenario where you need to progressively disclose information.
|
|
9
|
+
|
|
8
10
|
```html:preview
|
|
9
|
-
<zn-collapsible caption="
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
<
|
|
14
|
-
<zn-icon src="android"></zn-icon>
|
|
11
|
+
<zn-collapsible caption="Basic Collapsible"
|
|
12
|
+
description="Click to expand and view the content"
|
|
13
|
+
label="Optional Label">
|
|
14
|
+
<p>This is the collapsible content that can be toggled on and off.</p>
|
|
15
|
+
<zn-button>Action Button</zn-button>
|
|
15
16
|
</zn-collapsible>
|
|
16
17
|
```
|
|
17
18
|
|
|
18
19
|
## Examples
|
|
19
20
|
|
|
20
|
-
###
|
|
21
|
+
### Basic Usage
|
|
22
|
+
|
|
23
|
+
A simple collapsible with caption and description. Click anywhere on the header to expand or collapse.
|
|
24
|
+
|
|
25
|
+
```html:preview
|
|
26
|
+
<zn-collapsible caption="Click to expand"
|
|
27
|
+
description="Additional description text">
|
|
28
|
+
<p>This content is hidden by default and revealed when you click the header.</p>
|
|
29
|
+
</zn-collapsible>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Expanded State
|
|
33
|
+
|
|
34
|
+
Use the `expanded` attribute to show the collapsible in its open state by default.
|
|
35
|
+
|
|
36
|
+
```html:preview
|
|
37
|
+
<zn-collapsible caption="Already Expanded"
|
|
38
|
+
description="This collapsible starts in the open state"
|
|
39
|
+
expanded>
|
|
40
|
+
<p>This content is visible by default because the expanded attribute is set.</p>
|
|
41
|
+
<zn-button>Click Me</zn-button>
|
|
42
|
+
</zn-collapsible>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Default State
|
|
21
46
|
|
|
22
|
-
|
|
47
|
+
Use the `default` attribute to set the initial state. This is useful when you want to control the default behavior without directly manipulating the `expanded` property.
|
|
23
48
|
|
|
24
49
|
```html:preview
|
|
25
50
|
<zn-collapsible caption="Default Open"
|
|
26
|
-
|
|
27
|
-
description="Setting the default state show the element in it's open state on load"
|
|
51
|
+
description="Using the default attribute for initial state"
|
|
28
52
|
default="open">
|
|
29
|
-
<
|
|
30
|
-
|
|
53
|
+
<p>This collapsible opens by default using the 'default' attribute.</p>
|
|
54
|
+
</zn-collapsible>
|
|
55
|
+
|
|
56
|
+
<br />
|
|
57
|
+
|
|
58
|
+
<zn-collapsible caption="Default Closed"
|
|
59
|
+
description="This is the default behavior"
|
|
60
|
+
default="closed">
|
|
61
|
+
<p>This collapsible starts closed (default behavior).</p>
|
|
62
|
+
</zn-collapsible>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### With Label
|
|
66
|
+
|
|
67
|
+
Use the `label` attribute to add a label on the right side of the header.
|
|
68
|
+
|
|
69
|
+
```html:preview
|
|
70
|
+
<zn-collapsible caption="Section Title"
|
|
71
|
+
description="Optional description"
|
|
72
|
+
label="v2.0">
|
|
73
|
+
<p>Labels are useful for displaying version numbers, status, or other metadata.</p>
|
|
74
|
+
</zn-collapsible>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Item Counter
|
|
78
|
+
|
|
79
|
+
Use the `show-number` attribute to display a count of items within the collapsible. The count appears as a chip when the collapsible is closed.
|
|
80
|
+
|
|
81
|
+
```html:preview
|
|
82
|
+
<zn-collapsible caption="Team Members"
|
|
83
|
+
description="View all team members"
|
|
84
|
+
show-number>
|
|
85
|
+
<div>Alice Johnson</div>
|
|
86
|
+
<div>Bob Smith</div>
|
|
87
|
+
<div>Carol Williams</div>
|
|
88
|
+
<div>David Brown</div>
|
|
89
|
+
</zn-collapsible>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Custom Element Counter
|
|
93
|
+
|
|
94
|
+
Use the `count-element` attribute to count specific elements instead of all children. This is useful when you have complex content structures.
|
|
95
|
+
|
|
96
|
+
```html:preview
|
|
97
|
+
<zn-collapsible caption="Active Users"
|
|
98
|
+
description="Users currently online"
|
|
99
|
+
show-number
|
|
100
|
+
count-element="zn-chip">
|
|
101
|
+
<div>
|
|
102
|
+
<zn-chip>User 1</zn-chip>
|
|
103
|
+
<zn-chip>User 2</zn-chip>
|
|
104
|
+
<zn-chip>User 3</zn-chip>
|
|
105
|
+
</div>
|
|
106
|
+
<p>Additional content that won't be counted</p>
|
|
31
107
|
</zn-collapsible>
|
|
32
108
|
```
|
|
33
109
|
|
|
34
|
-
###
|
|
110
|
+
### Flush Content
|
|
111
|
+
|
|
112
|
+
Use the `flush` attribute to remove the left padding/margin from the content area, making it align with the edges.
|
|
113
|
+
|
|
114
|
+
```html:preview
|
|
115
|
+
<zn-collapsible caption="Flush Content"
|
|
116
|
+
description="No left padding on content"
|
|
117
|
+
flush>
|
|
118
|
+
<zn-button>This button aligns with the left edge</zn-button>
|
|
119
|
+
<p>Content starts at the container edge</p>
|
|
120
|
+
</zn-collapsible>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Custom Header Slot
|
|
124
|
+
|
|
125
|
+
Use the `header` slot to completely customize the header appearance and behavior.
|
|
126
|
+
|
|
127
|
+
```html:preview
|
|
128
|
+
<zn-collapsible>
|
|
129
|
+
<div slot="header" style="padding: 1rem; background: var(--zn-color-primary-50); display: flex; justify-content: space-between; align-items: center;">
|
|
130
|
+
<strong>Custom Header Design</strong>
|
|
131
|
+
<zn-icon src="expand_more" class="expand"></zn-icon>
|
|
132
|
+
</div>
|
|
133
|
+
<p>When you provide a custom header, you have full control over its appearance.</p>
|
|
134
|
+
</zn-collapsible>
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Custom Caption Slot
|
|
138
|
+
|
|
139
|
+
Use the `caption` slot to add custom content to the caption area, such as icons, badges, or toggles.
|
|
140
|
+
|
|
141
|
+
```html:preview
|
|
142
|
+
<zn-collapsible>
|
|
143
|
+
<div slot="caption" style="display: flex; align-items: center; gap: 0.5rem;">
|
|
144
|
+
<zn-icon src="settings"></zn-icon>
|
|
145
|
+
<span>Settings Section</span>
|
|
146
|
+
<zn-chip size="small" type="info">New</zn-chip>
|
|
147
|
+
</div>
|
|
148
|
+
<p>The caption slot allows you to add custom elements to the title area.</p>
|
|
149
|
+
</zn-collapsible>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### With Toggle Controls
|
|
153
|
+
|
|
154
|
+
Integrate toggles into the caption slot to create settings panels. The collapsible automatically detects toggles and adjusts the UI accordingly.
|
|
35
155
|
|
|
36
156
|
```html:preview
|
|
157
|
+
<zn-collapsible caption="Notification Settings">
|
|
158
|
+
<div class="flex-mid" slot="caption">
|
|
159
|
+
<div class="grow zn-pr">Email Notifications</div>
|
|
160
|
+
<zn-toggle name="email-enabled"></zn-toggle>
|
|
161
|
+
</div>
|
|
162
|
+
<div style="padding: 1rem;">
|
|
163
|
+
<zn-toggle name="marketing" size="medium">Marketing emails</zn-toggle>
|
|
164
|
+
<br />
|
|
165
|
+
<zn-toggle name="updates" size="medium" checked>Product updates</zn-toggle>
|
|
166
|
+
<br />
|
|
167
|
+
<zn-toggle name="alerts" size="medium" checked>Security alerts</zn-toggle>
|
|
168
|
+
</div>
|
|
169
|
+
</zn-collapsible>
|
|
170
|
+
```
|
|
37
171
|
|
|
38
|
-
|
|
172
|
+
### Permission Panel Example
|
|
173
|
+
|
|
174
|
+
A practical example showing how to build a permission management interface.
|
|
175
|
+
|
|
176
|
+
```html:preview
|
|
177
|
+
<zn-collapsible>
|
|
39
178
|
<div class="flex-mid" slot="caption">
|
|
40
|
-
<div class="grow zn-pr">Billing</div>
|
|
41
|
-
<zn-toggle name="enabled"></zn-toggle>
|
|
179
|
+
<div class="grow zn-pr">Billing Permissions</div>
|
|
180
|
+
<zn-toggle name="billing-enabled" checked></zn-toggle>
|
|
42
181
|
</div>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
<div class="flex-mid">
|
|
51
|
-
<zn-toggle class="permission-toggle" name="enabled" value="1" fallback="0" size="medium">
|
|
52
|
-
</zn-toggle>
|
|
182
|
+
|
|
183
|
+
<div style="display: flex; flex-direction: column; gap: 0.5rem;">
|
|
184
|
+
<div style="display: flex; justify-content: space-between; align-items: center; padding: 1rem; border-bottom: 1px solid var(--zn-color-neutral-200);">
|
|
185
|
+
<div>
|
|
186
|
+
<strong>View Invoices</strong>
|
|
187
|
+
<div style="font-size: 0.875rem; color: var(--zn-color-neutral-600);">
|
|
188
|
+
Can view all billing invoices
|
|
53
189
|
</div>
|
|
54
190
|
</div>
|
|
191
|
+
<zn-toggle name="view-invoices" size="medium" checked></zn-toggle>
|
|
55
192
|
</div>
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
<div
|
|
61
|
-
|
|
62
|
-
<span>Example Permission 2 Description</span>
|
|
193
|
+
|
|
194
|
+
<div style="display: flex; justify-content: space-between; align-items: center; padding: 1rem; border-bottom: 1px solid var(--zn-color-neutral-200);">
|
|
195
|
+
<div>
|
|
196
|
+
<strong>Manage Payment Methods</strong>
|
|
197
|
+
<div style="font-size: 0.875rem; color: var(--zn-color-neutral-600);">
|
|
198
|
+
Can add or remove payment methods
|
|
63
199
|
</div>
|
|
64
|
-
|
|
65
|
-
|
|
200
|
+
</div>
|
|
201
|
+
<zn-toggle name="manage-payments" size="medium"></zn-toggle>
|
|
202
|
+
</div>
|
|
203
|
+
|
|
204
|
+
<div style="display: flex; justify-content: space-between; align-items: center; padding: 1rem;">
|
|
205
|
+
<div>
|
|
206
|
+
<strong>Process Refunds</strong>
|
|
207
|
+
<div style="font-size: 0.875rem; color: var(--zn-color-neutral-600);">
|
|
208
|
+
Can issue refunds to customers
|
|
66
209
|
</div>
|
|
67
210
|
</div>
|
|
211
|
+
<zn-toggle name="process-refunds" size="medium"></zn-toggle>
|
|
68
212
|
</div>
|
|
69
213
|
</div>
|
|
70
214
|
</zn-collapsible>
|
|
71
215
|
```
|
|
72
216
|
|
|
73
|
-
###
|
|
217
|
+
### State Persistence with Session Storage
|
|
218
|
+
|
|
219
|
+
The collapsible can remember its state across page loads using session or local storage with the `store-key` attribute.
|
|
74
220
|
|
|
75
221
|
```html:preview
|
|
222
|
+
<zn-collapsible caption="Preferences"
|
|
223
|
+
description="State saved in session storage"
|
|
224
|
+
store-key="user-preferences">
|
|
225
|
+
<p>This collapsible's state will persist during your browser session.</p>
|
|
226
|
+
<p>Try expanding or collapsing it, then refresh the page.</p>
|
|
227
|
+
</zn-collapsible>
|
|
228
|
+
```
|
|
76
229
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
230
|
+
### State Persistence with Local Storage
|
|
231
|
+
|
|
232
|
+
Use the `local-storage` attribute to persist state permanently across browser sessions.
|
|
233
|
+
|
|
234
|
+
```html:preview
|
|
235
|
+
<zn-collapsible caption="Advanced Settings"
|
|
236
|
+
description="State saved permanently"
|
|
237
|
+
store-key="advanced-settings"
|
|
238
|
+
local-storage>
|
|
239
|
+
<p>This collapsible's state persists even after closing the browser.</p>
|
|
240
|
+
<p>The state is stored in localStorage instead of sessionStorage.</p>
|
|
241
|
+
</zn-collapsible>
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Storage with TTL
|
|
245
|
+
|
|
246
|
+
Use the `store-ttl` attribute to set a time-to-live (in seconds) for the stored state.
|
|
247
|
+
|
|
248
|
+
```html:preview
|
|
249
|
+
<zn-collapsible caption="Temporary State"
|
|
250
|
+
description="State expires after 60 seconds"
|
|
251
|
+
store-key="temporary-state"
|
|
252
|
+
store-ttl="60">
|
|
253
|
+
<p>This collapsible's state will be remembered for 60 seconds.</p>
|
|
254
|
+
<p>After that, it will revert to the default closed state.</p>
|
|
81
255
|
</zn-collapsible>
|
|
82
256
|
```
|
|
83
257
|
|
|
84
|
-
###
|
|
258
|
+
### Accordion Pattern
|
|
259
|
+
|
|
260
|
+
Create an accordion by grouping multiple collapsibles together.
|
|
85
261
|
|
|
86
262
|
```html:preview
|
|
87
|
-
<zn-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
263
|
+
<div style="border: 1px solid var(--zn-color-neutral-200); border-radius: 4px; overflow: hidden;">
|
|
264
|
+
<zn-collapsible caption="Section 1"
|
|
265
|
+
description="First section details"
|
|
266
|
+
default="open">
|
|
267
|
+
<p>Content for section 1.</p>
|
|
268
|
+
</zn-collapsible>
|
|
269
|
+
|
|
270
|
+
<zn-collapsible caption="Section 2"
|
|
271
|
+
description="Second section details">
|
|
272
|
+
<p>Content for section 2.</p>
|
|
273
|
+
</zn-collapsible>
|
|
274
|
+
|
|
275
|
+
<zn-collapsible caption="Section 3"
|
|
276
|
+
description="Third section details">
|
|
277
|
+
<p>Content for section 3.</p>
|
|
278
|
+
</zn-collapsible>
|
|
279
|
+
</div>
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Nested Collapsibles
|
|
283
|
+
|
|
284
|
+
Collapsibles can be nested to create hierarchical content structures.
|
|
285
|
+
|
|
286
|
+
```html:preview
|
|
287
|
+
<zn-collapsible caption="Parent Section" expanded>
|
|
288
|
+
<p>This is the parent content.</p>
|
|
289
|
+
|
|
290
|
+
<zn-collapsible caption="Child Section 1" flush>
|
|
291
|
+
<p>Nested collapsible content 1</p>
|
|
292
|
+
</zn-collapsible>
|
|
293
|
+
|
|
294
|
+
<zn-collapsible caption="Child Section 2" flush>
|
|
295
|
+
<p>Nested collapsible content 2</p>
|
|
296
|
+
</zn-collapsible>
|
|
297
|
+
</zn-collapsible>
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### Programmatic Control
|
|
301
|
+
|
|
302
|
+
You can control the collapsible programmatically by setting the `expanded` property.
|
|
303
|
+
|
|
304
|
+
```html:preview
|
|
305
|
+
<zn-collapsible id="programmatic-collapsible"
|
|
306
|
+
caption="Programmatic Control"
|
|
307
|
+
description="Control via JavaScript">
|
|
308
|
+
<p>This collapsible can be controlled programmatically.</p>
|
|
91
309
|
</zn-collapsible>
|
|
310
|
+
|
|
311
|
+
<br />
|
|
312
|
+
|
|
313
|
+
<zn-button id="expand-btn">Expand</zn-button>
|
|
314
|
+
<zn-button id="collapse-btn" color="secondary">Collapse</zn-button>
|
|
315
|
+
<zn-button id="toggle-btn" color="info">Toggle</zn-button>
|
|
316
|
+
|
|
317
|
+
<script type="module">
|
|
318
|
+
const collapsible = document.getElementById('programmatic-collapsible');
|
|
319
|
+
|
|
320
|
+
document.getElementById('expand-btn').addEventListener('click', () => {
|
|
321
|
+
collapsible.expanded = true;
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
document.getElementById('collapse-btn').addEventListener('click', () => {
|
|
325
|
+
collapsible.expanded = false;
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
document.getElementById('toggle-btn').addEventListener('click', () => {
|
|
329
|
+
collapsible.expanded = !collapsible.expanded;
|
|
330
|
+
});
|
|
331
|
+
</script>
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### State Change Detection
|
|
335
|
+
|
|
336
|
+
Monitor the collapsible's state changes using property observation or mutation observers.
|
|
337
|
+
|
|
338
|
+
```html:preview
|
|
339
|
+
<zn-collapsible id="state-monitor"
|
|
340
|
+
caption="State Monitor"
|
|
341
|
+
description="Watch for state changes">
|
|
342
|
+
<p>Click the header to expand or collapse.</p>
|
|
343
|
+
</zn-collapsible>
|
|
344
|
+
|
|
345
|
+
<div id="state-output" style="margin-top: 1rem; padding: 1rem; background: var(--zn-color-neutral-100); border-radius: 4px;">
|
|
346
|
+
<strong>State:</strong> <span id="state-text">Collapsed</span>
|
|
347
|
+
</div>
|
|
348
|
+
|
|
349
|
+
<script type="module">
|
|
350
|
+
const collapsible = document.getElementById('state-monitor');
|
|
351
|
+
const stateText = document.getElementById('state-text');
|
|
352
|
+
|
|
353
|
+
// Use a MutationObserver to watch for attribute changes
|
|
354
|
+
const observer = new MutationObserver((mutations) => {
|
|
355
|
+
mutations.forEach((mutation) => {
|
|
356
|
+
if (mutation.type === 'attributes' && mutation.attributeName === 'expanded') {
|
|
357
|
+
const isExpanded = collapsible.hasAttribute('expanded');
|
|
358
|
+
stateText.textContent = isExpanded ? 'Expanded' : 'Collapsed';
|
|
359
|
+
stateText.style.color = isExpanded ? 'var(--zn-color-success)' : 'var(--zn-color-neutral-600)';
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
observer.observe(collapsible, { attributes: true });
|
|
365
|
+
</script>
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### Methods
|
|
369
|
+
|
|
370
|
+
The collapsible provides a public method for recalculating item counts:
|
|
371
|
+
|
|
372
|
+
- `recalculateNumberOfItems()` - Recalculates the number of items when using `show-number`. Useful when content is dynamically updated.
|
|
373
|
+
|
|
374
|
+
```html:preview
|
|
375
|
+
<zn-collapsible id="dynamic-collapsible"
|
|
376
|
+
caption="Dynamic Items"
|
|
377
|
+
description="Items can be added dynamically"
|
|
378
|
+
show-number>
|
|
379
|
+
<div id="item-container">
|
|
380
|
+
<div>Item 1</div>
|
|
381
|
+
</div>
|
|
382
|
+
</zn-collapsible>
|
|
383
|
+
|
|
384
|
+
<br />
|
|
385
|
+
|
|
386
|
+
<zn-button id="add-item-btn">Add Item</zn-button>
|
|
387
|
+
|
|
388
|
+
<script type="module">
|
|
389
|
+
const collapsible = document.getElementById('dynamic-collapsible');
|
|
390
|
+
const container = document.getElementById('item-container');
|
|
391
|
+
let itemCount = 1;
|
|
392
|
+
|
|
393
|
+
document.getElementById('add-item-btn').addEventListener('click', () => {
|
|
394
|
+
itemCount++;
|
|
395
|
+
const newItem = document.createElement('div');
|
|
396
|
+
newItem.textContent = `Item ${itemCount}`;
|
|
397
|
+
container.appendChild(newItem);
|
|
398
|
+
|
|
399
|
+
// Manually trigger recalculation
|
|
400
|
+
collapsible.recalculateNumberOfItems();
|
|
401
|
+
});
|
|
402
|
+
</script>
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
### Complete Example
|
|
406
|
+
|
|
407
|
+
A comprehensive example demonstrating multiple features together.
|
|
408
|
+
|
|
409
|
+
```html:preview
|
|
410
|
+
<div style="max-width: 600px;">
|
|
411
|
+
<zn-collapsible
|
|
412
|
+
caption="User Profile Settings"
|
|
413
|
+
description="Manage your profile preferences"
|
|
414
|
+
label="Required"
|
|
415
|
+
show-number
|
|
416
|
+
count-element="zn-toggle"
|
|
417
|
+
store-key="profile-settings"
|
|
418
|
+
local-storage>
|
|
419
|
+
|
|
420
|
+
<div style="display: flex; flex-direction: column; gap: 1rem; padding: 1rem;">
|
|
421
|
+
<div>
|
|
422
|
+
<h4 style="margin: 0 0 0.5rem 0;">Privacy Settings</h4>
|
|
423
|
+
<zn-toggle name="profile-public" checked>Make profile public</zn-toggle>
|
|
424
|
+
<zn-toggle name="show-email">Show email address</zn-toggle>
|
|
425
|
+
<zn-toggle name="show-phone">Show phone number</zn-toggle>
|
|
426
|
+
</div>
|
|
427
|
+
|
|
428
|
+
<div>
|
|
429
|
+
<h4 style="margin: 0 0 0.5rem 0;">Notification Preferences</h4>
|
|
430
|
+
<zn-toggle name="email-notifications" checked>Email notifications</zn-toggle>
|
|
431
|
+
<zn-toggle name="sms-notifications">SMS notifications</zn-toggle>
|
|
432
|
+
<zn-toggle name="push-notifications" checked>Push notifications</zn-toggle>
|
|
433
|
+
</div>
|
|
434
|
+
|
|
435
|
+
<zn-button color="primary">Save Changes</zn-button>
|
|
436
|
+
</div>
|
|
437
|
+
</zn-collapsible>
|
|
438
|
+
</div>
|
|
92
439
|
```
|