@geoffcox/sterling-svelte 2.0.2 → 2.0.3
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/README.md +18 -0
- package/dist/@types/clickOutside.d.ts +15 -0
- package/dist/Button.svelte +29 -0
- package/dist/Button.svelte.d.ts +8 -0
- package/dist/Callout.svelte +243 -0
- package/dist/Callout.svelte.d.ts +14 -0
- package/dist/Callout.types.d.ts +11 -0
- package/dist/Callout.types.js +1 -0
- package/dist/Checkbox.svelte +62 -0
- package/dist/Checkbox.svelte.d.ts +9 -0
- package/dist/Dialog.svelte +201 -0
- package/dist/Dialog.svelte.d.ts +14 -0
- package/dist/Dropdown.svelte +159 -0
- package/dist/Dropdown.svelte.d.ts +23 -0
- package/dist/Input.svelte +80 -0
- package/dist/Input.svelte.d.ts +11 -0
- package/dist/Label.constants.d.ts +2 -0
- package/dist/Label.constants.js +2 -0
- package/dist/Label.svelte +135 -0
- package/dist/Label.svelte.d.ts +17 -0
- package/dist/Link.svelte +31 -0
- package/dist/Link.svelte.d.ts +11 -0
- package/dist/List.constants.d.ts +1 -0
- package/dist/List.constants.js +1 -0
- package/dist/List.svelte +258 -0
- package/dist/List.svelte.d.ts +19 -0
- package/dist/List.types.d.ts +5 -0
- package/dist/List.types.js +1 -0
- package/dist/ListItem.svelte +64 -0
- package/dist/ListItem.svelte.d.ts +12 -0
- package/dist/Menu.svelte +105 -0
- package/dist/Menu.svelte.d.ts +12 -0
- package/dist/MenuBar.constants.d.ts +1 -0
- package/dist/MenuBar.constants.js +1 -0
- package/dist/MenuBar.svelte +144 -0
- package/dist/MenuBar.svelte.d.ts +12 -0
- package/dist/MenuBar.types.d.ts +4 -0
- package/dist/MenuBar.types.js +1 -0
- package/dist/MenuButton.svelte +156 -0
- package/dist/MenuButton.svelte.d.ts +20 -0
- package/dist/MenuItem.constants.d.ts +2 -0
- package/dist/MenuItem.constants.js +2 -0
- package/dist/MenuItem.svelte +431 -0
- package/dist/MenuItem.svelte.d.ts +22 -0
- package/dist/MenuItem.types.d.ts +20 -0
- package/dist/MenuItem.types.js +1 -0
- package/dist/MenuItem.utils.d.ts +7 -0
- package/dist/MenuItem.utils.js +36 -0
- package/dist/MenuSeparator.svelte +11 -0
- package/dist/MenuSeparator.svelte.d.ts +5 -0
- package/dist/Pagination.svelte +267 -0
- package/dist/Pagination.svelte.d.ts +4 -0
- package/dist/Pagination.types.d.ts +24 -0
- package/dist/Pagination.types.js +1 -0
- package/dist/Popover.constants.d.ts +1 -0
- package/dist/Popover.constants.js +14 -0
- package/dist/Popover.svelte +175 -0
- package/dist/Popover.svelte.d.ts +14 -0
- package/dist/Popover.types.d.ts +4 -0
- package/dist/Popover.types.js +1 -0
- package/dist/Portal.constants.d.ts +2 -0
- package/dist/Portal.constants.js +2 -0
- package/dist/Portal.types.d.ts +3 -0
- package/dist/Portal.types.js +1 -0
- package/dist/Progress.constants.d.ts +1 -0
- package/dist/Progress.constants.js +1 -0
- package/dist/Progress.svelte +61 -0
- package/dist/Progress.svelte.d.ts +11 -0
- package/dist/Progress.types.d.ts +4 -0
- package/dist/Progress.types.js +1 -0
- package/dist/Radio.svelte +65 -0
- package/dist/Radio.svelte.d.ts +12 -0
- package/dist/Select.svelte +262 -0
- package/dist/Select.svelte.d.ts +26 -0
- package/dist/Slider.svelte +182 -0
- package/dist/Slider.svelte.d.ts +18 -0
- package/dist/Switch.svelte +92 -0
- package/dist/Switch.svelte.d.ts +21 -0
- package/dist/Tab.svelte +66 -0
- package/dist/Tab.svelte.d.ts +11 -0
- package/dist/TabList.constants.d.ts +1 -0
- package/dist/TabList.constants.js +1 -0
- package/dist/TabList.svelte +253 -0
- package/dist/TabList.svelte.d.ts +17 -0
- package/dist/TabList.types.d.ts +5 -0
- package/dist/TabList.types.js +1 -0
- package/dist/TextArea.constants.d.ts +1 -0
- package/dist/TextArea.constants.js +1 -0
- package/dist/TextArea.svelte +116 -0
- package/dist/TextArea.svelte.d.ts +18 -0
- package/dist/TextArea.types.d.ts +4 -0
- package/dist/TextArea.types.js +1 -0
- package/dist/Tooltip.svelte +95 -0
- package/dist/Tooltip.svelte.d.ts +10 -0
- package/dist/Tree.constants.d.ts +1 -0
- package/dist/Tree.constants.js +1 -0
- package/dist/Tree.svelte +81 -0
- package/dist/Tree.svelte.d.ts +14 -0
- package/dist/Tree.types.d.ts +5 -0
- package/dist/Tree.types.js +1 -0
- package/dist/TreeChevron.svelte +39 -0
- package/dist/TreeChevron.svelte.d.ts +8 -0
- package/dist/TreeItem.constants.d.ts +1 -0
- package/dist/TreeItem.constants.js +1 -0
- package/dist/TreeItem.svelte +396 -0
- package/dist/TreeItem.svelte.d.ts +22 -0
- package/dist/TreeItem.types.d.ts +4 -0
- package/dist/TreeItem.types.js +1 -0
- package/dist/actions/applyLightDarkMode.d.ts +10 -0
- package/dist/actions/applyLightDarkMode.js +36 -0
- package/dist/actions/clickOutside.d.ts +15 -0
- package/dist/actions/clickOutside.js +28 -0
- package/dist/actions/extraClass.d.ts +9 -0
- package/dist/actions/extraClass.js +15 -0
- package/dist/actions/forwardEvents.d.ts +12 -0
- package/dist/actions/forwardEvents.js +32 -0
- package/dist/actions/portal.d.ts +8 -0
- package/dist/actions/portal.js +19 -0
- package/dist/actions/trapKeyboardFocus.d.ts +3 -0
- package/dist/actions/trapKeyboardFocus.js +52 -0
- package/dist/idGenerator.d.ts +5 -0
- package/dist/idGenerator.js +11 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.js +55 -0
- package/dist/mediaQueries/prefersColorSchemeDark.d.ts +1 -0
- package/dist/mediaQueries/prefersColorSchemeDark.js +14 -0
- package/dist/mediaQueries/prefersReducedMotion.d.ts +1 -0
- package/dist/mediaQueries/prefersReducedMotion.js +14 -0
- package/dist/mediaQueries/usingKeyboard.d.ts +1 -0
- package/dist/mediaQueries/usingKeyboard.js +17 -0
- package/package.json +8 -7
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** @deprecated Use clsx class merging through class={['name1', 'name2']} */
|
|
2
|
+
export const extraClass = (node, params) => {
|
|
3
|
+
let _class = params?.extraClass;
|
|
4
|
+
!!_class && node.classList.add(_class);
|
|
5
|
+
return {
|
|
6
|
+
update(params) {
|
|
7
|
+
!!_class && node.classList.remove(_class);
|
|
8
|
+
_class = params.extraClass;
|
|
9
|
+
!!_class && node.classList.add(_class);
|
|
10
|
+
},
|
|
11
|
+
destroy() {
|
|
12
|
+
!!_class && node.classList.remove(_class);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const forwardEvents: (node: HTMLElement, params: {
|
|
2
|
+
target: HTMLElement;
|
|
3
|
+
events?: string[];
|
|
4
|
+
customEvents?: string[];
|
|
5
|
+
}) => {
|
|
6
|
+
update: (params: {
|
|
7
|
+
target: HTMLElement;
|
|
8
|
+
events?: string[];
|
|
9
|
+
customEvents?: [];
|
|
10
|
+
}) => void;
|
|
11
|
+
destroy(): void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export const forwardEvents = (node, params) => {
|
|
2
|
+
const addListeners = (node, target, events, customEvents) => {
|
|
3
|
+
let forward = (event) => {
|
|
4
|
+
target.dispatchEvent(event);
|
|
5
|
+
};
|
|
6
|
+
let forwardCustom = (event) => {
|
|
7
|
+
const customEvent = event;
|
|
8
|
+
target.dispatchEvent(new CustomEvent(customEvent.type, {
|
|
9
|
+
bubbles: customEvent.bubbles,
|
|
10
|
+
cancelable: customEvent.cancelable,
|
|
11
|
+
detail: customEvent.detail
|
|
12
|
+
}));
|
|
13
|
+
};
|
|
14
|
+
events?.forEach((e) => node.addEventListener(e, forward));
|
|
15
|
+
customEvents?.forEach((e) => node.addEventListener(e, forwardCustom));
|
|
16
|
+
return () => {
|
|
17
|
+
events?.forEach((e) => node.removeEventListener(e, forward));
|
|
18
|
+
customEvents?.forEach((e) => node.removeEventListener(e, forwardCustom));
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
let unsubscribe = addListeners(node, params.target, params.events, params.customEvents);
|
|
22
|
+
const update = (params) => {
|
|
23
|
+
unsubscribe();
|
|
24
|
+
unsubscribe = addListeners(node, params.target, params.events, params.customEvents);
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
update,
|
|
28
|
+
destroy() {
|
|
29
|
+
unsubscribe();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const portal = (node, params) => {
|
|
2
|
+
const child = node;
|
|
3
|
+
let portaled = false;
|
|
4
|
+
const createPortal = (node, params) => {
|
|
5
|
+
if (!portaled && params.target && node) {
|
|
6
|
+
params.target.appendChild(node);
|
|
7
|
+
portaled = true;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
createPortal(child, params);
|
|
11
|
+
return {
|
|
12
|
+
update: (params) => createPortal(child, params),
|
|
13
|
+
destroy() {
|
|
14
|
+
if (portaled) {
|
|
15
|
+
child?.parentNode?.removeChild(child);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const getFirstFocusable = (node) => {
|
|
2
|
+
// we can't select [tabIndex] as many elements don't have tabIndex as a declared property
|
|
3
|
+
// but do default to tabIndex >= 0.
|
|
4
|
+
const nodes = node.querySelectorAll('*');
|
|
5
|
+
const elements = Array.from(nodes)
|
|
6
|
+
.map((n) => n)
|
|
7
|
+
.filter((n) => n.tabIndex !== undefined && n.tabIndex >= 0);
|
|
8
|
+
return elements.length > 0 ? elements[0] : null;
|
|
9
|
+
};
|
|
10
|
+
const getLastFocusable = (node) => {
|
|
11
|
+
// we can't select [tabIndex] as many elements don't have tabIndex as a declared property
|
|
12
|
+
// but do default to tabIndex >= 0.
|
|
13
|
+
const nodes = node.querySelectorAll('*');
|
|
14
|
+
const elements = Array.from(nodes)
|
|
15
|
+
.map((n) => n)
|
|
16
|
+
.filter((n) => n.tabIndex !== undefined && n.tabIndex >= 0);
|
|
17
|
+
return elements.length > 0 ? elements[elements.length - 1] : null;
|
|
18
|
+
};
|
|
19
|
+
export const trapKeyboardFocus = (node) => {
|
|
20
|
+
const onKeydown = (e) => {
|
|
21
|
+
let handledFocus = false;
|
|
22
|
+
if (e.key === 'Tab') {
|
|
23
|
+
if (e.shiftKey) {
|
|
24
|
+
const firstFocusable = getFirstFocusable(node);
|
|
25
|
+
if (document.activeElement === firstFocusable) {
|
|
26
|
+
const lastFocusable = getLastFocusable(node);
|
|
27
|
+
lastFocusable?.focus();
|
|
28
|
+
handledFocus = true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const lastFocusable = getLastFocusable(node);
|
|
33
|
+
if (document.activeElement === lastFocusable) {
|
|
34
|
+
const firstFocusable = getFirstFocusable(node);
|
|
35
|
+
firstFocusable?.focus();
|
|
36
|
+
handledFocus = true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (handledFocus) {
|
|
41
|
+
e.stopPropagation();
|
|
42
|
+
e.preventDefault();
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
node.addEventListener('keydown', onKeydown);
|
|
47
|
+
return {
|
|
48
|
+
destroy: () => {
|
|
49
|
+
node.removeEventListener('keydown', onKeydown);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export type { ClickOutsideEvent, ClickOutsideEventDetail } from './@types/clickOutside';
|
|
2
|
+
export { applyLightDarkMode } from './actions/applyLightDarkMode';
|
|
3
|
+
export { clickOutside } from './actions/clickOutside';
|
|
4
|
+
export { extraClass } from './actions/extraClass';
|
|
5
|
+
export { forwardEvents } from './actions/forwardEvents';
|
|
6
|
+
export { portal } from './actions/portal';
|
|
7
|
+
export { trapKeyboardFocus } from './actions/trapKeyboardFocus';
|
|
8
|
+
export { prefersColorSchemeDark } from './mediaQueries/prefersColorSchemeDark';
|
|
9
|
+
export { prefersReducedMotion } from './mediaQueries/prefersReducedMotion';
|
|
10
|
+
export { usingKeyboard } from './mediaQueries/usingKeyboard';
|
|
11
|
+
export { idGenerator } from './idGenerator';
|
|
12
|
+
export type { ListContext } from './List.types';
|
|
13
|
+
export type { MenuBarContext } from './MenuBar.types';
|
|
14
|
+
export type { MenuItemContext, MenuItemRegistration, MenuItemRole } from './MenuItem.types';
|
|
15
|
+
export type { PopoverPlacement } from './Popover.types';
|
|
16
|
+
export type { ProgressOrientation } from './Progress.types';
|
|
17
|
+
export type { TabListContext } from './TabList.types';
|
|
18
|
+
export type { TextAreaResize } from './TextArea.types';
|
|
19
|
+
export type { TreeContext } from './Tree.types';
|
|
20
|
+
export type { TreeItemContext } from './TreeItem.types';
|
|
21
|
+
export { LABEL_STATUSES, LABEL_VARIANTS } from './Label.constants';
|
|
22
|
+
export { LIST_CONTEXT_KEY } from './List.constants';
|
|
23
|
+
export { MENU_BAR_CONTEXT_KEY } from './MenuBar.constants';
|
|
24
|
+
export { MENU_ITEM_CONTEXT_KEY, MENU_ITEM_ROLES } from './MenuItem.constants';
|
|
25
|
+
export { POPOVER_PLACEMENTS } from './Popover.constants';
|
|
26
|
+
export { PROGRESS_ORIENTATIONS } from './Progress.constants';
|
|
27
|
+
export { TAB_LIST_CONTEXT_KEY } from './TabList.constants';
|
|
28
|
+
export { TEXT_AREA_RESIZES } from './TextArea.constants';
|
|
29
|
+
export { TREE_CONTEXT_KEY } from './Tree.constants';
|
|
30
|
+
export { TREE_ITEM_CONTEXT_KEY } from './TreeItem.constants';
|
|
31
|
+
import Button from './Button.svelte';
|
|
32
|
+
import Callout from './Callout.svelte';
|
|
33
|
+
import Checkbox from './Checkbox.svelte';
|
|
34
|
+
import Dialog from './Dialog.svelte';
|
|
35
|
+
import Dropdown from './Dropdown.svelte';
|
|
36
|
+
import Input from './Input.svelte';
|
|
37
|
+
import Label from './Label.svelte';
|
|
38
|
+
import Link from './Link.svelte';
|
|
39
|
+
import List from './List.svelte';
|
|
40
|
+
import ListItem from './ListItem.svelte';
|
|
41
|
+
import Menu from './Menu.svelte';
|
|
42
|
+
import MenuBar from './MenuBar.svelte';
|
|
43
|
+
import MenuButton from './MenuButton.svelte';
|
|
44
|
+
import MenuItem from './MenuItem.svelte';
|
|
45
|
+
import MenuSeparator from './MenuSeparator.svelte';
|
|
46
|
+
import Pagination from './Pagination.svelte';
|
|
47
|
+
import Popover from './Popover.svelte';
|
|
48
|
+
import Progress from './Progress.svelte';
|
|
49
|
+
import Radio from './Radio.svelte';
|
|
50
|
+
import Select from './Select.svelte';
|
|
51
|
+
import Slider from './Slider.svelte';
|
|
52
|
+
import Switch from './Switch.svelte';
|
|
53
|
+
import Tab from './Tab.svelte';
|
|
54
|
+
import TabList from './TabList.svelte';
|
|
55
|
+
import TextArea from './TextArea.svelte';
|
|
56
|
+
import Tooltip from './Tooltip.svelte';
|
|
57
|
+
import Tree from './Tree.svelte';
|
|
58
|
+
import TreeChevron from './TreeChevron.svelte';
|
|
59
|
+
import TreeItem from './TreeItem.svelte';
|
|
60
|
+
export { Button, Callout, Checkbox, Dialog, Dropdown, Input, Label, Link, List, ListItem, Menu, MenuBar, MenuButton, MenuItem, MenuSeparator, Pagination, Popover, Progress, Radio, Select, Slider, Switch, Tab, TabList, TextArea, Tooltip, Tree, TreeChevron, TreeItem };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// ----- actions ----- //
|
|
2
|
+
export { applyLightDarkMode } from './actions/applyLightDarkMode';
|
|
3
|
+
export { clickOutside } from './actions/clickOutside';
|
|
4
|
+
export { extraClass } from './actions/extraClass';
|
|
5
|
+
export { forwardEvents } from './actions/forwardEvents';
|
|
6
|
+
export { portal } from './actions/portal';
|
|
7
|
+
export { trapKeyboardFocus } from './actions/trapKeyboardFocus';
|
|
8
|
+
// ----- media queries ----- //
|
|
9
|
+
export { prefersColorSchemeDark } from './mediaQueries/prefersColorSchemeDark';
|
|
10
|
+
export { prefersReducedMotion } from './mediaQueries/prefersReducedMotion';
|
|
11
|
+
export { usingKeyboard } from './mediaQueries/usingKeyboard';
|
|
12
|
+
// ----- functions ----- //
|
|
13
|
+
export { idGenerator } from './idGenerator';
|
|
14
|
+
// ----- Component constants ----- //
|
|
15
|
+
export { LABEL_STATUSES, LABEL_VARIANTS } from './Label.constants';
|
|
16
|
+
export { LIST_CONTEXT_KEY } from './List.constants';
|
|
17
|
+
export { MENU_BAR_CONTEXT_KEY } from './MenuBar.constants';
|
|
18
|
+
export { MENU_ITEM_CONTEXT_KEY, MENU_ITEM_ROLES } from './MenuItem.constants';
|
|
19
|
+
export { POPOVER_PLACEMENTS } from './Popover.constants';
|
|
20
|
+
export { PROGRESS_ORIENTATIONS } from './Progress.constants';
|
|
21
|
+
export { TAB_LIST_CONTEXT_KEY } from './TabList.constants';
|
|
22
|
+
export { TEXT_AREA_RESIZES } from './TextArea.constants';
|
|
23
|
+
export { TREE_CONTEXT_KEY } from './Tree.constants';
|
|
24
|
+
export { TREE_ITEM_CONTEXT_KEY } from './TreeItem.constants';
|
|
25
|
+
// ----- Components ----- //
|
|
26
|
+
import Button from './Button.svelte';
|
|
27
|
+
import Callout from './Callout.svelte';
|
|
28
|
+
import Checkbox from './Checkbox.svelte';
|
|
29
|
+
import Dialog from './Dialog.svelte';
|
|
30
|
+
import Dropdown from './Dropdown.svelte';
|
|
31
|
+
import Input from './Input.svelte';
|
|
32
|
+
import Label from './Label.svelte';
|
|
33
|
+
import Link from './Link.svelte';
|
|
34
|
+
import List from './List.svelte';
|
|
35
|
+
import ListItem from './ListItem.svelte';
|
|
36
|
+
import Menu from './Menu.svelte';
|
|
37
|
+
import MenuBar from './MenuBar.svelte';
|
|
38
|
+
import MenuButton from './MenuButton.svelte';
|
|
39
|
+
import MenuItem from './MenuItem.svelte';
|
|
40
|
+
import MenuSeparator from './MenuSeparator.svelte';
|
|
41
|
+
import Pagination from './Pagination.svelte';
|
|
42
|
+
import Popover from './Popover.svelte';
|
|
43
|
+
import Progress from './Progress.svelte';
|
|
44
|
+
import Radio from './Radio.svelte';
|
|
45
|
+
import Select from './Select.svelte';
|
|
46
|
+
import Slider from './Slider.svelte';
|
|
47
|
+
import Switch from './Switch.svelte';
|
|
48
|
+
import Tab from './Tab.svelte';
|
|
49
|
+
import TabList from './TabList.svelte';
|
|
50
|
+
import TextArea from './TextArea.svelte';
|
|
51
|
+
import Tooltip from './Tooltip.svelte';
|
|
52
|
+
import Tree from './Tree.svelte';
|
|
53
|
+
import TreeChevron from './TreeChevron.svelte';
|
|
54
|
+
import TreeItem from './TreeItem.svelte';
|
|
55
|
+
export { Button, Callout, Checkbox, Dialog, Dropdown, Input, Label, Link, List, ListItem, Menu, MenuBar, MenuButton, MenuItem, MenuSeparator, Pagination, Popover, Progress, Radio, Select, Slider, Switch, Tab, TabList, TextArea, Tooltip, Tree, TreeChevron, TreeItem };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const prefersColorSchemeDark: import("svelte/store").Writable<boolean>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { onMount } from 'svelte';
|
|
2
|
+
import { writable } from 'svelte/store';
|
|
3
|
+
export const prefersColorSchemeDark = writable(false, (set) => {
|
|
4
|
+
let matchMedia = undefined;
|
|
5
|
+
const mediaChangeHandler = (e) => set(e.matches);
|
|
6
|
+
onMount(() => {
|
|
7
|
+
matchMedia = window.matchMedia('(prefers-color-scheme: dark)');
|
|
8
|
+
set(matchMedia.matches);
|
|
9
|
+
matchMedia.addEventListener('change', mediaChangeHandler);
|
|
10
|
+
});
|
|
11
|
+
return () => {
|
|
12
|
+
matchMedia?.removeEventListener('change', mediaChangeHandler);
|
|
13
|
+
};
|
|
14
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const prefersReducedMotion: import("svelte/store").Writable<boolean>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { onMount } from 'svelte';
|
|
2
|
+
import { writable } from 'svelte/store';
|
|
3
|
+
export const prefersReducedMotion = writable(false, (set) => {
|
|
4
|
+
let matchMedia = undefined;
|
|
5
|
+
const mediaChangeHandler = (e) => set(e.matches);
|
|
6
|
+
onMount(() => {
|
|
7
|
+
matchMedia = window.matchMedia('(prefers-reduced-motion: reduce)');
|
|
8
|
+
set(matchMedia.matches);
|
|
9
|
+
matchMedia.addEventListener('change', mediaChangeHandler);
|
|
10
|
+
});
|
|
11
|
+
return () => {
|
|
12
|
+
matchMedia?.removeEventListener('change', mediaChangeHandler);
|
|
13
|
+
};
|
|
14
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const usingKeyboard: import("svelte/store").Writable<boolean>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { onMount } from 'svelte';
|
|
2
|
+
import { writable } from 'svelte/store';
|
|
3
|
+
import { createKeyborg } from 'keyborg';
|
|
4
|
+
export const usingKeyboard = writable(false, (set) => {
|
|
5
|
+
let keyborg = undefined;
|
|
6
|
+
const keyborgHandler = (value) => {
|
|
7
|
+
set(value);
|
|
8
|
+
};
|
|
9
|
+
onMount(() => {
|
|
10
|
+
keyborg = createKeyborg(window);
|
|
11
|
+
set(keyborg.isNavigatingWithKeyboard());
|
|
12
|
+
keyborg.subscribe(keyborgHandler);
|
|
13
|
+
});
|
|
14
|
+
return () => {
|
|
15
|
+
keyborg?.unsubscribe(keyborgHandler);
|
|
16
|
+
};
|
|
17
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geoffcox/sterling-svelte",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"author": "Geoff Cox",
|
|
5
5
|
"description": "A modern, accessible, and lightweight UI component library for Svelte.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"link",
|
|
29
29
|
"list",
|
|
30
30
|
"menu",
|
|
31
|
+
"pagination",
|
|
31
32
|
"popover",
|
|
32
33
|
"progress",
|
|
33
34
|
"radio",
|
|
@@ -41,14 +42,14 @@
|
|
|
41
42
|
],
|
|
42
43
|
"exports": {
|
|
43
44
|
".": {
|
|
44
|
-
"types": "./index.d.ts",
|
|
45
|
-
"svelte": "./index.js"
|
|
45
|
+
"types": "./dist/index.d.ts",
|
|
46
|
+
"svelte": "./dist/index.js"
|
|
46
47
|
}
|
|
47
48
|
},
|
|
48
49
|
"files": [
|
|
49
50
|
"dist",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
51
|
+
"!dist/**/*.test.*",
|
|
52
|
+
"!dist/**/*.spec.*"
|
|
52
53
|
],
|
|
53
54
|
"scripts": {
|
|
54
55
|
"build": "vite build && npm run package",
|
|
@@ -98,7 +99,7 @@
|
|
|
98
99
|
"keyborg": "^2.0.0",
|
|
99
100
|
"lodash-es": "^4.17.21"
|
|
100
101
|
},
|
|
101
|
-
"svelte": "./index.js",
|
|
102
|
-
"types": "./index.d.ts",
|
|
102
|
+
"svelte": "./dist/index.js",
|
|
103
|
+
"types": "./dist/index.d.ts",
|
|
103
104
|
"type": "module"
|
|
104
105
|
}
|