@geoffcox/sterling-svelte 0.0.26 → 0.0.28
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/Button.svelte +81 -25
- package/Button.svelte.d.ts +3 -0
- package/Checkbox.svelte +56 -26
- package/Checkbox.svelte.d.ts +2 -0
- package/ColorPicker.constants.d.ts +1 -0
- package/ColorPicker.constants.js +1 -0
- package/ColorPicker.svelte +257 -0
- package/ColorPicker.svelte.d.ts +49 -0
- package/ColorPicker.types.d.ts +4 -0
- package/Dialog.svelte +10 -10
- package/Dropdown.svelte +97 -58
- package/Dropdown.svelte.d.ts +4 -0
- package/HexColorSliders.svelte +171 -0
- package/HexColorSliders.svelte.d.ts +22 -0
- package/HslColorSliders.svelte +208 -0
- package/HslColorSliders.svelte.d.ts +22 -0
- package/Input.svelte +59 -25
- package/Input.svelte.d.ts +3 -2
- package/Label.constants.d.ts +1 -0
- package/Label.constants.js +1 -0
- package/Label.svelte +212 -14
- package/Label.svelte.d.ts +24 -4
- package/Label.types.d.ts +4 -0
- package/Label.types.js +1 -0
- package/Link.svelte +62 -16
- package/Link.svelte.d.ts +1 -0
- package/List.svelte +29 -16
- package/List.svelte.d.ts +1 -0
- package/List.types.d.ts +4 -3
- package/ListItem.svelte +30 -10
- package/ListItem.svelte.d.ts +1 -1
- package/Menu.svelte +7 -7
- package/MenuBar.svelte +1 -1
- package/MenuButton.svelte +3 -9
- package/MenuButton.svelte.d.ts +2 -4
- package/MenuItem.svelte +34 -12
- package/MenuItem.svelte.d.ts +2 -1
- package/MenuItemDisplay.svelte +8 -1
- package/MenuSeparator.svelte +3 -3
- package/Popover.svelte +66 -51
- package/Popover.svelte.d.ts +4 -2
- package/Progress.constants.d.ts +1 -1
- package/Progress.constants.js +1 -1
- package/Progress.svelte +34 -28
- package/Progress.svelte.d.ts +1 -1
- package/Progress.types.d.ts +3 -3
- package/Radio.svelte +54 -23
- package/Radio.svelte.d.ts +2 -0
- package/RgbColorSliders.svelte +182 -0
- package/RgbColorSliders.svelte.d.ts +22 -0
- package/Select.svelte +32 -25
- package/Select.svelte.d.ts +1 -1
- package/Slider.svelte +111 -123
- package/Slider.svelte.d.ts +1 -0
- package/Switch.svelte +112 -41
- package/Switch.svelte.d.ts +3 -2
- package/Tab.svelte +53 -29
- package/Tab.svelte.d.ts +7 -4
- package/TabList.svelte +21 -11
- package/TabList.svelte.d.ts +1 -0
- package/TabList.types.d.ts +1 -0
- package/TextArea.svelte +48 -22
- package/TextArea.svelte.d.ts +4 -3
- package/Tooltip.svelte +59 -16
- package/Tooltip.svelte.d.ts +34 -2
- package/Tree.svelte +35 -21
- package/Tree.svelte.d.ts +2 -0
- package/Tree.types.d.ts +6 -8
- package/TreeChevron.svelte +1 -1
- package/TreeItem.svelte +40 -9
- package/TreeItem.svelte.d.ts +2 -0
- package/TreeItem.types.d.ts +4 -4
- package/TreeItemDisplay.svelte +28 -9
- package/TreeItemDisplay.svelte.d.ts +3 -1
- package/actions/clickOutside.js +1 -1
- package/actions/trapKeyboardFocus.d.ts +3 -0
- package/actions/trapKeyboardFocus.js +52 -0
- package/floating-ui.types.d.ts +2 -0
- package/index.d.ts +14 -10
- package/index.js +11 -7
- package/package.json +12 -4
- package/theme/applyTheme.js +3 -2
- package/theme/colors.d.ts +1 -0
- package/theme/colors.js +28 -13
- package/theme/darkTheme.js +129 -87
- package/theme/lightTheme.js +109 -90
- package/Field.constants.d.ts +0 -1
- package/Field.constants.js +0 -1
- package/Field.svelte +0 -265
- package/Field.svelte.d.ts +0 -75
- package/Field.types.d.ts +0 -4
- /package/{Field.types.js → ColorPicker.types.js} +0 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
<script>import { createEventDispatcher } from "svelte";
|
|
2
|
+
import Input from "./Input.svelte";
|
|
3
|
+
import Slider from "./Slider.svelte";
|
|
4
|
+
import { round } from "lodash-es";
|
|
5
|
+
export let hue = 180;
|
|
6
|
+
export let saturation = 100;
|
|
7
|
+
export let lightness = 50;
|
|
8
|
+
export let alpha = 1;
|
|
9
|
+
export let colorful = false;
|
|
10
|
+
let hueText = hue.toString();
|
|
11
|
+
let saturationText = saturation.toString();
|
|
12
|
+
let lightnessText = lightness.toString();
|
|
13
|
+
let alphaText = alpha.toString();
|
|
14
|
+
$: {
|
|
15
|
+
hueText = hue.toString();
|
|
16
|
+
}
|
|
17
|
+
$: {
|
|
18
|
+
saturationText = saturation.toString();
|
|
19
|
+
}
|
|
20
|
+
$: {
|
|
21
|
+
lightnessText = lightness.toString();
|
|
22
|
+
}
|
|
23
|
+
$: {
|
|
24
|
+
alphaText = alpha.toString();
|
|
25
|
+
}
|
|
26
|
+
const dispatcher = createEventDispatcher();
|
|
27
|
+
const raiseChange = (hue2, saturation2, lightness2) => {
|
|
28
|
+
dispatcher("change", { hue: hue2, saturation: saturation2, lightness: lightness2 });
|
|
29
|
+
};
|
|
30
|
+
$:
|
|
31
|
+
raiseChange(hue, saturation, lightness);
|
|
32
|
+
const onHueInputChange = (event) => {
|
|
33
|
+
const inputChangeEvent = event;
|
|
34
|
+
const text = inputChangeEvent?.currentTarget?.value;
|
|
35
|
+
const newValue = text ? Number.parseFloat(text) : hue;
|
|
36
|
+
if (newValue && newValue !== Number.NaN) {
|
|
37
|
+
hue = Math.round(Math.max(0, Math.min(360, newValue)));
|
|
38
|
+
hueText = hue.toString();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const onSaturationInputChange = (event) => {
|
|
42
|
+
const inputChangeEvent = event;
|
|
43
|
+
const text = inputChangeEvent?.currentTarget?.value?.replace(/%/g, "");
|
|
44
|
+
const newValue = text ? Number.parseFloat(text) : saturation;
|
|
45
|
+
if (newValue && newValue !== Number.NaN) {
|
|
46
|
+
saturation = Math.round(Math.max(0, Math.min(100, newValue)));
|
|
47
|
+
saturationText = saturation.toString();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const onLightnessInputChange = (event) => {
|
|
51
|
+
const inputChangeEvent = event;
|
|
52
|
+
const text = inputChangeEvent?.currentTarget?.value?.replace(/%/g, "");
|
|
53
|
+
const newValue = text ? Number.parseFloat(text) : lightness;
|
|
54
|
+
if (newValue && newValue !== Number.NaN) {
|
|
55
|
+
lightness = Math.round(Math.max(0, Math.min(100, newValue)));
|
|
56
|
+
lightnessText = lightness.toString();
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const onAlphaInputchange = (event) => {
|
|
60
|
+
const inputChangeEvent = event;
|
|
61
|
+
const text = inputChangeEvent?.currentTarget?.value;
|
|
62
|
+
const newValue = text ? Number.parseFloat(text) : alpha;
|
|
63
|
+
if (newValue && newValue !== Number.NaN) {
|
|
64
|
+
alpha = round(Math.max(0, Math.min(1, newValue)), 2);
|
|
65
|
+
alphaText = alpha.toString();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
<div class="sterling-hsl-color-sliders">
|
|
71
|
+
<div class="slider hue">
|
|
72
|
+
<Slider min={0} max={360} precision={0} bind:value={hue} {colorful} />
|
|
73
|
+
</div>
|
|
74
|
+
<Input bind:value={hueText} {colorful} on:change={(e) => onHueInputChange(e)} />
|
|
75
|
+
<div class="slider saturation" style={`--hue:${hue};`}>
|
|
76
|
+
<Slider min={0} max={100} precision={0} bind:value={saturation} {colorful} />
|
|
77
|
+
</div>
|
|
78
|
+
<Input bind:value={saturationText} {colorful} on:change={(e) => onSaturationInputChange(e)} />
|
|
79
|
+
<div class="slider lightness" style={`--hue:${hue};--saturation:${saturation}%;`}>
|
|
80
|
+
<Slider min={0} max={100} precision={0} bind:value={lightness} {colorful} />
|
|
81
|
+
</div>
|
|
82
|
+
<Input bind:value={lightnessText} {colorful} on:change={(e) => onLightnessInputChange(e)} />
|
|
83
|
+
<div
|
|
84
|
+
class="slider alpha"
|
|
85
|
+
style={`--hue:${hue};--saturation:${saturation}%;--lightness:${lightness}%`}
|
|
86
|
+
>
|
|
87
|
+
<div class="alpha-hatch" />
|
|
88
|
+
<div class="alpha-gradient" />
|
|
89
|
+
<div class="alpha-slider">
|
|
90
|
+
<Slider min={0} max={1} precision={2} step={0.01} bind:value={alpha} {colorful} />
|
|
91
|
+
</div>
|
|
92
|
+
</div>
|
|
93
|
+
<Input bind:value={alphaText} {colorful} on:change={(e) => onAlphaInputchange(e)} />
|
|
94
|
+
</div>
|
|
95
|
+
|
|
96
|
+
<style>
|
|
97
|
+
.sterling-hsl-color-sliders {
|
|
98
|
+
align-items: center;
|
|
99
|
+
display: grid;
|
|
100
|
+
grid-template-columns: 1fr 5em;
|
|
101
|
+
column-gap: 0.5em;
|
|
102
|
+
row-gap: 0.25em;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.hue {
|
|
106
|
+
background: linear-gradient(
|
|
107
|
+
to right,
|
|
108
|
+
hsl(0, 100%, 50%) 0%,
|
|
109
|
+
hsl(60, 100%, 50%) 17%,
|
|
110
|
+
hsl(120, 100%, 50%) 33%,
|
|
111
|
+
hsl(180, 100%, 50%) 50%,
|
|
112
|
+
hsl(240, 100%, 50%) 67%,
|
|
113
|
+
hsl(300, 100%, 50%) 83%,
|
|
114
|
+
hsl(0, 100%, 50%) 100%
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.slider :global(.fill),
|
|
119
|
+
.slider :global(.sterling-slider.colorful .fill) {
|
|
120
|
+
background-color: transparent;
|
|
121
|
+
}
|
|
122
|
+
.slider :global(.track),
|
|
123
|
+
.slider :global(.sterling-slider.colorful .track) {
|
|
124
|
+
background-color: transparent;
|
|
125
|
+
opacity: 0.1;
|
|
126
|
+
background-image: linear-gradient(to right, #7f3a3a, #ffffff 1px, #000000 1px, #000000);
|
|
127
|
+
background-size: 2px 100%;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.saturation {
|
|
131
|
+
background: linear-gradient(
|
|
132
|
+
to right,
|
|
133
|
+
hsl(var(--hue), 0%, 50%) 0%,
|
|
134
|
+
hsl(var(--hue), 100%, 50%) 100%
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.lightness {
|
|
139
|
+
background: linear-gradient(
|
|
140
|
+
to right,
|
|
141
|
+
hsl(var(--hue), var(--saturation), 0%) 0%,
|
|
142
|
+
hsl(var(--hue), var(--saturation), 50%) 50%,
|
|
143
|
+
hsl(var(--hue), var(--saturation), 100%) 100%
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.alpha {
|
|
148
|
+
display: grid;
|
|
149
|
+
grid-template-columns: 1fr;
|
|
150
|
+
grid-template-rows: 1fr;
|
|
151
|
+
place-content: stretch;
|
|
152
|
+
place-items: stretch;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.alpha-gradient,
|
|
156
|
+
.alpha-hatch,
|
|
157
|
+
.alpha-slider {
|
|
158
|
+
grid-row: 1 / span 1;
|
|
159
|
+
grid-column: 1 / span 1;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.alpha-hatch {
|
|
163
|
+
background-color: #eee;
|
|
164
|
+
opacity: 0.1;
|
|
165
|
+
background-image: repeating-linear-gradient(
|
|
166
|
+
var(--stsv-common--disabled__stripe-angle),
|
|
167
|
+
#444 25%,
|
|
168
|
+
transparent 25%,
|
|
169
|
+
transparent 75%,
|
|
170
|
+
#444 75%,
|
|
171
|
+
#444
|
|
172
|
+
),
|
|
173
|
+
repeating-linear-gradient(
|
|
174
|
+
var(--stsv-common--disabled__stripe-angle),
|
|
175
|
+
#444 25%,
|
|
176
|
+
#eee 25%,
|
|
177
|
+
#eee 75%,
|
|
178
|
+
#444 75%,
|
|
179
|
+
#444
|
|
180
|
+
),
|
|
181
|
+
repeating-linear-gradient(
|
|
182
|
+
-var(--stsv-common--disabled__stripe-angle),
|
|
183
|
+
#444 25%,
|
|
184
|
+
transparent 25%,
|
|
185
|
+
transparent 75%,
|
|
186
|
+
#444 75%,
|
|
187
|
+
#444
|
|
188
|
+
),
|
|
189
|
+
repeating-linear-gradient(
|
|
190
|
+
-var(--stsv-common--disabled__stripe-angle),
|
|
191
|
+
#444 25%,
|
|
192
|
+
#eee 25%,
|
|
193
|
+
#eee 75%,
|
|
194
|
+
#444 75%,
|
|
195
|
+
#444
|
|
196
|
+
);
|
|
197
|
+
background-position: 0 0, 4px 4px;
|
|
198
|
+
background-size: 8px 8px;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.alpha-gradient {
|
|
202
|
+
background: linear-gradient(
|
|
203
|
+
to right,
|
|
204
|
+
hsla(var(--hue), var(--saturation), var(--lightness), 0) 0%,
|
|
205
|
+
hsla(var(--hue), var(--saturation), var(--lightness), 1) 100%
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
</style>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
hue?: number | undefined;
|
|
5
|
+
saturation?: number | undefined;
|
|
6
|
+
lightness?: number | undefined;
|
|
7
|
+
alpha?: number | undefined;
|
|
8
|
+
/** When true, applies colorful theme styles. */ colorful?: boolean | undefined;
|
|
9
|
+
};
|
|
10
|
+
events: {
|
|
11
|
+
change: CustomEvent<any>;
|
|
12
|
+
} & {
|
|
13
|
+
[evt: string]: CustomEvent<any>;
|
|
14
|
+
};
|
|
15
|
+
slots: {};
|
|
16
|
+
};
|
|
17
|
+
export type HslColorSlidersProps = typeof __propDef.props;
|
|
18
|
+
export type HslColorSlidersEvents = typeof __propDef.events;
|
|
19
|
+
export type HslColorSlidersSlots = typeof __propDef.slots;
|
|
20
|
+
export default class HslColorSliders extends SvelteComponentTyped<HslColorSlidersProps, HslColorSlidersEvents, HslColorSlidersSlots> {
|
|
21
|
+
}
|
|
22
|
+
export {};
|
package/Input.svelte
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<script>import { idGenerator } from "./idGenerator";
|
|
2
|
-
import Label from "./Label.svelte";
|
|
3
|
-
export let composed = false;
|
|
4
2
|
export let disabled = false;
|
|
5
3
|
export let id = void 0;
|
|
6
4
|
export let value = "";
|
|
5
|
+
export let colorful = false;
|
|
6
|
+
export let composed = false;
|
|
7
7
|
let inputRef;
|
|
8
8
|
$: {
|
|
9
9
|
if ($$slots.default && id === void 0) {
|
|
@@ -35,11 +35,11 @@ export const setRangeText = (replacement, start, end, selectionMode) => {
|
|
|
35
35
|
</script>
|
|
36
36
|
|
|
37
37
|
{#if $$slots.default}
|
|
38
|
-
<
|
|
38
|
+
<label for={id}>
|
|
39
39
|
<slot {composed} {disabled} {value} />
|
|
40
|
-
</
|
|
40
|
+
</label>
|
|
41
41
|
{/if}
|
|
42
|
-
<div class="sterling-input" class:composed class:disabled>
|
|
42
|
+
<div class="sterling-input" class:colorful class:composed class:disabled>
|
|
43
43
|
<input
|
|
44
44
|
bind:this={inputRef}
|
|
45
45
|
{disabled}
|
|
@@ -77,7 +77,7 @@ export const setRangeText = (replacement, start, end, selectionMode) => {
|
|
|
77
77
|
on:select
|
|
78
78
|
on:submit
|
|
79
79
|
on:reset
|
|
80
|
-
on:wheel
|
|
80
|
+
on:wheel|passive
|
|
81
81
|
{...$$restProps}
|
|
82
82
|
/>
|
|
83
83
|
</div>
|
|
@@ -92,33 +92,54 @@ export const setRangeText = (replacement, start, end, selectionMode) => {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
input {
|
|
95
|
-
background-color: var(--stsv-
|
|
96
|
-
border-color: var(--stsv-
|
|
97
|
-
border-radius: var(--stsv-
|
|
98
|
-
border-style: var(--stsv-
|
|
99
|
-
border-width: var(--stsv-
|
|
100
|
-
|
|
95
|
+
background-color: var(--stsv-input__background-color);
|
|
96
|
+
border-color: var(--stsv-input__border-color);
|
|
97
|
+
border-radius: var(--stsv-input__border-radius);
|
|
98
|
+
border-style: var(--stsv-input__border-style);
|
|
99
|
+
border-width: var(--stsv-input__border-width);
|
|
100
|
+
box-sizing: border-box;
|
|
101
|
+
color: var(--stsv-input__color);
|
|
102
|
+
display: block;
|
|
101
103
|
font: inherit;
|
|
102
104
|
margin: 0;
|
|
103
105
|
outline: none;
|
|
104
106
|
padding: 0.5em;
|
|
105
107
|
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
108
|
+
width: 100%;
|
|
106
109
|
}
|
|
107
110
|
|
|
108
|
-
.sterling-input:hover input {
|
|
109
|
-
background-color: var(--stsv-
|
|
110
|
-
border-color: var(--stsv-
|
|
111
|
-
color: var(--stsv-
|
|
111
|
+
.sterling-input:hover input:not(:disabled) {
|
|
112
|
+
background-color: var(--stsv-input__background-color--hover);
|
|
113
|
+
border-color: var(--stsv-input__border-color--hover);
|
|
114
|
+
color: var(--stsv-input__color--hover);
|
|
112
115
|
}
|
|
113
116
|
|
|
114
117
|
input:focus {
|
|
115
|
-
background-color: var(--stsv-
|
|
116
|
-
border-color: var(--stsv-
|
|
117
|
-
color: var(--stsv-
|
|
118
|
-
outline-color: var(--stsv-
|
|
119
|
-
outline-offset: var(--stsv-
|
|
120
|
-
outline-style: var(--stsv-
|
|
121
|
-
outline-width: var(--stsv-
|
|
118
|
+
background-color: var(--stsv-input__background-color--focus);
|
|
119
|
+
border-color: var(--stsv-input__border-color--focus);
|
|
120
|
+
color: var(--stsv-input__color--focus);
|
|
121
|
+
outline-color: var(--stsv-common__outline-color);
|
|
122
|
+
outline-offset: var(--stsv-common__outline-offset);
|
|
123
|
+
outline-style: var(--stsv-common__outline-style);
|
|
124
|
+
outline-width: var(--stsv-common__outline-width);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.sterling-input.colorful input {
|
|
128
|
+
background-color: var(--stsv-input--colorful__background-color);
|
|
129
|
+
border-color: var(--stsv-input--colorful__border-color);
|
|
130
|
+
color: var(--stsv-input--colorful__color);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.sterling-input.colorful:hover input:not(:disabled) {
|
|
134
|
+
background-color: var(--stsv-input--colorful__background-color--hover);
|
|
135
|
+
border-color: var(--stsv-input--colorful__border-color--hover);
|
|
136
|
+
color: var(--stsv-input--colorful__color--hover);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.sterling-input.colorful input:focus {
|
|
140
|
+
background-color: var(--stsv-input--colorful__background-color--focus);
|
|
141
|
+
border-color: var(--stsv-input--colorful__border-color--focus);
|
|
142
|
+
color: var(--stsv-input--colorful__color--focus);
|
|
122
143
|
}
|
|
123
144
|
|
|
124
145
|
.sterling-input.composed input,
|
|
@@ -130,7 +151,7 @@ export const setRangeText = (replacement, start, end, selectionMode) => {
|
|
|
130
151
|
}
|
|
131
152
|
|
|
132
153
|
input::placeholder {
|
|
133
|
-
color: var(--stsv-
|
|
154
|
+
color: var(--stsv-common__color--subtle);
|
|
134
155
|
}
|
|
135
156
|
|
|
136
157
|
.sterling-input.disabled * {
|
|
@@ -139,7 +160,14 @@ export const setRangeText = (replacement, start, end, selectionMode) => {
|
|
|
139
160
|
}
|
|
140
161
|
|
|
141
162
|
.sterling-input::after {
|
|
142
|
-
background:
|
|
163
|
+
background: repeating-linear-gradient(
|
|
164
|
+
var(--stsv-common--disabled__stripe-angle),
|
|
165
|
+
var(--stsv-common--disabled__stripe-color),
|
|
166
|
+
var(--stsv-common--disabled__stripe-color) var(--stsv-common--disabled__stripe-width),
|
|
167
|
+
var(--stsv-common--disabled__stripe-color--alt) var(--stsv-common--disabled__stripe-width),
|
|
168
|
+
var(--stsv-common--disabled__stripe-color--alt)
|
|
169
|
+
calc(2 * var(--stsv-common--disabled__stripe-width))
|
|
170
|
+
);
|
|
143
171
|
bottom: 0;
|
|
144
172
|
content: '';
|
|
145
173
|
left: 0;
|
|
@@ -151,6 +179,12 @@ export const setRangeText = (replacement, start, end, selectionMode) => {
|
|
|
151
179
|
transition: opacity 250ms;
|
|
152
180
|
}
|
|
153
181
|
|
|
182
|
+
label {
|
|
183
|
+
color: var(--stsv-common__color);
|
|
184
|
+
transition: color 250ms;
|
|
185
|
+
font: inherit;
|
|
186
|
+
}
|
|
187
|
+
|
|
154
188
|
.sterling-input.disabled::after {
|
|
155
189
|
opacity: 1;
|
|
156
190
|
}
|
package/Input.svelte.d.ts
CHANGED
|
@@ -2,10 +2,11 @@ import { SvelteComponentTyped } from "svelte";
|
|
|
2
2
|
declare const __propDef: {
|
|
3
3
|
props: {
|
|
4
4
|
[x: string]: any;
|
|
5
|
-
composed?: boolean | undefined;
|
|
6
5
|
disabled?: boolean | undefined;
|
|
7
6
|
id?: string | undefined;
|
|
8
7
|
value?: string | undefined;
|
|
8
|
+
colorful?: boolean | undefined;
|
|
9
|
+
composed?: boolean | undefined;
|
|
9
10
|
blur?: (() => void) | undefined;
|
|
10
11
|
click?: (() => void) | undefined;
|
|
11
12
|
focus?: ((options?: FocusOptions) => void) | undefined;
|
|
@@ -66,7 +67,7 @@ export default class Input extends SvelteComponentTyped<InputProps, InputEvents,
|
|
|
66
67
|
get click(): () => void;
|
|
67
68
|
get focus(): (options?: FocusOptions | undefined) => void;
|
|
68
69
|
get select(): () => void;
|
|
69
|
-
get setSelectionRange(): (start: number | null, end: number | null, direction?: "
|
|
70
|
+
get setSelectionRange(): (start: number | null, end: number | null, direction?: "forward" | "backward" | "none" | undefined) => void;
|
|
70
71
|
get setRangeText(): (replacement: string, start?: number | undefined, end?: number | undefined, selectionMode?: SelectionMode | undefined) => void;
|
|
71
72
|
}
|
|
72
73
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const LABEL_STATUSES: string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const LABEL_STATUSES = ['none', 'info', 'success', 'warning', 'danger'];
|
package/Label.svelte
CHANGED
|
@@ -1,23 +1,92 @@
|
|
|
1
|
-
<script>
|
|
1
|
+
<script>import Tooltip from "./Tooltip.svelte";
|
|
2
|
+
import { usingKeyboard } from "./stores/usingKeyboard";
|
|
3
|
+
let htmlFor = void 0;
|
|
4
|
+
export { htmlFor as for };
|
|
5
|
+
export let forwardClick = false;
|
|
6
|
+
export let text = void 0;
|
|
7
|
+
export let message = void 0;
|
|
8
|
+
export let required = false;
|
|
9
|
+
export let requiredReason = "required";
|
|
10
|
+
export let status = "none";
|
|
2
11
|
let labelRef;
|
|
3
|
-
|
|
4
|
-
|
|
12
|
+
let targetDisabled = false;
|
|
13
|
+
let targetRef = null;
|
|
14
|
+
const findTarget = () => {
|
|
15
|
+
let candidate = null;
|
|
16
|
+
if (htmlFor) {
|
|
17
|
+
candidate = labelRef?.querySelector(`[id="${htmlFor}"]`);
|
|
18
|
+
}
|
|
19
|
+
if (!candidate) {
|
|
20
|
+
candidate = labelRef?.querySelector(
|
|
21
|
+
'a[href], audio[controls], button, details, div[contenteditable], form, input, select, textarea, video[controls], [tabindex]:not([tabindex="-1"])'
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
targetRef = candidate;
|
|
25
|
+
};
|
|
26
|
+
const isElementDisabled = (element) => {
|
|
27
|
+
if (element) {
|
|
28
|
+
return element.getAttribute("aria-disabled") === "true" || element?.matches(":disabled") || element?.disabled === true || element?.classList.contains("disabled");
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
5
31
|
};
|
|
32
|
+
$:
|
|
33
|
+
$$slots.default, labelRef, htmlFor, findTarget();
|
|
34
|
+
$: {
|
|
35
|
+
targetDisabled = isElementDisabled(targetRef);
|
|
36
|
+
}
|
|
37
|
+
const mutationCallback = (mutations) => {
|
|
38
|
+
let disabled = void 0;
|
|
39
|
+
for (let i = 0; i < mutations.length; i++) {
|
|
40
|
+
const mutation = mutations[i];
|
|
41
|
+
if (mutation.type === "attributes") {
|
|
42
|
+
if (mutation.attributeName === "aria-disabled" || mutation.attributeName === "disabled" || mutation.attributeName === "class") {
|
|
43
|
+
if (isElementDisabled(targetRef)) {
|
|
44
|
+
disabled = true;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
disabled = false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (disabled !== void 0) {
|
|
52
|
+
targetDisabled = disabled;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
let mutationObserver = new MutationObserver(mutationCallback);
|
|
56
|
+
$: {
|
|
57
|
+
mutationObserver.disconnect();
|
|
58
|
+
if (targetRef) {
|
|
59
|
+
mutationObserver.observe(targetRef, {
|
|
60
|
+
attributes: true
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
6
64
|
export const click = () => {
|
|
7
65
|
labelRef?.click();
|
|
8
66
|
};
|
|
67
|
+
export const blur = () => {
|
|
68
|
+
labelRef?.blur();
|
|
69
|
+
};
|
|
9
70
|
export const focus = (options) => {
|
|
10
|
-
labelRef?.focus();
|
|
71
|
+
labelRef?.focus(options);
|
|
72
|
+
};
|
|
73
|
+
const onClick = () => {
|
|
74
|
+
if (forwardClick) {
|
|
75
|
+
targetRef?.click();
|
|
76
|
+
}
|
|
11
77
|
};
|
|
12
78
|
</script>
|
|
13
79
|
|
|
14
80
|
<label
|
|
15
81
|
bind:this={labelRef}
|
|
16
|
-
aria-disabled={
|
|
82
|
+
aria-disabled={targetDisabled}
|
|
17
83
|
class="sterling-label"
|
|
18
|
-
class:disabled
|
|
84
|
+
class:disabled={targetDisabled}
|
|
85
|
+
class:using-keyboard={$usingKeyboard}
|
|
86
|
+
for={htmlFor}
|
|
19
87
|
on:blur
|
|
20
88
|
on:click
|
|
89
|
+
on:click={onClick}
|
|
21
90
|
on:copy
|
|
22
91
|
on:cut
|
|
23
92
|
on:dblclick
|
|
@@ -41,26 +110,155 @@ export const focus = (options) => {
|
|
|
41
110
|
on:mouseout
|
|
42
111
|
on:mouseup
|
|
43
112
|
on:scroll
|
|
44
|
-
on:wheel
|
|
113
|
+
on:wheel|passive
|
|
45
114
|
on:paste
|
|
46
115
|
{...$$restProps}
|
|
47
116
|
>
|
|
48
|
-
|
|
117
|
+
{#if text || $$slots.text}
|
|
118
|
+
<slot name="text" disabled={targetDisabled} for={htmlFor} {forwardClick} {text} {required}>
|
|
119
|
+
<div class="text">
|
|
120
|
+
{text}
|
|
121
|
+
</div>
|
|
122
|
+
</slot>
|
|
123
|
+
{/if}
|
|
124
|
+
{#if $$slots.default}
|
|
125
|
+
<div class="content">
|
|
126
|
+
<slot />
|
|
127
|
+
</div>
|
|
128
|
+
{/if}
|
|
129
|
+
{#if message}
|
|
130
|
+
<slot name="message" disabled={targetDisabled} {message} {required} {status}>
|
|
131
|
+
<div
|
|
132
|
+
class="message"
|
|
133
|
+
class:info={status === 'info'}
|
|
134
|
+
class:success={status === 'success'}
|
|
135
|
+
class:warning={status === 'warning'}
|
|
136
|
+
class:error={status === 'danger'}
|
|
137
|
+
>
|
|
138
|
+
{message}
|
|
139
|
+
</div>
|
|
140
|
+
</slot>
|
|
141
|
+
{/if}
|
|
142
|
+
{#if required}
|
|
143
|
+
<slot name="required" {requiredReason}>
|
|
144
|
+
<Tooltip showOn="hover">
|
|
145
|
+
<span class="required-reason" slot="tip">{requiredReason}</span>
|
|
146
|
+
<div class="required">*</div>
|
|
147
|
+
</Tooltip>
|
|
148
|
+
</slot>
|
|
149
|
+
{/if}
|
|
49
150
|
</label>
|
|
50
151
|
|
|
51
152
|
<style>
|
|
52
|
-
label {
|
|
53
|
-
color: var(--stsv-
|
|
54
|
-
|
|
153
|
+
.sterling-label {
|
|
154
|
+
background-color: var(--stsv-input__background-color);
|
|
155
|
+
border-color: var(--stsv-input__border-color);
|
|
156
|
+
border-radius: var(--stsv-input__border-radius);
|
|
157
|
+
border-style: var(--stsv-input__border-style);
|
|
158
|
+
border-width: var(--stsv-input__border-width);
|
|
159
|
+
box-sizing: border-box;
|
|
160
|
+
color: var(--stsv-input__color);
|
|
161
|
+
display: flex;
|
|
162
|
+
flex-direction: column;
|
|
55
163
|
font: inherit;
|
|
164
|
+
margin: 0;
|
|
165
|
+
overflow: visible;
|
|
166
|
+
padding: 0;
|
|
167
|
+
position: relative;
|
|
168
|
+
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.sterling-label:not(.disabled):hover {
|
|
172
|
+
background-color: var(--stsv-input__background-color--hover);
|
|
173
|
+
border-color: var(--stsv-input__border-color--hover);
|
|
174
|
+
color: var(--stsv-input__color--hover);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.sterling-label.using-keyboard:focus-within {
|
|
178
|
+
border-color: var(--stsv-input__border-color--focus);
|
|
179
|
+
color: var(--stsv-input__color--focus);
|
|
180
|
+
outline-color: var(--stsv-common__outline-color);
|
|
181
|
+
outline-offset: var(--stsv-common__outline-offset);
|
|
182
|
+
outline-style: var(--stsv-common__outline-style);
|
|
183
|
+
outline-width: var(--stsv-common__outline-width);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.sterling-label.disabled {
|
|
187
|
+
cursor: not-allowed;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.sterling-label.disabled * {
|
|
191
|
+
cursor: not-allowed;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.text {
|
|
195
|
+
color: var(--stsv-common__color--secondary);
|
|
196
|
+
font-size: 0.8em;
|
|
197
|
+
margin: 0.5em 0.7em 0.2em 0.2em;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.text:empty {
|
|
201
|
+
margin: 0;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.content {
|
|
205
|
+
display: grid;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.message {
|
|
209
|
+
box-sizing: border-box;
|
|
210
|
+
font-size: 0.8em;
|
|
211
|
+
background-color: var(--stsv-common__background-color--secondary);
|
|
212
|
+
color: var(--stsv-common__color--secondary);
|
|
213
|
+
padding: 0.5em;
|
|
214
|
+
width: 100%;
|
|
215
|
+
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
.message.info {
|
|
219
|
+
background-color: var(--stsv-status--info__background-color);
|
|
220
|
+
border-color: var(--stsv-status--info__border-color);
|
|
221
|
+
color: var(--stsv-status--info__color);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.message.success {
|
|
225
|
+
background-color: var(--stsv-status--success__background-color);
|
|
226
|
+
border-color: var(--stsv-status--success__border-color);
|
|
227
|
+
color: var(--stsv-status--success__color);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
.message.warning {
|
|
231
|
+
background-color: var(--stsv-status--warning__background-color);
|
|
232
|
+
border-color: var(--stsv-status--warning__border-color);
|
|
233
|
+
color: var(--stsv-status--warning__color);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
.message.error {
|
|
237
|
+
background-color: var(--stsv-status--danger__background-color);
|
|
238
|
+
border-color: var(--stsv_--danger-color);
|
|
239
|
+
color: var(--stsv-status--danger__color);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
.required {
|
|
243
|
+
text-align: center;
|
|
244
|
+
font-weight: bold;
|
|
245
|
+
box-sizing: border-box;
|
|
246
|
+
width: 1em;
|
|
247
|
+
height: 1em;
|
|
248
|
+
position: absolute;
|
|
249
|
+
top: 0;
|
|
250
|
+
right: 0;
|
|
56
251
|
}
|
|
57
252
|
|
|
58
|
-
|
|
59
|
-
|
|
253
|
+
.required-reason {
|
|
254
|
+
display: block;
|
|
255
|
+
padding: 4px;
|
|
60
256
|
}
|
|
61
257
|
|
|
62
258
|
@media (prefers-reduced-motion) {
|
|
63
|
-
label
|
|
259
|
+
.sterling-label,
|
|
260
|
+
.sterling-label::after,
|
|
261
|
+
.message {
|
|
64
262
|
transition: none;
|
|
65
263
|
}
|
|
66
264
|
}
|