@geoffcox/sterling-svelte 0.0.25 → 0.0.26
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/Dropdown.svelte +9 -0
- package/Field.svelte +3 -15
- package/List.svelte +3 -14
- package/Menu.svelte +86 -115
- package/Menu.svelte.d.ts +8 -2
- package/MenuBar.svelte +76 -31
- package/MenuBar.types.d.ts +2 -2
- package/MenuButton.svelte +50 -28
- package/MenuItem.constants.d.ts +1 -0
- package/MenuItem.constants.js +1 -0
- package/MenuItem.svelte +169 -128
- package/MenuItem.svelte.d.ts +6 -3
- package/MenuItem.types.d.ts +14 -5
- package/MenuItem.utils.d.ts +2 -0
- package/MenuItem.utils.js +16 -0
- package/MenuItemDisplay.svelte +2 -1
- package/MenuItemDisplay.svelte.d.ts +1 -0
- package/Popover.svelte +3 -14
- package/Select.svelte +25 -13
- package/Tab.svelte +1 -1
- package/TabList.svelte +2 -18
- package/TabList.types.d.ts +0 -1
- package/Tree.svelte +3 -14
- package/TreeItem.svelte +7 -1
- package/index.d.ts +2 -2
- package/index.js +1 -1
- package/package.json +3 -1
- package/stores/prefersReducedMotion.d.ts +1 -0
- package/stores/prefersReducedMotion.js +10 -0
- package/stores/usingKeyboard.d.ts +1 -0
- package/stores/usingKeyboard.js +13 -0
package/TabList.svelte
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
<script>import {
|
|
2
|
-
import { createEventDispatcher, onMount, setContext } from "svelte";
|
|
1
|
+
<script>import { createEventDispatcher, setContext } from "svelte";
|
|
3
2
|
import { writable } from "svelte/store";
|
|
4
3
|
import { TAB_LIST_CONTEXT_KEY } from "./TabList.constants";
|
|
4
|
+
import { usingKeyboard } from "./stores/usingKeyboard";
|
|
5
5
|
export let disabled = false;
|
|
6
6
|
export let vertical = false;
|
|
7
7
|
export let selectedValue = void 0;
|
|
8
|
-
let keyborg = createKeyborg(window);
|
|
9
|
-
let usingKeyboard = keyborg.isNavigatingWithKeyboard();
|
|
10
|
-
const keyborgHandler = (value) => {
|
|
11
|
-
usingKeyboard = value;
|
|
12
|
-
};
|
|
13
8
|
let tabListRef;
|
|
14
9
|
let lastSelectedTabRef;
|
|
15
10
|
const disabledStore = writable(disabled);
|
|
16
11
|
const selectedValueStore = writable(selectedValue);
|
|
17
|
-
const usingKeyboardStore = writable(usingKeyboard);
|
|
18
12
|
const verticalStore = writable(vertical);
|
|
19
13
|
$:
|
|
20
14
|
disabledStore.set(disabled);
|
|
@@ -23,8 +17,6 @@ $:
|
|
|
23
17
|
$: {
|
|
24
18
|
selectedValue = $selectedValueStore;
|
|
25
19
|
}
|
|
26
|
-
$:
|
|
27
|
-
usingKeyboardStore.set(usingKeyboard);
|
|
28
20
|
$:
|
|
29
21
|
verticalStore.set(vertical);
|
|
30
22
|
const dispatch = createEventDispatcher();
|
|
@@ -106,12 +98,6 @@ export const selectLastTab = () => {
|
|
|
106
98
|
}
|
|
107
99
|
return false;
|
|
108
100
|
};
|
|
109
|
-
onMount(() => {
|
|
110
|
-
keyborg.subscribe(keyborgHandler);
|
|
111
|
-
return () => {
|
|
112
|
-
keyborg.unsubscribe(keyborgHandler);
|
|
113
|
-
};
|
|
114
|
-
});
|
|
115
101
|
const onClick = (event) => {
|
|
116
102
|
if (!disabled) {
|
|
117
103
|
let candidate = event.target;
|
|
@@ -126,7 +112,6 @@ const onClick = (event) => {
|
|
|
126
112
|
}
|
|
127
113
|
};
|
|
128
114
|
const onKeydown = (event) => {
|
|
129
|
-
console.log("tabList onKeydown", event);
|
|
130
115
|
if (!disabled && !event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) {
|
|
131
116
|
switch (event.key) {
|
|
132
117
|
case "Home":
|
|
@@ -175,7 +160,6 @@ const onKeydown = (event) => {
|
|
|
175
160
|
setContext(TAB_LIST_CONTEXT_KEY, {
|
|
176
161
|
disabled: disabledStore,
|
|
177
162
|
selectedValue: selectedValueStore,
|
|
178
|
-
usingKeyboard: usingKeyboardStore,
|
|
179
163
|
vertical: verticalStore
|
|
180
164
|
});
|
|
181
165
|
</script>
|
package/TabList.types.d.ts
CHANGED
package/Tree.svelte
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
<script>import {
|
|
2
|
-
import { createEventDispatcher, onMount, setContext } from "svelte";
|
|
1
|
+
<script>import { createEventDispatcher, setContext } from "svelte";
|
|
3
2
|
import { writable } from "svelte/store";
|
|
4
3
|
import { TREE_CONTEXT_KEY } from "./Tree.constants";
|
|
4
|
+
import { usingKeyboard } from "./stores/usingKeyboard";
|
|
5
5
|
export let composed = false;
|
|
6
6
|
export let disabled = false;
|
|
7
7
|
export let selectedValue = void 0;
|
|
@@ -23,11 +23,6 @@ const raiseExpandCollapse = (expandedValues2) => {
|
|
|
23
23
|
const raiseSelect = (selectedValue2) => {
|
|
24
24
|
dispatch("select", { selectedValue: selectedValue2 });
|
|
25
25
|
};
|
|
26
|
-
let keyborg = createKeyborg(window);
|
|
27
|
-
let usingKeyboard = keyborg.isNavigatingWithKeyboard();
|
|
28
|
-
const keyborgHandler = (value) => {
|
|
29
|
-
usingKeyboard = value;
|
|
30
|
-
};
|
|
31
26
|
$: {
|
|
32
27
|
selectedValueStore.set(selectedValue);
|
|
33
28
|
}
|
|
@@ -45,12 +40,6 @@ $: {
|
|
|
45
40
|
$: {
|
|
46
41
|
disabledStore.set(disabled);
|
|
47
42
|
}
|
|
48
|
-
onMount(() => {
|
|
49
|
-
keyborg.subscribe(keyborgHandler);
|
|
50
|
-
return () => {
|
|
51
|
-
keyborg.unsubscribe(keyborgHandler);
|
|
52
|
-
};
|
|
53
|
-
});
|
|
54
43
|
setContext(TREE_CONTEXT_KEY, {
|
|
55
44
|
expandedValues: expandedValuesStore,
|
|
56
45
|
selectedValue: selectedValueStore,
|
|
@@ -65,7 +54,7 @@ setContext(TREE_CONTEXT_KEY, {
|
|
|
65
54
|
class="sterling-tree"
|
|
66
55
|
class:composed
|
|
67
56
|
class:disabled
|
|
68
|
-
class:using-keyboard={usingKeyboard}
|
|
57
|
+
class:using-keyboard={$usingKeyboard}
|
|
69
58
|
role="tree"
|
|
70
59
|
on:blur
|
|
71
60
|
on:click
|
package/TreeItem.svelte
CHANGED
|
@@ -3,8 +3,14 @@ import { slide } from "svelte/transition";
|
|
|
3
3
|
import { TREE_CONTEXT_KEY, TREE_ITEM_CONTEXT_KEY } from "./Tree.constants";
|
|
4
4
|
import TreeItemDisplay from "./TreeItemDisplay.svelte";
|
|
5
5
|
import { writable } from "svelte/store";
|
|
6
|
+
import { prefersReducedMotion } from "./stores/prefersReducedMotion";
|
|
6
7
|
export let disabled = false;
|
|
7
8
|
export let value;
|
|
9
|
+
const slidNoOp = (node, params) => {
|
|
10
|
+
return { delay: 0, duration: 0 };
|
|
11
|
+
};
|
|
12
|
+
$:
|
|
13
|
+
slideMotion = !$prefersReducedMotion ? slide : slidNoOp;
|
|
8
14
|
const {
|
|
9
15
|
expandedValues,
|
|
10
16
|
selectedValue,
|
|
@@ -293,7 +299,7 @@ A item in a Tree displaying the item and children.
|
|
|
293
299
|
</slot>
|
|
294
300
|
</div>
|
|
295
301
|
{#if expanded && hasChildren}
|
|
296
|
-
<div class="children" transition:
|
|
302
|
+
<div class="children" transition:slideMotion={{ duration: 200 }} role="group">
|
|
297
303
|
<slot {depth} {selected} {value} />
|
|
298
304
|
</div>
|
|
299
305
|
{/if}
|
package/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type { FloatingPlacement } from './floating-ui.types';
|
|
|
16
16
|
export type { LinkVariant } from './Link.types';
|
|
17
17
|
export type { ListContext } from './List.types';
|
|
18
18
|
export type { MenuBarContext } from './MenuBar.types';
|
|
19
|
-
export type { MenuItemContext, MenuItemRegistration } from './MenuItem.types';
|
|
19
|
+
export type { MenuItemContext, MenuItemRegistration, MenuItemRole } from './MenuItem.types';
|
|
20
20
|
export type { ProgressColorful } from './Progress.types';
|
|
21
21
|
export type { TabListContext } from './TabList.types';
|
|
22
22
|
export type { TextAreaResize } from './TextArea.types';
|
|
@@ -29,7 +29,7 @@ export { FLOATING_PLACEMENTS } from './floating-ui.constants';
|
|
|
29
29
|
export { LINK_VARIANTS } from './Link.constants';
|
|
30
30
|
export { LIST_CONTEXT_KEY } from './List.constants';
|
|
31
31
|
export { MENU_BAR_CONTEXT_KEY } from './MenuBar.constants';
|
|
32
|
-
export { MENU_ITEM_CONTEXT_KEY } from './MenuItem.constants';
|
|
32
|
+
export { MENU_ITEM_CONTEXT_KEY, MENU_ITEM_ROLES } from './MenuItem.constants';
|
|
33
33
|
export { PROGRESS_COLORFULS } from './Progress.constants';
|
|
34
34
|
export { TAB_LIST_CONTEXT_KEY } from './TabList.constants';
|
|
35
35
|
export { TEXT_AREA_RESIZES } from './TextArea.constants';
|
package/index.js
CHANGED
|
@@ -20,7 +20,7 @@ export { FLOATING_PLACEMENTS } from './floating-ui.constants';
|
|
|
20
20
|
export { LINK_VARIANTS } from './Link.constants';
|
|
21
21
|
export { LIST_CONTEXT_KEY } from './List.constants';
|
|
22
22
|
export { MENU_BAR_CONTEXT_KEY } from './MenuBar.constants';
|
|
23
|
-
export { MENU_ITEM_CONTEXT_KEY } from './MenuItem.constants';
|
|
23
|
+
export { MENU_ITEM_CONTEXT_KEY, MENU_ITEM_ROLES } from './MenuItem.constants';
|
|
24
24
|
export { PROGRESS_COLORFULS } from './Progress.constants';
|
|
25
25
|
export { TAB_LIST_CONTEXT_KEY } from './TabList.constants';
|
|
26
26
|
export { TEXT_AREA_RESIZES } from './TextArea.constants';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geoffcox/sterling-svelte",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.26",
|
|
4
4
|
"author": "Geoff Cox",
|
|
5
5
|
"description": "A modern, accessible, and lightweight component library for Svelte.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -110,6 +110,8 @@
|
|
|
110
110
|
"./floating-ui.types": "./floating-ui.types.js",
|
|
111
111
|
"./idGenerator": "./idGenerator.js",
|
|
112
112
|
".": "./index.js",
|
|
113
|
+
"./stores/prefersReducedMotion": "./stores/prefersReducedMotion.js",
|
|
114
|
+
"./stores/usingKeyboard": "./stores/usingKeyboard.js",
|
|
113
115
|
"./theme/applyDarkTheme": "./theme/applyDarkTheme.js",
|
|
114
116
|
"./theme/applyLightTheme": "./theme/applyLightTheme.js",
|
|
115
117
|
"./theme/applyTheme": "./theme/applyTheme.js",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const prefersReducedMotion: import("svelte/store").Writable<boolean>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { writable } from 'svelte/store';
|
|
2
|
+
export const prefersReducedMotion = writable(false, (set) => {
|
|
3
|
+
const matchMedia = window.matchMedia('(prefers-reduced-motion: reduce)');
|
|
4
|
+
set(matchMedia.matches);
|
|
5
|
+
const mediaChangeHandler = (e) => set(e.matches);
|
|
6
|
+
matchMedia.addEventListener('change', mediaChangeHandler);
|
|
7
|
+
return () => {
|
|
8
|
+
matchMedia.removeEventListener('change', mediaChangeHandler);
|
|
9
|
+
};
|
|
10
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const usingKeyboard: import("svelte/store").Writable<boolean>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createKeyborg } from 'keyborg';
|
|
2
|
+
import { writable } from 'svelte/store';
|
|
3
|
+
export const usingKeyboard = writable(false, (set) => {
|
|
4
|
+
let keyborg = createKeyborg(window);
|
|
5
|
+
set(keyborg.isNavigatingWithKeyboard());
|
|
6
|
+
const keyborgHandler = (value) => {
|
|
7
|
+
set(value);
|
|
8
|
+
};
|
|
9
|
+
keyborg.subscribe(keyborgHandler);
|
|
10
|
+
return () => {
|
|
11
|
+
keyborg.unsubscribe(keyborgHandler);
|
|
12
|
+
};
|
|
13
|
+
});
|