@skeletonlabs/skeleton 0.76.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.
Files changed (173) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +33 -0
  3. package/actions/Clipboard/clipboard.d.ts +4 -0
  4. package/actions/Clipboard/clipboard.js +37 -0
  5. package/actions/Filters/filter.d.ts +3 -0
  6. package/actions/Filters/filter.js +23 -0
  7. package/actions/Filters/svg-filters/Apollo.svelte +13 -0
  8. package/actions/Filters/svg-filters/Apollo.svelte.d.ts +19 -0
  9. package/actions/Filters/svg-filters/BlueNight.svelte +12 -0
  10. package/actions/Filters/svg-filters/BlueNight.svelte.d.ts +19 -0
  11. package/actions/Filters/svg-filters/Emerald.svelte +23 -0
  12. package/actions/Filters/svg-filters/Emerald.svelte.d.ts +19 -0
  13. package/actions/Filters/svg-filters/GreenFall.svelte +18 -0
  14. package/actions/Filters/svg-filters/GreenFall.svelte.d.ts +19 -0
  15. package/actions/Filters/svg-filters/Noir.svelte +11 -0
  16. package/actions/Filters/svg-filters/Noir.svelte.d.ts +19 -0
  17. package/actions/Filters/svg-filters/NoirLight.svelte +10 -0
  18. package/actions/Filters/svg-filters/NoirLight.svelte.d.ts +19 -0
  19. package/actions/Filters/svg-filters/Rustic.svelte +14 -0
  20. package/actions/Filters/svg-filters/Rustic.svelte.d.ts +19 -0
  21. package/actions/Filters/svg-filters/Summer84.svelte +12 -0
  22. package/actions/Filters/svg-filters/Summer84.svelte.d.ts +19 -0
  23. package/actions/Filters/svg-filters/XPro.svelte +12 -0
  24. package/actions/Filters/svg-filters/XPro.svelte.d.ts +19 -0
  25. package/actions/FocusTrap/focusTrap.d.ts +4 -0
  26. package/actions/FocusTrap/focusTrap.js +42 -0
  27. package/components/Accordion/AccordionGroup.svelte +47 -0
  28. package/components/Accordion/AccordionGroup.svelte.d.ts +24 -0
  29. package/components/Accordion/AccordionItem.svelte +70 -0
  30. package/components/Accordion/AccordionItem.svelte.d.ts +35 -0
  31. package/components/Alert/Alert.svelte +65 -0
  32. package/components/Alert/Alert.svelte.d.ts +30 -0
  33. package/components/AppBar/AppBar.svelte +54 -0
  34. package/components/AppBar/AppBar.svelte.d.ts +30 -0
  35. package/components/AppRail/AppRail.svelte +48 -0
  36. package/components/AppRail/AppRail.svelte.d.ts +31 -0
  37. package/components/AppRail/AppRailTile.svelte +51 -0
  38. package/components/AppRail/AppRailTile.svelte.d.ts +33 -0
  39. package/components/AppShell/AppShell.svelte +80 -0
  40. package/components/AppShell/AppShell.svelte.d.ts +31 -0
  41. package/components/Avatar/Avatar.svelte +46 -0
  42. package/components/Avatar/Avatar.svelte.d.ts +32 -0
  43. package/components/Breadcrumb/Breadcrumb.svelte +24 -0
  44. package/components/Breadcrumb/Breadcrumb.svelte.d.ts +21 -0
  45. package/components/Breadcrumb/Crumb.svelte +29 -0
  46. package/components/Breadcrumb/Crumb.svelte.d.ts +21 -0
  47. package/components/ConicGradient/ConicGradient.svelte +80 -0
  48. package/components/ConicGradient/ConicGradient.svelte.d.ts +24 -0
  49. package/components/ConicGradient/types.d.ts +10 -0
  50. package/components/ConicGradient/types.js +2 -0
  51. package/components/Divider/Divider.svelte +21 -0
  52. package/components/Divider/Divider.svelte.d.ts +22 -0
  53. package/components/FileButton/FileButton.svelte +25 -0
  54. package/components/FileButton/FileButton.svelte.d.ts +22 -0
  55. package/components/FileDropzone/FileDropzone.svelte +83 -0
  56. package/components/FileDropzone/FileDropzone.svelte.d.ts +27 -0
  57. package/components/GradientHeading/GradientHeading.svelte +21 -0
  58. package/components/GradientHeading/GradientHeading.svelte.d.ts +22 -0
  59. package/components/ListBox/ListBox.svelte +54 -0
  60. package/components/ListBox/ListBox.svelte.d.ts +30 -0
  61. package/components/ListBox/ListBoxItem.svelte +87 -0
  62. package/components/ListBox/ListBoxItem.svelte.d.ts +30 -0
  63. package/components/Paginator/Paginator.svelte +62 -0
  64. package/components/Paginator/Paginator.svelte.d.ts +25 -0
  65. package/components/Paginator/types.d.ts +10 -0
  66. package/components/Paginator/types.js +2 -0
  67. package/components/ProgressBar/ProgressBar.svelte +57 -0
  68. package/components/ProgressBar/ProgressBar.svelte.d.ts +23 -0
  69. package/components/ProgressRadial/ProgressRadial.svelte +81 -0
  70. package/components/ProgressRadial/ProgressRadial.svelte.d.ts +25 -0
  71. package/components/Radio/RadioGroup.svelte +45 -0
  72. package/components/Radio/RadioGroup.svelte.d.ts +30 -0
  73. package/components/Radio/RadioItem.svelte +40 -0
  74. package/components/Radio/RadioItem.svelte.d.ts +29 -0
  75. package/components/RangeSlider/RangeSlider.svelte +95 -0
  76. package/components/RangeSlider/RangeSlider.svelte.d.ts +32 -0
  77. package/components/SlideToggle/SlideToggle.svelte +77 -0
  78. package/components/SlideToggle/SlideToggle.svelte.d.ts +31 -0
  79. package/components/Stepper/Step.svelte +94 -0
  80. package/components/Stepper/Step.svelte.d.ts +31 -0
  81. package/components/Stepper/Stepper.svelte +42 -0
  82. package/components/Stepper/Stepper.svelte.d.ts +27 -0
  83. package/components/SvgIcon/SvgIcon.svelte +45 -0
  84. package/components/SvgIcon/SvgIcon.svelte.d.ts +26 -0
  85. package/components/SvgIcon/icons.d.ts +1 -0
  86. package/components/SvgIcon/icons.js +171 -0
  87. package/components/Tab/Tab.svelte +54 -0
  88. package/components/Tab/Tab.svelte.d.ts +32 -0
  89. package/components/Tab/TabGroup.svelte +69 -0
  90. package/components/Tab/TabGroup.svelte.d.ts +30 -0
  91. package/components/Table/Table.svelte +102 -0
  92. package/components/Table/Table.svelte.d.ts +27 -0
  93. package/components/Table/types.d.ts +10 -0
  94. package/components/Table/types.js +1 -0
  95. package/components/Table/utils.d.ts +7 -0
  96. package/components/Table/utils.js +33 -0
  97. package/index.d.ts +59 -0
  98. package/index.js +68 -0
  99. package/package.json +147 -0
  100. package/styles/all.css +20 -0
  101. package/styles/core.css +53 -0
  102. package/styles/elements/badges.css +29 -0
  103. package/styles/elements/buttons.css +162 -0
  104. package/styles/elements/cards.css +34 -0
  105. package/styles/elements/lists.css +47 -0
  106. package/styles/elements/logo-clouds.css +31 -0
  107. package/styles/elements/menus.css +26 -0
  108. package/styles/elements/placeholders.css +17 -0
  109. package/styles/elements/tables.css +97 -0
  110. package/styles/elements/tooltips.css +83 -0
  111. package/styles/elements.css +15 -0
  112. package/styles/forms.css +154 -0
  113. package/styles/highlight-js.css +116 -0
  114. package/styles/tailwind.css +12 -0
  115. package/styles/tokens.css +171 -0
  116. package/styles/typography.css +115 -0
  117. package/tailwind/colors.d.ts +13 -0
  118. package/tailwind/colors.js +335 -0
  119. package/tailwind/theme.cjs +45 -0
  120. package/tailwind/theme.d.cts +5 -0
  121. package/themes/legacy/theme-skeleton.css +93 -0
  122. package/themes/theme-crimson.css +70 -0
  123. package/themes/theme-gold-nouveau.css +142 -0
  124. package/themes/theme-hamlindigo.css +82 -0
  125. package/themes/theme-modern.css +78 -0
  126. package/themes/theme-rocket.css +80 -0
  127. package/themes/theme-sahara.css +83 -0
  128. package/themes/theme-seafoam.css +81 -0
  129. package/themes/theme-seasonal.css +69 -0
  130. package/themes/theme-skeleton.css +99 -0
  131. package/themes/theme-vintage.css +80 -0
  132. package/utilities/CodeBlock/CodeBlock.svelte +63 -0
  133. package/utilities/CodeBlock/CodeBlock.svelte.d.ts +23 -0
  134. package/utilities/CodeBlock/stores.d.ts +2 -0
  135. package/utilities/CodeBlock/stores.js +3 -0
  136. package/utilities/DataTable/DataTable.d.ts +14 -0
  137. package/utilities/DataTable/DataTable.js +98 -0
  138. package/utilities/DataTable/actions.d.ts +8 -0
  139. package/utilities/DataTable/actions.js +114 -0
  140. package/utilities/DataTable/types.d.ts +15 -0
  141. package/utilities/DataTable/types.js +2 -0
  142. package/utilities/Drawer/Drawer.svelte +135 -0
  143. package/utilities/Drawer/Drawer.svelte.d.ts +36 -0
  144. package/utilities/LightSwitch/LightSwitch.svelte +70 -0
  145. package/utilities/LightSwitch/LightSwitch.svelte.d.ts +16 -0
  146. package/utilities/LightSwitch/stores.d.ts +3 -0
  147. package/utilities/LightSwitch/stores.js +5 -0
  148. package/utilities/LocalStorageStore/LocalStorageStore.d.ts +10 -0
  149. package/utilities/LocalStorageStore/LocalStorageStore.js +44 -0
  150. package/utilities/Menu/menu.d.ts +18 -0
  151. package/utilities/Menu/menu.js +100 -0
  152. package/utilities/Modal/Modal.d.ts +1 -0
  153. package/utilities/Modal/Modal.js +44 -0
  154. package/utilities/Modal/Modal.svelte +182 -0
  155. package/utilities/Modal/Modal.svelte.d.ts +33 -0
  156. package/utilities/Modal/examples/ModalExampleEmbed.svelte +20 -0
  157. package/utilities/Modal/examples/ModalExampleEmbed.svelte.d.ts +17 -0
  158. package/utilities/Modal/examples/ModalExampleForm.svelte +46 -0
  159. package/utilities/Modal/examples/ModalExampleForm.svelte.d.ts +17 -0
  160. package/utilities/Modal/examples/ModalExampleList.svelte +32 -0
  161. package/utilities/Modal/examples/ModalExampleList.svelte.d.ts +17 -0
  162. package/utilities/Modal/stores.d.ts +1 -0
  163. package/utilities/Modal/stores.js +22 -0
  164. package/utilities/Modal/types.d.ts +26 -0
  165. package/utilities/Modal/types.js +2 -0
  166. package/utilities/Toast/Toast.svelte +117 -0
  167. package/utilities/Toast/Toast.svelte.d.ts +28 -0
  168. package/utilities/Toast/stores.d.ts +10 -0
  169. package/utilities/Toast/stores.js +44 -0
  170. package/utilities/Toast/types.d.ts +21 -0
  171. package/utilities/Toast/types.js +2 -0
  172. package/utilities/Tooltip/tooltip.d.ts +35 -0
  173. package/utilities/Tooltip/tooltip.js +94 -0
