@skeletonlabs/skeleton 0.99.5 → 0.132.4
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 +1 -2
- package/actions/Filters/filter.js +6 -9
- package/components/Accordion/Accordion.svelte +34 -0
- package/components/Accordion/Accordion.svelte.d.ts +41 -0
- package/components/Accordion/AccordionItem.svelte +84 -39
- package/components/Accordion/AccordionItem.svelte.d.ts +24 -7
- package/components/AppBar/AppBar.svelte +36 -21
- package/components/AppBar/AppBar.svelte.d.ts +20 -1
- package/components/AppRail/AppRail.svelte +3 -2
- package/components/AppRail/AppRail.svelte.d.ts +13 -1
- package/components/AppRail/AppRailTile.svelte +10 -7
- package/components/AppRail/AppRailTile.svelte.d.ts +10 -4
- package/components/AppShell/AppShell.svelte +3 -2
- package/components/AppShell/AppShell.svelte.d.ts +11 -0
- package/components/Avatar/Avatar.svelte +9 -9
- package/components/Avatar/Avatar.svelte.d.ts +16 -5
- package/components/ConicGradient/ConicGradient.svelte +18 -8
- package/components/ConicGradient/ConicGradient.svelte.d.ts +11 -0
- package/components/ConicGradient/settings.d.ts +1 -5
- package/components/ConicGradient/settings.js +1 -2
- package/components/FileButton/FileButton.svelte +8 -6
- package/components/FileButton/FileButton.svelte.d.ts +3 -1
- package/components/FileDropzone/FileDropzone.svelte +43 -63
- package/components/FileDropzone/FileDropzone.svelte.d.ts +24 -8
- package/components/InputChip/InputChip.svelte +97 -52
- package/components/InputChip/InputChip.svelte.d.ts +28 -4
- package/components/ListBox/ListBox.svelte +13 -29
- package/components/ListBox/ListBox.svelte.d.ts +11 -10
- package/components/ListBox/ListBoxItem.svelte +60 -50
- package/components/ListBox/ListBoxItem.svelte.d.ts +12 -7
- package/components/Paginator/Paginator.svelte +4 -4
- package/components/Paginator/Paginator.svelte.d.ts +13 -2
- package/components/ProgressBar/ProgressBar.svelte +17 -24
- package/components/ProgressBar/ProgressBar.svelte.d.ts +9 -1
- package/components/ProgressRadial/ProgressRadial.svelte +6 -8
- package/components/ProgressRadial/ProgressRadial.svelte.d.ts +9 -2
- package/components/Radio/RadioGroup.svelte +13 -16
- package/components/Radio/RadioGroup.svelte.d.ts +15 -7
- package/components/Radio/RadioItem.svelte +25 -21
- package/components/Radio/RadioItem.svelte.d.ts +12 -7
- package/components/RangeSlider/RangeSlider.svelte +9 -17
- package/components/RangeSlider/RangeSlider.svelte.d.ts +11 -2
- package/components/SlideToggle/SlideToggle.svelte +10 -9
- package/components/SlideToggle/SlideToggle.svelte.d.ts +11 -3
- package/components/Stepper/Step.svelte +64 -107
- package/components/Stepper/Step.svelte.d.ts +17 -18
- package/components/Stepper/Stepper.svelte +58 -37
- package/components/Stepper/Stepper.svelte.d.ts +28 -14
- package/components/Tab/Tab.svelte +40 -38
- package/components/Tab/Tab.svelte.d.ts +20 -14
- package/components/Tab/TabGroup.svelte +28 -41
- package/components/Tab/TabGroup.svelte.d.ts +25 -9
- package/components/Table/Table.svelte.d.ts +9 -0
- package/components/TableOfContents/TableOfContents.svelte +3 -2
- package/components/TableOfContents/TableOfContents.svelte.d.ts +12 -0
- package/index.d.ts +5 -4
- package/index.js +10 -4
- package/package.json +24 -16
- package/styles/all.css +0 -3
- package/styles/elements/breadcrumbs.css +3 -4
- package/styles/elements/buttons.css +2 -4
- package/styles/elements/forms.css +265 -0
- package/styles/elements/lists.css +1 -1
- package/styles/elements/modals.css +15 -0
- package/styles/elements/popups.css +16 -0
- package/styles/elements.css +3 -2
- package/styles/typography.css +5 -5
- package/styles/variants.css +7 -7
- package/tailwind/core.cjs +1 -1
- package/tailwind/generated/intellisense-classes.cjs +1 -1
- package/tailwind/generated/intellisense-classes.d.cts +318 -404
- package/tailwind/intellisense.cjs +2 -2
- package/tailwind/skeleton.cjs +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/types/tailwind.d.ts +4 -0
- package/types/tailwind.js +2 -0
- package/utilities/CodeBlock/CodeBlock.svelte +14 -8
- package/utilities/CodeBlock/CodeBlock.svelte.d.ts +17 -1
- package/utilities/Drawer/Drawer.svelte +50 -37
- package/utilities/Drawer/Drawer.svelte.d.ts +20 -1
- package/utilities/Drawer/types.d.ts +8 -2
- package/utilities/LightSwitch/LightSwitch.svelte +43 -53
- package/utilities/LightSwitch/LightSwitch.svelte.d.ts +18 -2
- package/utilities/LightSwitch/lightswitch.d.ts +20 -0
- package/utilities/LightSwitch/lightswitch.js +71 -0
- package/utilities/LocalStorageStore/LocalStorageStore.js +1 -1
- package/utilities/Modal/Modal.svelte +96 -64
- package/utilities/Modal/Modal.svelte.d.ts +29 -0
- package/utilities/Modal/types.d.ts +9 -5
- package/utilities/Popup/popup.d.ts +7 -0
- package/utilities/Popup/popup.js +218 -0
- package/utilities/Popup/types.d.ts +32 -0
- package/utilities/Popup/types.js +3 -0
- package/utilities/Toast/Toast.svelte +17 -13
- package/utilities/Toast/Toast.svelte.d.ts +14 -0
- package/utilities/Toast/stores.js +9 -26
- package/utilities/Toast/types.d.ts +6 -1
- package/components/Accordion/AccordionGroup.svelte +0 -33
- package/components/Accordion/AccordionGroup.svelte.d.ts +0 -24
- package/components/SvgIcon/SvgIcon.svelte +0 -33
- package/components/SvgIcon/SvgIcon.svelte.d.ts +0 -26
- package/components/SvgIcon/icons.d.ts +0 -1
- package/components/SvgIcon/icons.js +0 -25
- package/styles/elements/menus.css +0 -29
- package/styles/elements/tooltips.css +0 -83
- package/styles/forms.css +0 -195
- package/utilities/LightSwitch/stores.d.ts +0 -2
- package/utilities/LightSwitch/stores.js +0 -5
- package/utilities/Menu/menu.d.ts +0 -18
- package/utilities/Menu/menu.js +0 -151
- package/utilities/Modal/examples/ModalExampleEmbed.svelte +0 -17
- package/utilities/Modal/examples/ModalExampleEmbed.svelte.d.ts +0 -17
- package/utilities/Modal/examples/ModalExampleForm.svelte +0 -41
- package/utilities/Modal/examples/ModalExampleForm.svelte.d.ts +0 -17
- package/utilities/Modal/examples/ModalExampleImage.svelte +0 -19
- package/utilities/Modal/examples/ModalExampleImage.svelte.d.ts +0 -16
- package/utilities/Modal/examples/ModalExampleList.svelte +0 -27
- package/utilities/Modal/examples/ModalExampleList.svelte.d.ts +0 -17
- package/utilities/Tooltip/tooltip.d.ts +0 -35
- package/utilities/Tooltip/tooltip.js +0 -94
|
@@ -3,16 +3,21 @@ import { fade, fly } from "svelte/transition";
|
|
|
3
3
|
const dispatch = createEventDispatcher();
|
|
4
4
|
import { focusTrap } from "../../actions/FocusTrap/focusTrap";
|
|
5
5
|
import { modalStore } from "./stores";
|
|
6
|
+
export let position = "items-center";
|
|
7
|
+
export let components = {};
|
|
6
8
|
export let duration = 150;
|
|
9
|
+
export let flyOpacity = 0;
|
|
10
|
+
export let flyX = 0;
|
|
11
|
+
export let flyY = 100;
|
|
7
12
|
export let background = "bg-surface-100-800-token";
|
|
8
|
-
export let width = "w-
|
|
13
|
+
export let width = "w-modal";
|
|
9
14
|
export let height = "h-auto";
|
|
10
15
|
export let padding = "p-4";
|
|
11
16
|
export let spacing = "space-y-4";
|
|
12
17
|
export let rounded = "rounded-container-token";
|
|
13
18
|
export let shadow = "shadow-xl";
|
|
14
19
|
export let buttonNeutral = "variant-ghost-surface";
|
|
15
|
-
export let buttonPositive = "variant-filled
|
|
20
|
+
export let buttonPositive = "variant-filled";
|
|
16
21
|
export let buttonTextCancel = "Cancel";
|
|
17
22
|
export let buttonTextConfirm = "Confirm";
|
|
18
23
|
export let buttonTextSubmit = "Submit";
|
|
@@ -20,8 +25,9 @@ export let regionBackdrop = "bg-surface-backdrop-token";
|
|
|
20
25
|
export let regionHeader = "text-2xl font-bold";
|
|
21
26
|
export let regionBody = "max-h-[200px] overflow-hidden";
|
|
22
27
|
export let regionFooter = "flex justify-end space-x-2";
|
|
23
|
-
const cBackdrop = "fixed top-0 left-0 right-0 bottom-0 z-[999]
|
|
24
|
-
const
|
|
28
|
+
const cBackdrop = "fixed top-0 left-0 right-0 bottom-0 z-[999]";
|
|
29
|
+
const cTransitionLayer = "w-full h-full p-4 overflow-y-auto flex justify-center";
|
|
30
|
+
const cModal = "block";
|
|
25
31
|
const cModalImage = "w-full h-auto";
|
|
26
32
|
let promptValue;
|
|
27
33
|
const buttonTextDefaults = {
|
|
@@ -29,19 +35,24 @@ const buttonTextDefaults = {
|
|
|
29
35
|
buttonTextConfirm,
|
|
30
36
|
buttonTextSubmit
|
|
31
37
|
};
|
|
32
|
-
|
|
33
|
-
|
|
38
|
+
let currentComponent;
|
|
39
|
+
modalStore.subscribe((modals) => {
|
|
40
|
+
if (!modals.length)
|
|
34
41
|
return;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
if (modals[0].type === "prompt")
|
|
43
|
+
promptValue = modals[0].value;
|
|
44
|
+
buttonTextCancel = modals[0].buttonTextCancel || buttonTextDefaults.buttonTextCancel;
|
|
45
|
+
buttonTextConfirm = modals[0].buttonTextConfirm || buttonTextDefaults.buttonTextConfirm;
|
|
46
|
+
buttonTextSubmit = modals[0].buttonTextSubmit || buttonTextDefaults.buttonTextSubmit;
|
|
47
|
+
currentComponent = typeof modals[0].component === "string" ? components[modals[0].component] : modals[0].component;
|
|
39
48
|
});
|
|
40
49
|
function onBackdropInteraction(event) {
|
|
41
50
|
if (!(event.target instanceof Element))
|
|
42
51
|
return;
|
|
43
52
|
if (event.target.classList.contains("modal-backdrop"))
|
|
44
53
|
onClose();
|
|
54
|
+
if (event.target.classList.contains("modal-transition"))
|
|
55
|
+
onClose();
|
|
45
56
|
dispatch("backdrop", event);
|
|
46
57
|
}
|
|
47
58
|
function onClose() {
|
|
@@ -66,11 +77,20 @@ function onKeyDown(event) {
|
|
|
66
77
|
onClose();
|
|
67
78
|
}
|
|
68
79
|
$:
|
|
69
|
-
|
|
80
|
+
cPosition = $modalStore[0]?.position ?? position;
|
|
81
|
+
$:
|
|
82
|
+
classesBackdrop = `${cBackdrop} ${regionBackdrop} ${$$props.class ?? ""} ${$modalStore[0]?.backdropClasses ?? ""}`;
|
|
70
83
|
$:
|
|
71
|
-
|
|
84
|
+
classesTransitionLayer = `${cTransitionLayer} ${cPosition ?? ""}`;
|
|
85
|
+
$:
|
|
86
|
+
classesModal = `${cModal} ${background} ${width} ${height} ${padding} ${spacing} ${rounded} ${shadow} ${$modalStore[0]?.modalClasses ?? ""}`;
|
|
72
87
|
$:
|
|
73
88
|
parent = {
|
|
89
|
+
position,
|
|
90
|
+
duration,
|
|
91
|
+
flyOpacity,
|
|
92
|
+
flyX,
|
|
93
|
+
flyY,
|
|
74
94
|
background,
|
|
75
95
|
width,
|
|
76
96
|
height,
|
|
@@ -97,62 +117,74 @@ $:
|
|
|
97
117
|
{#key $modalStore}
|
|
98
118
|
<!-- Backdrop -->
|
|
99
119
|
<div
|
|
100
|
-
class="modal-backdrop {classesBackdrop}
|
|
120
|
+
class="modal-backdrop {classesBackdrop}"
|
|
121
|
+
data-testid="modal-backdrop"
|
|
101
122
|
on:mousedown={onBackdropInteraction}
|
|
102
123
|
on:touchstart={onBackdropInteraction}
|
|
103
124
|
transition:fade={{ duration }}
|
|
104
|
-
|
|
125
|
+
use:focusTrap={true}
|
|
105
126
|
>
|
|
106
|
-
<!--
|
|
107
|
-
<div
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
127
|
+
<!-- Transition Layer -->
|
|
128
|
+
<div class="modal-transition {classesTransitionLayer}" transition:fly={{ duration, opacity: flyOpacity, x: flyX, y: flyY }}>
|
|
129
|
+
{#if $modalStore[0].type !== 'component'}
|
|
130
|
+
<!-- Modal: Presets -->
|
|
131
|
+
<div
|
|
132
|
+
class="modal {classesModal}"
|
|
133
|
+
data-testid="modal"
|
|
134
|
+
role="dialog"
|
|
135
|
+
aria-modal="true"
|
|
136
|
+
aria-label={$modalStore[0].title ?? ''}
|
|
137
|
+
transition:fly={{ duration, opacity: 0, y: 100 }}
|
|
138
|
+
>
|
|
139
|
+
<!-- Header -->
|
|
140
|
+
{#if $modalStore[0]?.title}
|
|
141
|
+
<header class="modal-header {regionHeader}">{@html $modalStore[0].title}</header>
|
|
142
|
+
{/if}
|
|
143
|
+
<!-- Body -->
|
|
144
|
+
{#if $modalStore[0]?.body}
|
|
145
|
+
<article class="modal-body {regionBody}">{@html $modalStore[0].body}</article>
|
|
146
|
+
{/if}
|
|
147
|
+
<!-- Image -->
|
|
148
|
+
{#if $modalStore[0]?.image && typeof $modalStore[0]?.image === 'string'}
|
|
149
|
+
<img class="modal-image {cModalImage}" src={$modalStore[0]?.image} alt="Modal" />
|
|
150
|
+
{/if}
|
|
151
|
+
<!-- Type -->
|
|
152
|
+
{#if $modalStore[0].type === 'alert'}
|
|
153
|
+
<!-- Template: Alert -->
|
|
154
|
+
<footer class="modal-footer {regionFooter}">
|
|
155
|
+
<button type="button" class="btn {buttonNeutral}" on:click={onClose}>{buttonTextCancel}</button>
|
|
156
|
+
</footer>
|
|
157
|
+
{:else if $modalStore[0].type === 'confirm'}
|
|
158
|
+
<!-- Template: Confirm -->
|
|
159
|
+
<footer class="modal-footer {regionFooter}">
|
|
160
|
+
<button type="button" class="btn {buttonNeutral}" on:click={onClose}>{buttonTextCancel}</button>
|
|
161
|
+
<button type="button" class="btn {buttonPositive}" on:click={onConfirm}>{buttonTextConfirm}</button>
|
|
162
|
+
</footer>
|
|
163
|
+
{:else if $modalStore[0].type === 'prompt'}
|
|
164
|
+
<!-- Template: Prompt -->
|
|
165
|
+
<form class="space-y-4" on:submit={onPromptSubmit}>
|
|
166
|
+
<input class="modal-prompt-input input" name="prompt" type="text" bind:value={promptValue} {...$modalStore[0].valueAttr} />
|
|
167
|
+
<footer class="modal-footer {regionFooter}">
|
|
168
|
+
<button type="button" class="btn {buttonNeutral}" on:click={onClose}>{buttonTextCancel}</button>
|
|
169
|
+
<button type="submit" class="btn {buttonPositive}">{buttonTextSubmit}</button>
|
|
170
|
+
</footer>
|
|
171
|
+
</form>
|
|
172
|
+
{/if}
|
|
173
|
+
</div>
|
|
174
|
+
{:else}
|
|
175
|
+
<!-- Modal: Components -->
|
|
176
|
+
<!-- Note: keep `contents` class to allow widths from children -->
|
|
177
|
+
<div
|
|
178
|
+
class="modal contents {$modalStore[0].modalClasses ?? ''}"
|
|
179
|
+
data-testid="modal-component"
|
|
180
|
+
role="dialog"
|
|
181
|
+
aria-modal="true"
|
|
182
|
+
aria-label={$modalStore[0].title ?? ''}
|
|
183
|
+
>
|
|
184
|
+
<svelte:component this={currentComponent?.ref} {...currentComponent?.props} {parent}>
|
|
185
|
+
{@html currentComponent?.slot}
|
|
186
|
+
</svelte:component>
|
|
187
|
+
</div>
|
|
156
188
|
{/if}
|
|
157
189
|
</div>
|
|
158
190
|
</div>
|
|
@@ -1,26 +1,55 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { ModalComponent } from './types';
|
|
2
3
|
declare const __propDef: {
|
|
3
4
|
props: {
|
|
4
5
|
[x: string]: any;
|
|
6
|
+
/** Set the modal position within the backdrop container*/
|
|
7
|
+
position?: string | undefined;
|
|
8
|
+
/** Register a list of reusable component modals.*/
|
|
9
|
+
components?: Record<string, ModalComponent> | undefined;
|
|
10
|
+
/** The open/close animation duration. Set '0' (zero) to disable.*/
|
|
5
11
|
duration?: number | undefined;
|
|
12
|
+
/** Set the fly transition opacity.*/
|
|
13
|
+
flyOpacity?: number | undefined;
|
|
14
|
+
/** Set the fly transition X axis value.*/
|
|
15
|
+
flyX?: number | undefined;
|
|
16
|
+
/** Set the fly transition Y axis value.*/
|
|
17
|
+
flyY?: number | undefined;
|
|
18
|
+
/** Provide classes to style the modal background.*/
|
|
6
19
|
background?: string | undefined;
|
|
20
|
+
/** Provide classes to style the modal width.*/
|
|
7
21
|
width?: string | undefined;
|
|
22
|
+
/** Provide classes to style the modal.*/
|
|
8
23
|
height?: string | undefined;
|
|
24
|
+
/** Provide classes to style the modal padding.*/
|
|
9
25
|
padding?: string | undefined;
|
|
26
|
+
/** Provide classes to style the modal spacing.*/
|
|
10
27
|
spacing?: string | undefined;
|
|
28
|
+
/** Provide classes to style the modal border radius.*/
|
|
11
29
|
rounded?: string | undefined;
|
|
30
|
+
/** Provide classes to style modal box shadow.*/
|
|
12
31
|
shadow?: string | undefined;
|
|
32
|
+
/** Provide classes for neutral buttons, such as Cancel.*/
|
|
13
33
|
buttonNeutral?: string | undefined;
|
|
34
|
+
/** Provide classes for positive actions, such as Confirm or Submit.*/
|
|
14
35
|
buttonPositive?: string | undefined;
|
|
36
|
+
/** Override the text for the Cancel button.*/
|
|
15
37
|
buttonTextCancel?: string | undefined;
|
|
38
|
+
/** Override the text for the Confirm button.*/
|
|
16
39
|
buttonTextConfirm?: string | undefined;
|
|
40
|
+
/** Override the text for the Submit button.*/
|
|
17
41
|
buttonTextSubmit?: string | undefined;
|
|
42
|
+
/** Provide classes to style the backdrop.*/
|
|
18
43
|
regionBackdrop?: string | undefined;
|
|
44
|
+
/** Provide arbitrary classes to modal header region.*/
|
|
19
45
|
regionHeader?: string | undefined;
|
|
46
|
+
/** Provide arbitrary classes to modal body region.*/
|
|
20
47
|
regionBody?: string | undefined;
|
|
48
|
+
/** Provide arbitrary classes to modal footer region.*/
|
|
21
49
|
regionFooter?: string | undefined;
|
|
22
50
|
};
|
|
23
51
|
events: {
|
|
52
|
+
/** {{ event }} backdrop - Fires on backdrop interaction.*/
|
|
24
53
|
backdrop: CustomEvent<any>;
|
|
25
54
|
} & {
|
|
26
55
|
[evt: string]: CustomEvent<any>;
|
|
@@ -9,16 +9,20 @@ export interface ModalComponent {
|
|
|
9
9
|
export interface ModalSettings {
|
|
10
10
|
/** Designate what type of component will display. */
|
|
11
11
|
type: 'alert' | 'confirm' | 'prompt' | 'component';
|
|
12
|
+
/** Set the modal position within the backdrop container. */
|
|
13
|
+
position?: string;
|
|
12
14
|
/** Provide the modal header content. Accepts HTML. */
|
|
13
15
|
title?: string;
|
|
14
16
|
/** Provide the modal body content. Accepts HTML. */
|
|
15
17
|
body?: string;
|
|
16
18
|
/** Provide a URL to display an image within the modal. */
|
|
17
|
-
image?:
|
|
18
|
-
/**
|
|
19
|
-
value?:
|
|
20
|
-
/** Provide
|
|
21
|
-
|
|
19
|
+
image?: string;
|
|
20
|
+
/** By default, used to provide a prompt value. */
|
|
21
|
+
value?: any;
|
|
22
|
+
/** Provide input attributes as key/value pairs. */
|
|
23
|
+
valueAttr?: object;
|
|
24
|
+
/** Provide your component reference key or object. */
|
|
25
|
+
component?: ModalComponent | string;
|
|
22
26
|
/** Provide a function. Returns the repsonse value. */
|
|
23
27
|
response?: (r: any) => void;
|
|
24
28
|
/** Provide abitrary classes to the backdrop. */
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Writable } from 'svelte/store';
|
|
2
|
+
import type { PopupSettings } from './types';
|
|
3
|
+
export declare const storePopup: Writable<any>;
|
|
4
|
+
export declare function popup(node: HTMLElement, args: PopupSettings): {
|
|
5
|
+
update(newArgs: any): void;
|
|
6
|
+
destroy(): void;
|
|
7
|
+
} | undefined;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { get, writable } from 'svelte/store';
|
|
2
|
+
// Store
|
|
3
|
+
export const storePopup = writable(undefined);
|
|
4
|
+
// Action
|
|
5
|
+
export function popup(node, args) {
|
|
6
|
+
// prettier-ignore
|
|
7
|
+
const { event = 'click', target, placement, closeQuery = 'a[href], button', middleware, state } = args;
|
|
8
|
+
if (!event || !target)
|
|
9
|
+
return;
|
|
10
|
+
// Local
|
|
11
|
+
const { computePosition, autoUpdate, flip, shift, offset, arrow } = get(storePopup);
|
|
12
|
+
const elemPopup = document.querySelector(`[data-popup="${target}"]`);
|
|
13
|
+
const elemArrow = elemPopup?.querySelector(`.arrow`) ?? null;
|
|
14
|
+
let isVisible = false;
|
|
15
|
+
// Local A11y Variables
|
|
16
|
+
const elemWhitelist = 'a[href], button, input, textarea, select, details, [tabindex]:not([tabindex="-1"])';
|
|
17
|
+
let activeFocusIdx;
|
|
18
|
+
let focusableElems;
|
|
19
|
+
// On Init (floating ui)
|
|
20
|
+
function render() {
|
|
21
|
+
if (!elemPopup || !computePosition)
|
|
22
|
+
return;
|
|
23
|
+
// Construct Middlware
|
|
24
|
+
// Note the order: https://floating-ui.com/docs/middleware#ordering
|
|
25
|
+
const genMiddlware = [];
|
|
26
|
+
// https://floating-ui.com/docs/offset
|
|
27
|
+
if (offset)
|
|
28
|
+
genMiddlware.push(offset(middleware?.offset ?? 8));
|
|
29
|
+
// https://floating-ui.com/docs/shift
|
|
30
|
+
if (shift)
|
|
31
|
+
genMiddlware.push(shift(middleware?.shift ?? { padding: 8 }));
|
|
32
|
+
// https://floating-ui.com/docs/flip
|
|
33
|
+
if (flip)
|
|
34
|
+
genMiddlware.push(flip(middleware?.flip));
|
|
35
|
+
// https://floating-ui.com/docs/arrow
|
|
36
|
+
if (arrow && elemArrow)
|
|
37
|
+
genMiddlware.push(arrow(middleware?.arrow ?? { element: elemArrow }));
|
|
38
|
+
// https://floating-ui.com/docs/computePosition
|
|
39
|
+
computePosition(node, elemPopup, {
|
|
40
|
+
placement: placement ?? 'bottom',
|
|
41
|
+
middleware: genMiddlware
|
|
42
|
+
}).then(({ x, y, placement, middlewareData }) => {
|
|
43
|
+
Object.assign(elemPopup.style, {
|
|
44
|
+
left: `${x}px`,
|
|
45
|
+
top: `${y}px`
|
|
46
|
+
});
|
|
47
|
+
// Handle Arrow Placement:
|
|
48
|
+
// https://floating-ui.com/docs/arrow
|
|
49
|
+
if (elemArrow) {
|
|
50
|
+
const { x: arrowX, y: arrowY } = middlewareData.arrow;
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
const staticSide = {
|
|
53
|
+
top: 'bottom',
|
|
54
|
+
right: 'left',
|
|
55
|
+
bottom: 'top',
|
|
56
|
+
left: 'right'
|
|
57
|
+
}[placement.split('-')[0]];
|
|
58
|
+
Object.assign(elemArrow.style, {
|
|
59
|
+
left: arrowX != null ? `${arrowX}px` : '',
|
|
60
|
+
top: arrowY != null ? `${arrowY}px` : '',
|
|
61
|
+
right: '',
|
|
62
|
+
bottom: '',
|
|
63
|
+
[staticSide]: '-4px'
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
// Set Focusable State
|
|
68
|
+
setFocusableState();
|
|
69
|
+
}
|
|
70
|
+
// Set Focusable State
|
|
71
|
+
function setFocusableState() {
|
|
72
|
+
if (!elemPopup)
|
|
73
|
+
return;
|
|
74
|
+
// Create array of all focusable elements, so that we can iterate through them
|
|
75
|
+
focusableElems = Array.from(elemPopup?.querySelectorAll(elemWhitelist));
|
|
76
|
+
// reset the focus index
|
|
77
|
+
activeFocusIdx = -1;
|
|
78
|
+
// Automatically focus the element if openWithFocus is true (for example if
|
|
79
|
+
// the menu was opened with Enter instead of with a click
|
|
80
|
+
activeFocusIdx = 0;
|
|
81
|
+
focusableElems[0]?.focus();
|
|
82
|
+
}
|
|
83
|
+
// Window Click Handler
|
|
84
|
+
const onWindowClick = (event) => {
|
|
85
|
+
if (!node || !elemPopup)
|
|
86
|
+
return;
|
|
87
|
+
// If click is within the trigger node
|
|
88
|
+
const clickTriggerNode = node.contains(event.target);
|
|
89
|
+
if (clickTriggerNode) {
|
|
90
|
+
isVisible == false ? show() : close();
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// If click is outside the popup
|
|
94
|
+
const clickedOutsidePopup = elemPopup && !elemPopup.contains(event.target);
|
|
95
|
+
if (clickedOutsidePopup) {
|
|
96
|
+
close();
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
// If click is interactive child element within popup (ex: anchor or button)
|
|
100
|
+
const interactiveMenuElems = elemPopup?.querySelectorAll(closeQuery);
|
|
101
|
+
if (!interactiveMenuElems.length)
|
|
102
|
+
return;
|
|
103
|
+
interactiveMenuElems.forEach((elem) => {
|
|
104
|
+
if (elem.contains(event.target))
|
|
105
|
+
close();
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
// Hover Handlers
|
|
111
|
+
const onMouseOver = () => {
|
|
112
|
+
show();
|
|
113
|
+
isVisible = true;
|
|
114
|
+
stateEventHandler(true);
|
|
115
|
+
};
|
|
116
|
+
const onMouseOut = () => {
|
|
117
|
+
close();
|
|
118
|
+
isVisible = false;
|
|
119
|
+
stateEventHandler(false);
|
|
120
|
+
};
|
|
121
|
+
// Visbility
|
|
122
|
+
function show() {
|
|
123
|
+
if (!elemPopup)
|
|
124
|
+
return;
|
|
125
|
+
render(); // update
|
|
126
|
+
elemPopup.style.display = 'block';
|
|
127
|
+
elemPopup.style.opacity = '1';
|
|
128
|
+
elemPopup.style.pointerEvents = 'initial';
|
|
129
|
+
isVisible = true;
|
|
130
|
+
stateEventHandler(true);
|
|
131
|
+
}
|
|
132
|
+
function close() {
|
|
133
|
+
if (!elemPopup)
|
|
134
|
+
return;
|
|
135
|
+
elemPopup.style.opacity = '0';
|
|
136
|
+
const cssTransitionDuration = parseFloat(window.getComputedStyle(elemPopup).transitionDuration.replace('s', '')) * 1000;
|
|
137
|
+
setTimeout(() => {
|
|
138
|
+
elemPopup.style.display = 'hidden';
|
|
139
|
+
elemPopup.style.pointerEvents = 'none';
|
|
140
|
+
isVisible = false;
|
|
141
|
+
stateEventHandler(false);
|
|
142
|
+
}, cssTransitionDuration);
|
|
143
|
+
}
|
|
144
|
+
// State Handler
|
|
145
|
+
const stateEventHandler = (value) => {
|
|
146
|
+
if (state)
|
|
147
|
+
state({ state: value });
|
|
148
|
+
};
|
|
149
|
+
// A11y Keydown Handler
|
|
150
|
+
const onWindowKeyDown = (event) => {
|
|
151
|
+
if (!isVisible)
|
|
152
|
+
return;
|
|
153
|
+
// Handle keys
|
|
154
|
+
const key = event.key;
|
|
155
|
+
// TODO: || (document.activeElement !== node && key === 'Tab')
|
|
156
|
+
if (key === 'Escape') {
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
close();
|
|
159
|
+
node.focus();
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
else if (key === 'ArrowDown') {
|
|
163
|
+
event.preventDefault();
|
|
164
|
+
if (activeFocusIdx < focusableElems.length - 1) {
|
|
165
|
+
// Move down the menu
|
|
166
|
+
activeFocusIdx += 1;
|
|
167
|
+
focusableElems[activeFocusIdx]?.focus();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else if (key === 'ArrowUp') {
|
|
171
|
+
event.preventDefault();
|
|
172
|
+
if (activeFocusIdx > 0) {
|
|
173
|
+
// Move up the menu
|
|
174
|
+
activeFocusIdx -= 1;
|
|
175
|
+
focusableElems[activeFocusIdx]?.focus();
|
|
176
|
+
}
|
|
177
|
+
else if (focusableElems.length && activeFocusIdx === -1) {
|
|
178
|
+
// Start at the bottom of the menu if first key is arrow up key
|
|
179
|
+
event.preventDefault();
|
|
180
|
+
activeFocusIdx = focusableElems.length - 1;
|
|
181
|
+
focusableElems[activeFocusIdx]?.focus();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
// On Init
|
|
186
|
+
render();
|
|
187
|
+
// Auto Update
|
|
188
|
+
autoUpdate(node, elemPopup, render);
|
|
189
|
+
// Event Listners
|
|
190
|
+
if (event === 'click') {
|
|
191
|
+
window.addEventListener('click', onWindowClick, true);
|
|
192
|
+
// node.addEventListener('click', onNodeClick, true);
|
|
193
|
+
}
|
|
194
|
+
if (event === 'hover') {
|
|
195
|
+
node.addEventListener('mouseover', show, true);
|
|
196
|
+
node.addEventListener('mouseout', close, true);
|
|
197
|
+
}
|
|
198
|
+
if (event === 'hover-click') {
|
|
199
|
+
node.addEventListener('mouseover', show, true);
|
|
200
|
+
window.addEventListener('click', onWindowClick, true);
|
|
201
|
+
}
|
|
202
|
+
// A11y Event Listeners
|
|
203
|
+
window.addEventListener('keydown', onWindowKeyDown, true);
|
|
204
|
+
// Lifecycle
|
|
205
|
+
return {
|
|
206
|
+
update(newArgs) {
|
|
207
|
+
args = newArgs;
|
|
208
|
+
},
|
|
209
|
+
destroy() {
|
|
210
|
+
window.removeEventListener('click', onWindowClick, true);
|
|
211
|
+
// node.removeEventListener('click', onNodeClick, true);
|
|
212
|
+
node.removeEventListener('mouseover', onMouseOver, true);
|
|
213
|
+
node.removeEventListener('mouseout', onMouseOut, true);
|
|
214
|
+
// ---
|
|
215
|
+
window.removeEventListener('keydown', onWindowKeyDown, true);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
type Direction = 'top' | 'bottom' | 'left' | 'right';
|
|
2
|
+
/** Placement https://floating-ui.com/docs/computePosition#placement */
|
|
3
|
+
type Placement = Direction | `${Direction}-start` | `${Direction}-end`;
|
|
4
|
+
interface Middlware {
|
|
5
|
+
/** Offset options: https://floating-ui.com/docs/offset */
|
|
6
|
+
offset?: number | Record<string, any>;
|
|
7
|
+
/** Shift options: https://floating-ui.com/docs/shift */
|
|
8
|
+
shift?: Record<string, any>;
|
|
9
|
+
/** Flip options: https://floating-ui.com/docs/flip */
|
|
10
|
+
flip?: Record<string, any>;
|
|
11
|
+
/** Arrow options: https://floating-ui.com/docs/arrow */
|
|
12
|
+
arrow?: {
|
|
13
|
+
element: string;
|
|
14
|
+
} & Record<string, any>;
|
|
15
|
+
}
|
|
16
|
+
export interface PopupSettings {
|
|
17
|
+
/** Provide the event type. */
|
|
18
|
+
event: 'click' | 'hover' | 'hover-click';
|
|
19
|
+
/** Match the popup data value `[data-popup]="targetNameHere"` */
|
|
20
|
+
target: string;
|
|
21
|
+
/** Set the placement position. Defaults 'bottom'. */
|
|
22
|
+
placement?: Placement;
|
|
23
|
+
/** Query list of elements that will close the popup. Default: `'a[href], button'`. */
|
|
24
|
+
closeQuery?: string;
|
|
25
|
+
/** Provide additional options and middleware settings. */
|
|
26
|
+
middleware?: Middlware;
|
|
27
|
+
/** Provide an optional callback function to monitor open/close state. */
|
|
28
|
+
state?: (event: {
|
|
29
|
+
state: boolean;
|
|
30
|
+
}) => void;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
<script>import { fly } from "svelte/transition";
|
|
2
|
+
import { flip } from "svelte/animate";
|
|
2
3
|
import { toastStore } from "./stores";
|
|
3
4
|
export let position = "b";
|
|
4
5
|
export let max = 3;
|
|
5
6
|
export let duration = 150;
|
|
6
|
-
export let background = "
|
|
7
|
+
export let background = "variant-filled-secondary";
|
|
7
8
|
export let width = "max-w-[640px]";
|
|
8
|
-
export let color = "
|
|
9
|
+
export let color = "";
|
|
9
10
|
export let padding = "p-4";
|
|
10
11
|
export let spacing = "space-x-4";
|
|
11
12
|
export let rounded = "rounded-container-token";
|
|
12
13
|
export let shadow = "shadow-lg";
|
|
13
|
-
export let buttonAction = "variant-filled";
|
|
14
|
-
export let buttonDismiss = "variant-filled";
|
|
14
|
+
export let buttonAction = "btn variant-filled";
|
|
15
|
+
export let buttonDismiss = "btn-icon btn-icon-sm variant-filled";
|
|
16
|
+
export let buttonDismissLabel = "\u2715";
|
|
15
17
|
const cWrapper = "flex fixed top-0 left-0 right-0 bottom-0 z-[888] pointer-events-none";
|
|
16
18
|
const cSnackbar = "flex flex-col space-y-2";
|
|
17
19
|
const cToast = "flex justify-between items-center pointer-events-auto";
|
|
20
|
+
const cToastActions = "flex items-center space-x-2";
|
|
18
21
|
let cPosition;
|
|
19
22
|
let cAlign;
|
|
20
23
|
let animAxis = { x: 0, y: 0 };
|
|
@@ -69,7 +72,9 @@ $:
|
|
|
69
72
|
$:
|
|
70
73
|
classesSnackbar = `${cSnackbar} ${cAlign} ${padding}`;
|
|
71
74
|
$:
|
|
72
|
-
|
|
75
|
+
classesToast = `${cToast} ${width} ${color} ${padding} ${spacing} ${rounded} ${shadow}`;
|
|
76
|
+
$:
|
|
77
|
+
filteredToasts = Array.from($toastStore).slice(0, max);
|
|
73
78
|
</script>
|
|
74
79
|
|
|
75
80
|
{#if $toastStore.length}
|
|
@@ -77,18 +82,17 @@ $:
|
|
|
77
82
|
<div class="snackbar-wrapper {classesWrapper}" data-testid="snackbar-wrapper">
|
|
78
83
|
<!-- List -->
|
|
79
84
|
<div class="snackbar {classesSnackbar}" transition:fly={{ x: animAxis.x, y: animAxis.y, duration }}>
|
|
80
|
-
{#each
|
|
81
|
-
|
|
85
|
+
{#each filteredToasts as t, i (t)}
|
|
86
|
+
<div animate:flip={{ duration }}>
|
|
82
87
|
<!-- Toast -->
|
|
83
|
-
<div class="toast {
|
|
88
|
+
<div class="toast {classesToast} {t.background ?? background} {t.classes}" role="alert" aria-live="polite" data-testid="toast">
|
|
84
89
|
<div class="text-base">{@html t.message}</div>
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
<button class="btn-icon {buttonDismiss}" on:click={() => { toastStore.close(t.id) }}>✕</button>
|
|
90
|
+
<div class="toast-actions {cToastActions}">
|
|
91
|
+
{#if t.action}<button class={buttonAction} on:click={() => onAction(i)}>{@html t.action.label}</button>{/if}
|
|
92
|
+
<button class={buttonDismiss} on:click={() => toastStore.close(t.id)}>{buttonDismissLabel}</button>
|
|
89
93
|
</div>
|
|
90
94
|
</div>
|
|
91
|
-
|
|
95
|
+
</div>
|
|
92
96
|
{/each}
|
|
93
97
|
</div>
|
|
94
98
|
</div>
|
|
@@ -2,18 +2,32 @@ import { SvelteComponentTyped } from "svelte";
|
|
|
2
2
|
declare const __propDef: {
|
|
3
3
|
props: {
|
|
4
4
|
[x: string]: any;
|
|
5
|
+
/** Set the toast position.*/
|
|
5
6
|
position?: string | undefined;
|
|
7
|
+
/** Maximum toasts that can show at once.*/
|
|
6
8
|
max?: number | undefined;
|
|
9
|
+
/** The duration of the fly in/out animation.*/
|
|
7
10
|
duration?: number | undefined;
|
|
11
|
+
/** Provide classes to set the background color.*/
|
|
8
12
|
background?: string | undefined;
|
|
13
|
+
/** Provide classes to set width styles.*/
|
|
9
14
|
width?: string | undefined;
|
|
15
|
+
/** Provide classes to set the text color.*/
|
|
10
16
|
color?: string | undefined;
|
|
17
|
+
/** Provide classes to set the padding.*/
|
|
11
18
|
padding?: string | undefined;
|
|
19
|
+
/** Provide classes to set toast horizontal spacing.*/
|
|
12
20
|
spacing?: string | undefined;
|
|
21
|
+
/** Provide classes to set the border radius styles.*/
|
|
13
22
|
rounded?: string | undefined;
|
|
23
|
+
/** Provide classes to set the border box shadow.*/
|
|
14
24
|
shadow?: string | undefined;
|
|
25
|
+
/** Provide styles for the action button.*/
|
|
15
26
|
buttonAction?: string | undefined;
|
|
27
|
+
/** Provide styles for the dismiss button.*/
|
|
16
28
|
buttonDismiss?: string | undefined;
|
|
29
|
+
/** The button label text.*/
|
|
30
|
+
buttonDismissLabel?: string | undefined;
|
|
17
31
|
};
|
|
18
32
|
events: {
|
|
19
33
|
[evt: string]: CustomEvent<any>;
|