@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.
- package/LICENSE +21 -0
- package/README.md +33 -0
- package/actions/Clipboard/clipboard.d.ts +4 -0
- package/actions/Clipboard/clipboard.js +37 -0
- package/actions/Filters/filter.d.ts +3 -0
- package/actions/Filters/filter.js +23 -0
- package/actions/Filters/svg-filters/Apollo.svelte +13 -0
- package/actions/Filters/svg-filters/Apollo.svelte.d.ts +19 -0
- package/actions/Filters/svg-filters/BlueNight.svelte +12 -0
- package/actions/Filters/svg-filters/BlueNight.svelte.d.ts +19 -0
- package/actions/Filters/svg-filters/Emerald.svelte +23 -0
- package/actions/Filters/svg-filters/Emerald.svelte.d.ts +19 -0
- package/actions/Filters/svg-filters/GreenFall.svelte +18 -0
- package/actions/Filters/svg-filters/GreenFall.svelte.d.ts +19 -0
- package/actions/Filters/svg-filters/Noir.svelte +11 -0
- package/actions/Filters/svg-filters/Noir.svelte.d.ts +19 -0
- package/actions/Filters/svg-filters/NoirLight.svelte +10 -0
- package/actions/Filters/svg-filters/NoirLight.svelte.d.ts +19 -0
- package/actions/Filters/svg-filters/Rustic.svelte +14 -0
- package/actions/Filters/svg-filters/Rustic.svelte.d.ts +19 -0
- package/actions/Filters/svg-filters/Summer84.svelte +12 -0
- package/actions/Filters/svg-filters/Summer84.svelte.d.ts +19 -0
- package/actions/Filters/svg-filters/XPro.svelte +12 -0
- package/actions/Filters/svg-filters/XPro.svelte.d.ts +19 -0
- package/actions/FocusTrap/focusTrap.d.ts +4 -0
- package/actions/FocusTrap/focusTrap.js +42 -0
- package/components/Accordion/AccordionGroup.svelte +47 -0
- package/components/Accordion/AccordionGroup.svelte.d.ts +24 -0
- package/components/Accordion/AccordionItem.svelte +70 -0
- package/components/Accordion/AccordionItem.svelte.d.ts +35 -0
- package/components/Alert/Alert.svelte +65 -0
- package/components/Alert/Alert.svelte.d.ts +30 -0
- package/components/AppBar/AppBar.svelte +54 -0
- package/components/AppBar/AppBar.svelte.d.ts +30 -0
- package/components/AppRail/AppRail.svelte +48 -0
- package/components/AppRail/AppRail.svelte.d.ts +31 -0
- package/components/AppRail/AppRailTile.svelte +51 -0
- package/components/AppRail/AppRailTile.svelte.d.ts +33 -0
- package/components/AppShell/AppShell.svelte +80 -0
- package/components/AppShell/AppShell.svelte.d.ts +31 -0
- package/components/Avatar/Avatar.svelte +46 -0
- package/components/Avatar/Avatar.svelte.d.ts +32 -0
- package/components/Breadcrumb/Breadcrumb.svelte +24 -0
- package/components/Breadcrumb/Breadcrumb.svelte.d.ts +21 -0
- package/components/Breadcrumb/Crumb.svelte +29 -0
- package/components/Breadcrumb/Crumb.svelte.d.ts +21 -0
- package/components/ConicGradient/ConicGradient.svelte +80 -0
- package/components/ConicGradient/ConicGradient.svelte.d.ts +24 -0
- package/components/ConicGradient/types.d.ts +10 -0
- package/components/ConicGradient/types.js +2 -0
- package/components/Divider/Divider.svelte +21 -0
- package/components/Divider/Divider.svelte.d.ts +22 -0
- package/components/FileButton/FileButton.svelte +25 -0
- package/components/FileButton/FileButton.svelte.d.ts +22 -0
- package/components/FileDropzone/FileDropzone.svelte +83 -0
- package/components/FileDropzone/FileDropzone.svelte.d.ts +27 -0
- package/components/GradientHeading/GradientHeading.svelte +21 -0
- package/components/GradientHeading/GradientHeading.svelte.d.ts +22 -0
- package/components/ListBox/ListBox.svelte +54 -0
- package/components/ListBox/ListBox.svelte.d.ts +30 -0
- package/components/ListBox/ListBoxItem.svelte +87 -0
- package/components/ListBox/ListBoxItem.svelte.d.ts +30 -0
- package/components/Paginator/Paginator.svelte +62 -0
- package/components/Paginator/Paginator.svelte.d.ts +25 -0
- package/components/Paginator/types.d.ts +10 -0
- package/components/Paginator/types.js +2 -0
- package/components/ProgressBar/ProgressBar.svelte +57 -0
- package/components/ProgressBar/ProgressBar.svelte.d.ts +23 -0
- package/components/ProgressRadial/ProgressRadial.svelte +81 -0
- package/components/ProgressRadial/ProgressRadial.svelte.d.ts +25 -0
- package/components/Radio/RadioGroup.svelte +45 -0
- package/components/Radio/RadioGroup.svelte.d.ts +30 -0
- package/components/Radio/RadioItem.svelte +40 -0
- package/components/Radio/RadioItem.svelte.d.ts +29 -0
- package/components/RangeSlider/RangeSlider.svelte +95 -0
- package/components/RangeSlider/RangeSlider.svelte.d.ts +32 -0
- package/components/SlideToggle/SlideToggle.svelte +77 -0
- package/components/SlideToggle/SlideToggle.svelte.d.ts +31 -0
- package/components/Stepper/Step.svelte +94 -0
- package/components/Stepper/Step.svelte.d.ts +31 -0
- package/components/Stepper/Stepper.svelte +42 -0
- package/components/Stepper/Stepper.svelte.d.ts +27 -0
- package/components/SvgIcon/SvgIcon.svelte +45 -0
- package/components/SvgIcon/SvgIcon.svelte.d.ts +26 -0
- package/components/SvgIcon/icons.d.ts +1 -0
- package/components/SvgIcon/icons.js +171 -0
- package/components/Tab/Tab.svelte +54 -0
- package/components/Tab/Tab.svelte.d.ts +32 -0
- package/components/Tab/TabGroup.svelte +69 -0
- package/components/Tab/TabGroup.svelte.d.ts +30 -0
- package/components/Table/Table.svelte +102 -0
- package/components/Table/Table.svelte.d.ts +27 -0
- package/components/Table/types.d.ts +10 -0
- package/components/Table/types.js +1 -0
- package/components/Table/utils.d.ts +7 -0
- package/components/Table/utils.js +33 -0
- package/index.d.ts +59 -0
- package/index.js +68 -0
- package/package.json +147 -0
- package/styles/all.css +20 -0
- package/styles/core.css +53 -0
- package/styles/elements/badges.css +29 -0
- package/styles/elements/buttons.css +162 -0
- package/styles/elements/cards.css +34 -0
- package/styles/elements/lists.css +47 -0
- package/styles/elements/logo-clouds.css +31 -0
- package/styles/elements/menus.css +26 -0
- package/styles/elements/placeholders.css +17 -0
- package/styles/elements/tables.css +97 -0
- package/styles/elements/tooltips.css +83 -0
- package/styles/elements.css +15 -0
- package/styles/forms.css +154 -0
- package/styles/highlight-js.css +116 -0
- package/styles/tailwind.css +12 -0
- package/styles/tokens.css +171 -0
- package/styles/typography.css +115 -0
- package/tailwind/colors.d.ts +13 -0
- package/tailwind/colors.js +335 -0
- package/tailwind/theme.cjs +45 -0
- package/tailwind/theme.d.cts +5 -0
- package/themes/legacy/theme-skeleton.css +93 -0
- package/themes/theme-crimson.css +70 -0
- package/themes/theme-gold-nouveau.css +142 -0
- package/themes/theme-hamlindigo.css +82 -0
- package/themes/theme-modern.css +78 -0
- package/themes/theme-rocket.css +80 -0
- package/themes/theme-sahara.css +83 -0
- package/themes/theme-seafoam.css +81 -0
- package/themes/theme-seasonal.css +69 -0
- package/themes/theme-skeleton.css +99 -0
- package/themes/theme-vintage.css +80 -0
- package/utilities/CodeBlock/CodeBlock.svelte +63 -0
- package/utilities/CodeBlock/CodeBlock.svelte.d.ts +23 -0
- package/utilities/CodeBlock/stores.d.ts +2 -0
- package/utilities/CodeBlock/stores.js +3 -0
- package/utilities/DataTable/DataTable.d.ts +14 -0
- package/utilities/DataTable/DataTable.js +98 -0
- package/utilities/DataTable/actions.d.ts +8 -0
- package/utilities/DataTable/actions.js +114 -0
- package/utilities/DataTable/types.d.ts +15 -0
- package/utilities/DataTable/types.js +2 -0
- package/utilities/Drawer/Drawer.svelte +135 -0
- package/utilities/Drawer/Drawer.svelte.d.ts +36 -0
- package/utilities/LightSwitch/LightSwitch.svelte +70 -0
- package/utilities/LightSwitch/LightSwitch.svelte.d.ts +16 -0
- package/utilities/LightSwitch/stores.d.ts +3 -0
- package/utilities/LightSwitch/stores.js +5 -0
- package/utilities/LocalStorageStore/LocalStorageStore.d.ts +10 -0
- package/utilities/LocalStorageStore/LocalStorageStore.js +44 -0
- package/utilities/Menu/menu.d.ts +18 -0
- package/utilities/Menu/menu.js +100 -0
- package/utilities/Modal/Modal.d.ts +1 -0
- package/utilities/Modal/Modal.js +44 -0
- package/utilities/Modal/Modal.svelte +182 -0
- package/utilities/Modal/Modal.svelte.d.ts +33 -0
- package/utilities/Modal/examples/ModalExampleEmbed.svelte +20 -0
- package/utilities/Modal/examples/ModalExampleEmbed.svelte.d.ts +17 -0
- package/utilities/Modal/examples/ModalExampleForm.svelte +46 -0
- package/utilities/Modal/examples/ModalExampleForm.svelte.d.ts +17 -0
- package/utilities/Modal/examples/ModalExampleList.svelte +32 -0
- package/utilities/Modal/examples/ModalExampleList.svelte.d.ts +17 -0
- package/utilities/Modal/stores.d.ts +1 -0
- package/utilities/Modal/stores.js +22 -0
- package/utilities/Modal/types.d.ts +26 -0
- package/utilities/Modal/types.js +2 -0
- package/utilities/Toast/Toast.svelte +117 -0
- package/utilities/Toast/Toast.svelte.d.ts +28 -0
- package/utilities/Toast/stores.d.ts +10 -0
- package/utilities/Toast/stores.js +44 -0
- package/utilities/Toast/types.d.ts +21 -0
- package/utilities/Toast/types.js +2 -0
- package/utilities/Tooltip/tooltip.d.ts +35 -0
- package/utilities/Tooltip/tooltip.js +94 -0
|
@@ -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 ModalExampleFormProps = typeof __propDef.props;
|
|
12
|
+
export type ModalExampleFormEvents = typeof __propDef.events;
|
|
13
|
+
export type ModalExampleFormSlots = typeof __propDef.slots;
|
|
14
|
+
/** This example creates a simple form modal. */
|
|
15
|
+
export default class ModalExampleForm extends SvelteComponentTyped<ModalExampleFormProps, ModalExampleFormEvents, ModalExampleFormSlots> {
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<script>import { writable } from 'svelte/store';
|
|
2
|
+
import ListBox from '../../../components/ListBox/ListBox.svelte';
|
|
3
|
+
import ListBoxItem from '../../../components/ListBox/ListBoxItem.svelte';
|
|
4
|
+
// Props
|
|
5
|
+
/** Exposes parent props to this component. */
|
|
6
|
+
export let parent;
|
|
7
|
+
// Stores
|
|
8
|
+
import { modalStore } from '../stores';
|
|
9
|
+
const storeFlavor = writable('chocolate');
|
|
10
|
+
function onFormSubmit() {
|
|
11
|
+
$modalStore[0].response($storeFlavor);
|
|
12
|
+
modalStore.close();
|
|
13
|
+
}
|
|
14
|
+
// Base Classes
|
|
15
|
+
const cBase = 'space-y-4';
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<!-- @component This example creates a simple form modal. -->
|
|
19
|
+
|
|
20
|
+
<div class="modal-example-form {cBase}">
|
|
21
|
+
<ListBox selected={storeFlavor} regionList="border border-surface-500 p-4 rounded-container-token">
|
|
22
|
+
<ListBoxItem value="chocolate">Chocolate</ListBoxItem>
|
|
23
|
+
<ListBoxItem value="vanilla">Vanilla</ListBoxItem>
|
|
24
|
+
<ListBoxItem value="strawberry">Strawberry</ListBoxItem>
|
|
25
|
+
<ListBoxItem value="peach">Peach</ListBoxItem>
|
|
26
|
+
</ListBox>
|
|
27
|
+
<!-- prettier-ignore -->
|
|
28
|
+
<footer class="modal-footer {parent.regionFooter}">
|
|
29
|
+
<button class="btn {parent.buttonNeutral}" on:click={parent.onClose}>{parent.buttonTextCancel}</button>
|
|
30
|
+
<button class="btn {parent.buttonPositive}" on:click={onFormSubmit}>Select Flavors</button>
|
|
31
|
+
</footer>
|
|
32
|
+
</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 ModalExampleListProps = typeof __propDef.props;
|
|
12
|
+
export type ModalExampleListEvents = typeof __propDef.events;
|
|
13
|
+
export type ModalExampleListSlots = typeof __propDef.slots;
|
|
14
|
+
/** This example creates a simple form modal. */
|
|
15
|
+
export default class ModalExampleList extends SvelteComponentTyped<ModalExampleListProps, ModalExampleListEvents, ModalExampleListSlots> {
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const modalStore: any;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Modal Store Queue
|
|
2
|
+
import { writable } from 'svelte/store';
|
|
3
|
+
function modalService() {
|
|
4
|
+
const { subscribe, set, update } = writable([]);
|
|
5
|
+
return {
|
|
6
|
+
subscribe,
|
|
7
|
+
/** Append to end of queue. */
|
|
8
|
+
trigger: (modal) => update((mStore) => {
|
|
9
|
+
mStore.push(modal);
|
|
10
|
+
return mStore;
|
|
11
|
+
}),
|
|
12
|
+
/** Remove first item in queue. */
|
|
13
|
+
close: () => update((mStore) => {
|
|
14
|
+
if (mStore.length > 0)
|
|
15
|
+
mStore.shift();
|
|
16
|
+
return mStore;
|
|
17
|
+
}),
|
|
18
|
+
/** Remove all items from queue. */
|
|
19
|
+
clear: () => set([])
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export const modalStore = modalService();
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface ModalComponent {
|
|
2
|
+
/** Import and provide your component reference. */
|
|
3
|
+
ref: any;
|
|
4
|
+
/** Provide a key/value pairs of component props. */
|
|
5
|
+
props?: Record<string, string>;
|
|
6
|
+
/** Provide an HTML template literal for the default slot. */
|
|
7
|
+
slot?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ModalSettings {
|
|
10
|
+
/** Designate what type of component will display. */
|
|
11
|
+
type: 'alert' | 'confirm' | 'prompt' | 'component';
|
|
12
|
+
/** Provide the modal header content. Accepts HTML. */
|
|
13
|
+
title?: string;
|
|
14
|
+
/** Provide the modal body content. Accepts HTML. */
|
|
15
|
+
body?: string;
|
|
16
|
+
/** 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;
|
|
22
|
+
/** Provide a function. Returns the repsonse value. */
|
|
23
|
+
response?: (r: any) => void;
|
|
24
|
+
/** Provide abritrary classes to apply to the Modal element. Use `!` for important. */
|
|
25
|
+
classes?: string;
|
|
26
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
<script>import { fly } from 'svelte/transition';
|
|
2
|
+
// Toast Store
|
|
3
|
+
import { toastStore } from './stores';
|
|
4
|
+
// Props
|
|
5
|
+
/** Set the toast position.
|
|
6
|
+
* @type {'t' | 'b' | 'l' | 'r' | 'tl' | 'tr' | 'bl' | 'br'}
|
|
7
|
+
*/
|
|
8
|
+
export let position = 'b';
|
|
9
|
+
/** Maximum toasts that can show at once. */
|
|
10
|
+
export let max = 3;
|
|
11
|
+
/** The duration of the fly in/out animation. */
|
|
12
|
+
export let duration = 150;
|
|
13
|
+
// Props (styles)
|
|
14
|
+
/** Provide classes to set the background color. */
|
|
15
|
+
export let background = 'bg-accent-500';
|
|
16
|
+
/** Provide classes to set width styles. */
|
|
17
|
+
export let width = 'max-w-[640px]';
|
|
18
|
+
/** Provide classes to set the text color. */
|
|
19
|
+
export let color = 'text-white';
|
|
20
|
+
/** Provide classes to set the padding. */
|
|
21
|
+
export let padding = 'p-4';
|
|
22
|
+
/** Provide classes to set the horizontal spacing. */
|
|
23
|
+
export let spacing = 'space-x-4';
|
|
24
|
+
/** Provide classes to set the border radius styles. */
|
|
25
|
+
export let rounded = 'rounded-container-token';
|
|
26
|
+
/** Provide classes to set the border box shadow. */
|
|
27
|
+
export let shadow = 'shadow-lg';
|
|
28
|
+
// Props (buttons)
|
|
29
|
+
/** Provide action button styles. */
|
|
30
|
+
export let buttonAction = 'btn-filled';
|
|
31
|
+
/** Provide dismiss button styles. */
|
|
32
|
+
export let buttonDismiss = 'btn-filled';
|
|
33
|
+
// Base Classes
|
|
34
|
+
const cWrapper = 'flex fixed top-0 left-0 right-0 bottom-0 z-[888] pointer-events-none';
|
|
35
|
+
const cSnackbar = 'flex flex-col space-y-2';
|
|
36
|
+
const cToast = 'flex justify-between items-center pointer-events-auto';
|
|
37
|
+
// Local
|
|
38
|
+
let cPosition;
|
|
39
|
+
let cAlign; // items-center
|
|
40
|
+
let animAxis = { x: 0, y: 0 };
|
|
41
|
+
// Set Position
|
|
42
|
+
// prettier-ignore
|
|
43
|
+
switch (position) {
|
|
44
|
+
// Centered
|
|
45
|
+
case ('t'):
|
|
46
|
+
cPosition = 'justify-center items-start';
|
|
47
|
+
cAlign = 'items-center';
|
|
48
|
+
animAxis = { x: 0, y: -100 };
|
|
49
|
+
break;
|
|
50
|
+
case ('b'):
|
|
51
|
+
cPosition = 'justify-center items-end';
|
|
52
|
+
cAlign = 'items-center';
|
|
53
|
+
animAxis = { x: 0, y: 100 };
|
|
54
|
+
break;
|
|
55
|
+
case ('l'):
|
|
56
|
+
cPosition = 'justify-start items-center';
|
|
57
|
+
cAlign = 'items-start';
|
|
58
|
+
animAxis = { x: -100, y: 0 };
|
|
59
|
+
break;
|
|
60
|
+
case ('r'):
|
|
61
|
+
cPosition = 'justify-end items-center';
|
|
62
|
+
cAlign = 'items-end';
|
|
63
|
+
animAxis = { x: 100, y: 0 };
|
|
64
|
+
break;
|
|
65
|
+
// Corners
|
|
66
|
+
case ('tl'):
|
|
67
|
+
cPosition = 'justify-start items-start';
|
|
68
|
+
cAlign = 'items-start';
|
|
69
|
+
animAxis = { x: -100, y: 0 };
|
|
70
|
+
break;
|
|
71
|
+
case ('tr'):
|
|
72
|
+
cPosition = 'justify-end items-start';
|
|
73
|
+
cAlign = 'items-end';
|
|
74
|
+
animAxis = { x: 100, y: 0 };
|
|
75
|
+
break;
|
|
76
|
+
case ('bl'):
|
|
77
|
+
cPosition = 'justify-start items-end';
|
|
78
|
+
cAlign = 'items-start';
|
|
79
|
+
animAxis = { x: -100, y: 0 };
|
|
80
|
+
break;
|
|
81
|
+
case ('br'):
|
|
82
|
+
cPosition = 'justify-end items-end';
|
|
83
|
+
cAlign = 'items-end';
|
|
84
|
+
animAxis = { x: 100, y: 0 };
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
function onAction(index) {
|
|
88
|
+
$toastStore[index]?.action?.response();
|
|
89
|
+
toastStore.close($toastStore[index].id);
|
|
90
|
+
}
|
|
91
|
+
// Reactive
|
|
92
|
+
$: classesWrapper = `${cWrapper} ${cPosition} ${$$props.class || ''}`;
|
|
93
|
+
$: classesSnackbar = `${cSnackbar} ${cAlign} ${padding}`;
|
|
94
|
+
$: classesBase = `${cToast} ${background} ${width} ${color} ${padding} ${spacing} ${rounded} ${shadow}`;
|
|
95
|
+
</script>
|
|
96
|
+
|
|
97
|
+
{#if $toastStore.length}
|
|
98
|
+
<!-- Wrapper -->
|
|
99
|
+
<div class="snackbar-wrapper {classesWrapper}" data-testid="snackbar-wrapper">
|
|
100
|
+
<!-- List -->
|
|
101
|
+
<div class="snackbar {classesSnackbar}" transition:fly={{ x: animAxis.x, y: animAxis.y, duration }}>
|
|
102
|
+
{#each $toastStore as t, i}
|
|
103
|
+
{#if i < max + 1}
|
|
104
|
+
<!-- Toast -->
|
|
105
|
+
<div class="toast {classesBase} {t.classes}" role="alert" aria-live="polite" data-testid="toast">
|
|
106
|
+
<div class="text-base">{@html t.message}</div>
|
|
107
|
+
<!-- prettier-ignore -->
|
|
108
|
+
<div class="flex items-center space-x-2">
|
|
109
|
+
{#if t.action}<button class="btn {buttonAction}" on:click={() => onAction(i)}>{@html t.action.label}</button>{/if}
|
|
110
|
+
<button class="btn-icon {buttonDismiss}" on:click={() => { toastStore.close(t.id) }}>✕</button>
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
113
|
+
{/if}
|
|
114
|
+
{/each}
|
|
115
|
+
</div>
|
|
116
|
+
</div>
|
|
117
|
+
{/if}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
[x: string]: any;
|
|
5
|
+
position?: string | undefined;
|
|
6
|
+
max?: number | undefined;
|
|
7
|
+
duration?: number | undefined;
|
|
8
|
+
background?: string | undefined;
|
|
9
|
+
width?: string | undefined;
|
|
10
|
+
color?: string | undefined;
|
|
11
|
+
padding?: string | undefined;
|
|
12
|
+
spacing?: string | undefined;
|
|
13
|
+
rounded?: string | undefined;
|
|
14
|
+
shadow?: string | undefined;
|
|
15
|
+
buttonAction?: string | undefined;
|
|
16
|
+
buttonDismiss?: string | undefined;
|
|
17
|
+
};
|
|
18
|
+
events: {
|
|
19
|
+
[evt: string]: CustomEvent<any>;
|
|
20
|
+
};
|
|
21
|
+
slots: {};
|
|
22
|
+
};
|
|
23
|
+
export type ToastProps = typeof __propDef.props;
|
|
24
|
+
export type ToastEvents = typeof __propDef.events;
|
|
25
|
+
export type ToastSlots = typeof __propDef.slots;
|
|
26
|
+
export default class Toast extends SvelteComponentTyped<ToastProps, ToastEvents, ToastSlots> {
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ToastSettings, Toast } from './types';
|
|
2
|
+
export declare const toastStore: {
|
|
3
|
+
subscribe: (this: void, run: import("svelte/store").Subscriber<Toast[]>, invalidate?: ((value?: Toast[] | undefined) => void) | undefined) => import("svelte/store").Unsubscriber;
|
|
4
|
+
/** Add a new toast to the queue. */
|
|
5
|
+
trigger: (toast: ToastSettings) => void;
|
|
6
|
+
/** Remove first toast in queue */
|
|
7
|
+
close: (id: string) => void;
|
|
8
|
+
/** Remove all toasts from queue */
|
|
9
|
+
clear: () => void;
|
|
10
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Toast Store Queue
|
|
2
|
+
import { writable } from 'svelte/store';
|
|
3
|
+
const toastDefaults = { message: 'Missing Toast Message', autohide: true, timeout: 5000 };
|
|
4
|
+
// Note for security; differentiates the queued toasts
|
|
5
|
+
function randomUUID() {
|
|
6
|
+
const random = Math.random();
|
|
7
|
+
return Number(random).toString(32);
|
|
8
|
+
}
|
|
9
|
+
// If toast should auto-hide, wait X time, then close by ID
|
|
10
|
+
function handleAutoHide(toast) {
|
|
11
|
+
if (toast.autohide === true) {
|
|
12
|
+
setTimeout(() => {
|
|
13
|
+
toastStore.close(toast.id);
|
|
14
|
+
}, toast.timeout);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function toastService() {
|
|
18
|
+
const { subscribe, set, update } = writable([]);
|
|
19
|
+
return {
|
|
20
|
+
subscribe,
|
|
21
|
+
/** Add a new toast to the queue. */
|
|
22
|
+
trigger: (toast) => update((tStore) => {
|
|
23
|
+
const id = randomUUID();
|
|
24
|
+
// Merge into store
|
|
25
|
+
const tMerged = { ...toastDefaults, ...toast, id };
|
|
26
|
+
tStore.push(tMerged);
|
|
27
|
+
// Handle auto-hide, if needed
|
|
28
|
+
handleAutoHide(tMerged);
|
|
29
|
+
// Return
|
|
30
|
+
return tStore;
|
|
31
|
+
}),
|
|
32
|
+
/** Remove first toast in queue */
|
|
33
|
+
close: (id) => update((tStore) => {
|
|
34
|
+
if (tStore.length > 0) {
|
|
35
|
+
const index = tStore.findIndex((t) => t.id === id);
|
|
36
|
+
tStore.splice(index, 1);
|
|
37
|
+
}
|
|
38
|
+
return tStore;
|
|
39
|
+
}),
|
|
40
|
+
/** Remove all toasts from queue */
|
|
41
|
+
clear: () => set([])
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export const toastStore = toastService();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface ToastSettings {
|
|
2
|
+
/** Provide the toast message. Supports HTML. */
|
|
3
|
+
message: string;
|
|
4
|
+
/** Enables auto-hide after the timeout duration. */
|
|
5
|
+
autohide?: boolean;
|
|
6
|
+
/** Set the auto-hide timeout duration. */
|
|
7
|
+
timeout?: number;
|
|
8
|
+
/** Generate a custom action button UI. */
|
|
9
|
+
action?: {
|
|
10
|
+
/** The button label. Supports HTML. */
|
|
11
|
+
label: string;
|
|
12
|
+
/** The function triggered when the button is pressed. */
|
|
13
|
+
response: () => void;
|
|
14
|
+
};
|
|
15
|
+
/** Provide arbitrary CSS classes to style the toast. */
|
|
16
|
+
classes?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface Toast extends ToastSettings {
|
|
19
|
+
/** A UUID will be auto-assigned on `.trigger()`. */
|
|
20
|
+
id: string;
|
|
21
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface ArgsTooltip {
|
|
2
|
+
/** The HTML content of the tooltip. */
|
|
3
|
+
content: string;
|
|
4
|
+
/** Provide a value of: top | bottom | left | right */
|
|
5
|
+
position?: string;
|
|
6
|
+
/** Sets the wrapping element to be either inline or block */
|
|
7
|
+
inline?: boolean;
|
|
8
|
+
/** Provide an optional callback function to handle open/close state changes. */
|
|
9
|
+
state?: (e: {
|
|
10
|
+
trigger: HTMLElement;
|
|
11
|
+
state: boolean;
|
|
12
|
+
}) => void;
|
|
13
|
+
/** Provide a class to set the background color. */
|
|
14
|
+
background?: string;
|
|
15
|
+
/** Provide a class to set the text color. */
|
|
16
|
+
color?: string;
|
|
17
|
+
/** Provide a class to set the width. */
|
|
18
|
+
width?: string;
|
|
19
|
+
/** Provide a class to set the padding. */
|
|
20
|
+
padding?: string;
|
|
21
|
+
/** Provide a class to set the box shadow. */
|
|
22
|
+
shadow?: string;
|
|
23
|
+
/** Provide a class to set the border radius. */
|
|
24
|
+
rounded?: string;
|
|
25
|
+
/** Provide arbitrary classes to the container element. */
|
|
26
|
+
regionContainer?: string;
|
|
27
|
+
/** Provide arbitrary classes to the tooltip element. */
|
|
28
|
+
regionTooltip?: string;
|
|
29
|
+
/** Provide arbitrary classes to the tooltip arrow element. */
|
|
30
|
+
regionArrow?: string;
|
|
31
|
+
}
|
|
32
|
+
export declare function tooltip(node: HTMLElement, args: ArgsTooltip): {
|
|
33
|
+
update(newArgs: ArgsTooltip): void;
|
|
34
|
+
destroy(): void;
|
|
35
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Action: Tooltip
|
|
2
|
+
export function tooltip(node, args) {
|
|
3
|
+
const animDuration = 150;
|
|
4
|
+
let elemTooltip;
|
|
5
|
+
// Map the Args and provide default values
|
|
6
|
+
// prettier-ignore
|
|
7
|
+
const { content = '(tooltip)', position = 'top', inline = true,
|
|
8
|
+
// Regions
|
|
9
|
+
regionContainer = 'regionContainer', regionTooltip = 'regionTooltip', regionArrow = 'regionArrow' } = args;
|
|
10
|
+
// Create a wrapping element, set relative positioning
|
|
11
|
+
const createElemContainer = () => {
|
|
12
|
+
const elemContainer = document.createElement(inline ? 'span' : 'div');
|
|
13
|
+
elemContainer.classList.add('tooltip-container', 'relative', regionContainer);
|
|
14
|
+
node.parentNode?.insertBefore(elemContainer, node);
|
|
15
|
+
elemContainer.appendChild(node);
|
|
16
|
+
};
|
|
17
|
+
createElemContainer();
|
|
18
|
+
// Create the tooltip element
|
|
19
|
+
// prettier-ignore
|
|
20
|
+
const createElemTooltip = () => {
|
|
21
|
+
elemTooltip = document.createElement('div');
|
|
22
|
+
elemTooltip.classList.add('tooltip', `tooltip-${position}`, 'hidden', regionTooltip);
|
|
23
|
+
if (args.background) {
|
|
24
|
+
elemTooltip.classList.add(args.background);
|
|
25
|
+
}
|
|
26
|
+
if (args.color)
|
|
27
|
+
elemTooltip.classList.add(args.color);
|
|
28
|
+
if (args.width)
|
|
29
|
+
elemTooltip.classList.add(args.width);
|
|
30
|
+
if (args.padding)
|
|
31
|
+
elemTooltip.classList.add(args.padding);
|
|
32
|
+
if (args.shadow)
|
|
33
|
+
elemTooltip.classList.add(args.shadow);
|
|
34
|
+
if (args.rounded)
|
|
35
|
+
elemTooltip.classList.add(args.rounded);
|
|
36
|
+
elemTooltip.setAttribute('role', 'tooltip');
|
|
37
|
+
elemTooltip.setAttribute('data-testid', 'tooltip');
|
|
38
|
+
elemTooltip.innerHTML = content;
|
|
39
|
+
node.parentNode?.insertBefore(elemTooltip, node);
|
|
40
|
+
};
|
|
41
|
+
createElemTooltip();
|
|
42
|
+
// Create the tooltip arrow
|
|
43
|
+
// prettier-ignore
|
|
44
|
+
const createElemArrow = () => {
|
|
45
|
+
const elemArrow = document.createElement('div');
|
|
46
|
+
elemArrow.classList.add(`tooltip-arrow-${position}`, regionArrow);
|
|
47
|
+
if (args.background)
|
|
48
|
+
elemArrow.classList.add(args.background);
|
|
49
|
+
elemTooltip.append(elemArrow);
|
|
50
|
+
};
|
|
51
|
+
createElemArrow();
|
|
52
|
+
// -- State
|
|
53
|
+
// On mouse over - show the tooltip
|
|
54
|
+
const onMouseEnter = () => {
|
|
55
|
+
elemTooltip.classList.remove('hidden');
|
|
56
|
+
setTimeout(() => {
|
|
57
|
+
elemTooltip.classList.add('!opacity-100');
|
|
58
|
+
}, animDuration);
|
|
59
|
+
stateEventHandler(true);
|
|
60
|
+
};
|
|
61
|
+
// On mouse out - hide the tooltip
|
|
62
|
+
const onMouseLeave = () => {
|
|
63
|
+
elemTooltip.classList.remove('!opacity-100');
|
|
64
|
+
setTimeout(() => {
|
|
65
|
+
elemTooltip.classList.add('hidden');
|
|
66
|
+
}, animDuration);
|
|
67
|
+
stateEventHandler(false);
|
|
68
|
+
};
|
|
69
|
+
const stateEventHandler = (state) => {
|
|
70
|
+
if (args.state)
|
|
71
|
+
args.state({ trigger: node, state });
|
|
72
|
+
};
|
|
73
|
+
// Ally ---
|
|
74
|
+
// A11y Input Handler
|
|
75
|
+
const onWindowKeyDown = (event) => {
|
|
76
|
+
if (event.code === 'Escape')
|
|
77
|
+
onMouseLeave();
|
|
78
|
+
};
|
|
79
|
+
// Event Listners ---
|
|
80
|
+
node.addEventListener('mouseenter', onMouseEnter);
|
|
81
|
+
node.addEventListener('mouseleave', onMouseLeave);
|
|
82
|
+
window.addEventListener('keydown', onWindowKeyDown);
|
|
83
|
+
// Lifecycle
|
|
84
|
+
return {
|
|
85
|
+
update(newArgs) {
|
|
86
|
+
args = newArgs;
|
|
87
|
+
},
|
|
88
|
+
destroy() {
|
|
89
|
+
node.removeEventListener('mouseenter', onMouseEnter);
|
|
90
|
+
node.removeEventListener('mouseleave', onMouseLeave);
|
|
91
|
+
window.removeEventListener('keydown', onWindowKeyDown);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|