svelte-multistyle-ui 0.0.8-alpha → 0.0.9-alpha
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 +59 -0
- package/dist/components/MultiSelect.svelte +38 -2
- package/dist/components/Select.svelte +178 -83
- package/dist/components/input-styles.css +1 -0
- package/dist/components/multiselect-styles.css +335 -338
- package/dist/components/select-styles.css +309 -252
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -140,6 +140,7 @@ pnpm install
|
|
|
140
140
|
pnpm dev # start the demo
|
|
141
141
|
pnpm build # build the demo (static HTML/CSS/JS) to docs/
|
|
142
142
|
pnpm build:lib # build the library for publishing (to dist/)
|
|
143
|
+
pnpm gen:sample # dry-run the CLI generator sample fixture
|
|
143
144
|
pnpm preview # preview the production demo
|
|
144
145
|
pnpm test # run Playwright visual tests
|
|
145
146
|
pnpm test:ui # open the Playwright UI runner
|
|
@@ -151,6 +152,64 @@ The demo supports URL parameters for quick visual regression checks:
|
|
|
151
152
|
/?style=brutalist&theme=midnight&mode=dark
|
|
152
153
|
```
|
|
153
154
|
|
|
155
|
+
## CLI page generator
|
|
156
|
+
|
|
157
|
+
`svelte-multistyle-ui` ships a YAML → Svelte 5 page generator. It auto-detects three YAML input styles and emits token-efficient markup with auto-bound state and fake data injection.
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
npx svelte-multistyle-ui generate --input page.yaml --output ./src/routes/demo/+page.svelte
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**Supported YAML styles:**
|
|
164
|
+
|
|
165
|
+
1. **Compact tree DSL** (recommended):
|
|
166
|
+
```yaml
|
|
167
|
+
Card:
|
|
168
|
+
- Row:
|
|
169
|
+
- Input:
|
|
170
|
+
label: Username
|
|
171
|
+
placeholder: Enter name
|
|
172
|
+
- Button:
|
|
173
|
+
label: Submit
|
|
174
|
+
```
|
|
175
|
+
2. **Root-level card list**:
|
|
176
|
+
```yaml
|
|
177
|
+
- Card:
|
|
178
|
+
- Row:
|
|
179
|
+
- Input:
|
|
180
|
+
label: Username
|
|
181
|
+
- Card:
|
|
182
|
+
- Row:
|
|
183
|
+
- Button:
|
|
184
|
+
label: Submit
|
|
185
|
+
```
|
|
186
|
+
3. **Inline shorthand**:
|
|
187
|
+
```yaml
|
|
188
|
+
Card
|
|
189
|
+
Row
|
|
190
|
+
Input: { label: Username }
|
|
191
|
+
Button: { label: Submit }
|
|
192
|
+
```
|
|
193
|
+
4. **Verbose schema**:
|
|
194
|
+
```yaml
|
|
195
|
+
state:
|
|
196
|
+
- { name: username, type: string, default: "" }
|
|
197
|
+
body:
|
|
198
|
+
- component: Input
|
|
199
|
+
props:
|
|
200
|
+
label: Username
|
|
201
|
+
bind: username
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**Features:**
|
|
205
|
+
|
|
206
|
+
- **Auto-binding** — `Input`, `Select`, `Checkbox`, `Toggle`, `Radio`, `Slider`, `DatePicker`, `ButtonGroup`, `Rating`, `Tabs`, `Pagination`, `Popover`, `Modal`, `Drawer`, and `CommandPalette` get automatic `$state` vars and the correct `bind:*` directive.
|
|
207
|
+
- **Fake data** — missing `options` for `Select`/`MultiSelect`, missing `data` for `Table`, and missing chart data are synthesized automatically.
|
|
208
|
+
- **Option conversion** — `options: [Apple, Banana]` becomes `[{value:"apple",label:"Apple"}, ...]`.
|
|
209
|
+
- **Lightweight output** — generated files import from `svelte-multistyle-ui`, declare `$state`, include an empty `onMount` stub, and emit markup only; dark/light mode is handled by `initMultistyleUI` in the app layout.
|
|
210
|
+
|
|
211
|
+
See `skill/references/generator-cli.md` for the full CLI reference.
|
|
212
|
+
|
|
154
213
|
## Architecture notes
|
|
155
214
|
|
|
156
215
|
- Each component uses a base class (`s-<component>`), a style override class (`s-<component>-<style>`), and a theme class (`theme-<theme>`).
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import "./multiselect-styles.css";
|
|
3
|
+
import { portal } from "../actions/portal.js";
|
|
3
4
|
import { defaults } from "../config.js";
|
|
4
5
|
import { cn } from "../utils/cn.js";
|
|
5
6
|
|
|
@@ -20,6 +21,8 @@
|
|
|
20
21
|
|
|
21
22
|
let open = $state(false);
|
|
22
23
|
let focused = $state(false);
|
|
24
|
+
let wrapperEl;
|
|
25
|
+
let dropdownEl;
|
|
23
26
|
let hasValue = $derived(selected.length > 0);
|
|
24
27
|
let floated = $derived(focused || hasValue);
|
|
25
28
|
|
|
@@ -55,15 +58,44 @@
|
|
|
55
58
|
return opt ? opt.label : val;
|
|
56
59
|
}
|
|
57
60
|
|
|
61
|
+
function positionDropdown() {
|
|
62
|
+
if (!wrapperEl || !dropdownEl) return;
|
|
63
|
+
const rect = wrapperEl.getBoundingClientRect();
|
|
64
|
+
const ddHeight = dropdownEl.offsetHeight || 200;
|
|
65
|
+
let top = rect.bottom + 4;
|
|
66
|
+
if (top + ddHeight > window.innerHeight - 8 && rect.top - ddHeight - 4 > 8) {
|
|
67
|
+
top = rect.top - ddHeight - 4;
|
|
68
|
+
}
|
|
69
|
+
dropdownEl.style.left = `${rect.left}px`;
|
|
70
|
+
dropdownEl.style.top = `${top}px`;
|
|
71
|
+
dropdownEl.style.width = `${rect.width}px`;
|
|
72
|
+
}
|
|
73
|
+
|
|
58
74
|
function handleBlur(e) {
|
|
59
|
-
if (
|
|
75
|
+
if (
|
|
76
|
+
wrapperEl && !wrapperEl.contains(e.relatedTarget) &&
|
|
77
|
+
!(dropdownEl && dropdownEl.contains(e.relatedTarget))
|
|
78
|
+
) {
|
|
60
79
|
open = false;
|
|
61
80
|
focused = false;
|
|
62
81
|
}
|
|
63
82
|
}
|
|
83
|
+
|
|
84
|
+
$effect(() => {
|
|
85
|
+
if (!open) return;
|
|
86
|
+
const reposition = () => positionDropdown();
|
|
87
|
+
window.addEventListener("scroll", reposition, true);
|
|
88
|
+
window.addEventListener("resize", reposition);
|
|
89
|
+
queueMicrotask(reposition);
|
|
90
|
+
return () => {
|
|
91
|
+
window.removeEventListener("scroll", reposition, true);
|
|
92
|
+
window.removeEventListener("resize", reposition);
|
|
93
|
+
};
|
|
94
|
+
});
|
|
64
95
|
</script>
|
|
65
96
|
|
|
66
97
|
<div
|
|
98
|
+
bind:this={wrapperEl}
|
|
67
99
|
class={cn("s-mselect-wrapper", styleClass, themeClass, className)}
|
|
68
100
|
class:disabled
|
|
69
101
|
class:focused
|
|
@@ -125,7 +157,11 @@
|
|
|
125
157
|
</span>
|
|
126
158
|
</div>
|
|
127
159
|
{#if open}
|
|
128
|
-
<div
|
|
160
|
+
<div
|
|
161
|
+
class="mselect-dropdown {styleClass} {themeClass}"
|
|
162
|
+
bind:this={dropdownEl}
|
|
163
|
+
use:portal
|
|
164
|
+
>
|
|
129
165
|
{#each options as opt}
|
|
130
166
|
<label
|
|
131
167
|
class="mselect-option"
|
|
@@ -1,83 +1,178 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import "./select-styles.css";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
let
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
1
|
+
<script>
|
|
2
|
+
import "./select-styles.css";
|
|
3
|
+
import { portal } from "../actions/portal.js";
|
|
4
|
+
import { defaults } from "../config.js";
|
|
5
|
+
import { cn } from "../utils/cn.js";
|
|
6
|
+
|
|
7
|
+
let {
|
|
8
|
+
style: styleProp,
|
|
9
|
+
theme: themeProp,
|
|
10
|
+
value = $bindable(""),
|
|
11
|
+
options = [],
|
|
12
|
+
placeholder = "Select...",
|
|
13
|
+
label = "",
|
|
14
|
+
disabled = false,
|
|
15
|
+
class: className = "",
|
|
16
|
+
...rest
|
|
17
|
+
} = $props();
|
|
18
|
+
|
|
19
|
+
const style = $derived(styleProp ?? defaults.style);
|
|
20
|
+
const theme = $derived(themeProp ?? defaults.theme);
|
|
21
|
+
|
|
22
|
+
let open = $state(false);
|
|
23
|
+
let focused = $state(false);
|
|
24
|
+
let wrapperEl;
|
|
25
|
+
let dropdownEl;
|
|
26
|
+
let hasValue = $derived(
|
|
27
|
+
value !== "" && value !== null && value !== undefined,
|
|
28
|
+
);
|
|
29
|
+
let floated = $derived(focused || hasValue);
|
|
30
|
+
|
|
31
|
+
const styleClass = $derived(`s-select-${style}`);
|
|
32
|
+
const themeClass = $derived(`theme-${theme}`);
|
|
33
|
+
|
|
34
|
+
const floatingStyles = [
|
|
35
|
+
"material",
|
|
36
|
+
"material3",
|
|
37
|
+
"fluent",
|
|
38
|
+
"carbon",
|
|
39
|
+
"bootstrap",
|
|
40
|
+
];
|
|
41
|
+
const hasFloatingLabel = $derived(
|
|
42
|
+
floatingStyles.includes(style) && (label || placeholder),
|
|
43
|
+
);
|
|
44
|
+
const displayLabel = $derived(label || placeholder);
|
|
45
|
+
|
|
46
|
+
function getLabel(val) {
|
|
47
|
+
const opt = options.find((o) => o.value === val);
|
|
48
|
+
return opt ? opt.label : val;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function selectOption(val) {
|
|
52
|
+
value = val;
|
|
53
|
+
open = false;
|
|
54
|
+
focused = false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function handleBlur() {
|
|
58
|
+
setTimeout(() => {
|
|
59
|
+
open = false;
|
|
60
|
+
focused = false;
|
|
61
|
+
}, 150);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function handleKeydown(e) {
|
|
65
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
open = !open;
|
|
68
|
+
focused = true;
|
|
69
|
+
} else if (e.key === "Escape") {
|
|
70
|
+
open = false;
|
|
71
|
+
focused = false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function positionDropdown() {
|
|
76
|
+
if (!wrapperEl || !dropdownEl) return;
|
|
77
|
+
const rect = wrapperEl.getBoundingClientRect();
|
|
78
|
+
const ddHeight = dropdownEl.offsetHeight || 200;
|
|
79
|
+
let top = rect.bottom + 4;
|
|
80
|
+
// Flip above the field if it would overflow the bottom of the viewport.
|
|
81
|
+
if (top + ddHeight > window.innerHeight - 8 && rect.top - ddHeight - 4 > 8) {
|
|
82
|
+
top = rect.top - ddHeight - 4;
|
|
83
|
+
}
|
|
84
|
+
dropdownEl.style.left = `${rect.left}px`;
|
|
85
|
+
dropdownEl.style.top = `${top}px`;
|
|
86
|
+
dropdownEl.style.width = `${rect.width}px`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
$effect(() => {
|
|
90
|
+
if (open) {
|
|
91
|
+
const handler = (e) => {
|
|
92
|
+
if (
|
|
93
|
+
wrapperEl && !wrapperEl.contains(e.target) &&
|
|
94
|
+
!(dropdownEl && dropdownEl.contains(e.target))
|
|
95
|
+
) {
|
|
96
|
+
open = false;
|
|
97
|
+
focused = false;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
document.addEventListener("pointerdown", handler);
|
|
101
|
+
const reposition = () => positionDropdown();
|
|
102
|
+
window.addEventListener("scroll", reposition, true);
|
|
103
|
+
window.addEventListener("resize", reposition);
|
|
104
|
+
queueMicrotask(reposition);
|
|
105
|
+
return () => {
|
|
106
|
+
document.removeEventListener("pointerdown", handler);
|
|
107
|
+
window.removeEventListener("scroll", reposition, true);
|
|
108
|
+
window.removeEventListener("resize", reposition);
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
</script>
|
|
113
|
+
|
|
114
|
+
<div
|
|
115
|
+
bind:this={wrapperEl}
|
|
116
|
+
class={cn("s-select-wrapper", styleClass, themeClass, className)}
|
|
117
|
+
class:disabled
|
|
118
|
+
class:focused
|
|
119
|
+
class:has-value={hasValue}
|
|
120
|
+
class:floated
|
|
121
|
+
class:open
|
|
122
|
+
tabindex="-1"
|
|
123
|
+
role="listbox"
|
|
124
|
+
aria-label={displayLabel}
|
|
125
|
+
onfocusin={() => (focused = true)}
|
|
126
|
+
onfocusout={handleBlur}
|
|
127
|
+
{...rest}
|
|
128
|
+
>
|
|
129
|
+
{#if hasFloatingLabel}
|
|
130
|
+
<label class="s-select-floating-label"
|
|
131
|
+
>{displayLabel}</label
|
|
132
|
+
>
|
|
133
|
+
{/if}
|
|
134
|
+
<div
|
|
135
|
+
class="s-select-control"
|
|
136
|
+
role="button"
|
|
137
|
+
tabindex="0"
|
|
138
|
+
onclick={() => (open = !open)}
|
|
139
|
+
onkeydown={handleKeydown}
|
|
140
|
+
>
|
|
141
|
+
{#if hasValue && !hasFloatingLabel}
|
|
142
|
+
<span class="s-select-value">{getLabel(value)}</span>
|
|
143
|
+
{:else if !hasFloatingLabel}
|
|
144
|
+
<span class="s-select-placeholder">{placeholder}</span>
|
|
145
|
+
{/if}
|
|
146
|
+
{#if hasFloatingLabel && hasValue}
|
|
147
|
+
<span class="s-select-value">{getLabel(value)}</span>
|
|
148
|
+
{/if}
|
|
149
|
+
<span class="s-select-arrow">
|
|
150
|
+
<svg width="12" height="12" viewBox="0 0 12 12" fill="none">
|
|
151
|
+
<path
|
|
152
|
+
d="M2.5 4.5L6 8L9.5 4.5"
|
|
153
|
+
stroke="currentColor"
|
|
154
|
+
stroke-width="1.5"
|
|
155
|
+
stroke-linecap="round"
|
|
156
|
+
stroke-linejoin="round"
|
|
157
|
+
/>
|
|
158
|
+
</svg>
|
|
159
|
+
</span>
|
|
160
|
+
</div>
|
|
161
|
+
{#if open}
|
|
162
|
+
<div
|
|
163
|
+
class="s-select-dropdown {styleClass} {themeClass}"
|
|
164
|
+
bind:this={dropdownEl}
|
|
165
|
+
use:portal
|
|
166
|
+
>
|
|
167
|
+
{#each options as opt}
|
|
168
|
+
<div
|
|
169
|
+
class="s-select-option"
|
|
170
|
+
class:selected={value === opt.value}
|
|
171
|
+
onclick={() => selectOption(opt.value)}
|
|
172
|
+
>
|
|
173
|
+
{opt.label}
|
|
174
|
+
</div>
|
|
175
|
+
{/each}
|
|
176
|
+
</div>
|
|
177
|
+
{/if}
|
|
178
|
+
</div>
|
|
@@ -383,6 +383,7 @@
|
|
|
383
383
|
-webkit-backdrop-filter: blur(24px) saturate(1.6);
|
|
384
384
|
box-shadow: var(--t-shadow-md), inset 0 1px 0 rgba(255,255,255,0.3);
|
|
385
385
|
transition: all 0.3s ease;
|
|
386
|
+
min-height: 59px;
|
|
386
387
|
}
|
|
387
388
|
.s-input-liquid-glass:hover {
|
|
388
389
|
background: rgba(255,255,255,0.15);
|