@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
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { cn } from '../../utils';
|
|
2
|
+
import { call } from '../../utils/function';
|
|
3
|
+
/**
|
|
4
|
+
* Cache for resolved variants to avoid recomputation
|
|
5
|
+
* Key: JSON stringified combination of variant props
|
|
6
|
+
*/
|
|
7
|
+
const variantCache = new Map();
|
|
8
|
+
/**
|
|
9
|
+
* Maximum cache size to prevent memory leaks
|
|
10
|
+
*/
|
|
11
|
+
const MAX_CACHE_SIZE = 100;
|
|
12
|
+
/**
|
|
13
|
+
* Resolves preset to its final value, handling both direct values and factory functions
|
|
14
|
+
*/
|
|
15
|
+
export function resolvePreset(preset) {
|
|
16
|
+
if (!preset)
|
|
17
|
+
return undefined;
|
|
18
|
+
const result = call(preset);
|
|
19
|
+
// If call returns a function, call it again (handle deferred preset)
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
return typeof result === 'function' ? result() : result;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Pure function to resolve variant definition to props
|
|
25
|
+
* Caches results to avoid recomputation with same inputs
|
|
26
|
+
*/
|
|
27
|
+
export function resolveVariants(def, bond, props) {
|
|
28
|
+
const { variants: variantMap, compounds, defaults, class: baseClass } = def;
|
|
29
|
+
// Merge props with defaults
|
|
30
|
+
const finalProps = { ...defaults, ...props };
|
|
31
|
+
// Create cache key from final props (only variant-related props)
|
|
32
|
+
const variantKeys = variantMap ? Object.keys(variantMap) : [];
|
|
33
|
+
const relevantProps = Object.fromEntries(Object.entries(finalProps).filter(([key]) => variantKeys.includes(key)));
|
|
34
|
+
const cacheKey = JSON.stringify({ relevantProps, baseClass, compounds });
|
|
35
|
+
// Check cache
|
|
36
|
+
if (variantCache.has(cacheKey)) {
|
|
37
|
+
return variantCache.get(cacheKey);
|
|
38
|
+
}
|
|
39
|
+
const classes = [];
|
|
40
|
+
const attributes = {};
|
|
41
|
+
// Add base class
|
|
42
|
+
if (baseClass)
|
|
43
|
+
classes.push(baseClass);
|
|
44
|
+
// Add variant classes
|
|
45
|
+
if (variantMap) {
|
|
46
|
+
for (const [key, value] of Object.entries(finalProps)) {
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
+
const variantValue = variantMap[key]?.[value];
|
|
49
|
+
if (variantValue !== undefined) {
|
|
50
|
+
const resolved = typeof variantValue === 'function' ? variantValue(bond) : variantValue;
|
|
51
|
+
if (typeof resolved === 'string') {
|
|
52
|
+
classes.push(resolved);
|
|
53
|
+
}
|
|
54
|
+
else if (typeof resolved === 'object' && resolved !== null) {
|
|
55
|
+
if ('class' in resolved) {
|
|
56
|
+
classes.push(resolved.class);
|
|
57
|
+
}
|
|
58
|
+
// Add other attributes (including Symbol-based attachment keys)
|
|
59
|
+
Object.getOwnPropertySymbols(resolved).forEach((sym) => {
|
|
60
|
+
attributes[sym] = resolved[sym];
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Add compound variants
|
|
67
|
+
if (compounds) {
|
|
68
|
+
for (const compound of compounds) {
|
|
69
|
+
const { class: compoundClass, ...compoundProps } = compound;
|
|
70
|
+
const matches = Object.entries(compoundProps).every(([key, value]) => finalProps[key] === value);
|
|
71
|
+
if (matches) {
|
|
72
|
+
if (compoundClass)
|
|
73
|
+
classes.push(compoundClass);
|
|
74
|
+
// Add compound attributes
|
|
75
|
+
Object.entries(compound).forEach(([k, v]) => {
|
|
76
|
+
if (k !== 'class' && !Object.keys(compoundProps).includes(k)) {
|
|
77
|
+
attributes[k] = v;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const result = {
|
|
84
|
+
class: classes,
|
|
85
|
+
...attributes
|
|
86
|
+
};
|
|
87
|
+
// Store in cache (limit cache size to prevent memory leaks)
|
|
88
|
+
if (variantCache.size >= MAX_CACHE_SIZE) {
|
|
89
|
+
// Clear oldest entry (first in Map)
|
|
90
|
+
const firstKey = variantCache.keys().next().value;
|
|
91
|
+
if (firstKey)
|
|
92
|
+
variantCache.delete(firstKey);
|
|
93
|
+
}
|
|
94
|
+
variantCache.set(cacheKey, result);
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Pure function to merge preset and local variant definitions
|
|
99
|
+
* Returns merged variant props with local overriding preset
|
|
100
|
+
*/
|
|
101
|
+
export function mergeVariants(
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
103
|
+
presetVariants, presetClass,
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
105
|
+
presetCompounds,
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
|
+
presetDefaults, localVariants, bond, props) {
|
|
108
|
+
// No variants at all
|
|
109
|
+
if (!presetVariants && !localVariants)
|
|
110
|
+
return undefined;
|
|
111
|
+
// Only preset variants (raw object from preset)
|
|
112
|
+
if (presetVariants && !localVariants) {
|
|
113
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
114
|
+
const variantDef = {
|
|
115
|
+
class: presetClass ?? '',
|
|
116
|
+
variants: presetVariants,
|
|
117
|
+
compounds: presetCompounds ?? [],
|
|
118
|
+
defaults: presetDefaults ?? {}
|
|
119
|
+
};
|
|
120
|
+
return resolveVariants(variantDef, bond, props);
|
|
121
|
+
}
|
|
122
|
+
// Only local variants
|
|
123
|
+
if (!presetVariants && localVariants) {
|
|
124
|
+
return localVariants;
|
|
125
|
+
}
|
|
126
|
+
// Both exist - merge them
|
|
127
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
128
|
+
const presetVariantDef = {
|
|
129
|
+
class: presetClass ?? '',
|
|
130
|
+
variants: presetVariants ?? {},
|
|
131
|
+
compounds: presetCompounds ?? [],
|
|
132
|
+
defaults: presetDefaults ?? {}
|
|
133
|
+
};
|
|
134
|
+
const presetResolved = resolveVariants(presetVariantDef, bond, props);
|
|
135
|
+
// Merge the resolved variant props
|
|
136
|
+
// Local variant classes and attributes override preset
|
|
137
|
+
const presetClasses = Array.isArray(presetResolved.class)
|
|
138
|
+
? presetResolved.class
|
|
139
|
+
: [presetResolved.class];
|
|
140
|
+
const localClasses = Array.isArray(localVariants?.class)
|
|
141
|
+
? localVariants.class
|
|
142
|
+
: [localVariants?.class];
|
|
143
|
+
return {
|
|
144
|
+
class: [...presetClasses, ...localClasses].filter(Boolean),
|
|
145
|
+
...presetResolved,
|
|
146
|
+
...localVariants
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Pure function to merge classes with $preset placeholder support
|
|
151
|
+
* Handles the special $preset placeholder for precise positioning of preset classes
|
|
152
|
+
*/
|
|
153
|
+
export function mergeClassesWithPreset(userClass, presetClass, variantClass) {
|
|
154
|
+
const klassStr = cn(userClass ?? '');
|
|
155
|
+
// Check for $preset placeholder first
|
|
156
|
+
if (!klassStr.includes('$preset')) {
|
|
157
|
+
// No placeholder - normal merge: variants override direct class
|
|
158
|
+
return cn(userClass, variantClass ?? '');
|
|
159
|
+
}
|
|
160
|
+
// Has placeholder - calculate position and inject preset classes
|
|
161
|
+
const parts = klassStr.split('$preset');
|
|
162
|
+
// Only keep the last $preset placeholder
|
|
163
|
+
const beforeLastPlaceholder = parts.slice(0, -1).join('');
|
|
164
|
+
const afterLastPlaceholder = parts[parts.length - 1];
|
|
165
|
+
const presetClassString = cn(presetClass);
|
|
166
|
+
// Merge: before + preset + variants + after
|
|
167
|
+
return cn(beforeLastPlaceholder, presetClassString, variantClass ?? '', afterLastPlaceholder);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Pure function to resolve local variants
|
|
171
|
+
* Handles both function-based and VariantDefinition-based variants
|
|
172
|
+
*/
|
|
173
|
+
export function resolveLocalVariants(
|
|
174
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
175
|
+
variants, bond, props) {
|
|
176
|
+
if (!variants)
|
|
177
|
+
return undefined;
|
|
178
|
+
// If it's a function, call it directly
|
|
179
|
+
if (typeof variants === 'function') {
|
|
180
|
+
return variants(bond, props);
|
|
181
|
+
}
|
|
182
|
+
// Otherwise it's a VariantDefinition, resolve it
|
|
183
|
+
return resolveVariants(variants, bond, props);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Pure function to extract rest props by filtering out preset and variant-specific props
|
|
187
|
+
*/
|
|
188
|
+
export function extractRestProps(
|
|
189
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
190
|
+
preset, mergedVariants, restProps) {
|
|
191
|
+
const presetProps = { ...preset };
|
|
192
|
+
const presetKeysToRemove = ['class', 'base', 'as', 'variants', 'compounds', 'defaults'];
|
|
193
|
+
for (const key of presetKeysToRemove) {
|
|
194
|
+
delete presetProps[key];
|
|
195
|
+
}
|
|
196
|
+
const variantsRestProps = { ...mergedVariants };
|
|
197
|
+
const variantKeysToRemove = ['class', 'variants', 'compounds', 'defaults'];
|
|
198
|
+
for (const key of variantKeysToRemove) {
|
|
199
|
+
delete variantsRestProps[key];
|
|
200
|
+
}
|
|
201
|
+
return { ...presetProps, ...variantsRestProps, ...restProps };
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Pure function to check if a base is a snippet
|
|
205
|
+
*/
|
|
206
|
+
export function isSnippetBase(base) {
|
|
207
|
+
return typeof base === 'function' && base.length === 1 && !base.prototype;
|
|
208
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
<script module>
|
|
2
|
-
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
-
import AvatarCmp from './avatar.svelte';
|
|
4
|
-
import CalendarRegularIcon from '../../icons/icon-arrow-down.svelte';
|
|
5
|
-
|
|
6
|
-
const { Story } = defineMeta({
|
|
7
|
-
title: 'ATOMS/Avatar'
|
|
8
|
-
});
|
|
9
|
-
</script>
|
|
10
|
-
|
|
11
|
-
<Story name="Avatar">
|
|
12
|
-
<div class="flex h-full w-full items-center justify-center gap-4">
|
|
13
|
-
<AvatarCmp alt="Abdelhalim Riache" />
|
|
14
|
-
|
|
15
|
-
<AvatarCmp src={CalendarRegularIcon} alt="Abdelhalim Riache" />
|
|
16
|
-
|
|
17
|
-
<AvatarCmp
|
|
18
|
-
src="https://sevennaturalwonders.org/wp-content/uploads/2023/12/1-Mount-Fuji.jpg"
|
|
19
|
-
alt="Mount Fuji"
|
|
20
|
-
/>
|
|
21
|
-
</div>
|
|
22
|
-
</Story>
|
|
1
|
+
<script module>
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import AvatarCmp from './avatar.svelte';
|
|
4
|
+
import CalendarRegularIcon from '../../icons/icon-arrow-down.svelte';
|
|
5
|
+
|
|
6
|
+
const { Story } = defineMeta({
|
|
7
|
+
title: 'ATOMS/Avatar'
|
|
8
|
+
});
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<Story name="Avatar">
|
|
12
|
+
<div class="flex h-full w-full items-center justify-center gap-4">
|
|
13
|
+
<AvatarCmp alt="Abdelhalim Riache" />
|
|
14
|
+
|
|
15
|
+
<AvatarCmp src={CalendarRegularIcon} alt="Abdelhalim Riache" />
|
|
16
|
+
|
|
17
|
+
<AvatarCmp
|
|
18
|
+
src="https://sevennaturalwonders.org/wp-content/uploads/2023/12/1-Mount-Fuji.jpg"
|
|
19
|
+
alt="Mount Fuji"
|
|
20
|
+
/>
|
|
21
|
+
</div>
|
|
22
|
+
</Story>
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
<script module>
|
|
2
|
-
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
-
import { Badge as BadgeModule } from '.';
|
|
4
|
-
|
|
5
|
-
const { Story } = defineMeta({
|
|
6
|
-
title: 'ATOMS/Badge'
|
|
7
|
-
});
|
|
8
|
-
</script>
|
|
9
|
-
|
|
10
|
-
<Story name="Badge">
|
|
11
|
-
<BadgeModule>Badge</BadgeModule>
|
|
12
|
-
</Story>
|
|
1
|
+
<script module>
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import { Badge as BadgeModule } from '.';
|
|
4
|
+
|
|
5
|
+
const { Story } = defineMeta({
|
|
6
|
+
title: 'ATOMS/Badge'
|
|
7
|
+
});
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<Story name="Badge">
|
|
11
|
+
<BadgeModule>Badge</BadgeModule>
|
|
12
|
+
</Story>
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { HtmlAtom } from '../atom';
|
|
3
|
-
import type { BadgeProps } from './types';
|
|
4
|
-
|
|
5
|
-
let { class: klass = '', as = 'span', children = undefined, ...restProps }: BadgeProps = $props();
|
|
6
|
-
</script>
|
|
7
|
-
|
|
8
|
-
<HtmlAtom
|
|
9
|
-
preset="badge"
|
|
10
|
-
class={[
|
|
11
|
-
'bg-foreground/10 border-border text-foreground inline-flex h-auto w-fit items-center rounded-full px-2.5 py-0.5 text-xs font-medium',
|
|
12
|
-
'$preset',
|
|
13
|
-
klass
|
|
14
|
-
]}
|
|
15
|
-
{as}
|
|
16
|
-
{...restProps}
|
|
17
|
-
>
|
|
18
|
-
{@render children?.()}
|
|
19
|
-
</HtmlAtom>
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { HtmlAtom } from '../atom';
|
|
3
|
+
import type { BadgeProps } from './types';
|
|
4
|
+
|
|
5
|
+
let { class: klass = '', as = 'span', children = undefined, ...restProps }: BadgeProps = $props();
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<HtmlAtom
|
|
9
|
+
preset="badge"
|
|
10
|
+
class={[
|
|
11
|
+
'bg-foreground/10 border-border text-foreground inline-flex h-auto w-fit items-center rounded-full px-2.5 py-0.5 text-xs font-medium',
|
|
12
|
+
'$preset',
|
|
13
|
+
klass
|
|
14
|
+
]}
|
|
15
|
+
{as}
|
|
16
|
+
{...restProps}
|
|
17
|
+
>
|
|
18
|
+
{@render children?.()}
|
|
19
|
+
</HtmlAtom>
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
<script module>
|
|
2
|
-
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
-
import { Breadcrumb as BreadcrumbModule } from '.';
|
|
4
|
-
|
|
5
|
-
const { Story } = defineMeta({
|
|
6
|
-
title: 'ATOMS/Breadcrumb'
|
|
7
|
-
});
|
|
8
|
-
</script>
|
|
9
|
-
|
|
10
|
-
<Story name="Breadcrumb">
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
</Story>
|
|
1
|
+
<script module>
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import { Breadcrumb as BreadcrumbModule } from '.';
|
|
4
|
+
|
|
5
|
+
const { Story } = defineMeta({
|
|
6
|
+
title: 'ATOMS/Breadcrumb'
|
|
7
|
+
});
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<Story name="Breadcrumb">
|
|
11
|
+
<BreadcrumbModule.Root>
|
|
12
|
+
<BreadcrumbModule.Item href="/">Home</BreadcrumbModule.Item>
|
|
13
|
+
<BreadcrumbModule.Separator>/</BreadcrumbModule.Separator>
|
|
14
|
+
<BreadcrumbModule.Item href="/vehicles">Vehicles</BreadcrumbModule.Item>
|
|
15
|
+
</BreadcrumbModule.Root>
|
|
16
|
+
</Story>
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
<script module>
|
|
2
|
-
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
-
import ButtonCmp from './button.svelte';
|
|
4
|
-
|
|
5
|
-
const { Story } = defineMeta({
|
|
6
|
-
title: 'ATOMS/Button',
|
|
7
|
-
argTypes: {
|
|
8
|
-
variant: {
|
|
9
|
-
control: 'select',
|
|
10
|
-
options: ['primary', 'secondary', 'destructive', 'outline', 'ghost'],
|
|
11
|
-
description: 'Button variant style',
|
|
12
|
-
table: {
|
|
13
|
-
defaultValue: { summary: 'primary' }
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
</script>
|
|
19
|
-
|
|
20
|
-
<script lang="ts">
|
|
21
|
-
</script>
|
|
22
|
-
|
|
23
|
-
<Story name="Button">
|
|
24
|
-
{#snippet template(args)}
|
|
25
|
-
<ButtonCmp {...args}>Click me</ButtonCmp>
|
|
26
|
-
{/snippet}
|
|
27
|
-
</Story>
|
|
1
|
+
<script module>
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import ButtonCmp from './button.svelte';
|
|
4
|
+
|
|
5
|
+
const { Story } = defineMeta({
|
|
6
|
+
title: 'ATOMS/Button',
|
|
7
|
+
argTypes: {
|
|
8
|
+
variant: {
|
|
9
|
+
control: 'select',
|
|
10
|
+
options: ['primary', 'secondary', 'destructive', 'outline', 'ghost'],
|
|
11
|
+
description: 'Button variant style',
|
|
12
|
+
table: {
|
|
13
|
+
defaultValue: { summary: 'primary' }
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<script lang="ts">
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<Story name="Button">
|
|
24
|
+
{#snippet template(args)}
|
|
25
|
+
<ButtonCmp {...args}>Click me</ButtonCmp>
|
|
26
|
+
{/snippet}
|
|
27
|
+
</Story>
|
|
@@ -34,6 +34,8 @@
|
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
function handleClick() {
|
|
37
|
+
if (day.disabled) return;
|
|
38
|
+
|
|
37
39
|
if (isRange) {
|
|
38
40
|
const start = calendarBond?.state.props.start;
|
|
39
41
|
if (!start) {
|
|
@@ -58,13 +60,16 @@
|
|
|
58
60
|
{preset}
|
|
59
61
|
class={[
|
|
60
62
|
'calendar-day text-foreground border-border hover:bg-accent hover:text-accent-foreground h-12 cursor-pointer border-b border-l p-1 transition-colors',
|
|
61
|
-
day.offmonth && 'text-muted-foreground bg-muted/
|
|
62
|
-
day.weekend && 'bg-
|
|
63
|
+
day.offmonth && !day.disabled && 'text-muted-foreground/50 bg-muted/50',
|
|
64
|
+
day.weekend && 'bg-accent',
|
|
63
65
|
isSelected &&
|
|
64
66
|
'bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground',
|
|
65
67
|
isSelected && day.offmonth && 'bg-primary/70',
|
|
66
|
-
day.today &&
|
|
67
|
-
|
|
68
|
+
day.today &&
|
|
69
|
+
!day.disabled &&
|
|
70
|
+
!isSelected &&
|
|
71
|
+
'border-primary bg-primary/5 border-2 font-semibold',
|
|
72
|
+
day.disabled && 'pointer-events-none opacity-25',
|
|
68
73
|
klass
|
|
69
74
|
]}
|
|
70
75
|
data-disabled={day.disabled}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
<script module>
|
|
2
|
-
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
-
import { Calendar as CalendarModule } from '.';
|
|
4
|
-
|
|
5
|
-
const { Story } = defineMeta({
|
|
6
|
-
title: 'Atoms/Calendar'
|
|
7
|
-
});
|
|
8
|
-
</script>
|
|
9
|
-
|
|
10
|
-
<script>
|
|
11
|
-
</script>
|
|
12
|
-
|
|
13
|
-
<Story name="Calendar">
|
|
14
|
-
{#snippet children({ args })}
|
|
15
|
-
<div class="flex h-fit items-center justify-center">
|
|
16
|
-
<CalendarModule.Root>
|
|
17
|
-
<CalendarModule.Header></CalendarModule.Header>
|
|
18
|
-
<CalendarModule.Body>
|
|
19
|
-
{#snippet children({ day })}
|
|
20
|
-
<CalendarModule.Day {day}></CalendarModule.Day>
|
|
21
|
-
{/snippet}
|
|
22
|
-
</CalendarModule.Body>
|
|
23
|
-
</CalendarModule.Root>
|
|
24
|
-
</div>
|
|
25
|
-
{/snippet}
|
|
26
|
-
</Story>
|
|
1
|
+
<script module>
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import { Calendar as CalendarModule } from '.';
|
|
4
|
+
|
|
5
|
+
const { Story } = defineMeta({
|
|
6
|
+
title: 'Atoms/Calendar'
|
|
7
|
+
});
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<script>
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<Story name="Calendar">
|
|
14
|
+
{#snippet children({ args })}
|
|
15
|
+
<div class="flex h-fit items-center justify-center">
|
|
16
|
+
<CalendarModule.Root>
|
|
17
|
+
<CalendarModule.Header></CalendarModule.Header>
|
|
18
|
+
<CalendarModule.Body>
|
|
19
|
+
{#snippet children({ day })}
|
|
20
|
+
<CalendarModule.Day {day}></CalendarModule.Day>
|
|
21
|
+
{/snippet}
|
|
22
|
+
</CalendarModule.Body>
|
|
23
|
+
</CalendarModule.Root>
|
|
24
|
+
</div>
|
|
25
|
+
{/snippet}
|
|
26
|
+
</Story>
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
<script lang="ts" generics="E extends keyof HTMLElementTagNameMap = 'div', B extends Base = Base">
|
|
2
|
-
import { HtmlAtom, type Base } from '../atom';
|
|
3
|
-
export type { CardContentProps } from './types';
|
|
4
|
-
import { CardBond } from './bond.svelte';
|
|
5
|
-
|
|
6
|
-
const bond = CardBond.get();
|
|
7
|
-
|
|
8
|
-
let {
|
|
9
|
-
class: klass = '',
|
|
10
|
-
children = undefined,
|
|
11
|
-
onmount = undefined,
|
|
12
|
-
ondestroy = undefined,
|
|
13
|
-
animate = undefined,
|
|
14
|
-
enter = undefined,
|
|
15
|
-
exit = undefined,
|
|
16
|
-
initial = undefined,
|
|
17
|
-
...restProps
|
|
18
|
-
}: CardContentProps<E, B> = $props();
|
|
19
|
-
|
|
20
|
-
const contentProps = $derived({
|
|
21
|
-
...bond?.content(),
|
|
22
|
-
...restProps
|
|
23
|
-
});
|
|
24
|
-
</script>
|
|
25
|
-
|
|
26
|
-
<HtmlAtom
|
|
27
|
-
{bond}
|
|
28
|
-
preset="card.content"
|
|
29
|
-
class={['card-content border-border px-4 pb-4', '$preset', klass]}
|
|
30
|
-
enter={enter?.bind(bond.state)}
|
|
31
|
-
exit={exit?.bind(bond.state)}
|
|
32
|
-
initial={initial?.bind(bond.state)}
|
|
33
|
-
animate={animate?.bind(bond.state)}
|
|
34
|
-
onmount={onmount?.bind(bond.state)}
|
|
35
|
-
ondestroy={ondestroy?.bind(bond.state)}
|
|
36
|
-
{...contentProps}
|
|
37
|
-
>
|
|
38
|
-
{@render children?.()}
|
|
39
|
-
</HtmlAtom>
|
|
1
|
+
<script lang="ts" generics="E extends keyof HTMLElementTagNameMap = 'div', B extends Base = Base">
|
|
2
|
+
import { HtmlAtom, type Base } from '../atom';
|
|
3
|
+
export type { CardContentProps } from './types';
|
|
4
|
+
import { CardBond } from './bond.svelte';
|
|
5
|
+
|
|
6
|
+
const bond = CardBond.get();
|
|
7
|
+
|
|
8
|
+
let {
|
|
9
|
+
class: klass = '',
|
|
10
|
+
children = undefined,
|
|
11
|
+
onmount = undefined,
|
|
12
|
+
ondestroy = undefined,
|
|
13
|
+
animate = undefined,
|
|
14
|
+
enter = undefined,
|
|
15
|
+
exit = undefined,
|
|
16
|
+
initial = undefined,
|
|
17
|
+
...restProps
|
|
18
|
+
}: CardContentProps<E, B> = $props();
|
|
19
|
+
|
|
20
|
+
const contentProps = $derived({
|
|
21
|
+
...bond?.content(),
|
|
22
|
+
...restProps
|
|
23
|
+
});
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<HtmlAtom
|
|
27
|
+
{bond}
|
|
28
|
+
preset="card.content"
|
|
29
|
+
class={['card-content border-border px-4 pb-4', '$preset', klass]}
|
|
30
|
+
enter={enter?.bind(bond.state)}
|
|
31
|
+
exit={exit?.bind(bond.state)}
|
|
32
|
+
initial={initial?.bind(bond.state)}
|
|
33
|
+
animate={animate?.bind(bond.state)}
|
|
34
|
+
onmount={onmount?.bind(bond.state)}
|
|
35
|
+
ondestroy={ondestroy?.bind(bond.state)}
|
|
36
|
+
{...contentProps}
|
|
37
|
+
>
|
|
38
|
+
{@render children?.()}
|
|
39
|
+
</HtmlAtom>
|