@geoffcox/sterling-svelte 1.0.1 → 1.0.4
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/Callout.svelte +10 -8
- package/Checkbox.svelte +1 -1
- package/ColorPicker.svelte +115 -83
- package/Dropdown.svelte +8 -4
- package/Dropdown.svelte.d.ts +5 -0
- package/Input.svelte +1 -1
- package/Label.svelte +9 -4
- package/MenuButton.svelte +4 -2
- package/MenuButton.svelte.d.ts +2 -3
- package/MenuItem.svelte +3 -1
- package/MenuItem.svelte.d.ts +1 -0
- package/Popover.svelte +13 -9
- package/Select.svelte +7 -3
- package/Select.svelte.d.ts +8 -0
- package/css/Input.base.css +2 -2
- package/mediaQueries/prefersColorSchemeDark.js +8 -4
- package/mediaQueries/prefersReducedMotion.js +8 -4
- package/mediaQueries/usingKeyboard.js +9 -5
- package/package.json +1 -1
package/Callout.svelte
CHANGED
|
@@ -26,9 +26,11 @@ let popupRef;
|
|
|
26
26
|
let arrowRef;
|
|
27
27
|
let popupPosition = { x: 0, y: 0 };
|
|
28
28
|
$: floatingUIPlacement = placement;
|
|
29
|
+
let bodyHeight = 0;
|
|
30
|
+
let resizeObserver = undefined;
|
|
29
31
|
// ----- Portal Host ----- //
|
|
30
32
|
const ensurePortalHost = () => {
|
|
31
|
-
if (document) {
|
|
33
|
+
if (globalThis?.document) {
|
|
32
34
|
if (portalHost) {
|
|
33
35
|
return portalHost;
|
|
34
36
|
}
|
|
@@ -43,11 +45,6 @@ const ensurePortalHost = () => {
|
|
|
43
45
|
}
|
|
44
46
|
};
|
|
45
47
|
// ----- Body Height Change ----- //
|
|
46
|
-
let bodyHeight = 0;
|
|
47
|
-
// create an Observer instance
|
|
48
|
-
const resizeObserver = new ResizeObserver((entries) => {
|
|
49
|
-
bodyHeight = entries[0].target.clientHeight;
|
|
50
|
-
});
|
|
51
48
|
// ----- Position ----- //
|
|
52
49
|
$: middleware = [
|
|
53
50
|
offset({ mainAxis: mainAxisOffset, crossAxis: crossAxisOffset }),
|
|
@@ -124,10 +121,15 @@ $: fadeMotion = !$prefersReducedMotion ? fade : fadeNoOp;
|
|
|
124
121
|
// ----- EventHandlers ----- //
|
|
125
122
|
onMount(() => {
|
|
126
123
|
ensurePortalHost();
|
|
124
|
+
resizeObserver = new ResizeObserver((entries) => {
|
|
125
|
+
bodyHeight = entries[0].target.clientHeight;
|
|
126
|
+
});
|
|
127
127
|
// start observing a DOM node
|
|
128
128
|
resizeObserver.observe(document.body);
|
|
129
129
|
return () => {
|
|
130
|
-
resizeObserver
|
|
130
|
+
resizeObserver?.unobserve(document.body);
|
|
131
|
+
resizeObserver?.disconnect();
|
|
132
|
+
resizeObserver = undefined;
|
|
131
133
|
};
|
|
132
134
|
});
|
|
133
135
|
const onKeydown = (event) => {
|
|
@@ -140,7 +142,7 @@ ensurePortalHost();
|
|
|
140
142
|
|
|
141
143
|
{#if open || !conditionalRender}
|
|
142
144
|
<div
|
|
143
|
-
use:portal={{ target: portalHost ?? document
|
|
145
|
+
use:portal={{ target: portalHost ?? globalThis?.document?.body }}
|
|
144
146
|
class="sterling-callout-portal"
|
|
145
147
|
transition:fadeMotion|global={{ duration: 250 }}
|
|
146
148
|
>
|
package/Checkbox.svelte
CHANGED
|
@@ -28,7 +28,7 @@ export const focus = (options) => {
|
|
|
28
28
|
@component
|
|
29
29
|
A styled HTML input type=checkbox element.
|
|
30
30
|
-->
|
|
31
|
-
<div class={`sterling-checkbox ${variant}`} class:disabled>
|
|
31
|
+
<div class={`sterling-checkbox ${variant}`} class:checked class:disabled>
|
|
32
32
|
<div class="container">
|
|
33
33
|
<input
|
|
34
34
|
bind:this={inputRef}
|
package/ColorPicker.svelte
CHANGED
|
@@ -36,107 +36,139 @@ let tabListRef;
|
|
|
36
36
|
let tabsRef;
|
|
37
37
|
// ----- Update HSL, RGB, Text ----- //
|
|
38
38
|
const updateFromRgb = async () => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const color = tinycolor({ r: red, g: green, b: blue, a: newAlpha });
|
|
43
|
-
const hsl = color.toHsl();
|
|
44
|
-
hue = Math.round(hsl.h);
|
|
45
|
-
saturation = Math.round(hsl.s * 100);
|
|
46
|
-
lightness = Math.round(hsl.l * 100);
|
|
47
|
-
switch (colorFormat) {
|
|
48
|
-
case 'rgb':
|
|
49
|
-
colorText = color.toRgbString();
|
|
50
|
-
hexAlpha = Math.round(alpha * 255);
|
|
51
|
-
break;
|
|
52
|
-
case 'hex':
|
|
53
|
-
colorText = alpha === 100 ? color.toHexString() : color.toHex8String();
|
|
54
|
-
alpha = round(hexAlpha / 255, 2);
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
await tick();
|
|
58
|
-
updating = false;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
const updateFromHsl = async () => {
|
|
62
|
-
if (!updating && colorFormat === 'hsl') {
|
|
63
|
-
updating = true;
|
|
64
|
-
const color = tinycolor({ h: hue, s: saturation / 100, l: lightness / 100, a: alpha });
|
|
65
|
-
const rgb = color.toRgb();
|
|
66
|
-
red = rgb.r;
|
|
67
|
-
green = rgb.g;
|
|
68
|
-
blue = rgb.b;
|
|
69
|
-
colorText = color.toHslString();
|
|
70
|
-
hexAlpha = Math.round(alpha * 255);
|
|
71
|
-
await tick();
|
|
72
|
-
updating = false;
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const updateColorsFromText = async () => {
|
|
76
|
-
const color = tinycolor(colorText);
|
|
77
|
-
if (color.isValid) {
|
|
78
|
-
if (!updating) {
|
|
39
|
+
// tinycolor requires window
|
|
40
|
+
if (globalThis.window) {
|
|
41
|
+
if (!updating && (colorFormat === 'hex' || colorFormat === 'rgb')) {
|
|
79
42
|
updating = true;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
43
|
+
const newAlpha = colorFormat === 'hex' ? hexAlpha / 255 : alpha;
|
|
44
|
+
const color = tinycolor({ r: red, g: green, b: blue, a: newAlpha });
|
|
45
|
+
const hsl = color.toHsl();
|
|
46
|
+
hue = Math.round(hsl.h);
|
|
47
|
+
saturation = Math.round(hsl.s * 100);
|
|
48
|
+
lightness = Math.round(hsl.l * 100);
|
|
49
|
+
switch (colorFormat) {
|
|
84
50
|
case 'rgb':
|
|
85
|
-
|
|
51
|
+
colorText = color.toRgbString();
|
|
52
|
+
hexAlpha = Math.round(alpha * 255);
|
|
86
53
|
break;
|
|
87
54
|
case 'hex':
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
colorFormat = 'hex';
|
|
91
|
-
break;
|
|
92
|
-
default:
|
|
55
|
+
colorText = alpha === 100 ? color.toHexString() : color.toHex8String();
|
|
56
|
+
alpha = round(hexAlpha / 255, 2);
|
|
93
57
|
break;
|
|
94
58
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
59
|
+
await tick();
|
|
60
|
+
updating = false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const updateFromHsl = async () => {
|
|
65
|
+
// tinycolor requires window
|
|
66
|
+
if (globalThis.window) {
|
|
67
|
+
if (!updating && colorFormat === 'hsl') {
|
|
68
|
+
updating = true;
|
|
69
|
+
const color = tinycolor({ h: hue, s: saturation / 100, l: lightness / 100, a: alpha });
|
|
99
70
|
const rgb = color.toRgb();
|
|
100
71
|
red = rgb.r;
|
|
101
72
|
green = rgb.g;
|
|
102
73
|
blue = rgb.b;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
hexAlpha = Math.round(alpha * 255);
|
|
106
|
-
}
|
|
74
|
+
colorText = color.toHslString();
|
|
75
|
+
hexAlpha = Math.round(alpha * 255);
|
|
107
76
|
await tick();
|
|
108
77
|
updating = false;
|
|
109
78
|
}
|
|
110
79
|
}
|
|
111
80
|
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
// ----- Event handlers ----- //
|
|
116
|
-
const onInputBlur = async () => {
|
|
117
|
-
if (!updating) {
|
|
118
|
-
if (colorText.trim().length === 0) {
|
|
119
|
-
colorText = defaultColorText;
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
81
|
+
const updateColorsFromText = async () => {
|
|
82
|
+
// tinycolor requires window
|
|
83
|
+
if (globalThis.window) {
|
|
122
84
|
const color = tinycolor(colorText);
|
|
123
85
|
if (color.isValid) {
|
|
124
|
-
updating
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
86
|
+
if (!updating) {
|
|
87
|
+
updating = true;
|
|
88
|
+
switch (color.format) {
|
|
89
|
+
case 'hsl':
|
|
90
|
+
colorFormat = 'hsl';
|
|
91
|
+
break;
|
|
92
|
+
case 'rgb':
|
|
93
|
+
colorFormat = 'rgb';
|
|
94
|
+
break;
|
|
95
|
+
case 'hex':
|
|
96
|
+
case 'hex4':
|
|
97
|
+
case 'hex8':
|
|
98
|
+
colorFormat = 'hex';
|
|
99
|
+
break;
|
|
100
|
+
default:
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
const hsl = color.toHsl();
|
|
104
|
+
hue = Math.round(hsl.h);
|
|
105
|
+
saturation = Math.round(hsl.s * 100);
|
|
106
|
+
lightness = Math.round(hsl.l * 100);
|
|
107
|
+
const rgb = color.toRgb();
|
|
108
|
+
red = rgb.r;
|
|
109
|
+
green = rgb.g;
|
|
110
|
+
blue = rgb.b;
|
|
111
|
+
if (rgb.a) {
|
|
112
|
+
alpha = hsl.a;
|
|
113
|
+
hexAlpha = Math.round(alpha * 255);
|
|
114
|
+
}
|
|
115
|
+
await tick();
|
|
116
|
+
updating = false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
$: {
|
|
122
|
+
globalThis.window;
|
|
123
|
+
colorText;
|
|
124
|
+
updateColorsFromText();
|
|
125
|
+
}
|
|
126
|
+
$: {
|
|
127
|
+
globalThis.window;
|
|
128
|
+
colorFormat;
|
|
129
|
+
hue;
|
|
130
|
+
saturation;
|
|
131
|
+
lightness;
|
|
132
|
+
alpha;
|
|
133
|
+
updateFromHsl();
|
|
134
|
+
}
|
|
135
|
+
$: {
|
|
136
|
+
globalThis.window;
|
|
137
|
+
colorFormat;
|
|
138
|
+
red;
|
|
139
|
+
green;
|
|
140
|
+
blue;
|
|
141
|
+
alpha;
|
|
142
|
+
hexAlpha;
|
|
143
|
+
updateFromRgb();
|
|
144
|
+
}
|
|
145
|
+
// ----- Event handlers ----- //
|
|
146
|
+
const onInputBlur = async () => {
|
|
147
|
+
if (globalThis.window && tinycolor) {
|
|
148
|
+
if (!updating) {
|
|
149
|
+
if (colorText.trim().length === 0) {
|
|
150
|
+
colorText = defaultColorText;
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const color = tinycolor(colorText);
|
|
154
|
+
if (color.isValid) {
|
|
155
|
+
updating = true;
|
|
156
|
+
switch (colorFormat) {
|
|
157
|
+
case 'hsl':
|
|
158
|
+
colorText = color.toHslString();
|
|
159
|
+
break;
|
|
160
|
+
case 'rgb':
|
|
161
|
+
colorText = color.toRgbString();
|
|
162
|
+
break;
|
|
163
|
+
case 'hex':
|
|
164
|
+
colorText = alpha === 1 ? color.toHexString() : color.toHex8String();
|
|
165
|
+
break;
|
|
166
|
+
default:
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
await tick();
|
|
170
|
+
updating = false;
|
|
137
171
|
}
|
|
138
|
-
await tick();
|
|
139
|
-
updating = false;
|
|
140
172
|
}
|
|
141
173
|
}
|
|
142
174
|
};
|
package/Dropdown.svelte
CHANGED
|
@@ -113,12 +113,16 @@ $: slideMotion = !$prefersReducedMotion ? slide : slideNoOp;
|
|
|
113
113
|
on:click_outside={onClickOutside}
|
|
114
114
|
{...$$restProps}
|
|
115
115
|
>
|
|
116
|
-
|
|
117
|
-
<
|
|
118
|
-
|
|
116
|
+
{#if $$slots.value}
|
|
117
|
+
<div class="value">
|
|
118
|
+
<slot name="value" {disabled} {open} {variant} />
|
|
119
|
+
</div>
|
|
120
|
+
{/if}
|
|
119
121
|
<slot name="button" {disabled} {open} {variant}>
|
|
120
122
|
<div class="button">
|
|
121
|
-
<
|
|
123
|
+
<slot name="icon" {disabled} {open} {variant}>
|
|
124
|
+
<div class="chevron" />
|
|
125
|
+
</slot>
|
|
122
126
|
</div>
|
|
123
127
|
</slot>
|
|
124
128
|
|
package/Dropdown.svelte.d.ts
CHANGED
package/Input.svelte
CHANGED
|
@@ -40,7 +40,7 @@ export const setRangeText = (replacement, start, end, selectionMode) => {
|
|
|
40
40
|
</script>
|
|
41
41
|
|
|
42
42
|
{#if $$slots.default}
|
|
43
|
-
<label class={`sterling-input-label ${variant}`} for={id}>
|
|
43
|
+
<label class={`sterling-input-label ${variant}`} class:disabled for={id}>
|
|
44
44
|
<slot {disabled} {value} {variant} />
|
|
45
45
|
</label>
|
|
46
46
|
{/if}
|
package/Label.svelte
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
<script>import
|
|
1
|
+
<script>import { onMount } from 'svelte';
|
|
2
|
+
import Tooltip from './Tooltip.svelte';
|
|
2
3
|
import { usingKeyboard } from './mediaQueries/usingKeyboard';
|
|
3
4
|
// ----- Props ----- //
|
|
4
5
|
let htmlFor = undefined;
|
|
@@ -82,11 +83,15 @@ const mutationCallback = (mutations) => {
|
|
|
82
83
|
targetDisabled = disabled;
|
|
83
84
|
}
|
|
84
85
|
};
|
|
85
|
-
let mutationObserver
|
|
86
|
+
let mutationObserver;
|
|
87
|
+
onMount(() => {
|
|
88
|
+
mutationObserver = new MutationObserver(mutationCallback);
|
|
89
|
+
return () => mutationObserver?.disconnect();
|
|
90
|
+
});
|
|
86
91
|
$: {
|
|
87
|
-
mutationObserver
|
|
92
|
+
mutationObserver?.disconnect();
|
|
88
93
|
if (targetRef) {
|
|
89
|
-
mutationObserver
|
|
94
|
+
mutationObserver?.observe(targetRef, {
|
|
90
95
|
attributes: true
|
|
91
96
|
});
|
|
92
97
|
}
|
package/MenuButton.svelte
CHANGED
|
@@ -13,6 +13,8 @@ export let open = false;
|
|
|
13
13
|
export let value;
|
|
14
14
|
/** Additional class names to apply. */
|
|
15
15
|
export let variant = '';
|
|
16
|
+
/** Additional class names to apply to the Menu*/
|
|
17
|
+
export let menuVariant = '';
|
|
16
18
|
// ----- State ----- //
|
|
17
19
|
const instanceId = idGenerator.nextId('MenuButton');
|
|
18
20
|
let buttonRef;
|
|
@@ -144,8 +146,8 @@ setContext(MENU_ITEM_CONTEXT_KEY, {
|
|
|
144
146
|
<slot {open} {value} {variant} />
|
|
145
147
|
</div>
|
|
146
148
|
<Popover {reference} {open}>
|
|
147
|
-
<Menu bind:this={menuRef} id={menuId} {reference} {open}>
|
|
148
|
-
<slot name="items"
|
|
149
|
+
<Menu bind:this={menuRef} id={menuId} {reference} {open} variant={menuVariant}>
|
|
150
|
+
<slot name="items" />
|
|
149
151
|
</Menu>
|
|
150
152
|
</Popover>
|
|
151
153
|
</Button>
|
package/MenuButton.svelte.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ declare const __propDef: {
|
|
|
5
5
|
open?: boolean | undefined;
|
|
6
6
|
value: string;
|
|
7
7
|
variant?: string | undefined;
|
|
8
|
+
menuVariant?: string | undefined;
|
|
8
9
|
click?: (() => void) | undefined;
|
|
9
10
|
blur?: (() => void) | undefined;
|
|
10
11
|
focus?: ((options?: FocusOptions) => void) | undefined;
|
|
@@ -53,9 +54,7 @@ declare const __propDef: {
|
|
|
53
54
|
value: string;
|
|
54
55
|
variant: string;
|
|
55
56
|
};
|
|
56
|
-
items: {
|
|
57
|
-
variant: string;
|
|
58
|
-
};
|
|
57
|
+
items: {};
|
|
59
58
|
};
|
|
60
59
|
};
|
|
61
60
|
export type MenuButtonProps = typeof __propDef.props;
|
package/MenuItem.svelte
CHANGED
|
@@ -24,6 +24,8 @@ export let text = undefined;
|
|
|
24
24
|
export let value;
|
|
25
25
|
/** Additional class names to apply. */
|
|
26
26
|
export let variant = '';
|
|
27
|
+
/** Additional class names to apply to the sub Menu*/
|
|
28
|
+
export let menuVariant = '';
|
|
27
29
|
// ----- Get Context ----- //
|
|
28
30
|
const { isMenuBarItem, openValues = writable([]), rootValue = value, depth = 0, closeContainingMenu = undefined, onOpen = undefined, onClose = undefined, onSelect = undefined } = getContext(MENU_ITEM_CONTEXT_KEY) || {};
|
|
29
31
|
const { openPreviousMenuBarItem = undefined, openNextMenuBarItem = undefined } = getContext(MENU_BAR_CONTEXT_KEY) || {};
|
|
@@ -376,7 +378,7 @@ setContext(MENU_ITEM_CONTEXT_KEY, {
|
|
|
376
378
|
placement={isMenuBarItem ? 'bottom-start' : 'right-start'}
|
|
377
379
|
{open}
|
|
378
380
|
>
|
|
379
|
-
<Menu bind:this={menuRef} id={menuId}>
|
|
381
|
+
<Menu bind:this={menuRef} id={menuId} variant={menuVariant}>
|
|
380
382
|
<slot {depth} {disabled} />
|
|
381
383
|
</Menu>
|
|
382
384
|
</Popover>
|
package/MenuItem.svelte.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ declare const __propDef: {
|
|
|
8
8
|
text?: string | undefined;
|
|
9
9
|
value: string;
|
|
10
10
|
variant?: string | undefined;
|
|
11
|
+
menuVariant?: string | undefined;
|
|
11
12
|
blur?: (() => void) | undefined;
|
|
12
13
|
click?: (() => void) | undefined;
|
|
13
14
|
focus?: ((options?: FocusOptions) => void) | undefined;
|
package/Popover.svelte
CHANGED
|
@@ -23,9 +23,11 @@ export let variant = '';
|
|
|
23
23
|
let popupRef;
|
|
24
24
|
let popupPosition = { x: 0, y: 0 };
|
|
25
25
|
$: floatingUIPlacement = placement;
|
|
26
|
+
let bodyHeight = 0;
|
|
27
|
+
let resizeObserver = undefined;
|
|
26
28
|
// ----- Portal Host ----- //
|
|
27
29
|
const ensurePortalHost = () => {
|
|
28
|
-
if (document) {
|
|
30
|
+
if (globalThis?.document) {
|
|
29
31
|
if (portalHost) {
|
|
30
32
|
return portalHost;
|
|
31
33
|
}
|
|
@@ -39,12 +41,6 @@ const ensurePortalHost = () => {
|
|
|
39
41
|
portalHost = host;
|
|
40
42
|
}
|
|
41
43
|
};
|
|
42
|
-
// ----- Body Height Change ----- //
|
|
43
|
-
let bodyHeight = 0;
|
|
44
|
-
// create an Observer instance
|
|
45
|
-
const resizeObserver = new ResizeObserver((entries) => {
|
|
46
|
-
bodyHeight = entries[0].target.clientHeight;
|
|
47
|
-
});
|
|
48
44
|
// ----- Position ----- //
|
|
49
45
|
$: middleware = [offset({ mainAxis: mainAxisOffset, crossAxis: crossAxisOffset }), flip()];
|
|
50
46
|
const computePopoverPosition = async () => {
|
|
@@ -71,10 +67,15 @@ $: open, bodyHeight, middleware, floatingUIPlacement, computePopoverPosition();
|
|
|
71
67
|
// ----- EventHandlers ----- //
|
|
72
68
|
onMount(() => {
|
|
73
69
|
ensurePortalHost();
|
|
70
|
+
resizeObserver = new ResizeObserver((entries) => {
|
|
71
|
+
bodyHeight = entries[0].target.clientHeight;
|
|
72
|
+
});
|
|
74
73
|
// start observing a DOM node
|
|
75
74
|
resizeObserver.observe(document.body);
|
|
76
75
|
return () => {
|
|
77
|
-
resizeObserver
|
|
76
|
+
resizeObserver?.unobserve(document.body);
|
|
77
|
+
resizeObserver?.disconnect();
|
|
78
|
+
resizeObserver = undefined;
|
|
78
79
|
};
|
|
79
80
|
});
|
|
80
81
|
const onKeydown = (event) => {
|
|
@@ -86,7 +87,10 @@ ensurePortalHost();
|
|
|
86
87
|
</script>
|
|
87
88
|
|
|
88
89
|
{#if open || !conditionalRender}
|
|
89
|
-
<div
|
|
90
|
+
<div
|
|
91
|
+
use:portal={{ target: portalHost ?? globalThis?.document?.body }}
|
|
92
|
+
class="sterling-popover-portal"
|
|
93
|
+
>
|
|
90
94
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
91
95
|
<div
|
|
92
96
|
bind:this={popupRef}
|
package/Select.svelte
CHANGED
|
@@ -12,6 +12,8 @@ export let open = false;
|
|
|
12
12
|
export let selectedValue = undefined;
|
|
13
13
|
/** Additional class names to apply. */
|
|
14
14
|
export let variant = '';
|
|
15
|
+
/** Additional class names to apply to the List*/
|
|
16
|
+
export let listVariant = '';
|
|
15
17
|
// ----- State ----- //
|
|
16
18
|
// Tracks the previous open state
|
|
17
19
|
let prevOpen = false;
|
|
@@ -209,7 +211,9 @@ const onListSelect = (event) => {
|
|
|
209
211
|
</div>
|
|
210
212
|
<div class="button">
|
|
211
213
|
<slot name="button" {disabled} {open} {selectedValue} {variant}>
|
|
212
|
-
<
|
|
214
|
+
<slot name="icon" {disabled} {open} {selectedValue} {variant}>
|
|
215
|
+
<div class="chevron" />
|
|
216
|
+
</slot>
|
|
213
217
|
</slot>
|
|
214
218
|
</div>
|
|
215
219
|
<Popover reference={selectRef} bind:open id={popupId} conditionalRender={false}>
|
|
@@ -222,9 +226,9 @@ const onListSelect = (event) => {
|
|
|
222
226
|
on:keydown={onListKeydown}
|
|
223
227
|
on:select={onListSelect}
|
|
224
228
|
tabIndex={open ? 0 : -1}
|
|
225
|
-
variant={`composed ${
|
|
229
|
+
variant={`composed ${listVariant}`}
|
|
226
230
|
>
|
|
227
|
-
<slot {variant} />
|
|
231
|
+
<slot {variant} {listVariant} />
|
|
228
232
|
</List>
|
|
229
233
|
</div>
|
|
230
234
|
</Popover>
|
package/Select.svelte.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ declare const __propDef: {
|
|
|
6
6
|
open?: boolean | undefined;
|
|
7
7
|
selectedValue?: string | undefined;
|
|
8
8
|
variant?: string | undefined;
|
|
9
|
+
listVariant?: string | undefined;
|
|
9
10
|
blur?: (() => void) | undefined;
|
|
10
11
|
click?: (() => void) | undefined;
|
|
11
12
|
focus?: ((options?: FocusOptions) => void) | undefined;
|
|
@@ -56,8 +57,15 @@ declare const __propDef: {
|
|
|
56
57
|
selectedValue: string | undefined;
|
|
57
58
|
variant: string;
|
|
58
59
|
};
|
|
60
|
+
icon: {
|
|
61
|
+
disabled: boolean;
|
|
62
|
+
open: boolean;
|
|
63
|
+
selectedValue: string | undefined;
|
|
64
|
+
variant: string;
|
|
65
|
+
};
|
|
59
66
|
default: {
|
|
60
67
|
variant: string;
|
|
68
|
+
listVariant: string;
|
|
61
69
|
};
|
|
62
70
|
};
|
|
63
71
|
};
|
package/css/Input.base.css
CHANGED
|
@@ -84,7 +84,7 @@ input::placeholder {
|
|
|
84
84
|
|
|
85
85
|
/* ----- label ----- */
|
|
86
86
|
|
|
87
|
-
label {
|
|
87
|
+
.sterling-input-label {
|
|
88
88
|
color: var(--stsv-common__color);
|
|
89
89
|
transition: color 250ms;
|
|
90
90
|
font: inherit;
|
|
@@ -94,7 +94,7 @@ label {
|
|
|
94
94
|
|
|
95
95
|
@media (prefers-reduced-motion) {
|
|
96
96
|
.sterling-input::after,
|
|
97
|
-
input {
|
|
97
|
+
.sterling-input-label {
|
|
98
98
|
transition: none;
|
|
99
99
|
}
|
|
100
100
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import { onMount } from 'svelte';
|
|
1
2
|
import { writable } from 'svelte/store';
|
|
2
3
|
export const prefersColorSchemeDark = writable(false, (set) => {
|
|
3
|
-
|
|
4
|
-
set(matchMedia.matches);
|
|
4
|
+
let matchMedia = undefined;
|
|
5
5
|
const mediaChangeHandler = (e) => set(e.matches);
|
|
6
|
-
|
|
6
|
+
onMount(() => {
|
|
7
|
+
matchMedia = window.matchMedia('(prefers-color-scheme: dark)');
|
|
8
|
+
set(matchMedia.matches);
|
|
9
|
+
matchMedia.addEventListener('change', mediaChangeHandler);
|
|
10
|
+
});
|
|
7
11
|
return () => {
|
|
8
|
-
matchMedia
|
|
12
|
+
matchMedia?.removeEventListener('change', mediaChangeHandler);
|
|
9
13
|
};
|
|
10
14
|
});
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import { onMount } from 'svelte';
|
|
1
2
|
import { writable } from 'svelte/store';
|
|
2
3
|
export const prefersReducedMotion = writable(false, (set) => {
|
|
3
|
-
|
|
4
|
-
set(matchMedia.matches);
|
|
4
|
+
let matchMedia = undefined;
|
|
5
5
|
const mediaChangeHandler = (e) => set(e.matches);
|
|
6
|
-
|
|
6
|
+
onMount(() => {
|
|
7
|
+
matchMedia = window.matchMedia('(prefers-reduced-motion: reduce)');
|
|
8
|
+
set(matchMedia.matches);
|
|
9
|
+
matchMedia.addEventListener('change', mediaChangeHandler);
|
|
10
|
+
});
|
|
7
11
|
return () => {
|
|
8
|
-
matchMedia
|
|
12
|
+
matchMedia?.removeEventListener('change', mediaChangeHandler);
|
|
9
13
|
};
|
|
10
14
|
});
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { onMount } from 'svelte';
|
|
2
2
|
import { writable } from 'svelte/store';
|
|
3
|
+
import { createKeyborg } from 'keyborg';
|
|
3
4
|
export const usingKeyboard = writable(false, (set) => {
|
|
4
|
-
let keyborg =
|
|
5
|
-
set(keyborg.isNavigatingWithKeyboard());
|
|
5
|
+
let keyborg = undefined;
|
|
6
6
|
const keyborgHandler = (value) => {
|
|
7
7
|
set(value);
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
onMount(() => {
|
|
10
|
+
keyborg = createKeyborg(window);
|
|
11
|
+
set(keyborg.isNavigatingWithKeyboard());
|
|
12
|
+
keyborg.subscribe(keyborgHandler);
|
|
13
|
+
});
|
|
10
14
|
return () => {
|
|
11
|
-
keyborg
|
|
15
|
+
keyborg?.unsubscribe(keyborgHandler);
|
|
12
16
|
};
|
|
13
17
|
});
|