@@ -0,0 +1,36 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import { type Writable } from 'svelte/store';
3
+ declare const __propDef: {
4
+ props: {
5
+ [x: string]: any;
6
+ open?: Writable<boolean> | undefined;
7
+ position?: string | undefined;
8
+ duration?: number | undefined;
9
+ bgBackdrop?: string | undefined;
10
+ blur?: string | undefined;
11
+ bgDrawer?: string | undefined;
12
+ border?: string | undefined;
13
+ rounded?: string | undefined;
14
+ width?: string | undefined;
15
+ height?: string | undefined;
16
+ margin?: string | undefined;
17
+ labelledby?: string | undefined;
18
+ describedby?: string | undefined;
19
+ };
20
+ events: {
21
+ keydown: KeyboardEvent;
22
+ keyup: KeyboardEvent;
23
+ keypress: KeyboardEvent;
24
+ } & {
25
+ [evt: string]: CustomEvent<any>;
26
+ };
27
+ slots: {
28
+ default: {};
29
+ };
30
+ };
31
+ export type DrawerProps = typeof __propDef.props;
32
+ export type DrawerEvents = typeof __propDef.events;
33
+ export type DrawerSlots = typeof __propDef.slots;
34
+ export default class Drawer extends SvelteComponentTyped<DrawerProps, DrawerEvents, DrawerSlots> {
35
+ }
36
+ export {};
@@ -0,0 +1,70 @@
1
+ <!-- https://tailwindcss.com/docs/dark-mode -->
2
+ <script>import { onMount } from 'svelte';
3
+ // Components
4
+ import SvgIcon from '../../components/SvgIcon/SvgIcon.svelte';
5
+ // Stores
6
+ import { storePrefersDarkScheme, storeLightSwitch } from './stores';
7
+ // Base Classes
8
+ const cTrack = 'inline-block bg-surface-200-700-token ring-[1px] ring-surface-300-600-token ring-inset w-12 h-6 rounded-full cursor-pointer transition-all duration-[100ms]';
9
+ const cThumb = 'bg-white dark:bg-black fill-white dark:fill-black w-6 h-6 flex justify-center items-center rounded-full shadow-lg transition-all duration-[100ms] scale-90';
10
+ const cIcon = 'block w-4 h-4';
11
+ // Set the users system prefers for light/dark mode
12
+ function setPrefersDarkScheme() {
13
+ const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
14
+ storePrefersDarkScheme.set(prefersDark);
15
+ }
16
+ // Toggles a 'dark' class on the <html> element
17
+ function setElemHtmlClass() {
18
+ const elemHtmlClassList = document.documentElement.classList;
19
+ // If $storeLightSwitch not set, match the OS preference
20
+ if ($storeLightSwitch === undefined) {
21
+ $storeLightSwitch = $storePrefersDarkScheme;
22
+ }
23
+ // Update HTML element class
24
+ $storeLightSwitch === true ? elemHtmlClassList.add('dark') : elemHtmlClassList.remove('dark');
25
+ }
26
+ // On Click Handler
27
+ function onClick() {
28
+ // Set the Store Value
29
+ storeLightSwitch.set(($storeLightSwitch = !$storeLightSwitch));
30
+ // Apply to <html> Element
31
+ setElemHtmlClass();
32
+ }
33
+ // A11y Input Handlers
34
+ function onKeyDown(event) {
35
+ // Enter/Space triggers selecton event
36
+ if (['Enter', 'Space'].includes(event.code)) {
37
+ event.preventDefault();
38
+ event.target.click();
39
+ }
40
+ }
41
+ // Lifecycle
42
+ onMount(() => {
43
+ // Determine OS Preference
44
+ setPrefersDarkScheme();
45
+ // Finally, update HTML element class as needed
46
+ setElemHtmlClass();
47
+ });
48
+ // Reactive Classses
49
+ $: classesPosition = $storeLightSwitch ? 'translate-x-full' : 'translate-x-0';
50
+ $: classesBase = `${cTrack} ${$$props.class ?? ''}`;
51
+ $: classesThumb = `${cThumb} ${classesPosition}`;
52
+ </script>
53
+
54
+ <!-- prettier-ignore -->
55
+ <div
56
+ class="lightswitch {classesBase}"
57
+ on:click={onClick}
58
+ on:keydown={onKeyDown}
59
+ role="switch"
60
+ aria-label="Light Switch"
61
+ aria-checked={$storeLightSwitch}
62
+ title="Toggle {$storeLightSwitch ? 'Light' : 'Dark'} Mode"
63
+ tabindex="0"
64
+ >
65
+ <!-- Thumb -->
66
+ <div class="lightswitch-thumb {classesThumb}">
67
+ <!-- SVG Icon -->
68
+ <SvgIcon name={$storeLightSwitch === false ? 'sun' : 'moon'} class="lightswitch-icon {cIcon}" />
69
+ </div>
70
+ </div>
@@ -0,0 +1,16 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ [x: string]: any;
5
+ };
6
+ events: {
7
+ [evt: string]: CustomEvent<any>;
8
+ };
9
+ slots: {};
10
+ };
11
+ export type LightSwitchProps = typeof __propDef.props;
12
+ export type LightSwitchEvents = typeof __propDef.events;
13
+ export type LightSwitchSlots = typeof __propDef.slots;
14
+ export default class LightSwitch extends SvelteComponentTyped<LightSwitchProps, LightSwitchEvents, LightSwitchSlots> {
15
+ }
16
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { Writable } from 'svelte/store';
2
+ export declare const storePrefersDarkScheme: Writable<boolean>;
3
+ export declare const storeLightSwitch: Writable<boolean | undefined>;
@@ -0,0 +1,5 @@
1
+ import { localStorageStore } from '../LocalStorageStore/LocalStorageStore';
2
+ // OS Prefers Dark Scheme - TRUE: dark | FALSE: light
3
+ export const storePrefersDarkScheme = localStorageStore('storePrefersDarkScheme', false);
4
+ // User Selected Mode - TRUE: dark | FALSE: light | undefined: use system preference
5
+ export const storeLightSwitch = localStorageStore('storeLightSwitch', undefined);
@@ -0,0 +1,10 @@
1
+ import { type Writable } from 'svelte/store';
2
+ interface Serializer<T> {
3
+ parse(text: string): T;
4
+ stringify(object: T): string;
5
+ }
6
+ interface Options<T> {
7
+ serializer: Serializer<T>;
8
+ }
9
+ export declare function localStorageStore<T>(key: string, initialValue: T, options?: Options<T>): Writable<T>;
10
+ export {};
@@ -0,0 +1,44 @@
1
+ // Source: https://github.com/joshnuss/svelte-local-storage-store
2
+ // https://github.com/joshnuss/svelte-local-storage-store/blob/master/index.ts
3
+ // Represents version v0.3.1 (2022-08-21)
4
+ import { writable as internal, get } from 'svelte/store';
5
+ const stores = {};
6
+ export function localStorageStore(key, initialValue, options) {
7
+ const browser = typeof localStorage != 'undefined' && typeof window != 'undefined';
8
+ const serializer = options?.serializer || JSON;
9
+ function updateStorage(key, value) {
10
+ if (!browser)
11
+ return;
12
+ localStorage.setItem(key, serializer.stringify(value));
13
+ }
14
+ if (!stores[key]) {
15
+ const store = internal(initialValue, (set) => {
16
+ const json = browser ? localStorage.getItem(key) : null;
17
+ if (json) {
18
+ set(serializer.parse(json));
19
+ }
20
+ if (browser) {
21
+ const handleStorage = (event) => {
22
+ if (event.key === key)
23
+ set(event.newValue ? serializer.parse(event.newValue) : null);
24
+ };
25
+ window.addEventListener('storage', handleStorage);
26
+ return () => window.removeEventListener('storage', handleStorage);
27
+ }
28
+ });
29
+ const { subscribe, set } = store;
30
+ stores[key] = {
31
+ set(value) {
32
+ updateStorage(key, value);
33
+ set(value);
34
+ },
35
+ update(updater) {
36
+ const value = updater(get(store));
37
+ updateStorage(key, value);
38
+ set(value);
39
+ },
40
+ subscribe
41
+ };
42
+ }
43
+ return stores[key];
44
+ }
@@ -0,0 +1,18 @@
1
+ interface ArgsMenu {
2
+ /** The value of 'x' from data-menu-[x] */
3
+ menu: string;
4
+ /** Origin - TRUE: fixed | FALSE: auto */
5
+ fixed?: boolean;
6
+ /** Clicks inside body will not close window */
7
+ interactive?: boolean;
8
+ /** Provide an optional callback function to handle open/close state changes. */
9
+ state?: (e: {
10
+ menu: string;
11
+ state: boolean;
12
+ }) => void;
13
+ }
14
+ export declare function menu(node: HTMLElement, args: ArgsMenu): {
15
+ update: (newArgs: ArgsMenu) => void;
16
+ destroy: () => void;
17
+ } | undefined;
18
+ export {};
@@ -0,0 +1,100 @@
1
+ // Action: Menu
2
+ // https://svelte.dev/repl/0ace7a508bd843b798ae599940a91783?version=3.16.7
3
+ // prettier-ignore
4
+ export function menu(node, args) {
5
+ const elemMenu = document.querySelector(`[data-menu="${args.menu}"]`);
6
+ if (!elemMenu)
7
+ return;
8
+ const onInit = () => {
9
+ autoUpdateOrigin();
10
+ // Apply a11y attributes
11
+ elemMenu.setAttribute('role', 'menu');
12
+ };
13
+ // Menu States ---
14
+ const menuOpen = () => {
15
+ elemMenu.style.display = 'block';
16
+ stateEventHandler(true);
17
+ };
18
+ const menuClose = () => {
19
+ elemMenu.style.display = 'none';
20
+ stateEventHandler(false);
21
+ };
22
+ const stateEventHandler = (state) => {
23
+ if (args.state)
24
+ args.state({ menu: args.menu, state });
25
+ };
26
+ // Click Handlers ---
27
+ const onTriggerClick = () => {
28
+ autoUpdateOrigin();
29
+ menuOpen();
30
+ };
31
+ const onWindowClick = (event) => {
32
+ args.interactive === true ? interactiveClickHandler(event) : standardClickHandler();
33
+ };
34
+ // Interactive FALSE - any click closes the menu
35
+ const standardClickHandler = () => {
36
+ menuClose();
37
+ };
38
+ // Interactive TRUE - clicks outside close menu
39
+ const interactiveClickHandler = (event) => {
40
+ const outsideNode = node && !node.contains(event.target);
41
+ const outsideMenu = elemMenu && !elemMenu.contains(event.target);
42
+ if (outsideNode && outsideMenu) {
43
+ menuClose();
44
+ }
45
+ };
46
+ // Menu - Set auto origin ---
47
+ const autoUpdateOrigin = () => {
48
+ if (!args.fixed && !elemMenu.classList.contains('hidden')) {
49
+ // Get the Menu's bounds
50
+ const elemTriggerBounds = node.getBoundingClientRect();
51
+ // Determine vertical and horizontal values
52
+ const vert = elemTriggerBounds.y < window.innerHeight / 2 ? 't' : 'b'; // top/bottom
53
+ const horz = elemTriggerBounds.x < window.innerWidth / 2 ? 'l' : 'r'; // left/right
54
+ // Strip and apply only the relevant class
55
+ elemMenu.classList.remove('menu-tl', 'menu-tr', 'menu-bl', 'menu-br');
56
+ elemMenu.classList.add(`menu-${vert}${horz}`);
57
+ }
58
+ };
59
+ // A11y Input Handlers ---
60
+ const onTriggerKeyDown = (event) => {
61
+ if (['Enter', 'Space'].includes(event.code)) {
62
+ event.preventDefault();
63
+ // Trigger Menu
64
+ onTriggerClick();
65
+ // If menu open, set focus
66
+ if (elemMenu.style.display === 'block') {
67
+ elemMenu.focus();
68
+ }
69
+ }
70
+ };
71
+ const onWindowKeyDown = (event) => {
72
+ if (['Escape'].includes(event.code)) {
73
+ event.preventDefault();
74
+ menuClose();
75
+ }
76
+ };
77
+ // On Action Init
78
+ onInit();
79
+ // Window Events
80
+ window.addEventListener('resize', autoUpdateOrigin, true);
81
+ window.addEventListener('click', onWindowClick, true);
82
+ window.addEventListener('keydown', onWindowKeyDown, true);
83
+ // Trigger Node Events
84
+ node.addEventListener('click', onTriggerClick);
85
+ node.addEventListener('keydown', onTriggerKeyDown);
86
+ node.addEventListener('change', (e) => {
87
+ console.log(e);
88
+ });
89
+ // Lifecycle
90
+ return {
91
+ update: (newArgs) => { args = newArgs; },
92
+ destroy: () => {
93
+ window.removeEventListener('resize', onWindowClick, true);
94
+ window.removeEventListener('click', onWindowClick, true);
95
+ window.removeEventListener('keydown', onWindowKeyDown, true);
96
+ node.removeEventListener('click', onTriggerClick);
97
+ node.removeEventListener('keydown', onTriggerKeyDown);
98
+ }
99
+ };
100
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,44 @@
1
+ import { render } from '@testing-library/svelte';
2
+ import { describe, it, expect } from 'vitest';
3
+ import { modalStore } from './stores';
4
+ // @ts-ignore
5
+ import Modal from './Modal.svelte';
6
+ // Modal Payloads
7
+ const modalAlert = {
8
+ type: 'alert',
9
+ title: 'Welcome to Skeleton.',
10
+ body: 'This is a standard alert modal.'
11
+ };
12
+ const modalConfirm = {
13
+ type: 'confirm',
14
+ title: 'Please Confirm',
15
+ body: 'Are you sure you wish to proceed?',
16
+ response: (r) => console.log(r)
17
+ };
18
+ const modalPrompt = {
19
+ type: 'prompt',
20
+ title: 'Enter Name',
21
+ body: 'Provide your first name in the field below.',
22
+ value: 'foobar',
23
+ response: (r) => console.log(r)
24
+ };
25
+ describe('Modal.svelte', () => {
26
+ it('Renders modal alert', async () => {
27
+ modalStore.trigger(modalAlert);
28
+ const { getByTestId } = render(Modal);
29
+ expect(getByTestId('modal-backdrop')).toBeTruthy();
30
+ expect(getByTestId('modal')).toBeTruthy();
31
+ });
32
+ it('Renders modal confirm', async () => {
33
+ modalStore.trigger(modalConfirm);
34
+ const { getByTestId } = render(Modal);
35
+ expect(getByTestId('modal-backdrop')).toBeTruthy();
36
+ expect(getByTestId('modal')).toBeTruthy();
37
+ });
38
+ it('Renders modal prompt', async () => {
39
+ modalStore.trigger(modalPrompt);
40
+ const { getByTestId } = render(Modal);
41
+ expect(getByTestId('modal-backdrop')).toBeTruthy();
42
+ expect(getByTestId('modal')).toBeTruthy();
43
+ });
44
+ });
@@ -0,0 +1,182 @@
1
+ <script>import { fade, fly } from 'svelte/transition';
2
+ // Actions
3
+ import { focusTrap } from '../../actions/FocusTrap/focusTrap';
4
+ // Stores
5
+ import { modalStore } from './stores';
6
+ // Props
7
+ /** The open/close animation duration. Set '0' (zero) to disable. */
8
+ export let duration = 150;
9
+ // Props (modal)
10
+ /** Provide classes to style the modal background. */
11
+ export let background = 'bg-surface-100-800-token';
12
+ /** Provide classes to style the modal width. */
13
+ export let width = 'w-full max-w-[640px]';
14
+ /** Provide classes to style the modal. */
15
+ export let height = 'h-auto';
16
+ /** Provide classes to style the modal padding. */
17
+ export let padding = 'p-4';
18
+ /** Provide classes to style the modal spacing. */
19
+ export let spacing = 'space-y-4';
20
+ /** Provide classes to style the modal border radius. */
21
+ export let rounded = 'rounded-container-token';
22
+ /** Provide classes to style modal box shadow. */
23
+ export let shadow = 'shadow-xl';
24
+ // Props (buttons)
25
+ /** Provide classes for neutral buttons, such as Cancel. */
26
+ export let buttonNeutral = 'btn-ghost-surface';
27
+ /** Provide classes for positive actions, such as Confirm or Submit. */
28
+ export let buttonPositive = 'btn-filled-primary';
29
+ /** Override the text for the Cancel button. */
30
+ export let buttonTextCancel = 'Cancel';
31
+ /** Override the text for the Confirm button. */
32
+ export let buttonTextConfirm = 'Confirm';
33
+ /** Override the text for the Submit button. */
34
+ export let buttonTextSubmit = 'Submit';
35
+ // Props (regions)
36
+ /** Provide classes to style the backdrop. */
37
+ export let regionBackdrop = 'bg-backdrop-token';
38
+ /** Provide arbitrary classes to modal header region. */
39
+ export let regionHeader = 'text-2xl font-bold';
40
+ /** Provide arbitrary classes to modal body region. */
41
+ export let regionBody = 'max-h-[200px] overflow-hidden';
42
+ /** Provide arbitrary classes to modal footer region. */
43
+ export let regionFooter = 'flex justify-end space-x-2';
44
+ // Base Styles
45
+ const cBackdrop = 'fixed top-0 left-0 right-0 bottom-0 z-[999] flex justify-center items-center p-4';
46
+ const cModalImage = 'w-full h-auto';
47
+ // Local
48
+ let promptValue;
49
+ // Modal Store Subscription
50
+ modalStore.subscribe((dArr) => {
51
+ if (!dArr.length)
52
+ return;
53
+ // Set the local modal value (for prompt)
54
+ promptValue = dArr[0].value;
55
+ });
56
+ // Event Handlers ---
57
+ function onBackdropInteraction(e) {
58
+ if (!(e.target instanceof Element))
59
+ return;
60
+ if (e.target.classList.contains('modal-backdrop'))
61
+ onClose();
62
+ }
63
+ function onClose() {
64
+ if ($modalStore[0].response)
65
+ $modalStore[0].response(false);
66
+ modalStore.close();
67
+ }
68
+ function onConfirm() {
69
+ if ($modalStore[0].response)
70
+ $modalStore[0].response(true);
71
+ modalStore.close();
72
+ }
73
+ function onPromptSubmit() {
74
+ if ($modalStore[0].response)
75
+ $modalStore[0].response(promptValue);
76
+ modalStore.close();
77
+ }
78
+ // A11y ---
79
+ function onKeyDown(event) {
80
+ if (!$modalStore.length)
81
+ return;
82
+ if (event.code === 'Escape')
83
+ onClose();
84
+ }
85
+ // Reactive
86
+ $: classesBackdrop = `${cBackdrop} ${regionBackdrop} ${$$props.class || ''}`;
87
+ $: classesModal = `${background} ${width} ${height} ${padding} ${spacing} ${rounded} ${shadow}`;
88
+ // IMPORTANT: add values to pass to the children templates.
89
+ // There is a way to self-reference component values, but it involes svelte-internal and is not yet stable.
90
+ // REPL: https://svelte.dev/repl/badd0f11aa99450ca69dca6690d4d5a4?version=3.52.0
91
+ // Source: https://discord.com/channels/457912077277855764/1037768846855118909
92
+ $: parent = {
93
+ background,
94
+ width,
95
+ height,
96
+ padding,
97
+ spacing,
98
+ rounded,
99
+ shadow,
100
+ // ---
101
+ buttonNeutral,
102
+ buttonPositive,
103
+ buttonTextCancel,
104
+ buttonTextConfirm,
105
+ buttonTextSubmit,
106
+ // ---
107
+ regionBackdrop,
108
+ regionHeader,
109
+ regionBody,
110
+ regionFooter,
111
+ // ---
112
+ onClose
113
+ };
114
+ </script>
115
+
116
+ <svelte:window on:keydown={onKeyDown} />
117
+
118
+ {#if $modalStore.length > 0}
119
+ {#key $modalStore}
120
+ <!-- Backdrop -->
121
+ <div
122
+ class="modal-backdrop {classesBackdrop}"
123
+ on:mousedown={onBackdropInteraction}
124
+ on:touchstart={onBackdropInteraction}
125
+ transition:fade={{ duration }}
126
+ data-testid="modal-backdrop"
127
+ >
128
+ <!-- Modal -->
129
+ <div
130
+ class="modal {classesModal} {$modalStore[0].classes}"
131
+ transition:fly={{ duration, opacity: 0, y: 100 }}
132
+ use:focusTrap={true}
133
+ data-testid="modal"
134
+ role="dialog"
135
+ aria-modal="true"
136
+ aria-label={$modalStore[0].title}
137
+ >
138
+ <!-- Header -->
139
+ {#if $modalStore[0]?.title}
140
+ <header class="modal-header {regionHeader}">{@html $modalStore[0].title}</header>
141
+ {/if}
142
+ <!-- Body -->
143
+ {#if $modalStore[0]?.body}
144
+ <article class="modal-body {regionBody}">{@html $modalStore[0].body}</article>
145
+ {/if}
146
+ <!-- Image -->
147
+ {#if $modalStore[0]?.image}
148
+ <img class="modal-image {cModalImage}" src={$modalStore[0]?.image} alt="Modal" />
149
+ {/if}
150
+ <!-- Type -->
151
+ {#if $modalStore[0].type === 'alert'}
152
+ <!-- Template: Alert -->
153
+ <footer class="modal-footer {regionFooter}">
154
+ <!-- prettier-ignore -->
155
+ <button class="btn {buttonNeutral}" on:click={onClose}>{buttonTextCancel}</button>
156
+ </footer>
157
+ {:else if $modalStore[0].type === 'confirm'}
158
+ <!-- Template: Confirm -->
159
+ <!-- prettier-ignore -->
160
+ <footer class="modal-footer {regionFooter}">
161
+ <button class="btn {buttonNeutral}" on:click={onClose}>{buttonTextCancel}</button>
162
+ <button class="btn {buttonPositive}" on:click={onConfirm}>{buttonTextConfirm}</button>
163
+ </footer>
164
+ {:else if $modalStore[0].type === 'prompt'}
165
+ <!-- Template: Prompt -->
166
+ <input class="modal-prompt-input" type="text" bind:value={promptValue} required />
167
+ <!-- prettier-ignore -->
168
+ <footer class="modal-footer {regionFooter}">
169
+ <button class="btn {buttonNeutral}" on:click={onClose}>{buttonTextCancel}</button>
170
+ <button class="btn {buttonPositive}" on:click={onPromptSubmit}>{buttonTextSubmit}</button>
171
+ </footer>
172
+ {:else if $modalStore[0].type === 'component'}
173
+ <!-- Template: Component -->
174
+ <!-- NOTE: users are repsonsible for handling all UI, including cancel/submit buttons -->
175
+ <svelte:component this={$modalStore[0].component.ref} {...$modalStore[0].component.props} {parent}>
176
+ {@html $modalStore[0].component.slot}
177
+ </svelte:component>
178
+ {/if}
179
+ </div>
180
+ </div>
181
+ {/key}
182
+ {/if}
@@ -0,0 +1,33 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ [x: string]: any;
5
+ duration?: number | undefined;
6
+ background?: string | undefined;
7
+ width?: string | undefined;
8
+ height?: string | undefined;
9
+ padding?: string | undefined;
10
+ spacing?: string | undefined;
11
+ rounded?: string | undefined;
12
+ shadow?: string | undefined;
13
+ buttonNeutral?: string | undefined;
14
+ buttonPositive?: string | undefined;
15
+ buttonTextCancel?: string | undefined;
16
+ buttonTextConfirm?: string | undefined;
17
+ buttonTextSubmit?: string | undefined;
18
+ regionBackdrop?: string | undefined;
19
+ regionHeader?: string | undefined;
20
+ regionBody?: string | undefined;
21
+ regionFooter?: string | undefined;
22
+ };
23
+ events: {
24
+ [evt: string]: CustomEvent<any>;
25
+ };
26
+ slots: {};
27
+ };
28
+ export type ModalProps = typeof __propDef.props;
29
+ export type ModalEvents = typeof __propDef.events;
30
+ export type ModalSlots = typeof __propDef.slots;
31
+ export default class Modal extends SvelteComponentTyped<ModalProps, ModalEvents, ModalSlots> {
32
+ }
33
+ export {};
@@ -0,0 +1,20 @@
1
+ <script>// Props
2
+ /** Exposes parent props to this component. */
3
+ export let parent;
4
+ // Base Classes
5
+ const cBase = 'relative';
6
+ </script>
7
+
8
+ <!-- @component This example creates an embedded video modal. -->
9
+
10
+ <div class="modal-example-form {cBase}">
11
+ <button class="absolute -top-4 -right-4 z-1 btn-icon btn-filled" on:click={parent.onClose}>✕</button>
12
+ <iframe
13
+ class="w-full aspect-video rounded-container-token overflow-hidden"
14
+ src="https://www.youtube.com/embed/vOGhAV-84iI"
15
+ title="YouTube video player"
16
+ frameborder="0"
17
+ allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
18
+ allowfullscreen
19
+ />
20
+ </div>
@@ -0,0 +1,17 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ /** Exposes parent props to this component. */ parent: any;
5
+ };
6
+ events: {
7
+ [evt: string]: CustomEvent<any>;
8
+ };
9
+ slots: {};
10
+ };
11
+ export type ModalExampleEmbedProps = typeof __propDef.props;
12
+ export type ModalExampleEmbedEvents = typeof __propDef.events;
13
+ export type ModalExampleEmbedSlots = typeof __propDef.slots;
14
+ /** This example creates an embedded video modal. */
15
+ export default class ModalExampleEmbed extends SvelteComponentTyped<ModalExampleEmbedProps, ModalExampleEmbedEvents, ModalExampleEmbedSlots> {
16
+ }
17
+ export {};
@@ -0,0 +1,46 @@
1
+ <script>// Props
2
+ /** Exposes parent props to this component. */
3
+ export let parent;
4
+ // Stores
5
+ import { modalStore } from '../stores';
6
+ // Form Data
7
+ const formData = {
8
+ name: 'Jane Doe',
9
+ tel: '214-555-1234',
10
+ email: 'jdoe@email.com'
11
+ };
12
+ // We've created a custom submit function to pass the response and close the modal.
13
+ function onFormSubmit() {
14
+ $modalStore[0].response(formData);
15
+ modalStore.close();
16
+ }
17
+ // Base Classes
18
+ const cBase = 'space-y-4';
19
+ const cForm = 'border border-surface-500 p-4 space-y-4 rounded-container-token';
20
+ </script>
21
+
22
+ <!-- @component This example creates a simple form modal. -->
23
+
24
+ <div class="modal-example-form {cBase}">
25
+ <!-- Enable for debugging: -->
26
+ <!-- <pre>{JSON.stringify(formData, null, 2)}</pre> -->
27
+ <form class="modal-form {cForm}">
28
+ <label>
29
+ <span>Name</span>
30
+ <input type="text" bind:value={formData.name} placeholder="Enter name..." />
31
+ </label>
32
+ <label>
33
+ <span>Phone Number</span>
34
+ <input type="tel" bind:value={formData.tel} placeholder="Enter phone..." />
35
+ </label>
36
+ <label>
37
+ <span>Email</span>
38
+ <input type="email" bind:value={formData.email} placeholder="Enter email address..." />
39
+ </label>
40
+ </form>
41
+ <!-- prettier-ignore -->
42
+ <footer class="modal-footer {parent.regionFooter}">
43
+ <button class="btn {parent.buttonNeutral}" on:click={parent.onClose}>{parent.buttonTextCancel}</button>
44
+ <button class="btn {parent.buttonPositive}" on:click={onFormSubmit}>Submit Form</button>
45
+ </footer>
46
+ </div>