@geoffcox/sterling-svelte 0.0.31 → 1.0.1
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/@types/clickOutside.d.ts +11 -7
- package/Button.svelte +11 -183
- package/Button.svelte.d.ts +2 -6
- package/Callout.svelte +107 -146
- package/Callout.svelte.d.ts +1 -1
- package/Checkbox.svelte +15 -177
- package/Checkbox.svelte.d.ts +2 -2
- package/ColorPicker.svelte +204 -223
- package/ColorPicker.svelte.d.ts +1 -2
- package/Dialog.svelte +90 -187
- package/Dialog.svelte.d.ts +2 -1
- package/Dropdown.svelte +52 -220
- package/Dropdown.svelte.d.ts +4 -8
- package/HexColorSliders.svelte +77 -145
- package/HexColorSliders.svelte.d.ts +28 -1
- package/HslColorSliders.svelte +99 -179
- package/HslColorSliders.svelte.d.ts +28 -1
- package/Input.svelte +27 -136
- package/Input.svelte.d.ts +2 -3
- package/Label.constants.d.ts +1 -0
- package/Label.constants.js +1 -0
- package/Label.svelte +96 -169
- package/Label.svelte.d.ts +6 -1
- package/Label.types.d.ts +3 -1
- package/Link.svelte +9 -106
- package/Link.svelte.d.ts +0 -1
- package/List.svelte +142 -230
- package/List.svelte.d.ts +2 -3
- package/List.types.d.ts +6 -1
- package/ListItem.svelte +25 -94
- package/ListItem.svelte.d.ts +2 -0
- package/Menu.svelte +48 -65
- package/Menu.svelte.d.ts +4 -1
- package/MenuBar.svelte +84 -86
- package/MenuBar.svelte.d.ts +4 -1
- package/MenuButton.svelte +66 -73
- package/MenuButton.svelte.d.ts +7 -3
- package/MenuItem.svelte +256 -288
- package/MenuItem.svelte.d.ts +2 -2
- package/MenuItemDisplay.svelte +12 -116
- package/MenuItemDisplay.svelte.d.ts +21 -7
- package/MenuSeparator.svelte +6 -45
- package/MenuSeparator.svelte.d.ts +8 -78
- package/Popover.constants.d.ts +1 -1
- package/Popover.constants.js +1 -1
- package/Popover.svelte +66 -80
- package/Popover.svelte.d.ts +5 -1
- package/Progress.svelte +28 -126
- package/Progress.svelte.d.ts +4 -3
- package/Radio.svelte +49 -192
- package/Radio.svelte.d.ts +2 -2
- package/RgbColorSliders.svelte +48 -137
- package/RgbColorSliders.svelte.d.ts +5 -5
- package/Select.svelte +122 -250
- package/Select.svelte.d.ts +6 -2
- package/Slider.svelte +90 -259
- package/Slider.svelte.d.ts +1 -2
- package/Switch.svelte +24 -259
- package/Switch.svelte.d.ts +3 -1
- package/Tab.svelte +27 -175
- package/Tab.svelte.d.ts +6 -4
- package/TabList.svelte +146 -171
- package/TabList.svelte.d.ts +3 -2
- package/TabList.types.d.ts +6 -1
- package/TextArea.svelte +32 -129
- package/TextArea.svelte.d.ts +1 -1
- package/Tooltip.svelte +46 -47
- package/Tooltip.svelte.d.ts +8 -3
- package/Tree.constants.d.ts +0 -1
- package/Tree.constants.js +0 -1
- package/Tree.svelte +35 -119
- package/Tree.svelte.d.ts +4 -4
- package/Tree.types.d.ts +1 -3
- package/TreeChevron.svelte +18 -98
- package/TreeChevron.svelte.d.ts +1 -0
- package/TreeItem.constants.d.ts +1 -0
- package/TreeItem.constants.js +1 -0
- package/TreeItem.svelte +251 -211
- package/TreeItem.svelte.d.ts +7 -3
- package/TreeItem.types.d.ts +1 -1
- package/TreeItemDisplay.svelte +20 -104
- package/TreeItemDisplay.svelte.d.ts +2 -2
- package/actions/applyLightDarkMode.d.ts +10 -0
- package/actions/applyLightDarkMode.js +36 -0
- package/actions/forwardEvents.js +3 -3
- package/css/Button.base.css +74 -0
- package/css/Button.colorful.css +17 -0
- package/css/Button.css +7 -0
- package/css/Button.secondary.colorful.css +15 -0
- package/css/Button.secondary.css +11 -0
- package/css/Button.shapes.css +14 -0
- package/css/Button.tool.colorful.css +13 -0
- package/css/Button.tool.css +18 -0
- package/css/Callout.base.css +43 -0
- package/css/Callout.colorful.css +5 -0
- package/css/Callout.css +2 -0
- package/css/Checkbox.base.css +145 -0
- package/css/Checkbox.colorful.css +17 -0
- package/css/Checkbox.css +2 -0
- package/css/ColorPicker.base.css +23 -0
- package/css/ColorPicker.css +1 -0
- package/css/Dialog.base.css +116 -0
- package/css/Dialog.css +1 -0
- package/css/Dropdown.base.css +147 -0
- package/css/Dropdown.colorful.css +23 -0
- package/css/Dropdown.css +2 -0
- package/css/HexColorSliders.base.css +106 -0
- package/css/HexColorSliders.css +1 -0
- package/css/HslColorSliders.base.css +124 -0
- package/css/HslColorSliders.css +1 -0
- package/css/Input.base.css +100 -0
- package/css/Input.colorful.css +22 -0
- package/css/Input.composed.css +8 -0
- package/css/Input.css +3 -0
- package/css/Label.base.css +119 -0
- package/css/Label.boxed.colorful.css +21 -0
- package/css/Label.boxed.css +31 -0
- package/css/Label.colorful.css +3 -0
- package/css/Label.css +4 -0
- package/css/Link.base.css +52 -0
- package/css/Link.colorful.css +15 -0
- package/css/Link.css +6 -0
- package/css/Link.ghost.colorful.css +7 -0
- package/css/Link.ghost.css +11 -0
- package/css/Link.undecorated.colorful.css +6 -0
- package/css/Link.undecorated.css +6 -0
- package/css/List.base.css +98 -0
- package/css/List.css +1 -0
- package/css/ListItem.base.css +59 -0
- package/css/ListItem.css +1 -0
- package/css/Menu.base.css +21 -0
- package/css/Menu.css +1 -0
- package/css/MenuBar.base.css +9 -0
- package/css/MenuBar.css +1 -0
- package/css/MenuButton.base.css +13 -0
- package/css/MenuButton.css +1 -0
- package/css/MenuItem.base.css +48 -0
- package/css/MenuItem.css +1 -0
- package/css/MenuItemDisplay.base.css +104 -0
- package/css/MenuItemDisplay.css +1 -0
- package/css/MenuSeparator.base.css +5 -0
- package/css/MenuSeparator.css +1 -0
- package/css/Popover copy.css +21 -0
- package/css/Popover.css +21 -0
- package/css/Progress.base.css +99 -0
- package/css/Progress.css +1 -0
- package/css/Radio.base.css +135 -0
- package/css/Radio.colorful.css +18 -0
- package/css/Radio.css +2 -0
- package/css/RgbColorSliders.base.css +94 -0
- package/css/RgbColorSliders.css +1 -0
- package/css/Select.base.css +127 -0
- package/css/Select.colorful.css +24 -0
- package/css/Select.composed.css +12 -0
- package/css/Select.css +3 -0
- package/css/Slider.base.css +182 -0
- package/css/Slider.colorful.css +11 -0
- package/css/Slider.composed.css +8 -0
- package/css/Slider.css +3 -0
- package/css/Switch.base.css +193 -0
- package/css/Switch.colorful.css +39 -0
- package/css/Switch.css +2 -0
- package/css/Tab.base.css +135 -0
- package/css/Tab.colorful.css +13 -0
- package/css/Tab.css +2 -0
- package/css/TabList.base.css +34 -0
- package/css/TabList.css +1 -0
- package/css/TextArea.base.css +85 -0
- package/css/TextArea.colorful.css +17 -0
- package/css/TextArea.composed.css +8 -0
- package/css/TextArea.css +3 -0
- package/css/Tooltip.base.css +6 -0
- package/css/Tooltip.css +1 -0
- package/css/Tree.base.css +74 -0
- package/css/Tree.composed.css +8 -0
- package/css/Tree.css +2 -0
- package/css/TreeChevron.base.css +86 -0
- package/css/TreeChevron.css +1 -0
- package/css/TreeItem.base.css +3 -0
- package/css/TreeItem.css +1 -0
- package/css/TreeItemDisplay.base.css +74 -0
- package/css/TreeItemDisplay.colorful.css +9 -0
- package/css/TreeItemDisplay.css +1 -0
- package/css/dark-mode.css +134 -0
- package/css/light-mode.css +134 -0
- package/css/sterling.css +37 -0
- package/index.d.ts +9 -13
- package/index.js +8 -12
- package/mediaQueries/prefersColorSchemeDark.d.ts +2 -0
- package/mediaQueries/prefersColorSchemeDark.js +10 -0
- package/{stores → mediaQueries}/prefersReducedMotion.d.ts +1 -0
- package/{stores → mediaQueries}/usingKeyboard.d.ts +1 -0
- package/package.json +121 -13
- package/Link.constants.d.ts +0 -1
- package/Link.constants.js +0 -1
- package/Link.types.d.ts +0 -4
- package/Link.types.js +0 -1
- package/theme/applyDarkTheme.d.ts +0 -7
- package/theme/applyDarkTheme.js +0 -11
- package/theme/applyLightTheme.d.ts +0 -7
- package/theme/applyLightTheme.js +0 -11
- package/theme/applyTheme.d.ts +0 -7
- package/theme/applyTheme.js +0 -20
- package/theme/colors.d.ts +0 -54
- package/theme/colors.js +0 -82
- package/theme/darkTheme.d.ts +0 -2
- package/theme/darkTheme.js +0 -142
- package/theme/lightTheme.d.ts +0 -2
- package/theme/lightTheme.js +0 -119
- package/theme/toggleDarkTheme.d.ts +0 -18
- package/theme/toggleDarkTheme.js +0 -53
- package/theme/types.d.ts +0 -21
- package/theme/types.js +0 -1
- /package/{stores → mediaQueries}/prefersReducedMotion.js +0 -0
- /package/{stores → mediaQueries}/usingKeyboard.js +0 -0
package/ListItem.svelte
CHANGED
|
@@ -1,40 +1,43 @@
|
|
|
1
|
-
<script>import { getContext } from
|
|
2
|
-
import { readable, writable } from
|
|
3
|
-
import { LIST_CONTEXT_KEY } from
|
|
1
|
+
<script>import { getContext } from 'svelte';
|
|
2
|
+
import { readable, writable } from 'svelte/store';
|
|
3
|
+
import { LIST_CONTEXT_KEY } from './List.constants';
|
|
4
|
+
// ----- Props ----- //
|
|
5
|
+
/** When true the item is disabled. The item is also disabled if the parent list is disabled. */
|
|
4
6
|
export let disabled = false;
|
|
7
|
+
/** The value uniquely identifying this item within the list. */
|
|
5
8
|
export let value;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
disabled: readable(false),
|
|
14
|
-
selectedValue: writable(void 0),
|
|
15
|
-
horizontal: readable(false)
|
|
9
|
+
/** Additional class names to apply. */
|
|
10
|
+
export let variant = '';
|
|
11
|
+
// ----- GetContext ----- //
|
|
12
|
+
const { disabled: listDisabled, selectedValue, horizontal } = getContext(LIST_CONTEXT_KEY) || {
|
|
13
|
+
disabled: readable(false),
|
|
14
|
+
selectedValue: writable(undefined),
|
|
15
|
+
horizontal: readable(false)
|
|
16
16
|
};
|
|
17
|
+
// ----- State ----- //
|
|
17
18
|
let itemRef;
|
|
18
|
-
$:
|
|
19
|
-
|
|
19
|
+
$: selected = $selectedValue === value;
|
|
20
|
+
// ----- Methods ----- //
|
|
20
21
|
export const click = () => {
|
|
21
|
-
|
|
22
|
+
itemRef?.click();
|
|
22
23
|
};
|
|
23
24
|
export const blur = () => {
|
|
24
|
-
|
|
25
|
+
itemRef?.blur();
|
|
25
26
|
};
|
|
26
27
|
export const focus = (options) => {
|
|
27
|
-
|
|
28
|
+
itemRef?.focus(options);
|
|
28
29
|
};
|
|
29
30
|
</script>
|
|
30
31
|
|
|
32
|
+
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
|
33
|
+
<!-- svelte-ignore a11y-role-supports-aria-props -->
|
|
31
34
|
<div
|
|
32
35
|
aria-selected={selected}
|
|
33
36
|
bind:this={itemRef}
|
|
34
|
-
class=
|
|
35
|
-
class:colorful={$colorful}
|
|
37
|
+
class={`sterling-list-item ${variant}`}
|
|
36
38
|
class:disabled={disabled || $listDisabled}
|
|
37
|
-
class:item-disabled={disabled
|
|
39
|
+
class:item-disabled={disabled}
|
|
40
|
+
class:list-disabled={$listDisabled}
|
|
38
41
|
class:selected
|
|
39
42
|
data-value={value}
|
|
40
43
|
role="listitem"
|
|
@@ -71,77 +74,5 @@ export const focus = (options) => {
|
|
|
71
74
|
on:wheel|passive
|
|
72
75
|
{...$$restProps}
|
|
73
76
|
>
|
|
74
|
-
<slot {disabled} {horizontal} {selected} {value}>{value}</slot>
|
|
77
|
+
<slot {disabled} {horizontal} {selected} {value} {variant}>{value}</slot>
|
|
75
78
|
</div>
|
|
76
|
-
|
|
77
|
-
<style>
|
|
78
|
-
.sterling-list-item {
|
|
79
|
-
background-color: transparent;
|
|
80
|
-
box-sizing: border-box;
|
|
81
|
-
color: var(--stsv-common__color);
|
|
82
|
-
cursor: pointer;
|
|
83
|
-
margin: 0;
|
|
84
|
-
padding: 0.5em;
|
|
85
|
-
position: relative;
|
|
86
|
-
outline: none;
|
|
87
|
-
text-overflow: ellipsis;
|
|
88
|
-
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
89
|
-
white-space: nowrap;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
.sterling-list-item:not(.disabled):not(.selected):hover {
|
|
93
|
-
background-color: var(--stsv-button__background-color--hover);
|
|
94
|
-
color: var(--stsv-button__color--hover);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
.sterling-list-item.selected {
|
|
98
|
-
background-color: var(--stsv-button__background-color--active);
|
|
99
|
-
color: var(--stsv-button__color--active);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
.sterling-list-item.colorful:not(.disabled):not(.selected):hover {
|
|
103
|
-
background-color: var(--stsv-button--colorful__background-color--hover);
|
|
104
|
-
color: var(--stsv-button--colorful__color--hover);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
.sterling-list-item.colorful.selected {
|
|
108
|
-
background-color: var(--stsv-button--colorful__background-color--active);
|
|
109
|
-
color: var(--stsv-button--colorful__color--active);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
.sterling-list-item.disabled {
|
|
113
|
-
cursor: not-allowed;
|
|
114
|
-
outline: none;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
.sterling-list-item::after {
|
|
118
|
-
background: repeating-linear-gradient(
|
|
119
|
-
var(--stsv-common--disabled__stripe-angle),
|
|
120
|
-
var(--stsv-common--disabled__stripe-color),
|
|
121
|
-
var(--stsv-common--disabled__stripe-color) var(--stsv-common--disabled__stripe-width),
|
|
122
|
-
var(--stsv-common--disabled__stripe-color--alt) var(--stsv-common--disabled__stripe-width),
|
|
123
|
-
var(--stsv-common--disabled__stripe-color--alt)
|
|
124
|
-
calc(2 * var(--stsv-common--disabled__stripe-width))
|
|
125
|
-
);
|
|
126
|
-
bottom: 0;
|
|
127
|
-
content: '';
|
|
128
|
-
left: 0;
|
|
129
|
-
opacity: 0;
|
|
130
|
-
position: absolute;
|
|
131
|
-
right: 0;
|
|
132
|
-
top: 0;
|
|
133
|
-
pointer-events: none;
|
|
134
|
-
transition: opacity 250ms;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
.sterling-list-item.item-disabled::after {
|
|
138
|
-
opacity: 1;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
@media (prefers-reduced-motion) {
|
|
142
|
-
.sterling-list-item,
|
|
143
|
-
.sterling-list-item::after {
|
|
144
|
-
transition: none;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
</style>
|
package/ListItem.svelte.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ declare const __propDef: {
|
|
|
4
4
|
[x: string]: any;
|
|
5
5
|
disabled?: boolean | undefined;
|
|
6
6
|
value: string;
|
|
7
|
+
variant?: string | undefined;
|
|
7
8
|
click?: (() => void) | undefined;
|
|
8
9
|
blur?: (() => void) | undefined;
|
|
9
10
|
focus?: ((options?: FocusOptions) => void) | undefined;
|
|
@@ -49,6 +50,7 @@ declare const __propDef: {
|
|
|
49
50
|
horizontal: import("svelte/store").Readable<boolean> | undefined;
|
|
50
51
|
selected: boolean;
|
|
51
52
|
value: string;
|
|
53
|
+
variant: string;
|
|
52
54
|
};
|
|
53
55
|
};
|
|
54
56
|
};
|
package/Menu.svelte
CHANGED
|
@@ -1,71 +1,78 @@
|
|
|
1
|
-
<script>import { getContext } from
|
|
2
|
-
import { slide } from
|
|
3
|
-
import { MENU_ITEM_CONTEXT_KEY } from
|
|
4
|
-
import { isElementEnabledMenuItem, isElementMenuItem } from
|
|
5
|
-
import { prefersReducedMotion } from
|
|
1
|
+
<script>import { getContext } from 'svelte';
|
|
2
|
+
import { slide } from 'svelte/transition';
|
|
3
|
+
import { MENU_ITEM_CONTEXT_KEY } from './MenuItem.constants';
|
|
4
|
+
import { isElementEnabledMenuItem, isElementMenuItem } from './MenuItem.utils';
|
|
5
|
+
import { prefersReducedMotion } from './mediaQueries/prefersReducedMotion';
|
|
6
|
+
// ----- Props ----- //
|
|
7
|
+
/** Additional class names to apply. */
|
|
8
|
+
export let variant = '';
|
|
9
|
+
// ----- State ----- //
|
|
6
10
|
let menuRef;
|
|
7
11
|
let menuItemsRef;
|
|
12
|
+
// ----- Media Queries ----- //
|
|
8
13
|
const slidNoOp = (node, params) => {
|
|
9
|
-
|
|
14
|
+
return { delay: 0, duration: 0 };
|
|
10
15
|
};
|
|
11
|
-
$:
|
|
12
|
-
|
|
16
|
+
$: slideMotion = !$prefersReducedMotion ? slide : slidNoOp;
|
|
17
|
+
// ----- Get Context ----- //
|
|
13
18
|
const { rootValue } = getContext(MENU_ITEM_CONTEXT_KEY) || {};
|
|
19
|
+
// ----- Methods ----- //
|
|
14
20
|
export const blur = () => {
|
|
15
|
-
|
|
21
|
+
menuRef?.blur();
|
|
16
22
|
};
|
|
17
23
|
export const focus = (options) => {
|
|
18
|
-
|
|
24
|
+
menuRef?.focus(options);
|
|
19
25
|
};
|
|
20
26
|
const isElementInThisMenu = (candidate) => {
|
|
21
|
-
|
|
27
|
+
return candidate && candidate.closest('[role="menu"]') === menuRef;
|
|
22
28
|
};
|
|
23
29
|
export const focusFirstMenuItem = () => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
let candidate = menuItemsRef?.firstElementChild;
|
|
31
|
+
while (candidate && !isElementEnabledMenuItem(candidate)) {
|
|
32
|
+
candidate = candidate.nextElementSibling;
|
|
33
|
+
}
|
|
34
|
+
candidate?.focus({ preventScroll: true });
|
|
35
|
+
return !!candidate;
|
|
30
36
|
};
|
|
31
37
|
export const focusPreviousMenuItem = () => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
let candidate = document.activeElement;
|
|
39
|
+
if (candidate && isElementMenuItem(candidate) && isElementInThisMenu(candidate)) {
|
|
40
|
+
candidate = menuItemsRef?.previousElementSibling;
|
|
41
|
+
while (candidate && !isElementEnabledMenuItem(candidate)) {
|
|
42
|
+
candidate = candidate.previousElementSibling;
|
|
43
|
+
}
|
|
44
|
+
candidate?.focus();
|
|
37
45
|
}
|
|
38
|
-
candidate
|
|
39
|
-
}
|
|
40
|
-
return !!candidate;
|
|
46
|
+
return !!candidate;
|
|
41
47
|
};
|
|
42
48
|
export const focusNextMenuItem = () => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
let candidate = document.activeElement;
|
|
50
|
+
if (candidate && isElementMenuItem(candidate) && isElementInThisMenu(candidate)) {
|
|
51
|
+
candidate = menuItemsRef?.nextElementSibling;
|
|
52
|
+
while (candidate && !isElementEnabledMenuItem(candidate)) {
|
|
53
|
+
candidate = candidate.nextElementSibling;
|
|
54
|
+
}
|
|
55
|
+
candidate?.focus();
|
|
48
56
|
}
|
|
49
|
-
candidate
|
|
50
|
-
}
|
|
51
|
-
return !!candidate;
|
|
57
|
+
return !!candidate;
|
|
52
58
|
};
|
|
53
59
|
export const focusLastMenuItem = () => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
let candidate = menuItemsRef?.lastElementChild;
|
|
61
|
+
while (candidate && !isElementEnabledMenuItem(candidate)) {
|
|
62
|
+
candidate = candidate.previousElementSibling;
|
|
63
|
+
}
|
|
64
|
+
candidate?.focus({ preventScroll: true });
|
|
65
|
+
return !!candidate;
|
|
60
66
|
};
|
|
61
67
|
</script>
|
|
62
68
|
|
|
63
69
|
<div
|
|
64
70
|
bind:this={menuRef}
|
|
65
|
-
class=
|
|
71
|
+
class={`sterling-menu ${variant}`}
|
|
66
72
|
role="menu"
|
|
67
73
|
class:open
|
|
68
74
|
data-root-value={rootValue}
|
|
75
|
+
tabindex="-1"
|
|
69
76
|
in:slideMotion|global={{ duration: 300 }}
|
|
70
77
|
out:slideMotion|global={{ duration: 100 }}
|
|
71
78
|
on:blur
|
|
@@ -98,30 +105,6 @@ export const focusLastMenuItem = () => {
|
|
|
98
105
|
{...$$restProps}
|
|
99
106
|
>
|
|
100
107
|
<div bind:this={menuItemsRef} class="menu-items">
|
|
101
|
-
<slot />
|
|
108
|
+
<slot {variant} />
|
|
102
109
|
</div>
|
|
103
110
|
</div>
|
|
104
|
-
|
|
105
|
-
<style>
|
|
106
|
-
.sterling-menu {
|
|
107
|
-
background-color: var(--stsv-common__background-color);
|
|
108
|
-
border-color: var(--stsv-common__border-color);
|
|
109
|
-
border-radius: var(--stsv-common__border-radius);
|
|
110
|
-
border-style: var(--stsv-common__border-style);
|
|
111
|
-
border-width: var(--stsv-common__border-width);
|
|
112
|
-
box-shadow: rgba(0, 0, 0, 0.4) 2px 2px 4px -1px;
|
|
113
|
-
box-sizing: border-box;
|
|
114
|
-
display: grid;
|
|
115
|
-
grid-template-columns: 1fr;
|
|
116
|
-
grid-template-rows: 1fr;
|
|
117
|
-
height: fit-content;
|
|
118
|
-
padding: 0.25em;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
.menu-items {
|
|
122
|
-
display: grid;
|
|
123
|
-
grid-template-columns: 1fr;
|
|
124
|
-
grid-template-rows: auto;
|
|
125
|
-
row-gap: calc(2 * var(--stsv-common__outline-width));
|
|
126
|
-
}
|
|
127
|
-
</style>
|
package/Menu.svelte.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { SvelteComponentTyped } from "svelte";
|
|
|
2
2
|
declare const __propDef: {
|
|
3
3
|
props: {
|
|
4
4
|
[x: string]: any;
|
|
5
|
+
variant?: string | undefined;
|
|
5
6
|
blur?: (() => void) | undefined;
|
|
6
7
|
focus?: ((options?: FocusOptions) => void) | undefined;
|
|
7
8
|
focusFirstMenuItem?: (() => boolean) | undefined;
|
|
@@ -41,7 +42,9 @@ declare const __propDef: {
|
|
|
41
42
|
[evt: string]: CustomEvent<any>;
|
|
42
43
|
};
|
|
43
44
|
slots: {
|
|
44
|
-
default: {
|
|
45
|
+
default: {
|
|
46
|
+
variant: string;
|
|
47
|
+
};
|
|
45
48
|
};
|
|
46
49
|
};
|
|
47
50
|
export type MenuProps = typeof __propDef.props;
|
package/MenuBar.svelte
CHANGED
|
@@ -1,115 +1,125 @@
|
|
|
1
|
-
<script>import { createEventDispatcher, setContext } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
<script>import { createEventDispatcher, setContext } from 'svelte';
|
|
2
|
+
import { writable } from 'svelte/store';
|
|
3
|
+
import { clickOutside } from './actions/clickOutside';
|
|
4
|
+
import { idGenerator } from './idGenerator';
|
|
5
|
+
import { MENU_BAR_CONTEXT_KEY } from './MenuBar.constants';
|
|
6
|
+
import { MENU_ITEM_CONTEXT_KEY } from './MenuItem.constants';
|
|
7
|
+
import { isElementEnabledMenuItem } from './MenuItem.utils';
|
|
8
|
+
// ----- Props ----- //
|
|
9
|
+
/** Additional class names to apply. */
|
|
10
|
+
export let variant = '';
|
|
11
|
+
// ----- State ----- //
|
|
8
12
|
const openValues = writable([]);
|
|
9
|
-
const rootValue = idGenerator.nextId(
|
|
13
|
+
const rootValue = idGenerator.nextId('MenuBar');
|
|
10
14
|
let menuBarRef;
|
|
11
|
-
let prevOpenValue =
|
|
15
|
+
let prevOpenValue = undefined;
|
|
16
|
+
// Remember the last open value
|
|
12
17
|
$: {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
if ($openValues.length > 0) {
|
|
19
|
+
prevOpenValue = $openValues[0];
|
|
20
|
+
}
|
|
16
21
|
}
|
|
22
|
+
// Restore focus to the last open menu bar item when it closes
|
|
17
23
|
$: {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
if ($openValues.length === 0 && prevOpenValue !== undefined) {
|
|
25
|
+
const candidate = menuBarRef.querySelector(`[data-value="${prevOpenValue}"]`);
|
|
26
|
+
candidate?.focus();
|
|
27
|
+
prevOpenValue = undefined;
|
|
28
|
+
}
|
|
23
29
|
}
|
|
30
|
+
// ----- Events ----- //
|
|
24
31
|
const dispatch = createEventDispatcher();
|
|
25
32
|
const raiseClose = (value) => {
|
|
26
|
-
|
|
33
|
+
dispatch('close', { value });
|
|
27
34
|
};
|
|
28
35
|
const raiseOpen = (value) => {
|
|
29
|
-
|
|
36
|
+
dispatch('open', { value });
|
|
30
37
|
};
|
|
31
38
|
const raiseSelect = (value) => {
|
|
32
|
-
|
|
39
|
+
dispatch('select', { value });
|
|
33
40
|
};
|
|
41
|
+
// ----- Methods ----- //
|
|
34
42
|
export const blur = () => {
|
|
35
|
-
|
|
43
|
+
menuBarRef?.blur();
|
|
36
44
|
};
|
|
37
45
|
export const focus = (options) => {
|
|
38
|
-
|
|
46
|
+
menuBarRef?.focus(options);
|
|
39
47
|
};
|
|
48
|
+
// ----- Open/Close ----- //
|
|
40
49
|
const getOpenMenuBarItem = () => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
50
|
+
const value = $openValues[0];
|
|
51
|
+
if (value) {
|
|
52
|
+
return menuBarRef.querySelector(`[data-value="${value}"]`);
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
46
55
|
};
|
|
47
56
|
const openPreviousMenuBarItem = () => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
const openItem = getOpenMenuBarItem() || menuBarRef.firstElementChild;
|
|
58
|
+
let candidate = openItem?.previousElementSibling || menuBarRef.lastElementChild;
|
|
59
|
+
while (candidate && !isElementEnabledMenuItem(candidate)) {
|
|
60
|
+
candidate = candidate.previousElementSibling || menuBarRef.lastElementChild;
|
|
61
|
+
if (candidate === openItem) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
54
64
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return !!candidate;
|
|
65
|
+
if (!candidate) {
|
|
66
|
+
candidate = menuBarRef.lastElementChild;
|
|
67
|
+
candidate = candidate && isElementEnabledMenuItem(candidate) ? candidate : null;
|
|
68
|
+
}
|
|
69
|
+
candidate?.click();
|
|
70
|
+
return !!candidate;
|
|
62
71
|
};
|
|
63
72
|
const openNextMenuBarItem = () => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
const openItem = getOpenMenuBarItem() || menuBarRef.lastElementChild;
|
|
74
|
+
let candidate = openItem?.nextElementSibling || menuBarRef.firstElementChild;
|
|
75
|
+
while (candidate && !isElementEnabledMenuItem(candidate)) {
|
|
76
|
+
candidate = candidate.nextElementSibling || menuBarRef.firstElementChild;
|
|
77
|
+
if (candidate === openItem) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!candidate) {
|
|
82
|
+
candidate = menuBarRef.firstElementChild;
|
|
83
|
+
candidate = candidate && isElementEnabledMenuItem(candidate) ? candidate : null;
|
|
70
84
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
candidate = menuBarRef.firstElementChild;
|
|
74
|
-
candidate = candidate && isElementEnabledMenuItem(candidate) ? candidate : null;
|
|
75
|
-
}
|
|
76
|
-
candidate?.click();
|
|
77
|
-
return !!candidate;
|
|
85
|
+
candidate?.click();
|
|
86
|
+
return !!candidate;
|
|
78
87
|
};
|
|
79
88
|
const closeAllMenus = () => {
|
|
80
|
-
|
|
89
|
+
openValues.set([]);
|
|
81
90
|
};
|
|
91
|
+
// ----- Event Handlers ----- //
|
|
82
92
|
const onClickOutside = (event) => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
93
|
+
const { detail: { mouseEvent } } = event;
|
|
94
|
+
let element = mouseEvent.target;
|
|
95
|
+
while (element) {
|
|
96
|
+
if (element.getAttribute('data-root-value') === rootValue) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
element = element.parentElement;
|
|
90
100
|
}
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
closeAllMenus?.();
|
|
101
|
+
closeAllMenus?.();
|
|
94
102
|
};
|
|
103
|
+
// ----- Set Context ----- //
|
|
95
104
|
setContext(MENU_BAR_CONTEXT_KEY, {
|
|
96
|
-
|
|
97
|
-
|
|
105
|
+
openPreviousMenuBarItem,
|
|
106
|
+
openNextMenuBarItem
|
|
98
107
|
});
|
|
99
108
|
setContext(MENU_ITEM_CONTEXT_KEY, {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
109
|
+
isMenuBarItem: true,
|
|
110
|
+
openValues,
|
|
111
|
+
rootValue,
|
|
112
|
+
onClose: raiseClose,
|
|
113
|
+
onOpen: raiseOpen,
|
|
114
|
+
onSelect: raiseSelect
|
|
106
115
|
});
|
|
107
116
|
</script>
|
|
108
117
|
|
|
109
118
|
<div
|
|
110
119
|
bind:this={menuBarRef}
|
|
111
|
-
class=
|
|
120
|
+
class={`sterling-menu-bar ${variant}`}
|
|
112
121
|
role="menubar"
|
|
122
|
+
tabindex="-1"
|
|
113
123
|
on:blur
|
|
114
124
|
on:click
|
|
115
125
|
on:copy
|
|
@@ -141,17 +151,5 @@ setContext(MENU_ITEM_CONTEXT_KEY, {
|
|
|
141
151
|
use:clickOutside
|
|
142
152
|
on:click_outside={onClickOutside}
|
|
143
153
|
>
|
|
144
|
-
<slot />
|
|
154
|
+
<slot {variant} />
|
|
145
155
|
</div>
|
|
146
|
-
|
|
147
|
-
<style>
|
|
148
|
-
.sterling-menu-bar {
|
|
149
|
-
background-color: transparent;
|
|
150
|
-
align-items: center;
|
|
151
|
-
align-content: stretch;
|
|
152
|
-
display: flex;
|
|
153
|
-
gap: 1em;
|
|
154
|
-
justify-content: flex-start;
|
|
155
|
-
justify-items: flex-start;
|
|
156
|
-
}
|
|
157
|
-
</style>
|
package/MenuBar.svelte.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { SvelteComponentTyped } from "svelte";
|
|
|
2
2
|
declare const __propDef: {
|
|
3
3
|
props: {
|
|
4
4
|
[x: string]: any;
|
|
5
|
+
variant?: string | undefined;
|
|
5
6
|
blur?: (() => void) | undefined;
|
|
6
7
|
focus?: ((options?: FocusOptions) => void) | undefined;
|
|
7
8
|
};
|
|
@@ -40,7 +41,9 @@ declare const __propDef: {
|
|
|
40
41
|
[evt: string]: CustomEvent<any>;
|
|
41
42
|
};
|
|
42
43
|
slots: {
|
|
43
|
-
default: {
|
|
44
|
+
default: {
|
|
45
|
+
variant: string;
|
|
46
|
+
};
|
|
44
47
|
};
|
|
45
48
|
};
|
|
46
49
|
export type MenuBarProps = typeof __propDef.props;
|