@svelte-atoms/core 1.0.0-alpha.30 → 1.0.0-alpha.32
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/LICENSE +21 -0
- package/README.md +176 -739
- package/dist/attachments/index.d.ts +1 -0
- package/dist/attachments/index.js +1 -0
- package/dist/components/accordion/accordion-root.svelte +65 -61
- package/dist/components/accordion/accordion.stories.svelte +70 -145
- package/dist/components/accordion/item/accordion-item-body.svelte +6 -4
- package/dist/components/accordion/item/accordion-item-header.svelte +2 -1
- package/dist/components/accordion/item/accordion-item-indicator.svelte +2 -1
- package/dist/components/accordion/item/accordion-item-root.svelte +2 -1
- package/dist/components/accordion/item/bond.svelte.d.ts +2 -0
- package/dist/components/accordion/item/index.d.ts +3 -0
- package/dist/components/accordion/item/index.js +3 -0
- package/dist/components/accordion/item/motion.svelte.d.ts +15 -0
- package/dist/components/accordion/item/motion.svelte.js +30 -0
- package/dist/components/accordion/item/types.d.ts +7 -24
- package/dist/components/alert/alert-close-button.svelte +32 -36
- package/dist/components/alert/alert-description.svelte +1 -1
- package/dist/components/alert/alert-description.svelte.d.ts +3 -6
- package/dist/components/alert/alert-root.svelte +3 -38
- package/dist/components/alert/alert-root.svelte.d.ts +2 -2
- package/dist/components/alert/alert.stories.svelte +400 -400
- package/dist/components/alert/bond.svelte.d.ts +0 -13
- package/dist/components/alert/bond.svelte.js +0 -32
- package/dist/components/alert/types.d.ts +8 -32
- package/dist/components/atom/html-atom.svelte +93 -261
- package/dist/components/atom/types.d.ts +3 -2
- package/dist/components/atom/utils.d.ts +37 -0
- package/dist/components/atom/utils.js +208 -0
- package/dist/components/avatar/avatar.stories.svelte +22 -22
- package/dist/components/badge/badge.stories.svelte +12 -12
- package/dist/components/badge/badge.svelte +19 -19
- package/dist/components/breadcrumb/breadcrumb-item.svelte +1 -1
- package/dist/components/breadcrumb/breadcrumb-separator.svelte +5 -1
- package/dist/components/breadcrumb/breadcrumb.stories.svelte +16 -16
- package/dist/components/button/button.stories.svelte +27 -27
- package/dist/components/calendar/calendar-day.svelte +9 -4
- package/dist/components/calendar/calendar.stories.svelte +26 -26
- package/dist/components/card/card-body.svelte +39 -39
- package/dist/components/card/card-footer.svelte +41 -41
- package/dist/components/card/card-root.svelte +91 -91
- package/dist/components/card/card.stories.svelte +133 -133
- package/dist/components/checkbox/checkbox.stories.svelte +22 -22
- package/dist/components/checkbox/checkbox.svelte +159 -155
- package/dist/components/collapsible/bond.svelte.js +2 -1
- package/dist/components/collapsible/collapsible-body.svelte +3 -2
- package/dist/components/collapsible/collapsible.stories.svelte +172 -172
- package/dist/components/collapsible/motion.svelte.d.ts +6 -0
- package/dist/components/collapsible/motion.svelte.js +15 -0
- package/dist/components/combobox/atoms.d.ts +3 -3
- package/dist/components/combobox/atoms.js +3 -3
- package/dist/components/combobox/bond.svelte.d.ts +6 -6
- package/dist/components/combobox/bond.svelte.js +3 -26
- package/dist/components/combobox/combobox-control.svelte +52 -52
- package/dist/components/combobox/{compobox-item.svelte → combobox-item.svelte} +62 -68
- package/dist/components/combobox/combobox-item.svelte.d.ts +12 -0
- package/dist/components/combobox/combobox-root.svelte +65 -65
- package/dist/components/combobox/combobox.stories.svelte +50 -0
- package/dist/components/combobox/combobox.stories.svelte.d.ts +3 -0
- package/dist/components/combobox/index.d.ts +1 -0
- package/dist/components/container/container.stories.svelte +20 -20
- package/dist/components/container/container.svelte.d.ts +1 -1
- package/dist/components/datagrid/datagrid.stories.svelte +72 -72
- package/dist/components/datagrid/tr/bond.svelte.d.ts +4 -2
- package/dist/components/datagrid/tr/bond.svelte.js +9 -7
- package/dist/components/datagrid/tr/datagrid-tr.svelte +9 -7
- package/dist/components/date-picker/bond.svelte.d.ts +15 -5
- package/dist/components/date-picker/bond.svelte.js +5 -11
- package/dist/components/date-picker/date-picker-calendar.svelte +2 -2
- package/dist/components/date-picker/date-picker-root.svelte +95 -95
- package/dist/components/date-picker/date-picker.stories.svelte +35 -35
- package/dist/components/dialog/bond.svelte.d.ts +13 -3
- package/dist/components/dialog/bond.svelte.js +52 -6
- package/dist/components/dialog/dialog-content.svelte +2 -20
- package/dist/components/dialog/dialog-root.svelte +3 -22
- package/dist/components/dialog/dialog.stories.svelte +64 -64
- package/dist/components/dialog/motion.svelte.d.ts +13 -0
- package/dist/components/dialog/motion.svelte.js +44 -0
- package/dist/components/drawer/attachments.svelte.d.ts +1 -1
- package/dist/components/drawer/attachments.svelte.js +1 -3
- package/dist/components/drawer/bond.svelte.d.ts +30 -9
- package/dist/components/drawer/bond.svelte.js +80 -24
- package/dist/components/drawer/drawer-content.svelte +49 -57
- package/dist/components/drawer/drawer-root.svelte +5 -4
- package/dist/components/drawer/drawer.stories.svelte +141 -212
- package/dist/components/drawer/index.d.ts +2 -0
- package/dist/components/drawer/index.js +2 -0
- package/dist/components/drawer/motion.d.ts +15 -0
- package/dist/components/drawer/motion.js +28 -0
- package/dist/components/dropdown/atoms.d.ts +1 -1
- package/dist/components/dropdown/atoms.js +1 -1
- package/dist/components/dropdown/bond.svelte.d.ts +22 -19
- package/dist/components/dropdown/bond.svelte.js +29 -53
- package/dist/components/dropdown/dropdown-root.svelte +7 -1
- package/dist/components/dropdown/dropdown-values.svelte +17 -17
- package/dist/components/dropdown/dropdown-values.svelte.d.ts +1 -2
- package/dist/components/dropdown/dropdown.stories.svelte +13 -10
- package/dist/components/dropdown/index.d.ts +2 -0
- package/dist/components/dropdown/index.js +1 -0
- package/dist/components/dropdown/item/attachments.svelte.d.ts +2 -2
- package/dist/components/dropdown/item/attachments.svelte.js +2 -2
- package/dist/components/dropdown/item/controller.svelte.d.ts +34 -0
- package/dist/components/dropdown/item/controller.svelte.js +82 -0
- package/dist/components/dropdown/item/dropdown-item.svelte +109 -102
- package/dist/components/dropdown/item/dropdown-item.svelte.d.ts +13 -28
- package/dist/components/dropdown/item/index.d.ts +3 -0
- package/dist/components/dropdown/item/index.js +3 -0
- package/dist/components/dropdown/item/types.d.ts +29 -0
- package/dist/components/dropdown/item/types.js +1 -0
- package/dist/components/form/form.stories.svelte +96 -96
- package/dist/components/image/image.stories.svelte +20 -20
- package/dist/components/input/input.stories.svelte +35 -35
- package/dist/components/label/label.stories.svelte +15 -15
- package/dist/components/lazy/lazy.stories.svelte +28 -28
- package/dist/components/link/link.stories.svelte +15 -15
- package/dist/components/list/list-item.svelte +2 -2
- package/dist/components/menu/atoms.d.ts +9 -3
- package/dist/components/menu/atoms.js +9 -3
- package/dist/components/menu/bond.svelte.d.ts +54 -0
- package/dist/components/menu/bond.svelte.js +132 -0
- package/dist/components/menu/index.d.ts +3 -1
- package/dist/components/menu/index.js +2 -1
- package/dist/components/menu/item/controller.svelte.d.ts +26 -0
- package/dist/components/menu/item/controller.svelte.js +69 -0
- package/dist/components/menu/item/index.d.ts +2 -0
- package/dist/components/menu/item/index.js +2 -0
- package/dist/components/menu/item/menu-item.svelte +103 -0
- package/dist/components/menu/item/menu-item.svelte.d.ts +31 -0
- package/dist/components/menu/item/types.d.ts +62 -0
- package/dist/components/menu/item/types.js +1 -0
- package/dist/components/menu/{menu-list.svelte → menu-content.svelte} +40 -40
- package/dist/components/menu/{menu-list.svelte.d.ts → menu-content.svelte.d.ts} +3 -3
- package/dist/components/menu/menu-root.svelte +15 -0
- package/dist/components/menu/menu-root.svelte.d.ts +8 -0
- package/dist/components/menu/menu.stories.svelte +5 -5
- package/dist/components/menu/types.d.ts +0 -7
- package/dist/components/popover/bond.svelte.d.ts +18 -8
- package/dist/components/popover/bond.svelte.js +76 -40
- package/dist/components/popover/motion.d.ts +6 -0
- package/dist/components/popover/motion.js +56 -0
- package/dist/components/popover/popover-arrow.svelte +111 -111
- package/dist/components/popover/popover-content.svelte +137 -175
- package/dist/components/popover/popover-indicator.svelte +44 -44
- package/dist/components/popover/popover-root.svelte +48 -48
- package/dist/components/popover/popover.stories.svelte +37 -49
- package/dist/components/popover/types.d.ts +9 -7
- package/dist/components/portal/active-portal.svelte +12 -5
- package/dist/components/portal/active-portal.svelte.d.ts +2 -9
- package/dist/components/portal/portal-root.svelte +1 -8
- package/dist/components/portal/portal-root.svelte.d.ts +4 -6
- package/dist/components/portal/teleport.svelte +1 -2
- package/dist/components/portal/teleport.svelte.d.ts +3 -4
- package/dist/components/qr-code/qr-code.stories.svelte +18 -18
- package/dist/components/radio/radio-group.stories.svelte +41 -41
- package/dist/components/radio/radio.stories.svelte +17 -17
- package/dist/components/radio/radio.svelte +109 -109
- package/dist/components/radio/types.d.ts +98 -0
- package/dist/components/radio/types.js +2 -0
- package/dist/components/root/index.d.ts +1 -0
- package/dist/components/root/index.js +1 -0
- package/dist/components/root/l0-portal.svelte +8 -0
- package/dist/components/{radio/types.svelte.d.ts → root/l0-portal.svelte.d.ts} +3 -3
- package/dist/components/root/l1-portal.svelte +7 -0
- package/dist/components/root/l1-portal.svelte.d.ts +26 -0
- package/dist/components/root/root.css +119 -119
- package/dist/components/root/root.svelte +26 -44
- package/dist/components/root/root.svelte.d.ts +2 -6
- package/dist/components/root/toasts-portal.svelte +7 -0
- package/dist/components/root/toasts-portal.svelte.d.ts +26 -0
- package/dist/components/root/types.d.ts +17 -0
- package/dist/components/scrollable/scrollable-root.svelte.d.ts +2 -2
- package/dist/components/scrollable/scrollable.stories.svelte +116 -116
- package/dist/components/sidebar/index.d.ts +2 -0
- package/dist/components/sidebar/index.js +2 -0
- package/dist/components/sidebar/motion.svelte.d.ts +11 -0
- package/dist/components/sidebar/motion.svelte.js +16 -0
- package/dist/components/sidebar/sidebar-content.svelte +40 -50
- package/dist/components/sidebar/sidebar-root.svelte +39 -39
- package/dist/components/sidebar/sidebar.stories.svelte +43 -43
- package/dist/components/sidebar/types.d.ts +2 -12
- package/dist/components/tabs/tabs.stories.svelte +56 -56
- package/dist/components/textarea/atoms.d.ts +1 -0
- package/dist/components/textarea/atoms.js +1 -0
- package/dist/components/textarea/textarea-input.svelte +4 -1
- package/dist/components/textarea/textarea-root.svelte +2 -2
- package/dist/components/textarea/textarea-root.svelte.d.ts +2 -0
- package/dist/components/tooltip/tooltip-trigger.svelte +39 -39
- package/dist/components/tooltip/tooltip-trigger.svelte.d.ts +1 -0
- package/dist/components/tooltip/tooltip.stories.svelte +32 -32
- package/dist/components/tree/index.d.ts +1 -0
- package/dist/components/tree/index.js +1 -0
- package/dist/components/tree/motion.svelte.d.ts +6 -0
- package/dist/components/tree/motion.svelte.js +14 -0
- package/dist/components/tree/tree-body.svelte +4 -3
- package/dist/components/tree/tree.stories.svelte +142 -142
- package/dist/context/preset.svelte.d.ts +3 -1
- package/dist/icons/icon-copy.svelte +6 -0
- package/dist/icons/icon-copy.svelte.d.ts +26 -0
- package/dist/utils/dom.svelte.d.ts +2 -0
- package/dist/utils/dom.svelte.js +21 -0
- package/dist/utils/function.d.ts +1 -1
- package/dist/utils/promise.svelte.d.ts +5 -0
- package/dist/utils/promise.svelte.js +20 -0
- package/package.json +4 -3
- package/dist/components/combobox/compobox-item.svelte.d.ts +0 -34
- package/dist/components/combobox/compobox.stories.svelte +0 -51
- package/dist/components/combobox/compobox.stories.svelte.d.ts +0 -3
- package/dist/components/dropdown/item/bond.svelte.d.ts +0 -42
- package/dist/components/dropdown/item/bond.svelte.js +0 -99
- package/dist/components/menu/menu-item.svelte +0 -51
- package/dist/components/menu/menu-item.svelte.d.ts +0 -36
- package/dist/components/radio/types.svelte +0 -0
- package/llm/composition.md +0 -395
- package/llm/crafting.md +0 -838
- package/llm/motion.md +0 -970
- package/llm/philosophy.md +0 -23
- package/llm/preset-variant-integration.md +0 -516
- package/llm/preset.md +0 -383
- package/llm/styling.md +0 -216
- package/llm/usage.md +0 -46
- package/llm/variants.md +0 -1259
package/llm/preset.md
DELETED
|
@@ -1,383 +0,0 @@
|
|
|
1
|
-
# Global Component Configuration with Presets
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
Presets in @svelte-atoms/core allow you to configure component styling, props, and behavior **globally** across your application. Instead of repeating the same classes or props on every component, define them once at the top level and have all components inherit those configurations automatically.
|
|
6
|
-
|
|
7
|
-
Presets can be:
|
|
8
|
-
|
|
9
|
-
- Declared at the **app root** for global configuration
|
|
10
|
-
- Overridden at the **route level** for section-specific styling
|
|
11
|
-
- Overridden at the **component level** for local customization
|
|
12
|
-
|
|
13
|
-
## How Presets Work
|
|
14
|
-
|
|
15
|
-
Each component has a `preset` prop that references a key in the preset configuration:
|
|
16
|
-
|
|
17
|
-
```svelte
|
|
18
|
-
<HtmlAtom preset="button" class={['default-button-classes', '$preset', klass]} />
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
The `$preset` placeholder gets replaced with classes/props from the preset configuration at that context level.
|
|
22
|
-
|
|
23
|
-
## Setting Up Presets
|
|
24
|
-
|
|
25
|
-
### 1. Global Preset (App Root)
|
|
26
|
-
|
|
27
|
-
Set presets at the app root to apply them everywhere:
|
|
28
|
-
|
|
29
|
-
```svelte
|
|
30
|
-
<!-- +layout.svelte or App.svelte -->
|
|
31
|
-
<script lang="ts">
|
|
32
|
-
import { setPreset, type Preset } from '@svelte-atoms/core/context';
|
|
33
|
-
import { Root } from '@svelte-atoms/core/components/root';
|
|
34
|
-
|
|
35
|
-
const globalPreset: Partial<Preset> = {
|
|
36
|
-
button: () => ({
|
|
37
|
-
class: 'rounded-lg px-4 py-2 font-semibold transition-colors'
|
|
38
|
-
}),
|
|
39
|
-
card: () => ({
|
|
40
|
-
class: 'rounded-xl border border-gray-200 shadow-sm'
|
|
41
|
-
}),
|
|
42
|
-
'card.title': () => ({
|
|
43
|
-
class: 'text-xl font-bold text-gray-900'
|
|
44
|
-
}),
|
|
45
|
-
dialog: () => ({
|
|
46
|
-
class: 'max-w-2xl rounded-2xl'
|
|
47
|
-
})
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
setPreset(globalPreset);
|
|
51
|
-
</script>
|
|
52
|
-
|
|
53
|
-
<Root>
|
|
54
|
-
<slot />
|
|
55
|
-
</Root>
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
Now all `Button`, `Card`, and `Dialog` components automatically inherit these styles.
|
|
59
|
-
|
|
60
|
-
### 2. Route-Level Override
|
|
61
|
-
|
|
62
|
-
Override presets for specific routes:
|
|
63
|
-
|
|
64
|
-
```svelte
|
|
65
|
-
<!-- routes/dashboard/+layout.svelte -->
|
|
66
|
-
<script lang="ts">
|
|
67
|
-
import { setPreset } from '@svelte-atoms/core/context';
|
|
68
|
-
|
|
69
|
-
const dashboardPreset = {
|
|
70
|
-
button: () => ({
|
|
71
|
-
class: 'rounded-md px-3 py-1.5 text-sm' // Smaller buttons for dashboard
|
|
72
|
-
}),
|
|
73
|
-
card: () => ({
|
|
74
|
-
class: 'bg-slate-50 border-slate-200' // Different card style
|
|
75
|
-
})
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
setPreset(dashboardPreset);
|
|
79
|
-
</script>
|
|
80
|
-
|
|
81
|
-
<div>
|
|
82
|
-
<slot />
|
|
83
|
-
</div>
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
Components in `/dashboard/*` routes now use the dashboard preset, **merging** with the global preset.
|
|
87
|
-
|
|
88
|
-
### 3. Component-Level Override
|
|
89
|
-
|
|
90
|
-
Override presets in a parent component for its children:
|
|
91
|
-
|
|
92
|
-
```svelte
|
|
93
|
-
<!-- components/SettingsPanel.svelte -->
|
|
94
|
-
<script lang="ts">
|
|
95
|
-
import { setPreset } from '@svelte-atoms/core/context';
|
|
96
|
-
import { Card } from '@svelte-atoms/core/components/card';
|
|
97
|
-
|
|
98
|
-
const settingsPreset = {
|
|
99
|
-
'card.title': () => ({
|
|
100
|
-
class: 'text-lg text-purple-600' // Purple titles in settings
|
|
101
|
-
})
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
setPreset(settingsPreset);
|
|
105
|
-
</script>
|
|
106
|
-
|
|
107
|
-
<Card.Root>
|
|
108
|
-
<Card.Header>
|
|
109
|
-
<Card.Title>Settings</Card.Title>
|
|
110
|
-
<!-- Purple text -->
|
|
111
|
-
</Card.Header>
|
|
112
|
-
<Card.Content>
|
|
113
|
-
<!-- Content here -->
|
|
114
|
-
</Card.Content>
|
|
115
|
-
</Card.Root>
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
## Preset Structure
|
|
119
|
-
|
|
120
|
-
### Basic Preset Entry
|
|
121
|
-
|
|
122
|
-
Return an object with `class`, `as`, or other props:
|
|
123
|
-
|
|
124
|
-
```typescript
|
|
125
|
-
const preset: Partial<Preset> = {
|
|
126
|
-
button: () => ({
|
|
127
|
-
class: 'px-4 py-2 rounded-lg',
|
|
128
|
-
type: 'button'
|
|
129
|
-
}),
|
|
130
|
-
|
|
131
|
-
accordion: () => ({
|
|
132
|
-
as: 'ul', // Change element type
|
|
133
|
-
class: 'space-y-2'
|
|
134
|
-
})
|
|
135
|
-
};
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
### Dynamic Preset with Bond State
|
|
139
|
-
|
|
140
|
-
Access component state via bond to create reactive presets:
|
|
141
|
-
|
|
142
|
-
```typescript
|
|
143
|
-
const preset: Partial<Preset> = {
|
|
144
|
-
'accordion.item.header': (bond) => {
|
|
145
|
-
// Access bond.state to make preset reactive
|
|
146
|
-
return {
|
|
147
|
-
class: bond?.state?.isActive ? 'text-foreground bg-accent' : 'text-muted-foreground'
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
### Using defineState for Reactive Props
|
|
154
|
-
|
|
155
|
-
For more complex reactive logic, use `defineState` and `defineProperty`:
|
|
156
|
-
|
|
157
|
-
```typescript
|
|
158
|
-
import { defineState, defineProperty } from '@svelte-atoms/core/utils';
|
|
159
|
-
|
|
160
|
-
const preset: Partial<Preset> = {
|
|
161
|
-
'collapsible.header': (bond) => {
|
|
162
|
-
return defineState([
|
|
163
|
-
defineProperty('class', () => [
|
|
164
|
-
'px-4 py-2 cursor-pointer transition-colors',
|
|
165
|
-
bond?.state?.isOpen ? 'bg-blue-50' : 'hover:bg-gray-50'
|
|
166
|
-
]),
|
|
167
|
-
defineProperty('aria-expanded', () => bond?.state?.isOpen)
|
|
168
|
-
]);
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
## Preset Merging
|
|
174
|
-
|
|
175
|
-
Presets **merge** across context levels using deep merge:
|
|
176
|
-
|
|
177
|
-
```svelte
|
|
178
|
-
<!-- App root -->
|
|
179
|
-
<script>
|
|
180
|
-
setPreset({
|
|
181
|
-
button: () => ({
|
|
182
|
-
class: 'px-4 py-2 rounded-lg font-semibold'
|
|
183
|
-
})
|
|
184
|
-
});
|
|
185
|
-
</script>
|
|
186
|
-
|
|
187
|
-
<!-- Route level -->
|
|
188
|
-
<script>
|
|
189
|
-
setPreset({
|
|
190
|
-
button: () => ({
|
|
191
|
-
class: 'text-sm' // Merges with root
|
|
192
|
-
})
|
|
193
|
-
});
|
|
194
|
-
</script>
|
|
195
|
-
|
|
196
|
-
<!-- Result: Button has both classes -->
|
|
197
|
-
<!-- class="px-4 py-2 rounded-lg font-semibold text-sm" -->
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
## Available Preset Keys
|
|
201
|
-
|
|
202
|
-
Components use dot notation for sub-components:
|
|
203
|
-
|
|
204
|
-
```typescript
|
|
205
|
-
type PresetModuleName =
|
|
206
|
-
| 'button'
|
|
207
|
-
| 'card'
|
|
208
|
-
| 'card.title'
|
|
209
|
-
| 'card.content'
|
|
210
|
-
| 'card.header'
|
|
211
|
-
| 'card.footer'
|
|
212
|
-
| 'accordion'
|
|
213
|
-
| 'accordion.item'
|
|
214
|
-
| 'accordion.item.header'
|
|
215
|
-
| 'accordion.item.body'
|
|
216
|
-
| 'dialog'
|
|
217
|
-
| 'dialog.content'
|
|
218
|
-
| 'dialog.title'
|
|
219
|
-
| 'popover.content'
|
|
220
|
-
| 'popover.trigger'
|
|
221
|
-
| 'datagrid'
|
|
222
|
-
| 'datagrid.th'
|
|
223
|
-
| 'datagrid.td';
|
|
224
|
-
// ... and many more
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
Check `src/lib/context/preset.svelte.ts` for the complete list.
|
|
228
|
-
|
|
229
|
-
## Real-World Examples
|
|
230
|
-
|
|
231
|
-
### Example 1: Global Theme Setup
|
|
232
|
-
|
|
233
|
-
```svelte
|
|
234
|
-
<!-- +layout.svelte -->
|
|
235
|
-
<script lang="ts">
|
|
236
|
-
import { setPreset } from '@svelte-atoms/core/context';
|
|
237
|
-
|
|
238
|
-
const theme = {
|
|
239
|
-
// Base components
|
|
240
|
-
button: () => ({
|
|
241
|
-
class: 'rounded-lg px-4 py-2 font-medium transition-all duration-200'
|
|
242
|
-
}),
|
|
243
|
-
input: () => ({
|
|
244
|
-
class: 'rounded-md border border-gray-300 px-3 py-2 focus:border-blue-500'
|
|
245
|
-
}),
|
|
246
|
-
|
|
247
|
-
// Card system
|
|
248
|
-
card: () => ({
|
|
249
|
-
class: 'rounded-xl border border-gray-200 bg-white shadow-sm'
|
|
250
|
-
}),
|
|
251
|
-
'card.title': () => ({
|
|
252
|
-
class: 'text-lg font-semibold text-gray-900'
|
|
253
|
-
}),
|
|
254
|
-
'card.content': () => ({
|
|
255
|
-
class: 'p-6'
|
|
256
|
-
}),
|
|
257
|
-
|
|
258
|
-
// Dialog system
|
|
259
|
-
dialog: () => ({
|
|
260
|
-
class: 'max-w-lg rounded-2xl'
|
|
261
|
-
}),
|
|
262
|
-
'dialog.content': () => ({
|
|
263
|
-
class: 'p-6'
|
|
264
|
-
}),
|
|
265
|
-
'dialog.title': () => ({
|
|
266
|
-
class: 'text-xl font-bold'
|
|
267
|
-
})
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
setPreset(theme);
|
|
271
|
-
</script>
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
### Example 2: Dashboard Route Override
|
|
275
|
-
|
|
276
|
-
```svelte
|
|
277
|
-
<!-- routes/dashboard/+layout.svelte -->
|
|
278
|
-
<script lang="ts">
|
|
279
|
-
import { setPreset } from '@svelte-atoms/core/context';
|
|
280
|
-
|
|
281
|
-
// Override for compact dashboard UI
|
|
282
|
-
const dashboardTheme = {
|
|
283
|
-
button: () => ({
|
|
284
|
-
class: 'rounded-md px-3 py-1.5 text-sm'
|
|
285
|
-
}),
|
|
286
|
-
card: () => ({
|
|
287
|
-
class: 'rounded-lg bg-slate-50'
|
|
288
|
-
}),
|
|
289
|
-
'datagrid.th': () => ({
|
|
290
|
-
class: 'text-xs uppercase text-slate-500'
|
|
291
|
-
})
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
setPreset(dashboardTheme);
|
|
295
|
-
</script>
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
### Example 3: Component-Specific Styling
|
|
299
|
-
|
|
300
|
-
```svelte
|
|
301
|
-
<!-- components/PricingCards.svelte -->
|
|
302
|
-
<script lang="ts">
|
|
303
|
-
import { setPreset } from '@svelte-atoms/core/context';
|
|
304
|
-
import { Card } from '@svelte-atoms/core/components/card';
|
|
305
|
-
|
|
306
|
-
// Custom styling just for pricing cards
|
|
307
|
-
setPreset({
|
|
308
|
-
card: () => ({
|
|
309
|
-
class: 'rounded-2xl border-2 border-purple-200 hover:border-purple-400 transition-all'
|
|
310
|
-
}),
|
|
311
|
-
'card.title': () => ({
|
|
312
|
-
class: 'text-2xl font-bold text-purple-900'
|
|
313
|
-
})
|
|
314
|
-
});
|
|
315
|
-
</script>
|
|
316
|
-
|
|
317
|
-
<div class="grid grid-cols-3 gap-4">
|
|
318
|
-
<Card.Root>
|
|
319
|
-
<Card.Header>
|
|
320
|
-
<Card.Title>Basic</Card.Title>
|
|
321
|
-
</Card.Header>
|
|
322
|
-
<Card.Content>$9/month</Card.Content>
|
|
323
|
-
</Card.Root>
|
|
324
|
-
|
|
325
|
-
<!-- More pricing cards... -->
|
|
326
|
-
</div>
|
|
327
|
-
```
|
|
328
|
-
|
|
329
|
-
### Example 4: Reactive State-Based Styling
|
|
330
|
-
|
|
331
|
-
```svelte
|
|
332
|
-
<script lang="ts">
|
|
333
|
-
import { setPreset } from '@svelte-atoms/core/context';
|
|
334
|
-
import { defineState, defineProperty } from '@svelte-atoms/core/utils';
|
|
335
|
-
|
|
336
|
-
setPreset({
|
|
337
|
-
'accordion.item.header': (bond) => {
|
|
338
|
-
return defineState([
|
|
339
|
-
defineProperty('class', () => [
|
|
340
|
-
'px-4 py-3 cursor-pointer transition-all duration-200',
|
|
341
|
-
bond?.state?.isOpen
|
|
342
|
-
? 'bg-blue-50 text-blue-900 font-semibold'
|
|
343
|
-
: 'hover:bg-gray-50 text-gray-700'
|
|
344
|
-
])
|
|
345
|
-
]);
|
|
346
|
-
},
|
|
347
|
-
|
|
348
|
-
'collapsible.indicator': (bond) => ({
|
|
349
|
-
class: bond?.state?.isOpen
|
|
350
|
-
? 'rotate-180 transition-transform duration-200'
|
|
351
|
-
: 'transition-transform duration-200'
|
|
352
|
-
})
|
|
353
|
-
});
|
|
354
|
-
</script>
|
|
355
|
-
```
|
|
356
|
-
|
|
357
|
-
## Best Practices
|
|
358
|
-
|
|
359
|
-
1. **Set global presets at app root** - Define your base theme in `+layout.svelte` or `App.svelte`
|
|
360
|
-
|
|
361
|
-
2. **Override at route level** - Use route layouts (`+layout.svelte`) to customize sections
|
|
362
|
-
|
|
363
|
-
3. **Use component-level overrides sparingly** - Only when a specific component tree needs unique styling
|
|
364
|
-
|
|
365
|
-
4. **Use dot notation for specificity** - `'card.title'` is more specific than `'card'`
|
|
366
|
-
|
|
367
|
-
5. **Access bond state for reactivity** - Use bond parameter in preset functions to create dynamic styles
|
|
368
|
-
|
|
369
|
-
6. **Merge, don't replace** - Presets merge across contexts, so you can build up configurations gradually
|
|
370
|
-
|
|
371
|
-
7. **Keep presets simple** - Presets are for common patterns; use component props for one-off customizations
|
|
372
|
-
|
|
373
|
-
## Summary
|
|
374
|
-
|
|
375
|
-
Presets provide a powerful way to configure components globally:
|
|
376
|
-
|
|
377
|
-
- **Global**: Set at app root for consistent styling across your app
|
|
378
|
-
- **Route-level**: Override in route layouts for section-specific themes
|
|
379
|
-
- **Component-level**: Override in parent components for localized styling
|
|
380
|
-
- **Reactive**: Access bond state to create dynamic, state-based configurations
|
|
381
|
-
- **Merging**: Presets deep-merge across contexts, allowing gradual customization
|
|
382
|
-
|
|
383
|
-
Instead of repeating classes on every component, define them once in presets and let components inherit the configuration automatically.
|
package/llm/styling.md
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
# Styling Guide for @svelte-atoms/core
|
|
2
|
-
|
|
3
|
-
> **Audience**: LLMs and developers working with @svelte-atoms/core
|
|
4
|
-
|
|
5
|
-
## Core Concepts
|
|
6
|
-
|
|
7
|
-
All components accept a `class` prop that supports:
|
|
8
|
-
|
|
9
|
-
```svelte
|
|
10
|
-
<!-- String -->
|
|
11
|
-
<Button class="bg-blue-500 px-4 py-2 text-white">Click me</Button>
|
|
12
|
-
|
|
13
|
-
<!-- Array with conditionals -->
|
|
14
|
-
<Button class={['base-class', isActive && 'active-class', klass]}>Click me</Button>
|
|
15
|
-
|
|
16
|
-
<!-- Object -->
|
|
17
|
-
<Button class={{ 'bg-blue-500': isPrimary, 'bg-gray-500': !isPrimary }}>Click me</Button>
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## 1. TailwindCSS (Primary Method)
|
|
21
|
-
|
|
22
|
-
Use Tailwind utility classes for all styling needs:
|
|
23
|
-
|
|
24
|
-
```svelte
|
|
25
|
-
<!-- Layout & spacing -->
|
|
26
|
-
<Card.Root class="max-w-sm p-4">
|
|
27
|
-
<Card.Header>
|
|
28
|
-
<Card.Title class="text-lg font-semibold">Title</Card.Title>
|
|
29
|
-
</Card.Header>
|
|
30
|
-
</Card.Root>
|
|
31
|
-
|
|
32
|
-
<!-- Interactive states -->
|
|
33
|
-
<button class="bg-blue-500 px-4 py-2 text-white hover:bg-blue-600 active:bg-blue-700">
|
|
34
|
-
Action
|
|
35
|
-
</button>
|
|
36
|
-
|
|
37
|
-
<!-- Responsive -->
|
|
38
|
-
<h2 class="text-2xl md:text-3xl lg:text-4xl">Responsive heading</h2>
|
|
39
|
-
|
|
40
|
-
<!-- With opacity -->
|
|
41
|
-
<div class="bg-foreground/10">Subtle background</div>
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
### Class Order Pattern
|
|
45
|
-
|
|
46
|
-
```svelte
|
|
47
|
-
<HtmlAtom
|
|
48
|
-
class={[
|
|
49
|
-
'base-layout-classes', // flex, grid, etc.
|
|
50
|
-
'sizing-classes', // w-full, px-4, etc.
|
|
51
|
-
'visual-classes', // bg-blue-500, border, etc.
|
|
52
|
-
isOpen && 'conditional', // Conditional classes
|
|
53
|
-
'$preset', // Preset placeholder (if using presets)
|
|
54
|
-
klass // User overrides (highest priority)
|
|
55
|
-
]}
|
|
56
|
-
/>
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## 2. Preset System
|
|
60
|
-
|
|
61
|
-
Define default styles once, use everywhere:
|
|
62
|
-
|
|
63
|
-
```svelte
|
|
64
|
-
<script lang="ts">
|
|
65
|
-
import { setPreset } from '@svelte-atoms/core/context';
|
|
66
|
-
|
|
67
|
-
const preset = {
|
|
68
|
-
// Simple preset
|
|
69
|
-
button: () => ({
|
|
70
|
-
class: 'bg-primary text-primary-foreground px-4 py-2 rounded'
|
|
71
|
-
}),
|
|
72
|
-
|
|
73
|
-
// With custom element
|
|
74
|
-
accordion: () => ({
|
|
75
|
-
as: 'ul',
|
|
76
|
-
class: 'w-full max-w-md rounded-md border'
|
|
77
|
-
}),
|
|
78
|
-
|
|
79
|
-
// Dynamic with state
|
|
80
|
-
'accordion.item.header': (bond) => ({
|
|
81
|
-
class: bond?.state?.isActive ? 'text-foreground' : 'text-foreground/50'
|
|
82
|
-
})
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
setPreset(preset);
|
|
86
|
-
</script>
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
**Using the `$preset` placeholder:**
|
|
90
|
-
|
|
91
|
-
```svelte
|
|
92
|
-
<!-- In your component -->
|
|
93
|
-
<HtmlAtom
|
|
94
|
-
preset="button"
|
|
95
|
-
class={[
|
|
96
|
-
'component-defaults',
|
|
97
|
-
'$preset', // Replaced with preset classes
|
|
98
|
-
klass // User classes override
|
|
99
|
-
]}
|
|
100
|
-
/>
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
## 3. CSS Custom Properties
|
|
104
|
-
|
|
105
|
-
Use design tokens from `root.css`:
|
|
106
|
-
|
|
107
|
-
```svelte
|
|
108
|
-
<!-- Color tokens -->
|
|
109
|
-
<div class="bg-background text-foreground">Background color</div>
|
|
110
|
-
<Button class="bg-primary text-primary-foreground">Primary button</Button>
|
|
111
|
-
|
|
112
|
-
<!-- With opacity -->
|
|
113
|
-
<div class="bg-foreground/10 text-foreground/50">Subtle styling</div>
|
|
114
|
-
|
|
115
|
-
<!-- Borders and shadows -->
|
|
116
|
-
<Card.Root class="border-border border shadow-lg">Card</Card.Root>
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
**Available tokens:**
|
|
120
|
-
|
|
121
|
-
- Colors: `background`, `foreground`, `primary`, `secondary`, `muted`, `accent`, `destructive`, `border`
|
|
122
|
-
- Each color has `-foreground` variant
|
|
123
|
-
- Shadows: `shadow-sm`, `shadow-md`, `shadow-lg`, `shadow-xl`
|
|
124
|
-
|
|
125
|
-
## 4. Conditional Classes
|
|
126
|
-
|
|
127
|
-
Most common pattern from stories:
|
|
128
|
-
|
|
129
|
-
```svelte
|
|
130
|
-
<script>
|
|
131
|
-
let isOpen = $state(false);
|
|
132
|
-
</script>
|
|
133
|
-
|
|
134
|
-
<!-- Array with conditions -->
|
|
135
|
-
<Collapsible.Body class={['pointer-events-none h-0 opacity-0', isOpen && 'pointer-events-auto']}>
|
|
136
|
-
Content
|
|
137
|
-
</Collapsible.Body>
|
|
138
|
-
|
|
139
|
-
<!-- Ternary -->
|
|
140
|
-
<Tab.Root class={isActive ? 'opacity-100' : 'opacity-50'}>Tab content</Tab.Root>
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
## 5. Component Variants
|
|
144
|
-
|
|
145
|
-
Create reusable variants:
|
|
146
|
-
|
|
147
|
-
```svelte
|
|
148
|
-
<script lang="ts">
|
|
149
|
-
let { variant = 'primary', size = 'md', class: klass = '' } = $props();
|
|
150
|
-
|
|
151
|
-
const variants = {
|
|
152
|
-
primary: 'bg-blue-500 text-white hover:bg-blue-600',
|
|
153
|
-
secondary: 'bg-gray-200 text-gray-800 hover:bg-gray-300'
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
const sizes = {
|
|
157
|
-
sm: 'px-3 py-1.5 text-xs',
|
|
158
|
-
md: 'px-4 py-2 text-sm',
|
|
159
|
-
lg: 'px-6 py-3 text-base'
|
|
160
|
-
};
|
|
161
|
-
</script>
|
|
162
|
-
|
|
163
|
-
<Button class="{variants[variant]} {sizes[size]} {klass}">
|
|
164
|
-
{@render children?.()}
|
|
165
|
-
</Button>
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
## 6. Inline Styles
|
|
169
|
-
|
|
170
|
-
Use for dynamic values only:
|
|
171
|
-
|
|
172
|
-
```svelte
|
|
173
|
-
<script>
|
|
174
|
-
let width = $state(240);
|
|
175
|
-
</script>
|
|
176
|
-
|
|
177
|
-
<!-- ✅ Good: Dynamic values -->
|
|
178
|
-
<div style="width: {width}px; opacity: {isOpen ? 1 : 0}">Dynamic sizing</div>
|
|
179
|
-
|
|
180
|
-
<!-- ❌ Avoid: Static styling -->
|
|
181
|
-
<div style="padding: 16px; background: blue;">Use Tailwind instead</div>
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
## Quick Reference
|
|
185
|
-
|
|
186
|
-
| Need | Use |
|
|
187
|
-
| -------------- | ------------------------------------ |
|
|
188
|
-
| Static styling | TailwindCSS classes |
|
|
189
|
-
| Theme/defaults | Preset system |
|
|
190
|
-
| Conditional | Array syntax with `&&` |
|
|
191
|
-
| Responsive | Tailwind breakpoints (`md:`, `lg:`) |
|
|
192
|
-
| Colors | CSS custom properties (`bg-primary`) |
|
|
193
|
-
| Dynamic values | Inline styles |
|
|
194
|
-
| Variants | Computed class objects |
|
|
195
|
-
|
|
196
|
-
## Best Practices
|
|
197
|
-
|
|
198
|
-
1. **Prefer Tailwind** - Use utility classes for 90% of styling
|
|
199
|
-
2. **Class order matters** - Base → Conditionals → `$preset` → User classes
|
|
200
|
-
3. **Use presets for consistency** - Define theme defaults once
|
|
201
|
-
4. **Avoid inline styles** - Use only for truly dynamic values
|
|
202
|
-
5. **Keep specificity low** - Avoid `!important`, let cascade work
|
|
203
|
-
|
|
204
|
-
## Class Merging
|
|
205
|
-
|
|
206
|
-
The `cn()` utility merges classes intelligently:
|
|
207
|
-
|
|
208
|
-
```typescript
|
|
209
|
-
import { cn } from '@svelte-atoms/core/utils';
|
|
210
|
-
|
|
211
|
-
// Resolves conflicts automatically
|
|
212
|
-
cn('px-2 py-1', 'px-4'); // Result: 'py-1 px-4'
|
|
213
|
-
|
|
214
|
-
// Handles conditionals
|
|
215
|
-
cn('base', isActive && 'active', false && 'ignored');
|
|
216
|
-
```
|
package/llm/usage.md
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
# Component Usage Patterns
|
|
2
|
-
|
|
3
|
-
## Namespace.Atom Pattern
|
|
4
|
-
|
|
5
|
-
Components follow a hierarchical naming pattern using dot notation:
|
|
6
|
-
|
|
7
|
-
```svelte
|
|
8
|
-
<Form.Root>
|
|
9
|
-
<Form.Field>
|
|
10
|
-
<Form.Label />
|
|
11
|
-
<Form.Control />
|
|
12
|
-
</Form.Field>
|
|
13
|
-
</Form.Root>
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
## Naming Convention
|
|
17
|
-
|
|
18
|
-
- **Namespace** = Component family (e.g., `Form`, `Button`, `Dropdown`)
|
|
19
|
-
- **Atom** = Specific component within the family (e.g., `Root`, `Field`, `Label`)
|
|
20
|
-
|
|
21
|
-
## Import Pattern
|
|
22
|
-
|
|
23
|
-
```javascript
|
|
24
|
-
import { Form } from '$lib/components/form';
|
|
25
|
-
|
|
26
|
-
// Usage
|
|
27
|
-
<Form.Root>
|
|
28
|
-
<Form.Field>
|
|
29
|
-
<Form.Label>Username</Form.Label>
|
|
30
|
-
<Form.Control type="text" />
|
|
31
|
-
</Form.Field>
|
|
32
|
-
</Form.Root>;
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Benefits
|
|
36
|
-
|
|
37
|
-
- **Clear hierarchy** - Components group logically
|
|
38
|
-
- **Namespace isolation** - Prevents naming conflicts
|
|
39
|
-
- **Discoverable API** - IDE autocomplete shows related components
|
|
40
|
-
- **Consistent patterns** - Same structure across all component families
|
|
41
|
-
|
|
42
|
-
## Examples
|
|
43
|
-
|
|
44
|
-
- `Button.Root`, `Button.Icon`, `Button.Text`
|
|
45
|
-
- `Dropdown.Root`, `Dropdown.Trigger`, `Dropdown.Content`
|
|
46
|
-
- `Form.Root`, `Form.Field`, `Form.Label`, `Form.Control`
|