@skeletonlabs/skeleton 1.2.0 → 1.5.0
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/dist/actions/Clipboard/clipboard.js +1 -1
- package/dist/actions/Filters/svg-filters/Emerald.svelte +1 -1
- package/dist/components/Accordion/Accordion.svelte +4 -1
- package/dist/components/Accordion/Accordion.svelte.d.ts +4 -0
- package/dist/components/Accordion/AccordionItem.svelte +2 -0
- package/dist/components/Accordion/AccordionItem.svelte.d.ts +3 -1
- package/dist/components/AppRail/AppRail.svelte +1 -1
- package/dist/components/AppRail/AppRail.svelte.d.ts +3 -3
- package/dist/components/AppRail/AppRailTile.svelte +9 -2
- package/dist/components/AppRail/AppRailTile.svelte.d.ts +6 -6
- package/dist/components/AppShell/AppShell.svelte +2 -2
- package/dist/components/AppShell/AppShell.svelte.d.ts +8 -8
- package/dist/components/Autocomplete/Autocomplete.svelte +12 -10
- package/dist/components/Autocomplete/Autocomplete.svelte.d.ts +7 -5
- package/dist/components/Autocomplete/types.d.ts +1 -1
- package/dist/components/Avatar/Avatar.svelte +10 -1
- package/dist/components/Avatar/Avatar.svelte.d.ts +2 -0
- package/dist/components/InputChip/InputChip.svelte +5 -1
- package/dist/components/InputChip/InputChip.svelte.d.ts +4 -2
- package/dist/components/ListBox/ListBox.svelte.d.ts +1 -1
- package/dist/components/ListBox/ListBoxItem.svelte +1 -1
- package/dist/components/Paginator/Paginator.svelte.d.ts +1 -1
- package/dist/components/ProgressBar/ProgressBar.svelte +2 -2
- package/dist/components/Stepper/Step.svelte +2 -1
- package/dist/components/Tab/Tab.svelte +33 -1
- package/dist/components/Tab/TabGroup.svelte +4 -2
- package/dist/components/TableOfContents/TableOfContents.svelte +2 -2
- package/dist/utilities/CodeBlock/CodeBlock.svelte +12 -5
- package/dist/utilities/CodeBlock/CodeBlock.svelte.d.ts +2 -0
- package/dist/utilities/DataTable/actions.js +1 -1
- package/dist/utilities/Drawer/Drawer.svelte +3 -2
- package/dist/utilities/Drawer/Drawer.svelte.d.ts +1 -1
- package/dist/utilities/LightSwitch/LightSwitch.svelte +8 -2
- package/dist/utilities/LocalStorageStore/LocalStorageStore.js +4 -4
- package/dist/utilities/Popup/popup.d.ts +2 -2
- package/dist/utilities/Popup/popup.js +161 -211
- package/dist/utilities/Popup/types.d.ts +20 -12
- package/dist/utilities/Popup/types.js +0 -1
- package/dist/utilities/Toast/Toast.svelte +20 -4
- package/dist/utilities/Toast/Toast.svelte.d.ts +1 -1
- package/package.json +5 -2
- package/src/lib/styles/all.css +21 -9
- package/src/lib/styles/elements/breadcrumbs.css +10 -0
- package/src/lib/styles/elements/buttons.css +1 -1
- package/src/lib/styles/elements/codeblocks.css +16 -0
- package/src/lib/styles/elements/forms.css +15 -0
- package/src/lib/styles/elements/lists.css +2 -3
- package/src/lib/styles/elements/popups.css +2 -2
- package/src/lib/styles/{core.css → partials/core.css} +1 -0
- package/src/lib/styles/partials/elements.css +20 -0
- package/src/lib/styles/{tailwind.css → partials/tailwind.css} +1 -1
- package/src/lib/styles/{typography.css → partials/typography-next.css} +33 -35
- package/src/lib/styles/partials/typography-prose.css +51 -0
- package/src/lib/styles/partials/typography.css +99 -0
- package/src/lib/styles/{variants.css → partials/variants.css} +54 -6
- package/src/lib/styles/skeleton-minimal.css +30 -0
- package/src/lib/styles/skeleton.css +30 -0
- package/src/lib/tailwind/generated/intellisense-classes.cjs +1 -1
- package/src/lib/tailwind/intellisense.cjs +2 -2
- package/src/lib/styles/elements.css +0 -19
- package/src/lib/styles/highlight-js.css +0 -116
|
@@ -10,7 +10,7 @@ declare const __propDef: {
|
|
|
10
10
|
bgBackdrop?: string | undefined;
|
|
11
11
|
/** Backdrop - Provide classes to set the blur style.*/
|
|
12
12
|
blur?: string | undefined;
|
|
13
|
-
/**
|
|
13
|
+
/** Backdrop - Provide classes to set padding.*/
|
|
14
14
|
padding?: string | undefined;
|
|
15
15
|
/** Drawer - Provide classes to set the drawer background color.*/
|
|
16
16
|
bgDrawer?: string | undefined;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
<script>import {
|
|
1
|
+
<script>import { onMount } from "svelte";
|
|
2
|
+
import { modeCurrent, setModeUserPrefers, setModeCurrent, setInitialClassState, getModeOsPrefers } from "./lightswitch";
|
|
2
3
|
export let bgLight = "bg-surface-50";
|
|
3
4
|
export let bgDark = "bg-surface-900";
|
|
4
5
|
export let fillLight = "fill-surface-50";
|
|
@@ -26,6 +27,11 @@ function onKeyDown(event) {
|
|
|
26
27
|
event.currentTarget.click();
|
|
27
28
|
}
|
|
28
29
|
}
|
|
30
|
+
onMount(() => {
|
|
31
|
+
if (!("modeCurrent" in localStorage)) {
|
|
32
|
+
setModeCurrent(getModeOsPrefers());
|
|
33
|
+
}
|
|
34
|
+
});
|
|
29
35
|
$:
|
|
30
36
|
trackBg = $modeCurrent === true ? bgLight : bgDark;
|
|
31
37
|
$:
|
|
@@ -43,7 +49,7 @@ $:
|
|
|
43
49
|
</script>
|
|
44
50
|
|
|
45
51
|
<svelte:head>
|
|
46
|
-
{@html `<script>(${setInitialClassState.toString()})();</script>`}
|
|
52
|
+
{@html `<script nonce="%sveltekit.nonce%">(${setInitialClassState.toString()})();</script>`}
|
|
47
53
|
</svelte:head>
|
|
48
54
|
|
|
49
55
|
<div
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Source: https://github.com/joshnuss/svelte-local-storage-store
|
|
2
2
|
// https://github.com/joshnuss/svelte-local-storage-store/blob/master/index.ts
|
|
3
3
|
// Represents version v0.4.0 (2023-01-18)
|
|
4
|
+
import { BROWSER } from 'esm-env';
|
|
4
5
|
import { writable as internal, get } from 'svelte/store';
|
|
5
6
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
6
7
|
const stores = {};
|
|
@@ -10,19 +11,18 @@ function getStorage(type) {
|
|
|
10
11
|
export function localStorageStore(key, initialValue, options) {
|
|
11
12
|
const serializer = options?.serializer ?? JSON;
|
|
12
13
|
const storageType = options?.storage ?? 'local';
|
|
13
|
-
const browser = typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
14
14
|
function updateStorage(key, value) {
|
|
15
|
-
if (!
|
|
15
|
+
if (!BROWSER)
|
|
16
16
|
return;
|
|
17
17
|
getStorage(storageType).setItem(key, serializer.stringify(value));
|
|
18
18
|
}
|
|
19
19
|
if (!stores[key]) {
|
|
20
20
|
const store = internal(initialValue, (set) => {
|
|
21
|
-
const json =
|
|
21
|
+
const json = BROWSER ? getStorage(storageType).getItem(key) : null;
|
|
22
22
|
if (json) {
|
|
23
23
|
set(serializer.parse(json));
|
|
24
24
|
}
|
|
25
|
-
if (
|
|
25
|
+
if (BROWSER) {
|
|
26
26
|
const handleStorage = (event) => {
|
|
27
27
|
if (event.key === key)
|
|
28
28
|
set(event.newValue ? serializer.parse(event.newValue) : null);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Writable } from 'svelte/store';
|
|
2
2
|
import type { PopupSettings } from './types';
|
|
3
3
|
export declare const storePopup: Writable<any>;
|
|
4
|
-
export declare function popup(
|
|
4
|
+
export declare function popup(triggerNode: HTMLElement, args: PopupSettings): {
|
|
5
5
|
update(newArgs: PopupSettings): void;
|
|
6
6
|
destroy(): void;
|
|
7
|
-
}
|
|
7
|
+
};
|
|
@@ -1,46 +1,72 @@
|
|
|
1
1
|
import { get, writable } from 'svelte/store';
|
|
2
|
-
//
|
|
2
|
+
// Use a store to pass the Floating UI import references
|
|
3
3
|
export const storePopup = writable(undefined);
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
let
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
4
|
+
export function popup(triggerNode, args) {
|
|
5
|
+
// Floating UI Modules
|
|
6
|
+
const { computePosition, autoUpdate, offset, shift, flip, arrow, size, autoPlacement, hide, inline } = get(storePopup);
|
|
7
|
+
// Local State
|
|
8
|
+
let popupState = {
|
|
9
|
+
open: false,
|
|
10
|
+
autoUpdateCleanup: () => { }
|
|
11
|
+
};
|
|
12
|
+
const focusableAllowedList = ':is(a[href], button, input, textarea, select, details, [tabindex]):not([tabindex="-1"])';
|
|
13
|
+
let focusablePoupupElements;
|
|
14
|
+
const documentationLink = 'https://www.skeleton.dev/utilities/popups';
|
|
15
|
+
// Elements
|
|
16
|
+
let elemPopup;
|
|
17
|
+
let elemArrow;
|
|
18
|
+
function setDomElements() {
|
|
19
|
+
elemPopup = document.querySelector(`[data-popup="${args.target}"]`) ?? new HTMLElement();
|
|
20
|
+
elemArrow = elemPopup?.querySelector(`.arrow`) ?? new HTMLElement();
|
|
21
|
+
}
|
|
22
|
+
setDomElements(); // init
|
|
23
|
+
// Render Floating UI Popup
|
|
22
24
|
function render() {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
// Error handling for required Floating UI modules
|
|
26
|
+
if (!elemPopup)
|
|
27
|
+
throw new Error(`The data-popup="${args.target}" element was not found. ${documentationLink}`);
|
|
28
|
+
if (!computePosition)
|
|
29
|
+
throw new Error(`Floating UI 'computePosition' not found for data-popup="${args.target}". ${documentationLink}`);
|
|
30
|
+
if (!offset)
|
|
31
|
+
throw new Error(`Floating UI 'offset' not found for data-popup="${args.target}". ${documentationLink}`);
|
|
32
|
+
if (!shift)
|
|
33
|
+
throw new Error(`Floating UI 'shift' not found for data-popup="${args.target}". ${documentationLink}`);
|
|
34
|
+
if (!flip)
|
|
35
|
+
throw new Error(`Floating UI 'flip' not found for data-popup="${args.target}". ${documentationLink}`);
|
|
36
|
+
if (!arrow)
|
|
37
|
+
throw new Error(`Floating UI 'arrow' not found for data-popup="${args.target}". ${documentationLink}`);
|
|
38
|
+
// Bundle optional middlware
|
|
39
|
+
const optionalMiddlware = [];
|
|
40
|
+
// https://floating-ui.com/docs/size
|
|
41
|
+
if (size)
|
|
42
|
+
optionalMiddlware.push(size(args.middleware?.size));
|
|
43
|
+
// https://floating-ui.com/docs/autoPlacement
|
|
44
|
+
if (autoPlacement)
|
|
45
|
+
optionalMiddlware.push(autoPlacement(args.middleware?.autoPlacement));
|
|
46
|
+
// https://floating-ui.com/docs/hide
|
|
47
|
+
if (hide)
|
|
48
|
+
optionalMiddlware.push(hide(args.middleware?.hide));
|
|
49
|
+
// https://floating-ui.com/docs/inline
|
|
50
|
+
if (inline)
|
|
51
|
+
optionalMiddlware.push(inline(args.middleware?.inline));
|
|
52
|
+
// Floating UI Compute Position
|
|
40
53
|
// https://floating-ui.com/docs/computePosition
|
|
41
|
-
computePosition(
|
|
54
|
+
computePosition(triggerNode, elemPopup, {
|
|
42
55
|
placement: args.placement ?? 'bottom',
|
|
43
|
-
|
|
56
|
+
// Middleware - NOTE: the order matters:
|
|
57
|
+
// https://floating-ui.com/docs/middleware#ordering
|
|
58
|
+
middleware: [
|
|
59
|
+
// https://floating-ui.com/docs/offset
|
|
60
|
+
offset(args.middleware?.offset ?? 8),
|
|
61
|
+
// https://floating-ui.com/docs/shift
|
|
62
|
+
shift(args.middleware?.shift ?? { padding: 8 }),
|
|
63
|
+
// https://floating-ui.com/docs/flip
|
|
64
|
+
flip(args.middleware?.flip),
|
|
65
|
+
// https://floating-ui.com/docs/arrow
|
|
66
|
+
arrow(args.middleware?.arrow ?? { element: elemArrow || null }),
|
|
67
|
+
// Implement optional middlware
|
|
68
|
+
...optionalMiddlware
|
|
69
|
+
]
|
|
44
70
|
}).then(({ x, y, placement, middlewareData }) => {
|
|
45
71
|
Object.assign(elemPopup.style, {
|
|
46
72
|
left: `${x}px`,
|
|
@@ -65,215 +91,139 @@ export function popup(node, args) {
|
|
|
65
91
|
[staticSide]: '-4px'
|
|
66
92
|
});
|
|
67
93
|
}
|
|
68
|
-
// Set Focusable State
|
|
69
|
-
setFocusableState();
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
// Set Focusable State
|
|
73
|
-
function setFocusableState() {
|
|
74
|
-
if (!elemPopup)
|
|
75
|
-
return;
|
|
76
|
-
// Create array of all focusable elements, so that we can iterate through them
|
|
77
|
-
focusableElems = Array.from(elemPopup?.querySelectorAll(elemWhitelist));
|
|
78
|
-
// reset the focus index
|
|
79
|
-
activeFocusIdx = -1;
|
|
80
|
-
// Automatically focus the element if openWithFocus is true (for example if
|
|
81
|
-
// the menu was opened with Enter instead of with a click
|
|
82
|
-
activeFocusIdx = 0;
|
|
83
|
-
// if the popup was triggered via focus, we don't want to move that focus
|
|
84
|
-
if (args.event !== 'focus' && args.event !== 'focus-click') {
|
|
85
|
-
focusableElems[0]?.focus();
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
// Close popup if element matching closeQuery is clicked
|
|
89
|
-
function closeOnQueryClick(clickedEl) {
|
|
90
|
-
if (!clickedEl)
|
|
91
|
-
return;
|
|
92
|
-
const interactiveMenuElems = elemPopup?.querySelectorAll(args.closeQuery || 'a[href], button');
|
|
93
|
-
if (!interactiveMenuElems?.length)
|
|
94
|
-
return;
|
|
95
|
-
interactiveMenuElems.forEach((elem) => {
|
|
96
|
-
if (elem.contains(clickedEl))
|
|
97
|
-
close();
|
|
98
94
|
});
|
|
99
95
|
}
|
|
100
|
-
//
|
|
101
|
-
|
|
102
|
-
if (!node || !elemPopup)
|
|
103
|
-
return;
|
|
104
|
-
// If click is within the trigger node
|
|
105
|
-
const clickTriggerNode = node.contains(event.target);
|
|
106
|
-
if (clickTriggerNode) {
|
|
107
|
-
isVisible == false ? show() : close();
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
// If click is outside the popup
|
|
111
|
-
const clickedOutsidePopup = elemPopup && !elemPopup.contains(event.target);
|
|
112
|
-
if (clickedOutsidePopup) {
|
|
113
|
-
close();
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
closeOnQueryClick(event.target);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
// Hover Handlers
|
|
121
|
-
const onMouseOver = () => {
|
|
122
|
-
show();
|
|
123
|
-
isVisible = true;
|
|
124
|
-
stateEventHandler(true);
|
|
125
|
-
};
|
|
126
|
-
const onMouseOut = () => {
|
|
127
|
-
close();
|
|
128
|
-
isVisible = false;
|
|
129
|
-
stateEventHandler(false);
|
|
130
|
-
};
|
|
131
|
-
// Focus Handlers
|
|
132
|
-
function onFocusIn() {
|
|
133
|
-
if (!isVisible)
|
|
134
|
-
node.focus();
|
|
135
|
-
}
|
|
136
|
-
function onFocusOut(e) {
|
|
137
|
-
// if the focus is within the popup, or on the trigger node, do nothing
|
|
138
|
-
if (e.relatedTarget instanceof Element && (elemPopup?.contains(e.relatedTarget) || node.isSameNode(e.relatedTarget)))
|
|
139
|
-
return;
|
|
140
|
-
close();
|
|
141
|
-
}
|
|
142
|
-
function onMouseDown(e) {
|
|
143
|
-
e.preventDefault();
|
|
144
|
-
if (isNode(document.activeElement)) {
|
|
145
|
-
if (!node.isSameNode(document.activeElement)) {
|
|
146
|
-
node.focus();
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
if (isVisible)
|
|
150
|
-
close();
|
|
151
|
-
else
|
|
152
|
-
show();
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
// Visibility
|
|
156
|
-
function show() {
|
|
96
|
+
// State Handlers
|
|
97
|
+
function open() {
|
|
157
98
|
if (!elemPopup)
|
|
158
99
|
return;
|
|
159
|
-
|
|
100
|
+
// Set open state to on
|
|
101
|
+
popupState.open = true;
|
|
102
|
+
// Return the current state
|
|
103
|
+
if (args.state)
|
|
104
|
+
args.state({ state: popupState.open });
|
|
105
|
+
// Update render settings
|
|
106
|
+
render();
|
|
107
|
+
// Update the DOM
|
|
160
108
|
elemPopup.style.display = 'block';
|
|
161
109
|
elemPopup.style.opacity = '1';
|
|
162
|
-
elemPopup.style.pointerEvents = '
|
|
163
|
-
|
|
164
|
-
stateEventHandler(true);
|
|
165
|
-
// Utilize autoUpdate ONLY when the popup is.
|
|
110
|
+
elemPopup.style.pointerEvents = 'auto';
|
|
111
|
+
// Trigger Floating UI autoUpdate (open only)
|
|
166
112
|
// https://floating-ui.com/docs/autoUpdate
|
|
167
|
-
autoUpdateCleanup = autoUpdate(
|
|
113
|
+
popupState.autoUpdateCleanup = autoUpdate(triggerNode, elemPopup, render);
|
|
114
|
+
// Focus the first focusable element within the popup
|
|
115
|
+
focusablePoupupElements = Array.from(elemPopup?.querySelectorAll(focusableAllowedList));
|
|
168
116
|
}
|
|
169
|
-
function close() {
|
|
117
|
+
function close(callback) {
|
|
170
118
|
if (!elemPopup)
|
|
171
119
|
return;
|
|
172
|
-
|
|
120
|
+
// Set transition duration
|
|
173
121
|
const cssTransitionDuration = parseFloat(window.getComputedStyle(elemPopup).transitionDuration.replace('s', '')) * 1000;
|
|
174
122
|
setTimeout(() => {
|
|
175
|
-
|
|
123
|
+
// Set open state to off
|
|
124
|
+
popupState.open = false;
|
|
125
|
+
// Return the current state
|
|
126
|
+
if (args.state)
|
|
127
|
+
args.state({ state: popupState.open });
|
|
128
|
+
// Update the DOM
|
|
129
|
+
elemPopup.style.opacity = '0';
|
|
176
130
|
elemPopup.style.pointerEvents = 'none';
|
|
177
|
-
|
|
178
|
-
|
|
131
|
+
// Cleanup Floating UI autoUpdate (close only)
|
|
132
|
+
if (popupState.autoUpdateCleanup)
|
|
133
|
+
popupState.autoUpdateCleanup();
|
|
134
|
+
// Trigger callback
|
|
135
|
+
if (callback)
|
|
136
|
+
callback();
|
|
179
137
|
}, cssTransitionDuration);
|
|
180
|
-
// Cleanup autoUpdate on close (REQUIRED)
|
|
181
|
-
if (autoUpdateCleanup)
|
|
182
|
-
autoUpdateCleanup();
|
|
183
138
|
}
|
|
184
|
-
//
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
139
|
+
// Event Handlers
|
|
140
|
+
function toggle() {
|
|
141
|
+
popupState.open === false ? open() : close();
|
|
142
|
+
}
|
|
143
|
+
function onWindowClick(event) {
|
|
144
|
+
// Return if the popup is not yet open
|
|
145
|
+
if (popupState.open === false)
|
|
146
|
+
return;
|
|
147
|
+
// Return if click is the trigger element
|
|
148
|
+
if (triggerNode.contains(event.target))
|
|
149
|
+
return;
|
|
150
|
+
// If click it outside the popup
|
|
151
|
+
if (elemPopup && elemPopup.contains(event.target) === false) {
|
|
152
|
+
close();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
// Handle Close Query State
|
|
156
|
+
const closeQueryString = args.closeQuery === undefined ? 'a[href], button' : args.closeQuery;
|
|
157
|
+
const closableMenuElements = elemPopup?.querySelectorAll(closeQueryString);
|
|
158
|
+
closableMenuElements?.forEach((elem) => {
|
|
159
|
+
if (elem.contains(event.target))
|
|
160
|
+
close();
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
// Keyboard Interactions for A11y
|
|
190
164
|
const onWindowKeyDown = (event) => {
|
|
191
|
-
if (
|
|
165
|
+
if (popupState.open === false)
|
|
192
166
|
return;
|
|
193
167
|
// Handle keys
|
|
194
168
|
const key = event.key;
|
|
195
|
-
//
|
|
169
|
+
// On Esc key
|
|
196
170
|
if (key === 'Escape') {
|
|
197
171
|
event.preventDefault();
|
|
172
|
+
triggerNode.focus();
|
|
198
173
|
close();
|
|
199
|
-
node.focus();
|
|
200
174
|
return;
|
|
201
175
|
}
|
|
202
|
-
|
|
176
|
+
// On Tab or ArrowDown key
|
|
177
|
+
const triggerMenuFocused = popupState.open && document.activeElement === triggerNode;
|
|
178
|
+
if (triggerMenuFocused && (key === 'ArrowDown' || key === 'Tab')) {
|
|
203
179
|
event.preventDefault();
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
activeFocusIdx += 1;
|
|
207
|
-
focusableElems[activeFocusIdx]?.focus();
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
else if (key === 'ArrowUp') {
|
|
211
|
-
event.preventDefault();
|
|
212
|
-
if (activeFocusIdx > 0) {
|
|
213
|
-
// Move up the menu
|
|
214
|
-
activeFocusIdx -= 1;
|
|
215
|
-
focusableElems[activeFocusIdx]?.focus();
|
|
216
|
-
}
|
|
217
|
-
else if (focusableElems.length && activeFocusIdx === -1) {
|
|
218
|
-
// Start at the bottom of the menu if first key is arrow up key
|
|
219
|
-
event.preventDefault();
|
|
220
|
-
activeFocusIdx = focusableElems.length - 1;
|
|
221
|
-
focusableElems[activeFocusIdx]?.focus();
|
|
222
|
-
}
|
|
180
|
+
if (focusableAllowedList.length > 0)
|
|
181
|
+
focusablePoupupElements[0].focus();
|
|
223
182
|
}
|
|
224
183
|
};
|
|
225
|
-
// On Init
|
|
226
|
-
render();
|
|
227
184
|
// Event Listeners
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
185
|
+
switch (args.event) {
|
|
186
|
+
case 'click':
|
|
187
|
+
triggerNode.addEventListener('click', toggle, true);
|
|
188
|
+
window.addEventListener('click', onWindowClick, true);
|
|
189
|
+
break;
|
|
190
|
+
case 'hover':
|
|
191
|
+
triggerNode.addEventListener('mouseover', open, true);
|
|
192
|
+
triggerNode.addEventListener('mouseleave', close, true);
|
|
193
|
+
break;
|
|
194
|
+
case 'focus-blur':
|
|
195
|
+
triggerNode.addEventListener('focus', toggle, true);
|
|
196
|
+
triggerNode.addEventListener('blur', close, true);
|
|
197
|
+
break;
|
|
198
|
+
case 'focus-click':
|
|
199
|
+
triggerNode.addEventListener('focus', open, true);
|
|
200
|
+
window.addEventListener('click', onWindowClick, true);
|
|
201
|
+
break;
|
|
202
|
+
default:
|
|
203
|
+
throw new Error(`Event value of '${args.event}' is not supported. ${documentationLink}`);
|
|
234
204
|
}
|
|
235
|
-
if (args.event === 'hover-click') {
|
|
236
|
-
node.addEventListener('mouseover', show, true);
|
|
237
|
-
window.addEventListener('click', onWindowClick, true);
|
|
238
|
-
}
|
|
239
|
-
if (args.event === 'focus' || args.event === 'focus-click') {
|
|
240
|
-
if (!elemPopup)
|
|
241
|
-
return;
|
|
242
|
-
node.addEventListener('focusin', show, true);
|
|
243
|
-
node.addEventListener('focusout', onFocusOut, true);
|
|
244
|
-
// if we tab into a closed popup, we will tab into the last element of any focusable element in elemPopup
|
|
245
|
-
// so we add an event listener to move the focus back to the node the `use:popup` directive is on
|
|
246
|
-
elemPopup.addEventListener('focusin', onFocusIn, true);
|
|
247
|
-
// when we focus off the end of the list, close the popup
|
|
248
|
-
elemPopup.addEventListener('focusout', onFocusOut, true);
|
|
249
|
-
// when an element inside the popup is clicked, close the popup if the element matches the closeQuery
|
|
250
|
-
elemPopup.addEventListener('click', onWindowClick, true);
|
|
251
|
-
}
|
|
252
|
-
if (args.event === 'focus-click') {
|
|
253
|
-
// we must use mousedown instead of click because click fires after focusin, meaning isVisible would always be true
|
|
254
|
-
// if the active element (one with current focus) is the same as the node (the element with the use:popup directive),
|
|
255
|
-
// then the user clicked on the node, so we should toggle the state of the popup
|
|
256
|
-
node.addEventListener('mousedown', onMouseDown, true);
|
|
257
|
-
}
|
|
258
|
-
// A11y Event Listeners
|
|
259
205
|
window.addEventListener('keydown', onWindowKeyDown, true);
|
|
206
|
+
// Render popup on initilization
|
|
207
|
+
render();
|
|
260
208
|
// Lifecycle
|
|
261
209
|
return {
|
|
262
210
|
update(newArgs) {
|
|
263
|
-
|
|
264
|
-
|
|
211
|
+
close(() => {
|
|
212
|
+
args = newArgs;
|
|
213
|
+
render();
|
|
214
|
+
setDomElements();
|
|
215
|
+
});
|
|
265
216
|
},
|
|
266
217
|
destroy() {
|
|
267
|
-
//
|
|
218
|
+
// Trigger Events
|
|
219
|
+
triggerNode.removeEventListener('click', toggle, true);
|
|
220
|
+
triggerNode.removeEventListener('mouseover', open, true);
|
|
221
|
+
triggerNode.removeEventListener('mouseleave', close, true);
|
|
222
|
+
triggerNode.removeEventListener('focus', toggle, true);
|
|
223
|
+
triggerNode.removeEventListener('focus', open, true);
|
|
224
|
+
triggerNode.removeEventListener('blur', close, true);
|
|
225
|
+
// Window Events
|
|
268
226
|
window.removeEventListener('click', onWindowClick, true);
|
|
269
|
-
node.removeEventListener('mouseover', onMouseOver, true);
|
|
270
|
-
node.removeEventListener('mouseout', onMouseOut, true);
|
|
271
|
-
node.removeEventListener('focusin', show, true);
|
|
272
|
-
node.removeEventListener('focusout', onFocusOut, true);
|
|
273
|
-
node.removeEventListener('mousedown', onMouseDown, true);
|
|
274
|
-
elemPopup?.removeEventListener('focusin', onFocusIn, true);
|
|
275
|
-
elemPopup?.removeEventListener('focusout', onFocusOut, true);
|
|
276
|
-
// ---
|
|
277
227
|
window.removeEventListener('keydown', onWindowKeyDown, true);
|
|
278
228
|
}
|
|
279
229
|
};
|
|
@@ -1,32 +1,40 @@
|
|
|
1
|
-
type Direction = 'top' | 'bottom' | 'left' | 'right';
|
|
2
1
|
/** Placement https://floating-ui.com/docs/computePosition#placement */
|
|
2
|
+
type Direction = 'top' | 'bottom' | 'left' | 'right';
|
|
3
3
|
type Placement = Direction | `${Direction}-start` | `${Direction}-end`;
|
|
4
|
-
interface
|
|
5
|
-
/** Offset
|
|
4
|
+
export interface Middleware {
|
|
5
|
+
/** Offset middleware settings: https://floating-ui.com/docs/offset */
|
|
6
6
|
offset?: number | Record<string, any>;
|
|
7
|
-
/** Shift
|
|
7
|
+
/** Shift middleware settings: https://floating-ui.com/docs/shift */
|
|
8
8
|
shift?: Record<string, any>;
|
|
9
|
-
/** Flip
|
|
9
|
+
/** Flip middleware settings: https://floating-ui.com/docs/flip */
|
|
10
10
|
flip?: Record<string, any>;
|
|
11
|
-
/** Arrow
|
|
11
|
+
/** Arrow middleware settings: https://floating-ui.com/docs/arrow */
|
|
12
12
|
arrow?: {
|
|
13
13
|
element: string;
|
|
14
14
|
} & Record<string, any>;
|
|
15
|
+
/** Size middleware settings: https://floating-ui.com/docs/size */
|
|
16
|
+
size?: Record<string, any>;
|
|
17
|
+
/** Auto Placement middleware settings: https://floating-ui.com/docs/autoPlacement */
|
|
18
|
+
autoPlacement?: Record<string, any>;
|
|
19
|
+
/** Hide middleware settings: https://floating-ui.com/docs/hide */
|
|
20
|
+
hide?: Record<string, any>;
|
|
21
|
+
/** Inline middleware settings: https://floating-ui.com/docs/inline */
|
|
22
|
+
inline?: Record<string, any>;
|
|
15
23
|
}
|
|
16
24
|
export interface PopupSettings {
|
|
17
25
|
/** Provide the event type. */
|
|
18
|
-
event: 'click' | 'hover' | '
|
|
19
|
-
/** Match the popup data value `
|
|
26
|
+
event: 'click' | 'hover' | 'focus-blur' | 'focus-click';
|
|
27
|
+
/** Match the popup data value `data-popup="targetNameHere"` */
|
|
20
28
|
target: string;
|
|
21
29
|
/** Set the placement position. Defaults 'bottom'. */
|
|
22
30
|
placement?: Placement;
|
|
23
|
-
/** Query
|
|
31
|
+
/** Query elements that close the popup when clicked. Defaults `'a[href], button'`. */
|
|
24
32
|
closeQuery?: string;
|
|
25
|
-
/**
|
|
26
|
-
middleware?: Middlware;
|
|
27
|
-
/** Provide an optional callback function to monitor open/close state. */
|
|
33
|
+
/** Optional callback function that reports state change. */
|
|
28
34
|
state?: (event: {
|
|
29
35
|
state: boolean;
|
|
30
36
|
}) => void;
|
|
37
|
+
/** Provide Floating UI middleware settings. */
|
|
38
|
+
middleware?: Middleware;
|
|
31
39
|
}
|
|
32
40
|
export {};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
<script>import {
|
|
1
|
+
<script>import { crossfade } from "svelte/transition";
|
|
2
|
+
import { cubicInOut } from "svelte/easing";
|
|
2
3
|
import { flip } from "svelte/animate";
|
|
3
4
|
import { toastStore } from "./stores";
|
|
4
5
|
export let position = "b";
|
|
5
6
|
export let max = 3;
|
|
6
|
-
export let duration =
|
|
7
|
+
export let duration = 250;
|
|
7
8
|
export let background = "variant-filled-secondary";
|
|
8
9
|
export let width = "max-w-[640px]";
|
|
9
10
|
export let color = "";
|
|
@@ -76,15 +77,30 @@ $:
|
|
|
76
77
|
classesToast = `${cToast} ${width} ${color} ${padding} ${spacing} ${rounded} ${shadow}`;
|
|
77
78
|
$:
|
|
78
79
|
filteredToasts = Array.from($toastStore).slice(0, max);
|
|
80
|
+
const [send, receive] = crossfade({
|
|
81
|
+
duration: (d) => Math.sqrt(d * duration),
|
|
82
|
+
fallback(node) {
|
|
83
|
+
const style = getComputedStyle(node);
|
|
84
|
+
const transform = style.transform === "none" ? "" : style.transform;
|
|
85
|
+
return {
|
|
86
|
+
duration,
|
|
87
|
+
easing: cubicInOut,
|
|
88
|
+
css: (t, u) => `
|
|
89
|
+
transform: ${transform} scale(${t}) translate(${u * animAxis.x}%, ${u * animAxis.y}%);
|
|
90
|
+
opacity: ${t}
|
|
91
|
+
`
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
});
|
|
79
95
|
</script>
|
|
80
96
|
|
|
81
97
|
{#if $toastStore.length}
|
|
82
98
|
<!-- Wrapper -->
|
|
83
99
|
<div class="snackbar-wrapper {classesWrapper}" data-testid="snackbar-wrapper">
|
|
84
100
|
<!-- List -->
|
|
85
|
-
<div class="snackbar {classesSnackbar}"
|
|
101
|
+
<div class="snackbar {classesSnackbar}">
|
|
86
102
|
{#each filteredToasts as t, i (t)}
|
|
87
|
-
<div animate:flip={{ duration }}>
|
|
103
|
+
<div animate:flip={{ duration }} in:receive={{ key: t.id }} out:send={{ key: t.id }}>
|
|
88
104
|
<!-- Toast -->
|
|
89
105
|
<div class="toast {classesToast} {t.background ?? background} {t.classes}" role="alert" aria-live="polite" data-testid="toast">
|
|
90
106
|
<div class="text-base">{@html t.message}</div>
|
|
@@ -3,7 +3,7 @@ declare const __propDef: {
|
|
|
3
3
|
props: {
|
|
4
4
|
[x: string]: any;
|
|
5
5
|
/** Set the toast position.*/
|
|
6
|
-
position?:
|
|
6
|
+
position?: "b" | "br" | "tr" | "t" | "l" | "r" | "tl" | "bl" | undefined;
|
|
7
7
|
/** Maximum toasts that can show at once.*/
|
|
8
8
|
max?: number | undefined;
|
|
9
9
|
/** The duration of the fly in/out animation.*/
|