solid-tom-ui 1.0.11 → 1.0.14
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 +246 -246
- package/dist/README.md +246 -246
- package/dist/components/avatar/avatar.js.map +1 -1
- package/dist/components/badge/badge.js.map +1 -1
- package/dist/components/breadcrumb/breadcrumb.js.map +1 -1
- package/dist/components/button/button.js.map +1 -1
- package/dist/components/carousel/carousel.js.map +1 -1
- package/dist/components/chat-bubble/chatBubble.js.map +1 -1
- package/dist/components/checkbox/checkbox.js.map +1 -1
- package/dist/components/collapse/collapse.js.map +1 -1
- package/dist/components/context-menu/context-menu.js.map +1 -1
- package/dist/components/context-menu/context-menu.store.js.map +1 -1
- package/dist/components/divider/divider.js.map +1 -1
- package/dist/components/dropdown/dropdown.js.map +1 -1
- package/dist/components/dropdown/dropdown.store.js.map +1 -1
- package/dist/components/float-button/float-button.js.map +1 -1
- package/dist/components/hover-3d-image/hover-3d-image.js.map +1 -1
- package/dist/components/image-preview/image-preview.js.map +1 -1
- package/dist/components/input/input.js.map +1 -1
- package/dist/components/input/input.utils.js.map +1 -1
- package/dist/components/input/variants/input-color.js.map +1 -1
- package/dist/components/input/variants/input-date.js.map +1 -1
- package/dist/components/input/variants/input-number.d.ts.map +1 -1
- package/dist/components/input/variants/input-number.js +1 -1
- package/dist/components/input/variants/input-number.js.map +1 -1
- package/dist/components/input/variants/input-otp.js.map +1 -1
- package/dist/components/input/variants/input-password.js.map +1 -1
- package/dist/components/input/variants/input-radio.js.map +1 -1
- package/dist/components/input/variants/input-range.js.map +1 -1
- package/dist/components/input/variants/input-text.d.ts.map +1 -1
- package/dist/components/input/variants/input-text.js +1 -1
- package/dist/components/input/variants/input-text.js.map +1 -1
- package/dist/components/input/variants/input-textarea.js.map +1 -1
- package/dist/components/loading/loading.js.map +1 -1
- package/dist/components/mansory/mansory.js.map +1 -1
- package/dist/components/menu/menu.js.map +1 -1
- package/dist/components/modal/modal.js.map +1 -1
- package/dist/components/modal/modalContext.js.map +1 -1
- package/dist/components/pagination/pagination.js.map +1 -1
- package/dist/components/progress-bar/progress-bar.js.map +1 -1
- package/dist/components/qr-code/qr-code.js.map +1 -1
- package/dist/components/select/select.js.map +1 -1
- package/dist/components/select-zone/select-zone.js.map +1 -1
- package/dist/components/skeleton/skeleton.js.map +1 -1
- package/dist/components/slider/slider.js.map +1 -1
- package/dist/components/splitter/splitter.js.map +1 -1
- package/dist/components/steps/steps.js.map +1 -1
- package/dist/components/swap/swap.js.map +1 -1
- package/dist/components/switch/switch.js.map +1 -1
- package/dist/components/tab/tab.js.map +1 -1
- package/dist/components/table/table.js.map +1 -1
- package/dist/components/timeline/timeline.js.map +1 -1
- package/dist/components/toast/icons/ErrorIcon.js.map +1 -1
- package/dist/components/toast/icons/IconCircle.js.map +1 -1
- package/dist/components/toast/icons/InfoIcon.js.map +1 -1
- package/dist/components/toast/icons/LoaderIcon.js.map +1 -1
- package/dist/components/toast/icons/SuccessIcon.js.map +1 -1
- package/dist/components/toast/icons/WarningIcon.js.map +1 -1
- package/dist/components/toast/toast.js.map +1 -1
- package/dist/components/toast/toast.store.js.map +1 -1
- package/dist/components/tooltip/tooltip.js.map +1 -1
- package/dist/components/tour/tour.js.map +1 -1
- package/dist/components/upload/upload.js.map +1 -1
- package/dist/components/z-index/z-index.context.js.map +1 -1
- package/dist/components/z-index/z-index.js.map +1 -1
- package/dist/components/z-index/z-index.store.js.map +1 -1
- package/dist/components/z-index/z-index.types.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/skill/avatar.skill.md.txt +255 -255
- package/dist/skill/badge.skill.md.txt +223 -223
- package/dist/skill/breadcrumb.skill.md.txt +177 -177
- package/dist/skill/button.skill.md.txt +198 -198
- package/dist/skill/carousel.skill.md.txt +406 -406
- package/dist/skill/chat-bubble.skill.md.txt +342 -342
- package/dist/skill/checkbox.skill.md.txt +326 -326
- package/dist/skill/code-preview.skill.md.txt +240 -240
- package/dist/skill/collapse.skill.md.txt +329 -329
- package/dist/skill/context-menu.skill.md.txt +233 -233
- package/dist/skill/diff.skill.md.txt +244 -244
- package/dist/skill/divider.skill.md.txt +151 -151
- package/dist/skill/doc.skill.md.txt +191 -191
- package/dist/skill/drawer.skill.md.txt +157 -157
- package/dist/skill/dropdown.skill.md.txt +198 -198
- package/dist/skill/float-button.skill.md.txt +315 -315
- package/dist/skill/hover-3d-image.skill.md.txt +120 -120
- package/dist/skill/iframe.skill.md.txt +114 -114
- package/dist/skill/image-preview.skill.md.txt +162 -162
- package/dist/skill/indicator.skill.md.txt +60 -60
- package/dist/skill/input.skill.md.txt +489 -489
- package/dist/skill/loading.skill.md.txt +127 -127
- package/dist/skill/menu.skill.md.txt +476 -476
- package/dist/skill/modal.skill.md.txt +359 -359
- package/dist/skill/pagination.skill.md.txt +405 -405
- package/dist/skill/progress-bar.skill.md.txt +207 -207
- package/dist/skill/qr-code.skill.md.txt +136 -136
- package/dist/skill/rating.skill.md.txt +167 -167
- package/dist/skill/select-zone.skill.md.txt +93 -93
- package/dist/skill/select.skill.md.txt +663 -663
- package/dist/skill/skeleton.skill.md.txt +192 -192
- package/dist/skill/slider.skill.md.txt +404 -404
- package/dist/skill/splitter.skill.md.txt +411 -411
- package/dist/skill/steps.skill.md.txt +264 -264
- package/dist/skill/swap.skill.md.txt +139 -139
- package/dist/skill/switch.skill.md.txt +191 -191
- package/dist/skill/tab.skill.md.txt +484 -484
- package/dist/skill/table.example.header.md.txt +666 -666
- package/dist/skill/table.skill.md.txt +1407 -1407
- package/dist/skill/text-rotate.skill.md.txt +186 -186
- package/dist/skill/timeline.skill.md.txt +247 -247
- package/dist/skill/toast.skill.md.txt +531 -531
- package/dist/skill/tooltip.skill.md.txt +222 -222
- package/dist/skill/tour.skill.md.txt +156 -156
- package/dist/skill/upload.skill.md.txt +358 -358
- package/dist/utils/cn.js.map +1 -1
- package/dist/utils/element-tracker.js.map +1 -1
- package/dist/utils/helper.js.map +1 -1
- package/dist/utils/hoc.js.map +1 -1
- package/package.json +132 -133
|
@@ -1,329 +1,329 @@
|
|
|
1
|
-
## COMPONENT IDENTITY
|
|
2
|
-
- **Import**: `import { Collapse } from 'solid-tom-ui';`
|
|
3
|
-
- **Export**: `Collapse` (named export)
|
|
4
|
-
- **Framework**: SolidJS
|
|
5
|
-
- **Purpose**: Collapsible panel — NOT a `ParentComponent`; content passed via `content` prop
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## TYPE SIGNATURE
|
|
10
|
-
|
|
11
|
-
```ts
|
|
12
|
-
interface CollapseProps {
|
|
13
|
-
title: string; // REQUIRED — header text
|
|
14
|
-
content: SolidComponent; // REQUIRED — body content (JSX, string, or function component)
|
|
15
|
-
icon?: {
|
|
16
|
-
type?: 'arrow' | 'plus'; // icon style; default: 'arrow'
|
|
17
|
-
postion?: 'start' | 'end'; // icon position; default: 'end'
|
|
18
|
-
};
|
|
19
|
-
force?: 'open' | 'close'; // controlled visibility — omit for uncontrolled
|
|
20
|
-
onOpen?: () => void; // callback when panel opens (uncontrolled only)
|
|
21
|
-
onClose?: () => void; // callback when panel closes (uncontrolled only)
|
|
22
|
-
id?: string; // id applied to the internal checkbox input
|
|
23
|
-
color?: BaseColorProps | 'transparent'; // semantic color theme; default: 'transparent'
|
|
24
|
-
class?: Partial<Record<'root' | 'title' | 'content', string>>;
|
|
25
|
-
}
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
---
|
|
29
|
-
|
|
30
|
-
## DEFAULT VALUES (via `mergeProps`)
|
|
31
|
-
|
|
32
|
-
| Prop | Default |
|
|
33
|
-
|-----------------|-----------------|
|
|
34
|
-
| `icon.type` | `'arrow'` |
|
|
35
|
-
| `icon.postion` | `'end'` |
|
|
36
|
-
| `color` | `'transparent'` |
|
|
37
|
-
|
|
38
|
-
---
|
|
39
|
-
|
|
40
|
-
## PROP REFERENCE
|
|
41
|
-
|
|
42
|
-
| Prop | Type | Required | Description |
|
|
43
|
-
|-----------------|-----------------------------------|----------|------------------------------------------------------------------------------------------|
|
|
44
|
-
| `title` | `string` | ✅ YES | Text shown in the collapse header bar |
|
|
45
|
-
| `content` | `SolidComponent` | ✅ YES | Content rendered in the collapsible body panel |
|
|
46
|
-
| `icon.type` | `'arrow' \| 'plus'` | ❌ NO | `'arrow'` → chevron icon; `'plus'` → plus/minus icon |
|
|
47
|
-
| `icon.postion` | `'start' \| 'end'` | ❌ NO | `'end'` → icon on right side (default); `'start'` → icon on left side |
|
|
48
|
-
| `force` | `'open' \| 'close'` | ❌ NO | Forces panel open or closed. When set, checkbox is removed and callbacks are ignored |
|
|
49
|
-
| `onOpen` | `() => void` | ❌ NO | Fired when user opens the panel (uncontrolled only — ignored when `force` is set) |
|
|
50
|
-
| `onClose` | `() => void` | ❌ NO | Fired when user closes the panel (uncontrolled only — ignored when `force` is set) |
|
|
51
|
-
| `id` | `string` | ❌ NO | `id` attribute on the internal `<input type="checkbox">` — enables external label links |
|
|
52
|
-
| `color` | `BaseColorProps \| 'transparent'` | ❌ NO | Semantic color theme — sets border, background tint, and title/icon color via `--color` |
|
|
53
|
-
| `class.root` | `string` | ❌ NO | Extra classes on the root `<div class="collapse">` |
|
|
54
|
-
| `class.title` | `string` | ❌ NO | Extra classes on `<div class="collapse-title">` |
|
|
55
|
-
| `class.content` | `string` | ❌ NO | Extra classes on `<div class="collapse-content">` |
|
|
56
|
-
|
|
57
|
-
> ⚠️ NOTE: `icon.postion` has a typo in source — it is `postion` (missing 'i'), not `position`. Use exactly `postion` when passing the prop.
|
|
58
|
-
|
|
59
|
-
---
|
|
60
|
-
|
|
61
|
-
## OPEN/CLOSE MODES
|
|
62
|
-
|
|
63
|
-
### Mode 1 — Uncontrolled (default, no `force` prop)
|
|
64
|
-
- An `<input type="checkbox">` is rendered inside the root div
|
|
65
|
-
- DaisyUI uses the checkbox checked state to show/hide the panel via CSS
|
|
66
|
-
- `onOpen` fires when checkbox becomes checked; `onClose` fires when unchecked
|
|
67
|
-
- `id` prop sets the checkbox's `id` — allows external `<label for="id">` to toggle the collapse
|
|
68
|
-
|
|
69
|
-
```tsx
|
|
70
|
-
<Collapse
|
|
71
|
-
title="What is SolidJS?"
|
|
72
|
-
content={<p>SolidJS is a declarative UI library.</p>}
|
|
73
|
-
onOpen={() => console.log('opened')}
|
|
74
|
-
onClose={() => console.log('closed')}
|
|
75
|
-
/>
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
### Mode 2 — Controlled (`force` prop)
|
|
79
|
-
- `force="open"` → adds `collapse-open` class, checkbox is **removed from DOM**
|
|
80
|
-
- `force="close"` → adds `collapse-close` class, checkbox is **removed from DOM**
|
|
81
|
-
- `onOpen` and `onClose` are **completely ignored** when `force` is set
|
|
82
|
-
- Toggling is the consumer's responsibility via a reactive signal
|
|
83
|
-
|
|
84
|
-
```tsx
|
|
85
|
-
const [status, setStatus] = createSignal<'open' | 'close'>('close');
|
|
86
|
-
|
|
87
|
-
<Button onClick={() => setStatus(s => s === 'open' ? 'close' : 'open')}>
|
|
88
|
-
Toggle
|
|
89
|
-
</Button>
|
|
90
|
-
|
|
91
|
-
<Collapse
|
|
92
|
-
title="Controlled Collapse"
|
|
93
|
-
content={<p>Controlled by external signal.</p>}
|
|
94
|
-
force={status()}
|
|
95
|
-
/>
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
### Mode 3 — Mixed: `force={undefined}` restores uncontrolled
|
|
99
|
-
- Passing `force={undefined}` (or not passing `force`) keeps the checkbox in the DOM
|
|
100
|
-
- Useful when signal can return `undefined` as a "no override" state
|
|
101
|
-
|
|
102
|
-
```tsx
|
|
103
|
-
// signal can be 'open' | 'close' | undefined
|
|
104
|
-
const [force, setForce] = createSignal<'open' | 'close' | undefined>(undefined);
|
|
105
|
-
|
|
106
|
-
<Collapse title="..." content="..." force={force()} />
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
---
|
|
110
|
-
|
|
111
|
-
## ICON VARIANTS
|
|
112
|
-
|
|
113
|
-
### `icon.type`
|
|
114
|
-
| Value | DaisyUI class | Visual |
|
|
115
|
-
|-----------|--------------------|----------------------------|
|
|
116
|
-
| `'arrow'` | `collapse-arrow` | Chevron (▼) rotates on open |
|
|
117
|
-
| `'plus'` | `collapse-plus` | Plus (+) changes to minus (−) on open |
|
|
118
|
-
|
|
119
|
-
### `icon.postion`
|
|
120
|
-
| Value | CSS effect |
|
|
121
|
-
|-----------|---------------------------------------------------------|
|
|
122
|
-
| `'end'` | Icon on the right side (default DaisyUI behavior) |
|
|
123
|
-
| `'start'` | Icon on the left side — applies `after:start-5 after:end-auto pe-4 ps-12` |
|
|
124
|
-
|
|
125
|
-
---
|
|
126
|
-
|
|
127
|
-
## `content` PROP — Accepts multiple forms
|
|
128
|
-
|
|
129
|
-
`SolidComponent` means the prop accepts:
|
|
130
|
-
|
|
131
|
-
```tsx
|
|
132
|
-
// 1. String literal
|
|
133
|
-
content="Plain text content"
|
|
134
|
-
|
|
135
|
-
// 2. JSX element
|
|
136
|
-
content={<p class="text-sm">Some <strong>HTML</strong> content</p>}
|
|
137
|
-
|
|
138
|
-
// 3. Function component (with own reactive state)
|
|
139
|
-
content={() => {
|
|
140
|
-
const [count, setCount] = createSignal(0);
|
|
141
|
-
return (
|
|
142
|
-
<Button onClick={() => setCount(c => c + 1)}>
|
|
143
|
-
Count = {count()}
|
|
144
|
-
</Button>
|
|
145
|
-
);
|
|
146
|
-
}}
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
> ℹ️ Function form is useful when the content needs its own SolidJS reactive state. The function is called as a component, preserving signal reactivity.
|
|
150
|
-
|
|
151
|
-
---
|
|
152
|
-
|
|
153
|
-
## INTERNAL DOM STRUCTURE
|
|
154
|
-
|
|
155
|
-
```
|
|
156
|
-
<div class="bg-base-100 border-base-300 collapse border collapse-arrow|plus [collapse-open|collapse-close] [class.root]">
|
|
157
|
-
│
|
|
158
|
-
├── <input type="checkbox" id="?" onChange={...} /> ← only when force is undefined
|
|
159
|
-
│
|
|
160
|
-
├── <div class="collapse-title font-semibold [iconPosition classes] [class.title]">
|
|
161
|
-
│ {title}
|
|
162
|
-
│ </div>
|
|
163
|
-
│
|
|
164
|
-
└── <div class="collapse-content text-sm [class.content]">
|
|
165
|
-
{content}
|
|
166
|
-
</div>
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
---
|
|
170
|
-
|
|
171
|
-
## `id` PROP — External trigger via `<label>`
|
|
172
|
-
|
|
173
|
-
The `id` is applied to the internal `<input type="checkbox">`, enabling an external `<label>` element to toggle the collapse without clicking the title bar directly:
|
|
174
|
-
|
|
175
|
-
```tsx
|
|
176
|
-
<label for="my-collapse" class="btn">Toggle from outside</label>
|
|
177
|
-
|
|
178
|
-
<Collapse
|
|
179
|
-
id="my-collapse"
|
|
180
|
-
title="Externally triggered"
|
|
181
|
-
content="Toggled by the label above"
|
|
182
|
-
/>
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
> ⚠️ `id` only works in uncontrolled mode — when `force` is set, the checkbox is removed from the DOM and the `id` has no effect.
|
|
186
|
-
|
|
187
|
-
---
|
|
188
|
-
|
|
189
|
-
## BEHAVIOR NOTES FOR AGENTS
|
|
190
|
-
|
|
191
|
-
1. **`force` removes the checkbox entirely** — when `force` is set, `<Show when={!p.force}>` evaluates to false and the `<input>` is unmounted. The DaisyUI `collapse-open`/`collapse-close` classes on the root div take over visibility control.
|
|
192
|
-
|
|
193
|
-
2. **`onOpen`/`onClose` are checkbox-based** — they fire on `onChange` of the checkbox, which only exists in uncontrolled mode. Setting `force` silently disables these callbacks with no error.
|
|
194
|
-
|
|
195
|
-
3. **`content` renders inside `collapse-content` with `text-sm`** — the wrapper always has `text-sm`. Override with `class.content` if larger text is needed.
|
|
196
|
-
|
|
197
|
-
4. **`title` is `string` only** — no JSX allowed in the title. For rich title content, use `class.title` to style and keep the text in `title`.
|
|
198
|
-
|
|
199
|
-
5. **`icon.postion` typo is intentional** — the source code has `postion` (not `position`). Always use `postion` in the prop object or TypeScript will error.
|
|
200
|
-
|
|
201
|
-
6. **Root div always has `bg-base-100 border-base-300 border`** — there is no prop to remove the border or background. Use `class.root` to override with Tailwind.
|
|
202
|
-
|
|
203
|
-
7. **Accordion pattern** — to build an accordion (only one item open at a time), use the native HTML behavior: give all checkboxes the same `name` attribute. However, this component does not expose a `name` prop — implement accordion via controlled `force` signals instead.
|
|
204
|
-
|
|
205
|
-
8. **`color` prop adds `sui-collapse` class** — when `color` is set to any value other than `'transparent'`, the class `sui-collapse` is added to the root div. This class uses `var(--color)` (set by `.color-primary` etc.) to apply border tint, background tint, title color, and icon color.
|
|
206
|
-
|
|
207
|
-
---
|
|
208
|
-
|
|
209
|
-
## COLOR SYSTEM
|
|
210
|
-
|
|
211
|
-
The `color` prop accepts any `BaseColorProps` value (`'primary' | 'neutral' | 'secondary' | 'accent' | 'info' | 'success' | 'warning' | 'error'`) or `'transparent'` (default — no color applied).
|
|
212
|
-
|
|
213
|
-
### How it works
|
|
214
|
-
1. `getColor(p.color)` maps the value to a CSS class (e.g. `color-primary`) that sets `--color: var(--color-primary)`.
|
|
215
|
-
2. When color is not `'transparent'`, the class `sui-collapse` is also added — this class consumes `var(--color)` to style the collapse:
|
|
216
|
-
- **Border**: `color-mix(in oklch, var(--color) 30%, var(--color-base-300))`
|
|
217
|
-
- **Background**: `color-mix(in oklch, var(--color) 5%, var(--color-base-100))` — a subtle tint
|
|
218
|
-
- **Title text**: `var(--color)`
|
|
219
|
-
- **Icon (arrow/plus)**: `var(--color)` via `::after` pseudo-element
|
|
220
|
-
|
|
221
|
-
```tsx
|
|
222
|
-
// All 8 color variants
|
|
223
|
-
<Collapse color="primary" title="Primary" content="..." />
|
|
224
|
-
<Collapse color="secondary" title="Secondary" content="..." />
|
|
225
|
-
<Collapse color="accent" title="Accent" content="..." />
|
|
226
|
-
<Collapse color="neutral" title="Neutral" content="..." />
|
|
227
|
-
<Collapse color="info" title="Info" content="..." />
|
|
228
|
-
<Collapse color="success" title="Success" content="..." />
|
|
229
|
-
<Collapse color="warning" title="Warning" content="..." />
|
|
230
|
-
<Collapse color="error" title="Error" content="..." />
|
|
231
|
-
|
|
232
|
-
// Default — no color styling
|
|
233
|
-
<Collapse title="No color" content="..." />
|
|
234
|
-
// Explicit transparent — same as default
|
|
235
|
-
<Collapse color="transparent" title="Transparent" content="..." />
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
> ℹ️ The `color` prop and the `class` prop are independent — you can combine `color="primary"` with `class.content` to further customize the content area without affecting the color theme.
|
|
239
|
-
|
|
240
|
-
---
|
|
241
|
-
|
|
242
|
-
## COMMON MISTAKES TO AVOID
|
|
243
|
-
|
|
244
|
-
| Mistake | Correct approach |
|
|
245
|
-
|---|---|
|
|
246
|
-
| Using `icon.position` (with 'i') | Use `icon.postion` — the prop has a typo in source |
|
|
247
|
-
| Expecting `onOpen`/`onClose` to fire when `force` is set | These callbacks only fire in uncontrolled mode |
|
|
248
|
-
| Passing JSX to `title` | `title` is `string` only; style text with `class.title` |
|
|
249
|
-
| Setting `id` when `force` is also set | `id` targets the checkbox which is removed in controlled mode |
|
|
250
|
-
| Overriding `text-sm` inside content without `class.content` | Use `class.content` to override content text styles |
|
|
251
|
-
| Using `force={false}` expecting uncontrolled | `force` accepts `'open' \| 'close' \| undefined` — use `undefined` or omit prop for uncontrolled |
|
|
252
|
-
| Using `class.root` for semantic color when `color` prop exists | Prefer `color="primary"` over `class={{ root: 'border-primary bg-primary/5' }}` |
|
|
253
|
-
|
|
254
|
-
---
|
|
255
|
-
|
|
256
|
-
## FULL EXAMPLE — All features
|
|
257
|
-
|
|
258
|
-
```tsx
|
|
259
|
-
import { Collapse } from 'solid-tom-ui';
|
|
260
|
-
import { createSignal } from 'solid-js';
|
|
261
|
-
import { Button } from 'solid-tom-ui';
|
|
262
|
-
|
|
263
|
-
// 1. Uncontrolled with arrow icon (default)
|
|
264
|
-
<Collapse
|
|
265
|
-
title="What is SolidJS?"
|
|
266
|
-
content={<p>SolidJS is a fine-grained reactive UI library.</p>}
|
|
267
|
-
onOpen={() => console.log('opened')}
|
|
268
|
-
onClose={() => console.log('closed')}
|
|
269
|
-
/>
|
|
270
|
-
|
|
271
|
-
// 2. Plus icon, icon on start (left)
|
|
272
|
-
<Collapse
|
|
273
|
-
title="How does reactivity work?"
|
|
274
|
-
content="Signals track dependencies automatically at runtime."
|
|
275
|
-
icon={{ type: 'plus', postion: 'start' }}
|
|
276
|
-
/>
|
|
277
|
-
|
|
278
|
-
// 3. Controlled mode
|
|
279
|
-
const [force, setForce] = createSignal<'open' | 'close' | undefined>(undefined);
|
|
280
|
-
|
|
281
|
-
<Button onClick={() => setForce(f => f === 'open' ? 'close' : 'open')}>
|
|
282
|
-
Toggle
|
|
283
|
-
</Button>
|
|
284
|
-
<Collapse
|
|
285
|
-
title="Controlled Collapse"
|
|
286
|
-
content={<p>Opened and closed externally.</p>}
|
|
287
|
-
force={force()}
|
|
288
|
-
/>
|
|
289
|
-
|
|
290
|
-
// 4. Content with own reactive state
|
|
291
|
-
<Collapse
|
|
292
|
-
title="Interactive Content"
|
|
293
|
-
content={() => {
|
|
294
|
-
const [count, setCount] = createSignal(0);
|
|
295
|
-
return (
|
|
296
|
-
<Button variant="solid" onClick={() => setCount(c => c + 1)}>
|
|
297
|
-
Clicked {count()} times
|
|
298
|
-
</Button>
|
|
299
|
-
);
|
|
300
|
-
}}
|
|
301
|
-
/>
|
|
302
|
-
|
|
303
|
-
// 5. External label trigger via id
|
|
304
|
-
<label for="faq-1" class="btn btn-sm">Open FAQ</label>
|
|
305
|
-
<Collapse
|
|
306
|
-
id="faq-1"
|
|
307
|
-
title="Frequently Asked Question"
|
|
308
|
-
content="This is the answer to the FAQ."
|
|
309
|
-
class={{ root: 'mt-2' }}
|
|
310
|
-
/>
|
|
311
|
-
|
|
312
|
-
// 6. Custom styling
|
|
313
|
-
<Collapse
|
|
314
|
-
title="Styled Collapse"
|
|
315
|
-
content="Custom styled content area."
|
|
316
|
-
class={{
|
|
317
|
-
root: 'border-primary bg-primary/5',
|
|
318
|
-
title: 'text-primary text-lg',
|
|
319
|
-
content: 'text-base text-base-content/70',
|
|
320
|
-
}}
|
|
321
|
-
/>
|
|
322
|
-
```
|
|
323
|
-
---
|
|
324
|
-
|
|
325
|
-
## Component Conventions
|
|
326
|
-
|
|
327
|
-
> **CSS encoding**: internal CSS classes use short encoded names (e.g. `co01`, `co02`) per project convention.
|
|
328
|
-
|
|
329
|
-
> **Unique IDs**: if this component needs to generate HTML `id` attributes, always use `createUniqueId()` from `solid-js` — never `Math.random()` or `Date.now()`.
|
|
1
|
+
## COMPONENT IDENTITY
|
|
2
|
+
- **Import**: `import { Collapse } from 'solid-tom-ui';`
|
|
3
|
+
- **Export**: `Collapse` (named export)
|
|
4
|
+
- **Framework**: SolidJS
|
|
5
|
+
- **Purpose**: Collapsible panel — NOT a `ParentComponent`; content passed via `content` prop
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## TYPE SIGNATURE
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
interface CollapseProps {
|
|
13
|
+
title: string; // REQUIRED — header text
|
|
14
|
+
content: SolidComponent; // REQUIRED — body content (JSX, string, or function component)
|
|
15
|
+
icon?: {
|
|
16
|
+
type?: 'arrow' | 'plus'; // icon style; default: 'arrow'
|
|
17
|
+
postion?: 'start' | 'end'; // icon position; default: 'end'
|
|
18
|
+
};
|
|
19
|
+
force?: 'open' | 'close'; // controlled visibility — omit for uncontrolled
|
|
20
|
+
onOpen?: () => void; // callback when panel opens (uncontrolled only)
|
|
21
|
+
onClose?: () => void; // callback when panel closes (uncontrolled only)
|
|
22
|
+
id?: string; // id applied to the internal checkbox input
|
|
23
|
+
color?: BaseColorProps | 'transparent'; // semantic color theme; default: 'transparent'
|
|
24
|
+
class?: Partial<Record<'root' | 'title' | 'content', string>>;
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## DEFAULT VALUES (via `mergeProps`)
|
|
31
|
+
|
|
32
|
+
| Prop | Default |
|
|
33
|
+
|-----------------|-----------------|
|
|
34
|
+
| `icon.type` | `'arrow'` |
|
|
35
|
+
| `icon.postion` | `'end'` |
|
|
36
|
+
| `color` | `'transparent'` |
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## PROP REFERENCE
|
|
41
|
+
|
|
42
|
+
| Prop | Type | Required | Description |
|
|
43
|
+
|-----------------|-----------------------------------|----------|------------------------------------------------------------------------------------------|
|
|
44
|
+
| `title` | `string` | ✅ YES | Text shown in the collapse header bar |
|
|
45
|
+
| `content` | `SolidComponent` | ✅ YES | Content rendered in the collapsible body panel |
|
|
46
|
+
| `icon.type` | `'arrow' \| 'plus'` | ❌ NO | `'arrow'` → chevron icon; `'plus'` → plus/minus icon |
|
|
47
|
+
| `icon.postion` | `'start' \| 'end'` | ❌ NO | `'end'` → icon on right side (default); `'start'` → icon on left side |
|
|
48
|
+
| `force` | `'open' \| 'close'` | ❌ NO | Forces panel open or closed. When set, checkbox is removed and callbacks are ignored |
|
|
49
|
+
| `onOpen` | `() => void` | ❌ NO | Fired when user opens the panel (uncontrolled only — ignored when `force` is set) |
|
|
50
|
+
| `onClose` | `() => void` | ❌ NO | Fired when user closes the panel (uncontrolled only — ignored when `force` is set) |
|
|
51
|
+
| `id` | `string` | ❌ NO | `id` attribute on the internal `<input type="checkbox">` — enables external label links |
|
|
52
|
+
| `color` | `BaseColorProps \| 'transparent'` | ❌ NO | Semantic color theme — sets border, background tint, and title/icon color via `--color` |
|
|
53
|
+
| `class.root` | `string` | ❌ NO | Extra classes on the root `<div class="collapse">` |
|
|
54
|
+
| `class.title` | `string` | ❌ NO | Extra classes on `<div class="collapse-title">` |
|
|
55
|
+
| `class.content` | `string` | ❌ NO | Extra classes on `<div class="collapse-content">` |
|
|
56
|
+
|
|
57
|
+
> ⚠️ NOTE: `icon.postion` has a typo in source — it is `postion` (missing 'i'), not `position`. Use exactly `postion` when passing the prop.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## OPEN/CLOSE MODES
|
|
62
|
+
|
|
63
|
+
### Mode 1 — Uncontrolled (default, no `force` prop)
|
|
64
|
+
- An `<input type="checkbox">` is rendered inside the root div
|
|
65
|
+
- DaisyUI uses the checkbox checked state to show/hide the panel via CSS
|
|
66
|
+
- `onOpen` fires when checkbox becomes checked; `onClose` fires when unchecked
|
|
67
|
+
- `id` prop sets the checkbox's `id` — allows external `<label for="id">` to toggle the collapse
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
<Collapse
|
|
71
|
+
title="What is SolidJS?"
|
|
72
|
+
content={<p>SolidJS is a declarative UI library.</p>}
|
|
73
|
+
onOpen={() => console.log('opened')}
|
|
74
|
+
onClose={() => console.log('closed')}
|
|
75
|
+
/>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Mode 2 — Controlled (`force` prop)
|
|
79
|
+
- `force="open"` → adds `collapse-open` class, checkbox is **removed from DOM**
|
|
80
|
+
- `force="close"` → adds `collapse-close` class, checkbox is **removed from DOM**
|
|
81
|
+
- `onOpen` and `onClose` are **completely ignored** when `force` is set
|
|
82
|
+
- Toggling is the consumer's responsibility via a reactive signal
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
const [status, setStatus] = createSignal<'open' | 'close'>('close');
|
|
86
|
+
|
|
87
|
+
<Button onClick={() => setStatus(s => s === 'open' ? 'close' : 'open')}>
|
|
88
|
+
Toggle
|
|
89
|
+
</Button>
|
|
90
|
+
|
|
91
|
+
<Collapse
|
|
92
|
+
title="Controlled Collapse"
|
|
93
|
+
content={<p>Controlled by external signal.</p>}
|
|
94
|
+
force={status()}
|
|
95
|
+
/>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Mode 3 — Mixed: `force={undefined}` restores uncontrolled
|
|
99
|
+
- Passing `force={undefined}` (or not passing `force`) keeps the checkbox in the DOM
|
|
100
|
+
- Useful when signal can return `undefined` as a "no override" state
|
|
101
|
+
|
|
102
|
+
```tsx
|
|
103
|
+
// signal can be 'open' | 'close' | undefined
|
|
104
|
+
const [force, setForce] = createSignal<'open' | 'close' | undefined>(undefined);
|
|
105
|
+
|
|
106
|
+
<Collapse title="..." content="..." force={force()} />
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## ICON VARIANTS
|
|
112
|
+
|
|
113
|
+
### `icon.type`
|
|
114
|
+
| Value | DaisyUI class | Visual |
|
|
115
|
+
|-----------|--------------------|----------------------------|
|
|
116
|
+
| `'arrow'` | `collapse-arrow` | Chevron (▼) rotates on open |
|
|
117
|
+
| `'plus'` | `collapse-plus` | Plus (+) changes to minus (−) on open |
|
|
118
|
+
|
|
119
|
+
### `icon.postion`
|
|
120
|
+
| Value | CSS effect |
|
|
121
|
+
|-----------|---------------------------------------------------------|
|
|
122
|
+
| `'end'` | Icon on the right side (default DaisyUI behavior) |
|
|
123
|
+
| `'start'` | Icon on the left side — applies `after:start-5 after:end-auto pe-4 ps-12` |
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## `content` PROP — Accepts multiple forms
|
|
128
|
+
|
|
129
|
+
`SolidComponent` means the prop accepts:
|
|
130
|
+
|
|
131
|
+
```tsx
|
|
132
|
+
// 1. String literal
|
|
133
|
+
content="Plain text content"
|
|
134
|
+
|
|
135
|
+
// 2. JSX element
|
|
136
|
+
content={<p class="text-sm">Some <strong>HTML</strong> content</p>}
|
|
137
|
+
|
|
138
|
+
// 3. Function component (with own reactive state)
|
|
139
|
+
content={() => {
|
|
140
|
+
const [count, setCount] = createSignal(0);
|
|
141
|
+
return (
|
|
142
|
+
<Button onClick={() => setCount(c => c + 1)}>
|
|
143
|
+
Count = {count()}
|
|
144
|
+
</Button>
|
|
145
|
+
);
|
|
146
|
+
}}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
> ℹ️ Function form is useful when the content needs its own SolidJS reactive state. The function is called as a component, preserving signal reactivity.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## INTERNAL DOM STRUCTURE
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
<div class="bg-base-100 border-base-300 collapse border collapse-arrow|plus [collapse-open|collapse-close] [class.root]">
|
|
157
|
+
│
|
|
158
|
+
├── <input type="checkbox" id="?" onChange={...} /> ← only when force is undefined
|
|
159
|
+
│
|
|
160
|
+
├── <div class="collapse-title font-semibold [iconPosition classes] [class.title]">
|
|
161
|
+
│ {title}
|
|
162
|
+
│ </div>
|
|
163
|
+
│
|
|
164
|
+
└── <div class="collapse-content text-sm [class.content]">
|
|
165
|
+
{content}
|
|
166
|
+
</div>
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## `id` PROP — External trigger via `<label>`
|
|
172
|
+
|
|
173
|
+
The `id` is applied to the internal `<input type="checkbox">`, enabling an external `<label>` element to toggle the collapse without clicking the title bar directly:
|
|
174
|
+
|
|
175
|
+
```tsx
|
|
176
|
+
<label for="my-collapse" class="btn">Toggle from outside</label>
|
|
177
|
+
|
|
178
|
+
<Collapse
|
|
179
|
+
id="my-collapse"
|
|
180
|
+
title="Externally triggered"
|
|
181
|
+
content="Toggled by the label above"
|
|
182
|
+
/>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
> ⚠️ `id` only works in uncontrolled mode — when `force` is set, the checkbox is removed from the DOM and the `id` has no effect.
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## BEHAVIOR NOTES FOR AGENTS
|
|
190
|
+
|
|
191
|
+
1. **`force` removes the checkbox entirely** — when `force` is set, `<Show when={!p.force}>` evaluates to false and the `<input>` is unmounted. The DaisyUI `collapse-open`/`collapse-close` classes on the root div take over visibility control.
|
|
192
|
+
|
|
193
|
+
2. **`onOpen`/`onClose` are checkbox-based** — they fire on `onChange` of the checkbox, which only exists in uncontrolled mode. Setting `force` silently disables these callbacks with no error.
|
|
194
|
+
|
|
195
|
+
3. **`content` renders inside `collapse-content` with `text-sm`** — the wrapper always has `text-sm`. Override with `class.content` if larger text is needed.
|
|
196
|
+
|
|
197
|
+
4. **`title` is `string` only** — no JSX allowed in the title. For rich title content, use `class.title` to style and keep the text in `title`.
|
|
198
|
+
|
|
199
|
+
5. **`icon.postion` typo is intentional** — the source code has `postion` (not `position`). Always use `postion` in the prop object or TypeScript will error.
|
|
200
|
+
|
|
201
|
+
6. **Root div always has `bg-base-100 border-base-300 border`** — there is no prop to remove the border or background. Use `class.root` to override with Tailwind.
|
|
202
|
+
|
|
203
|
+
7. **Accordion pattern** — to build an accordion (only one item open at a time), use the native HTML behavior: give all checkboxes the same `name` attribute. However, this component does not expose a `name` prop — implement accordion via controlled `force` signals instead.
|
|
204
|
+
|
|
205
|
+
8. **`color` prop adds `sui-collapse` class** — when `color` is set to any value other than `'transparent'`, the class `sui-collapse` is added to the root div. This class uses `var(--color)` (set by `.color-primary` etc.) to apply border tint, background tint, title color, and icon color.
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## COLOR SYSTEM
|
|
210
|
+
|
|
211
|
+
The `color` prop accepts any `BaseColorProps` value (`'primary' | 'neutral' | 'secondary' | 'accent' | 'info' | 'success' | 'warning' | 'error'`) or `'transparent'` (default — no color applied).
|
|
212
|
+
|
|
213
|
+
### How it works
|
|
214
|
+
1. `getColor(p.color)` maps the value to a CSS class (e.g. `color-primary`) that sets `--color: var(--color-primary)`.
|
|
215
|
+
2. When color is not `'transparent'`, the class `sui-collapse` is also added — this class consumes `var(--color)` to style the collapse:
|
|
216
|
+
- **Border**: `color-mix(in oklch, var(--color) 30%, var(--color-base-300))`
|
|
217
|
+
- **Background**: `color-mix(in oklch, var(--color) 5%, var(--color-base-100))` — a subtle tint
|
|
218
|
+
- **Title text**: `var(--color)`
|
|
219
|
+
- **Icon (arrow/plus)**: `var(--color)` via `::after` pseudo-element
|
|
220
|
+
|
|
221
|
+
```tsx
|
|
222
|
+
// All 8 color variants
|
|
223
|
+
<Collapse color="primary" title="Primary" content="..." />
|
|
224
|
+
<Collapse color="secondary" title="Secondary" content="..." />
|
|
225
|
+
<Collapse color="accent" title="Accent" content="..." />
|
|
226
|
+
<Collapse color="neutral" title="Neutral" content="..." />
|
|
227
|
+
<Collapse color="info" title="Info" content="..." />
|
|
228
|
+
<Collapse color="success" title="Success" content="..." />
|
|
229
|
+
<Collapse color="warning" title="Warning" content="..." />
|
|
230
|
+
<Collapse color="error" title="Error" content="..." />
|
|
231
|
+
|
|
232
|
+
// Default — no color styling
|
|
233
|
+
<Collapse title="No color" content="..." />
|
|
234
|
+
// Explicit transparent — same as default
|
|
235
|
+
<Collapse color="transparent" title="Transparent" content="..." />
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
> ℹ️ The `color` prop and the `class` prop are independent — you can combine `color="primary"` with `class.content` to further customize the content area without affecting the color theme.
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## COMMON MISTAKES TO AVOID
|
|
243
|
+
|
|
244
|
+
| Mistake | Correct approach |
|
|
245
|
+
|---|---|
|
|
246
|
+
| Using `icon.position` (with 'i') | Use `icon.postion` — the prop has a typo in source |
|
|
247
|
+
| Expecting `onOpen`/`onClose` to fire when `force` is set | These callbacks only fire in uncontrolled mode |
|
|
248
|
+
| Passing JSX to `title` | `title` is `string` only; style text with `class.title` |
|
|
249
|
+
| Setting `id` when `force` is also set | `id` targets the checkbox which is removed in controlled mode |
|
|
250
|
+
| Overriding `text-sm` inside content without `class.content` | Use `class.content` to override content text styles |
|
|
251
|
+
| Using `force={false}` expecting uncontrolled | `force` accepts `'open' \| 'close' \| undefined` — use `undefined` or omit prop for uncontrolled |
|
|
252
|
+
| Using `class.root` for semantic color when `color` prop exists | Prefer `color="primary"` over `class={{ root: 'border-primary bg-primary/5' }}` |
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## FULL EXAMPLE — All features
|
|
257
|
+
|
|
258
|
+
```tsx
|
|
259
|
+
import { Collapse } from 'solid-tom-ui';
|
|
260
|
+
import { createSignal } from 'solid-js';
|
|
261
|
+
import { Button } from 'solid-tom-ui';
|
|
262
|
+
|
|
263
|
+
// 1. Uncontrolled with arrow icon (default)
|
|
264
|
+
<Collapse
|
|
265
|
+
title="What is SolidJS?"
|
|
266
|
+
content={<p>SolidJS is a fine-grained reactive UI library.</p>}
|
|
267
|
+
onOpen={() => console.log('opened')}
|
|
268
|
+
onClose={() => console.log('closed')}
|
|
269
|
+
/>
|
|
270
|
+
|
|
271
|
+
// 2. Plus icon, icon on start (left)
|
|
272
|
+
<Collapse
|
|
273
|
+
title="How does reactivity work?"
|
|
274
|
+
content="Signals track dependencies automatically at runtime."
|
|
275
|
+
icon={{ type: 'plus', postion: 'start' }}
|
|
276
|
+
/>
|
|
277
|
+
|
|
278
|
+
// 3. Controlled mode
|
|
279
|
+
const [force, setForce] = createSignal<'open' | 'close' | undefined>(undefined);
|
|
280
|
+
|
|
281
|
+
<Button onClick={() => setForce(f => f === 'open' ? 'close' : 'open')}>
|
|
282
|
+
Toggle
|
|
283
|
+
</Button>
|
|
284
|
+
<Collapse
|
|
285
|
+
title="Controlled Collapse"
|
|
286
|
+
content={<p>Opened and closed externally.</p>}
|
|
287
|
+
force={force()}
|
|
288
|
+
/>
|
|
289
|
+
|
|
290
|
+
// 4. Content with own reactive state
|
|
291
|
+
<Collapse
|
|
292
|
+
title="Interactive Content"
|
|
293
|
+
content={() => {
|
|
294
|
+
const [count, setCount] = createSignal(0);
|
|
295
|
+
return (
|
|
296
|
+
<Button variant="solid" onClick={() => setCount(c => c + 1)}>
|
|
297
|
+
Clicked {count()} times
|
|
298
|
+
</Button>
|
|
299
|
+
);
|
|
300
|
+
}}
|
|
301
|
+
/>
|
|
302
|
+
|
|
303
|
+
// 5. External label trigger via id
|
|
304
|
+
<label for="faq-1" class="btn btn-sm">Open FAQ</label>
|
|
305
|
+
<Collapse
|
|
306
|
+
id="faq-1"
|
|
307
|
+
title="Frequently Asked Question"
|
|
308
|
+
content="This is the answer to the FAQ."
|
|
309
|
+
class={{ root: 'mt-2' }}
|
|
310
|
+
/>
|
|
311
|
+
|
|
312
|
+
// 6. Custom styling
|
|
313
|
+
<Collapse
|
|
314
|
+
title="Styled Collapse"
|
|
315
|
+
content="Custom styled content area."
|
|
316
|
+
class={{
|
|
317
|
+
root: 'border-primary bg-primary/5',
|
|
318
|
+
title: 'text-primary text-lg',
|
|
319
|
+
content: 'text-base text-base-content/70',
|
|
320
|
+
}}
|
|
321
|
+
/>
|
|
322
|
+
```
|
|
323
|
+
---
|
|
324
|
+
|
|
325
|
+
## Component Conventions
|
|
326
|
+
|
|
327
|
+
> **CSS encoding**: internal CSS classes use short encoded names (e.g. `co01`, `co02`) per project convention.
|
|
328
|
+
|
|
329
|
+
> **Unique IDs**: if this component needs to generate HTML `id` attributes, always use `createUniqueId()` from `solid-js` — never `Math.random()` or `Date.now()`.
|