svelte-multistyle-ui 0.0.13-alpha → 0.0.14-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/dist/components/DatePicker.svelte +493 -488
- package/dist/components/Input.svelte +52 -48
- package/dist/components/MultiSelect.svelte +37 -13
- package/dist/components/Select.svelte +182 -177
- package/dist/components/Textarea.svelte +16 -11
- package/dist/components/button-styles.css +266 -263
- package/dist/components/codeeditor-styles.css +12 -2
- package/dist/components/datepicker-styles.css +70 -59
- package/dist/components/input-styles.css +399 -403
- package/dist/components/multiselect-styles.css +76 -47
- package/dist/components/select-styles.css +65 -18
- package/dist/components/textarea-styles.css +250 -210
- package/dist/components/texteditor-styles.css +13 -1
- package/dist/components/theme-base.css +6 -0
- package/dist/components/theme.css +15 -1
- package/dist/config.svelte.d.ts +8 -2
- package/dist/config.svelte.js +46 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/themes/fonts.d.ts +25 -0
- package/dist/themes/fonts.js +178 -0
- package/dist/themes/index.d.ts +1 -0
- package/dist/themes/index.js +2 -1
- package/package.json +1 -1
|
@@ -55,15 +55,14 @@
|
|
|
55
55
|
const uid = Math.random().toString(36).slice(2, 9);
|
|
56
56
|
const internalId = $derived(id || `input-${uid}`);
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
floatingStyles.includes(style) && (label || placeholder),
|
|
58
|
+
// Floating label (animates inside the field) — Material / Material 3 only.
|
|
59
|
+
// Every other style renders a static label above the field.
|
|
60
|
+
const floatingLabelStyles = ["material", "material3"];
|
|
61
|
+
const useFloatingLabel = $derived(
|
|
62
|
+
floatingLabelStyles.includes(style) && (label || placeholder),
|
|
63
|
+
);
|
|
64
|
+
const useAboveLabel = $derived(
|
|
65
|
+
!floatingLabelStyles.includes(style) && (label || placeholder),
|
|
67
66
|
);
|
|
68
67
|
const displayLabel = $derived(label || placeholder);
|
|
69
68
|
</script>
|
|
@@ -76,48 +75,53 @@
|
|
|
76
75
|
class:floated
|
|
77
76
|
class:has-icon-start={hasIconStart}
|
|
78
77
|
class:has-icon-end={hasIconEnd}
|
|
78
|
+
class:above-label={useAboveLabel}
|
|
79
79
|
>
|
|
80
|
-
{#if
|
|
81
|
-
<
|
|
80
|
+
{#if useAboveLabel}
|
|
81
|
+
<label class="s-input-label-above" for={internalId}>{displayLabel}</label>
|
|
82
82
|
{/if}
|
|
83
|
-
{#if
|
|
83
|
+
{#if useFloatingLabel}
|
|
84
84
|
<label class="s-input-floating-label" for={internalId}>{displayLabel}</label
|
|
85
85
|
>
|
|
86
86
|
{/if}
|
|
87
|
-
<input
|
|
88
|
-
{
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
87
|
+
<div class="s-input-field">
|
|
88
|
+
{#if iconStart}
|
|
89
|
+
<span class="s-input-icon s-input-icon-start {iconClass}">{iconStart}</span>
|
|
90
|
+
{/if}
|
|
91
|
+
<input
|
|
92
|
+
{type}
|
|
93
|
+
bind:value
|
|
94
|
+
placeholder={useFloatingLabel || (useAboveLabel && !label)
|
|
95
|
+
? ""
|
|
96
|
+
: placeholder}
|
|
97
|
+
{disabled}
|
|
98
|
+
{readonly}
|
|
99
|
+
{required}
|
|
100
|
+
{name}
|
|
101
|
+
id={internalId}
|
|
102
|
+
{min}
|
|
103
|
+
{max}
|
|
104
|
+
{minlength}
|
|
105
|
+
{maxlength}
|
|
106
|
+
{step}
|
|
107
|
+
{pattern}
|
|
108
|
+
{autocomplete}
|
|
109
|
+
{autofocus}
|
|
110
|
+
{multiple}
|
|
111
|
+
{accept}
|
|
112
|
+
{list}
|
|
113
|
+
{size}
|
|
114
|
+
{tabindex}
|
|
115
|
+
{title}
|
|
116
|
+
{form}
|
|
117
|
+
{inputmode}
|
|
118
|
+
{spellcheck}
|
|
119
|
+
onfocus={() => (focused = true)}
|
|
120
|
+
onblur={() => (focused = false)}
|
|
121
|
+
{...rest}
|
|
122
|
+
/>
|
|
123
|
+
{#if iconEnd}
|
|
124
|
+
<span class="s-input-icon s-input-icon-end {iconClass}">{iconEnd}</span>
|
|
125
|
+
{/if}
|
|
126
|
+
</div>
|
|
123
127
|
</div>
|
|
@@ -29,17 +29,19 @@
|
|
|
29
29
|
const styleClass = $derived(`s-mselect-${style}`);
|
|
30
30
|
const themeClass = $derived(`theme-${theme}`);
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
floatingStyles.includes(style) && (label || placeholder),
|
|
32
|
+
// Floating label (animates inside the field) — Material / Material 3 only.
|
|
33
|
+
// Every other style renders a static label above the field.
|
|
34
|
+
const floatingLabelStyles = ["material", "material3"];
|
|
35
|
+
const useFloatingLabel = $derived(
|
|
36
|
+
floatingLabelStyles.includes(style) && (label || placeholder),
|
|
37
|
+
);
|
|
38
|
+
const useAboveLabel = $derived(
|
|
39
|
+
!floatingLabelStyles.includes(style) && (label || placeholder),
|
|
41
40
|
);
|
|
42
41
|
const displayLabel = $derived(label || placeholder);
|
|
42
|
+
const showInFieldPlaceholder = $derived(
|
|
43
|
+
!(useFloatingLabel || (useAboveLabel && !label)),
|
|
44
|
+
);
|
|
43
45
|
|
|
44
46
|
function toggle(val) {
|
|
45
47
|
if (selected.includes(val)) {
|
|
@@ -72,9 +74,16 @@
|
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
function handleBlur(e) {
|
|
77
|
+
const related = e.relatedTarget;
|
|
78
|
+
// Clicking a non-focusable element (e.g. the option label text) leaves
|
|
79
|
+
// relatedTarget null. Don't close here — the document mousedown handler
|
|
80
|
+
// below handles outside clicks. Closing now would unmount the checkbox
|
|
81
|
+
// before the label-forwarded click toggles it, so the option wouldn't
|
|
82
|
+
// select when its text is clicked.
|
|
83
|
+
if (related === null) return;
|
|
75
84
|
if (
|
|
76
|
-
wrapperEl && !wrapperEl.contains(
|
|
77
|
-
!(dropdownEl && dropdownEl.contains(
|
|
85
|
+
wrapperEl && !wrapperEl.contains(related) &&
|
|
86
|
+
!(dropdownEl && dropdownEl.contains(related))
|
|
78
87
|
) {
|
|
79
88
|
open = false;
|
|
80
89
|
focused = false;
|
|
@@ -84,12 +93,23 @@
|
|
|
84
93
|
$effect(() => {
|
|
85
94
|
if (!open) return;
|
|
86
95
|
const reposition = () => positionDropdown();
|
|
96
|
+
const onDocMouseDown = (e) => {
|
|
97
|
+
if (
|
|
98
|
+
wrapperEl && !wrapperEl.contains(e.target) &&
|
|
99
|
+
!(dropdownEl && dropdownEl.contains(e.target))
|
|
100
|
+
) {
|
|
101
|
+
open = false;
|
|
102
|
+
focused = false;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
87
105
|
window.addEventListener("scroll", reposition, true);
|
|
88
106
|
window.addEventListener("resize", reposition);
|
|
107
|
+
document.addEventListener("mousedown", onDocMouseDown);
|
|
89
108
|
queueMicrotask(reposition);
|
|
90
109
|
return () => {
|
|
91
110
|
window.removeEventListener("scroll", reposition, true);
|
|
92
111
|
window.removeEventListener("resize", reposition);
|
|
112
|
+
document.removeEventListener("mousedown", onDocMouseDown);
|
|
93
113
|
};
|
|
94
114
|
});
|
|
95
115
|
</script>
|
|
@@ -102,6 +122,7 @@
|
|
|
102
122
|
class:open
|
|
103
123
|
class:has-value={hasValue}
|
|
104
124
|
class:floated
|
|
125
|
+
class:above-label={useAboveLabel}
|
|
105
126
|
tabindex="-1"
|
|
106
127
|
role="listbox"
|
|
107
128
|
aria-label={displayLabel}
|
|
@@ -109,7 +130,10 @@
|
|
|
109
130
|
onfocusout={handleBlur}
|
|
110
131
|
{...rest}
|
|
111
132
|
>
|
|
112
|
-
{#if
|
|
133
|
+
{#if useAboveLabel}
|
|
134
|
+
<label class="s-mselect-label-above">{displayLabel}</label>
|
|
135
|
+
{/if}
|
|
136
|
+
{#if useFloatingLabel}
|
|
113
137
|
<label class="s-mselect-floating-label">{displayLabel}</label>
|
|
114
138
|
{/if}
|
|
115
139
|
<div
|
|
@@ -141,7 +165,7 @@
|
|
|
141
165
|
</span>
|
|
142
166
|
{/each}
|
|
143
167
|
</div>
|
|
144
|
-
{:else if
|
|
168
|
+
{:else if showInFieldPlaceholder}
|
|
145
169
|
<span class="mselect-placeholder">{placeholder}</span>
|
|
146
170
|
{/if}
|
|
147
171
|
<span class="mselect-arrow">
|
|
@@ -1,178 +1,183 @@
|
|
|
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
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
class
|
|
121
|
-
class:
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
{
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
class="s-select-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
{
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
<
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
+
// Floating label (animates inside the field) — Material / Material 3 only.
|
|
35
|
+
// Every other style renders a static label above the field.
|
|
36
|
+
const floatingLabelStyles = ["material", "material3"];
|
|
37
|
+
const useFloatingLabel = $derived(
|
|
38
|
+
floatingLabelStyles.includes(style) && (label || placeholder),
|
|
39
|
+
);
|
|
40
|
+
const useAboveLabel = $derived(
|
|
41
|
+
!floatingLabelStyles.includes(style) && (label || placeholder),
|
|
42
|
+
);
|
|
43
|
+
const displayLabel = $derived(label || placeholder);
|
|
44
|
+
// Show the in-field placeholder hint only when it isn't lifted to the
|
|
45
|
+
// above-label (label set) and there's no floating label acting as placeholder.
|
|
46
|
+
const showInFieldPlaceholder = $derived(
|
|
47
|
+
!(useFloatingLabel || (useAboveLabel && !label)),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
function getLabel(val) {
|
|
51
|
+
const opt = options.find((o) => o.value === val);
|
|
52
|
+
return opt ? opt.label : val;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function selectOption(val) {
|
|
56
|
+
value = val;
|
|
57
|
+
open = false;
|
|
58
|
+
focused = false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function handleBlur() {
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
open = false;
|
|
64
|
+
focused = false;
|
|
65
|
+
}, 150);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function handleKeydown(e) {
|
|
69
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
70
|
+
e.preventDefault();
|
|
71
|
+
open = !open;
|
|
72
|
+
focused = true;
|
|
73
|
+
} else if (e.key === "Escape") {
|
|
74
|
+
open = false;
|
|
75
|
+
focused = false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function positionDropdown() {
|
|
80
|
+
if (!wrapperEl || !dropdownEl) return;
|
|
81
|
+
const rect = wrapperEl.getBoundingClientRect();
|
|
82
|
+
const ddHeight = dropdownEl.offsetHeight || 200;
|
|
83
|
+
let top = rect.bottom + 4;
|
|
84
|
+
// Flip above the field if it would overflow the bottom of the viewport.
|
|
85
|
+
if (top + ddHeight > window.innerHeight - 8 && rect.top - ddHeight - 4 > 8) {
|
|
86
|
+
top = rect.top - ddHeight - 4;
|
|
87
|
+
}
|
|
88
|
+
dropdownEl.style.left = `${rect.left}px`;
|
|
89
|
+
dropdownEl.style.top = `${top}px`;
|
|
90
|
+
dropdownEl.style.width = `${rect.width}px`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
$effect(() => {
|
|
94
|
+
if (open) {
|
|
95
|
+
const handler = (e) => {
|
|
96
|
+
if (
|
|
97
|
+
wrapperEl && !wrapperEl.contains(e.target) &&
|
|
98
|
+
!(dropdownEl && dropdownEl.contains(e.target))
|
|
99
|
+
) {
|
|
100
|
+
open = false;
|
|
101
|
+
focused = false;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
document.addEventListener("pointerdown", handler);
|
|
105
|
+
const reposition = () => positionDropdown();
|
|
106
|
+
window.addEventListener("scroll", reposition, true);
|
|
107
|
+
window.addEventListener("resize", reposition);
|
|
108
|
+
queueMicrotask(reposition);
|
|
109
|
+
return () => {
|
|
110
|
+
document.removeEventListener("pointerdown", handler);
|
|
111
|
+
window.removeEventListener("scroll", reposition, true);
|
|
112
|
+
window.removeEventListener("resize", reposition);
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
</script>
|
|
117
|
+
|
|
118
|
+
<div
|
|
119
|
+
bind:this={wrapperEl}
|
|
120
|
+
class={cn("s-select-wrapper", styleClass, themeClass, className)}
|
|
121
|
+
class:disabled
|
|
122
|
+
class:focused
|
|
123
|
+
class:has-value={hasValue}
|
|
124
|
+
class:floated
|
|
125
|
+
class:open
|
|
126
|
+
class:above-label={useAboveLabel}
|
|
127
|
+
tabindex="-1"
|
|
128
|
+
role="listbox"
|
|
129
|
+
aria-label={displayLabel}
|
|
130
|
+
onfocusin={() => (focused = true)}
|
|
131
|
+
onfocusout={handleBlur}
|
|
132
|
+
{...rest}
|
|
133
|
+
>
|
|
134
|
+
{#if useAboveLabel}
|
|
135
|
+
<label class="s-select-label-above">{displayLabel}</label>
|
|
136
|
+
{/if}
|
|
137
|
+
{#if useFloatingLabel}
|
|
138
|
+
<label class="s-select-floating-label"
|
|
139
|
+
>{displayLabel}</label
|
|
140
|
+
>
|
|
141
|
+
{/if}
|
|
142
|
+
<div
|
|
143
|
+
class="s-select-control"
|
|
144
|
+
role="button"
|
|
145
|
+
tabindex="0"
|
|
146
|
+
onclick={() => (open = !open)}
|
|
147
|
+
onkeydown={handleKeydown}
|
|
148
|
+
>
|
|
149
|
+
{#if hasValue}
|
|
150
|
+
<span class="s-select-value">{getLabel(value)}</span>
|
|
151
|
+
{:else if showInFieldPlaceholder}
|
|
152
|
+
<span class="s-select-placeholder">{placeholder}</span>
|
|
153
|
+
{/if}
|
|
154
|
+
<span class="s-select-arrow">
|
|
155
|
+
<svg width="12" height="12" viewBox="0 0 12 12" fill="none">
|
|
156
|
+
<path
|
|
157
|
+
d="M2.5 4.5L6 8L9.5 4.5"
|
|
158
|
+
stroke="currentColor"
|
|
159
|
+
stroke-width="1.5"
|
|
160
|
+
stroke-linecap="round"
|
|
161
|
+
stroke-linejoin="round"
|
|
162
|
+
/>
|
|
163
|
+
</svg>
|
|
164
|
+
</span>
|
|
165
|
+
</div>
|
|
166
|
+
{#if open}
|
|
167
|
+
<div
|
|
168
|
+
class="s-select-dropdown {styleClass} {themeClass}"
|
|
169
|
+
bind:this={dropdownEl}
|
|
170
|
+
use:portal
|
|
171
|
+
>
|
|
172
|
+
{#each options as opt}
|
|
173
|
+
<div
|
|
174
|
+
class="s-select-option"
|
|
175
|
+
class:selected={value === opt.value}
|
|
176
|
+
onclick={() => selectOption(opt.value)}
|
|
177
|
+
>
|
|
178
|
+
{opt.label}
|
|
179
|
+
</div>
|
|
180
|
+
{/each}
|
|
181
|
+
</div>
|
|
182
|
+
{/if}
|
|
178
183
|
</div>
|
|
@@ -34,15 +34,14 @@
|
|
|
34
34
|
const uid = Math.random().toString(36).slice(2, 9);
|
|
35
35
|
const internalId = `textarea-${uid}`;
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
floatingStyles.includes(style) && (label || placeholder),
|
|
37
|
+
// Floating label (animates inside the field) — Material / Material 3 only.
|
|
38
|
+
// Every other style renders a static label above the field.
|
|
39
|
+
const floatingLabelStyles = ["material", "material3"];
|
|
40
|
+
const useFloatingLabel = $derived(
|
|
41
|
+
floatingLabelStyles.includes(style) && (label || placeholder),
|
|
42
|
+
);
|
|
43
|
+
const useAboveLabel = $derived(
|
|
44
|
+
!floatingLabelStyles.includes(style) && (label || placeholder),
|
|
46
45
|
);
|
|
47
46
|
const displayLabel = $derived(label || placeholder);
|
|
48
47
|
|
|
@@ -61,15 +60,21 @@
|
|
|
61
60
|
class:focused
|
|
62
61
|
class:has-value={hasValue}
|
|
63
62
|
class:floated
|
|
63
|
+
class:above-label={useAboveLabel}
|
|
64
64
|
>
|
|
65
|
-
{#if
|
|
65
|
+
{#if useAboveLabel}
|
|
66
|
+
<label class="s-textarea-label-above" for={internalId}>{displayLabel}</label>
|
|
67
|
+
{/if}
|
|
68
|
+
{#if useFloatingLabel}
|
|
66
69
|
<label class="s-textarea-floating-label" for={internalId}
|
|
67
70
|
>{displayLabel}</label
|
|
68
71
|
>
|
|
69
72
|
{/if}
|
|
70
73
|
<textarea
|
|
71
74
|
bind:value
|
|
72
|
-
placeholder={
|
|
75
|
+
placeholder={useFloatingLabel || (useAboveLabel && !label)
|
|
76
|
+
? ""
|
|
77
|
+
: placeholder}
|
|
73
78
|
{disabled}
|
|
74
79
|
{readonly}
|
|
75
80
|
{required}
|