@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/MenuButton.svelte
CHANGED
|
@@ -1,87 +1,95 @@
|
|
|
1
|
-
<script>import { createEventDispatcher, setContext, tick } from
|
|
2
|
-
import { writable } from
|
|
3
|
-
import Button from
|
|
4
|
-
import Menu from
|
|
5
|
-
import { MENU_ITEM_CONTEXT_KEY } from
|
|
6
|
-
import { idGenerator } from
|
|
7
|
-
import Popover from
|
|
8
|
-
import { clickOutside } from
|
|
1
|
+
<script>import { createEventDispatcher, setContext, tick } from 'svelte';
|
|
2
|
+
import { writable } from 'svelte/store';
|
|
3
|
+
import Button from './Button.svelte';
|
|
4
|
+
import Menu from './Menu.svelte';
|
|
5
|
+
import { MENU_ITEM_CONTEXT_KEY } from './MenuItem.constants';
|
|
6
|
+
import { idGenerator } from './idGenerator';
|
|
7
|
+
import Popover from './Popover.svelte';
|
|
8
|
+
import { clickOutside } from './actions/clickOutside';
|
|
9
|
+
// ----- Props ----- //
|
|
10
|
+
/** When true, the menu is open. */
|
|
9
11
|
export let open = false;
|
|
12
|
+
/** The value uniquely identifying this menu button as the root of the menu hierarchy. */
|
|
10
13
|
export let value;
|
|
11
|
-
|
|
14
|
+
/** Additional class names to apply. */
|
|
15
|
+
export let variant = '';
|
|
16
|
+
// ----- State ----- //
|
|
17
|
+
const instanceId = idGenerator.nextId('MenuButton');
|
|
12
18
|
let buttonRef;
|
|
13
19
|
let reference;
|
|
14
20
|
let menuRef;
|
|
15
21
|
let prevOpen = open;
|
|
16
|
-
$:
|
|
17
|
-
|
|
18
|
-
$:
|
|
19
|
-
hasChildren = $$slots.items;
|
|
22
|
+
$: menuId = `${value}-menu-${instanceId}`;
|
|
23
|
+
$: hasChildren = $$slots.items;
|
|
20
24
|
const openValues = writable([]);
|
|
21
25
|
$: {
|
|
22
|
-
|
|
26
|
+
open = $openValues.length > 0;
|
|
23
27
|
}
|
|
28
|
+
// ----- Events ----- //
|
|
24
29
|
const dispatch = createEventDispatcher();
|
|
25
|
-
const raiseClose = (
|
|
26
|
-
|
|
30
|
+
const raiseClose = (value) => {
|
|
31
|
+
dispatch('close', { value });
|
|
27
32
|
};
|
|
28
|
-
const raiseOpen = (
|
|
29
|
-
|
|
33
|
+
const raiseOpen = (value) => {
|
|
34
|
+
dispatch('open', { value });
|
|
30
35
|
};
|
|
31
|
-
const raiseSelect = (
|
|
32
|
-
|
|
36
|
+
const raiseSelect = (value) => {
|
|
37
|
+
dispatch('select', { value });
|
|
33
38
|
};
|
|
39
|
+
// ----- Methods ----- //
|
|
34
40
|
export const click = () => {
|
|
35
|
-
|
|
41
|
+
buttonRef?.click();
|
|
36
42
|
};
|
|
37
43
|
export const blur = () => {
|
|
38
|
-
|
|
44
|
+
buttonRef?.blur();
|
|
39
45
|
};
|
|
40
46
|
export const focus = (options) => {
|
|
41
|
-
|
|
47
|
+
buttonRef?.focus(options);
|
|
42
48
|
};
|
|
49
|
+
// ----- Event Handlers ----- //
|
|
43
50
|
const onClick = async () => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
if (!open) {
|
|
52
|
+
openValues.set(['menu-button']);
|
|
53
|
+
await tick();
|
|
54
|
+
menuRef?.focusFirstMenuItem();
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
open = false;
|
|
58
|
+
openValues.set([]);
|
|
59
|
+
}
|
|
52
60
|
};
|
|
53
61
|
$: {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
if (!open && open !== prevOpen) {
|
|
63
|
+
focus();
|
|
64
|
+
}
|
|
65
|
+
prevOpen = open;
|
|
58
66
|
}
|
|
67
|
+
// ----- Event Handlers ----- //
|
|
59
68
|
const closeAllMenus = () => {
|
|
60
|
-
|
|
69
|
+
openValues.set([]);
|
|
61
70
|
};
|
|
62
71
|
const onClickOutside = (event) => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
const { detail: { mouseEvent } } = event;
|
|
73
|
+
let element = mouseEvent.target;
|
|
74
|
+
while (element) {
|
|
75
|
+
if (element.getAttribute('data-root-value') === value) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
element = element.parentElement;
|
|
70
79
|
}
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
closeAllMenus?.();
|
|
80
|
+
closeAllMenus?.();
|
|
74
81
|
};
|
|
82
|
+
// ----- Set Context ----- //
|
|
75
83
|
setContext(MENU_ITEM_CONTEXT_KEY, {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
depth: 1,
|
|
85
|
+
openValues,
|
|
86
|
+
rootValue: value,
|
|
87
|
+
closeContainingMenu: () => {
|
|
88
|
+
open = false;
|
|
89
|
+
},
|
|
90
|
+
onOpen: raiseOpen,
|
|
91
|
+
onClose: raiseClose,
|
|
92
|
+
onSelect: raiseSelect
|
|
85
93
|
});
|
|
86
94
|
</script>
|
|
87
95
|
|
|
@@ -97,6 +105,7 @@ setContext(MENU_ITEM_CONTEXT_KEY, {
|
|
|
97
105
|
aria-owns={menuId}
|
|
98
106
|
data-value={value}
|
|
99
107
|
data-root-value={value}
|
|
108
|
+
variant={`sterling-menu-button ${variant}`}
|
|
100
109
|
on:blur
|
|
101
110
|
on:click
|
|
102
111
|
on:click={onClick}
|
|
@@ -132,27 +141,11 @@ setContext(MENU_ITEM_CONTEXT_KEY, {
|
|
|
132
141
|
{...$$restProps}
|
|
133
142
|
>
|
|
134
143
|
<div class="reference" bind:this={reference} use:clickOutside on:click_outside={onClickOutside}>
|
|
135
|
-
<slot
|
|
144
|
+
<slot {open} {value} {variant} />
|
|
136
145
|
</div>
|
|
137
146
|
<Popover {reference} {open}>
|
|
138
147
|
<Menu bind:this={menuRef} id={menuId} {reference} {open}>
|
|
139
|
-
<slot name="items" />
|
|
148
|
+
<slot name="items" {variant} />
|
|
140
149
|
</Menu>
|
|
141
150
|
</Popover>
|
|
142
151
|
</Button>
|
|
143
|
-
|
|
144
|
-
<style>
|
|
145
|
-
.reference {
|
|
146
|
-
align-content: center;
|
|
147
|
-
align-items: center;
|
|
148
|
-
box-sizing: border-box;
|
|
149
|
-
display: inline-flex;
|
|
150
|
-
flex-direction: row;
|
|
151
|
-
justify-content: center;
|
|
152
|
-
justify-items: center;
|
|
153
|
-
column-gap: 0.25em;
|
|
154
|
-
overflow: hidden;
|
|
155
|
-
text-overflow: ellipsis;
|
|
156
|
-
white-space: nowrap;
|
|
157
|
-
}
|
|
158
|
-
</style>
|
package/MenuButton.svelte.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ declare const __propDef: {
|
|
|
4
4
|
[x: string]: any;
|
|
5
5
|
open?: 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;
|
|
@@ -48,10 +49,13 @@ declare const __propDef: {
|
|
|
48
49
|
};
|
|
49
50
|
slots: {
|
|
50
51
|
default: {
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
open: boolean;
|
|
53
|
+
value: string;
|
|
54
|
+
variant: string;
|
|
55
|
+
};
|
|
56
|
+
items: {
|
|
57
|
+
variant: string;
|
|
53
58
|
};
|
|
54
|
-
items: {};
|
|
55
59
|
};
|
|
56
60
|
};
|
|
57
61
|
export type MenuButtonProps = typeof __propDef.props;
|