@skeletonlabs/skeleton 0.124.2 → 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.
Files changed (73) hide show
  1. package/README.md +1 -1
  2. package/components/Accordion/Accordion.svelte +4 -0
  3. package/components/Accordion/Accordion.svelte.d.ts +4 -0
  4. package/components/Accordion/AccordionItem.svelte +14 -5
  5. package/components/Accordion/AccordionItem.svelte.d.ts +4 -1
  6. package/components/ConicGradient/settings.d.ts +0 -2
  7. package/components/ConicGradient/settings.js +0 -1
  8. package/components/FileButton/FileButton.svelte +1 -1
  9. package/components/FileDropzone/FileDropzone.svelte +1 -1
  10. package/components/InputChip/InputChip.svelte +3 -3
  11. package/components/ListBox/ListBoxItem.svelte +3 -3
  12. package/components/ListBox/ListBoxItem.svelte.d.ts +2 -1
  13. package/components/Paginator/Paginator.svelte +3 -3
  14. package/components/Radio/RadioItem.svelte +2 -2
  15. package/components/Radio/RadioItem.svelte.d.ts +2 -1
  16. package/components/RangeSlider/RangeSlider.svelte.d.ts +4 -4
  17. package/components/Stepper/Step.svelte +3 -3
  18. package/components/Tab/Tab.svelte +2 -2
  19. package/components/Tab/Tab.svelte.d.ts +2 -1
  20. package/index.d.ts +3 -3
  21. package/index.js +9 -3
  22. package/package.json +10 -11
  23. package/styles/elements/forms.css +5 -9
  24. package/styles/elements/modals.css +15 -0
  25. package/styles/elements/popups.css +16 -0
  26. package/styles/elements.css +2 -2
  27. package/styles/typography.css +3 -3
  28. package/tailwind/core.cjs +1 -1
  29. package/tailwind/generated/intellisense-classes.cjs +1 -1
  30. package/tailwind/generated/intellisense-classes.d.cts +65 -208
  31. package/tailwind/intellisense.cjs +2 -2
  32. package/tailwind/skeleton.cjs +1 -1
  33. package/types/index.d.ts +1 -0
  34. package/types/index.js +1 -0
  35. package/types/tailwind.d.ts +4 -0
  36. package/types/tailwind.js +2 -0
  37. package/utilities/CodeBlock/CodeBlock.svelte +12 -8
  38. package/utilities/CodeBlock/CodeBlock.svelte.d.ts +9 -1
  39. package/utilities/Drawer/Drawer.svelte +50 -37
  40. package/utilities/Drawer/Drawer.svelte.d.ts +8 -2
  41. package/utilities/Drawer/types.d.ts +8 -2
  42. package/utilities/LightSwitch/LightSwitch.svelte +43 -53
  43. package/utilities/LightSwitch/LightSwitch.svelte.d.ts +18 -4
  44. package/utilities/LightSwitch/lightswitch.d.ts +20 -0
  45. package/utilities/LightSwitch/lightswitch.js +71 -0
  46. package/utilities/LocalStorageStore/LocalStorageStore.js +1 -1
  47. package/utilities/Modal/Modal.svelte +96 -64
  48. package/utilities/Modal/Modal.svelte.d.ts +11 -0
  49. package/utilities/Modal/types.d.ts +9 -5
  50. package/utilities/Popup/popup.d.ts +7 -0
  51. package/utilities/Popup/popup.js +218 -0
  52. package/utilities/Popup/types.d.ts +32 -0
  53. package/utilities/Popup/types.js +3 -0
  54. package/utilities/Toast/Toast.svelte +17 -13
  55. package/utilities/Toast/Toast.svelte.d.ts +5 -3
  56. package/utilities/Toast/stores.js +9 -26
  57. package/utilities/Toast/types.d.ts +6 -1
  58. package/styles/elements/menus.css +0 -29
  59. package/styles/elements/tooltips.css +0 -83
  60. package/utilities/LightSwitch/stores.d.ts +0 -2
  61. package/utilities/LightSwitch/stores.js +0 -5
  62. package/utilities/Menu/menu.d.ts +0 -18
  63. package/utilities/Menu/menu.js +0 -151
  64. package/utilities/Modal/examples/ModalExampleEmbed.svelte +0 -17
  65. package/utilities/Modal/examples/ModalExampleEmbed.svelte.d.ts +0 -17
  66. package/utilities/Modal/examples/ModalExampleForm.svelte +0 -41
  67. package/utilities/Modal/examples/ModalExampleForm.svelte.d.ts +0 -17
  68. package/utilities/Modal/examples/ModalExampleImage.svelte +0 -19
  69. package/utilities/Modal/examples/ModalExampleImage.svelte.d.ts +0 -16
  70. package/utilities/Modal/examples/ModalExampleList.svelte +0 -26
  71. package/utilities/Modal/examples/ModalExampleList.svelte.d.ts +0 -17
  72. package/utilities/Tooltip/tooltip.d.ts +0 -35
  73. 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-full max-w-[640px]";
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-primary";
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] flex justify-center items-center p-4";
24
- const cModal = "max-h-full overflow-y-auto overflow-x-hidden";
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
- modalStore.subscribe((dArr) => {
33
- if (!dArr.length)
38
+ let currentComponent;
39
+ modalStore.subscribe((modals) => {
40
+ if (!modals.length)
34
41
  return;
35
- promptValue = dArr[0].value;
36
- buttonTextCancel = dArr[0].buttonTextCancel || buttonTextDefaults.buttonTextCancel;
37
- buttonTextConfirm = dArr[0].buttonTextConfirm || buttonTextDefaults.buttonTextConfirm;
38
- buttonTextSubmit = dArr[0].buttonTextSubmit || buttonTextDefaults.buttonTextSubmit;
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
- classesBackdrop = `${cBackdrop} ${regionBackdrop} ${$$props.class || ""}`;
80
+ cPosition = $modalStore[0]?.position ?? position;
81
+ $:
82
+ classesBackdrop = `${cBackdrop} ${regionBackdrop} ${$$props.class ?? ""} ${$modalStore[0]?.backdropClasses ?? ""}`;
70
83
  $:
71
- classesModal = `${cModal} ${background} ${width} ${height} ${padding} ${spacing} ${rounded} ${shadow}`;
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} {$modalStore[0].backdropClasses}"
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
- data-testid="modal-backdrop"
125
+ use:focusTrap={true}
105
126
  >
106
- <!-- Modal -->
107
- <div
108
- class="modal {classesModal} {$modalStore[0].modalClasses}"
109
- transition:fly={{ duration, opacity: 0, y: 100 }}
110
- use:focusTrap={true}
111
- data-testid="modal"
112
- role="dialog"
113
- aria-modal="true"
114
- aria-label={$modalStore[0].title}
115
- >
116
- <!-- Header -->
117
- {#if $modalStore[0]?.title}
118
- <header class="modal-header {regionHeader}">{@html $modalStore[0].title}</header>
119
- {/if}
120
- <!-- Body -->
121
- {#if $modalStore[0]?.body}
122
- <article class="modal-body {regionBody}">{@html $modalStore[0].body}</article>
123
- {/if}
124
- <!-- Image -->
125
- {#if $modalStore[0]?.image && typeof $modalStore[0]?.image === 'string'}
126
- <img class="modal-image {cModalImage}" src={$modalStore[0]?.image} alt="Modal" />
127
- {/if}
128
- <!-- Type -->
129
- {#if $modalStore[0].type === 'alert'}
130
- <!-- Template: Alert -->
131
- <footer class="modal-footer {regionFooter}">
132
- <!-- prettier-ignore -->
133
- <button class="btn {buttonNeutral}" on:click={onClose}>{buttonTextCancel}</button>
134
- </footer>
135
- {:else if $modalStore[0].type === 'confirm'}
136
- <!-- Template: Confirm -->
137
- <!-- prettier-ignore -->
138
- <footer class="modal-footer {regionFooter}">
139
- <button class="btn {buttonNeutral}" on:click={onClose}>{buttonTextCancel}</button>
140
- <button class="btn {buttonPositive}" on:click={onConfirm}>{buttonTextConfirm}</button>
141
- </footer>
142
- {:else if $modalStore[0].type === 'prompt'}
143
- <!-- Template: Prompt -->
144
- <input class="modal-prompt-input input" type="text" bind:value={promptValue} />
145
- <!-- prettier-ignore -->
146
- <footer class="modal-footer {regionFooter}">
147
- <button class="btn {buttonNeutral}" on:click={onClose}>{buttonTextCancel}</button>
148
- <button class="btn {buttonPositive}" on:click={onPromptSubmit} disabled={!promptValue}>{buttonTextSubmit}</button>
149
- </footer>
150
- {:else if $modalStore[0].type === 'component'}
151
- <!-- Template: Component -->
152
- <!-- NOTE: users are repsonsible for handling all UI, including cancel/submit buttons -->
153
- <svelte:component this={$modalStore[0].component?.ref} {...$modalStore[0].component?.props} {parent}>
154
- {@html $modalStore[0].component?.slot}
155
- </svelte:component>
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,9 +1,20 @@
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;
5
10
  /** The open/close animation duration. Set '0' (zero) to disable.*/
6
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;
7
18
  /** Provide classes to style the modal background.*/
8
19
  background?: string | undefined;
9
20
  /** Provide classes to style the modal width.*/
@@ -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?: URL | string;
18
- /** Prompt Only - provide a prompt value. */
19
- value?: unknown;
20
- /** Provide your component reference, props, and slot details. */
21
- component?: ModalComponent;
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 {};
@@ -0,0 +1,3 @@
1
+ // Popup Types
2
+ // Note: these are a simple iteration based on the official docs.
3
+ 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 = "bg-secondary-500";
7
+ export let background = "variant-filled-secondary";
7
8
  export let width = "max-w-[640px]";
8
- export let color = "text-on-secondary-token";
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
- classesBase = `${cToast} ${background} ${width} ${color} ${padding} ${spacing} ${rounded} ${shadow}`;
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 $toastStore as t, i}
81
- {#if i < max}
85
+ {#each filteredToasts as t, i (t)}
86
+ <div animate:flip={{ duration }}>
82
87
  <!-- Toast -->
83
- <div class="toast {classesBase} {t.classes}" role="alert" aria-live="polite" data-testid="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
- <!-- prettier-ignore -->
86
- <div class="flex items-center space-x-2">
87
- {#if t.action}<button class="btn {buttonAction}" on:click={() => onAction(i)}>{@html t.action.label}</button>{/if}
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
- {/if}
95
+ </div>
92
96
  {/each}
93
97
  </div>
94
98
  </div>
@@ -16,16 +16,18 @@ declare const __propDef: {
16
16
  color?: string | undefined;
17
17
  /** Provide classes to set the padding.*/
18
18
  padding?: string | undefined;
19
- /** Provide classes to set the horizontal spacing.*/
19
+ /** Provide classes to set toast horizontal spacing.*/
20
20
  spacing?: string | undefined;
21
21
  /** Provide classes to set the border radius styles.*/
22
22
  rounded?: string | undefined;
23
23
  /** Provide classes to set the border box shadow.*/
24
24
  shadow?: string | undefined;
25
- /** Provide action button styles.*/
25
+ /** Provide styles for the action button.*/
26
26
  buttonAction?: string | undefined;
27
- /** Provide dismiss button styles.*/
27
+ /** Provide styles for the dismiss button.*/
28
28
  buttonDismiss?: string | undefined;
29
+ /** The button label text.*/
30
+ buttonDismissLabel?: string | undefined;
29
31
  };
30
32
  events: {
31
33
  [evt: string]: CustomEvent<any>;