@skeletonlabs/skeleton 0.124.2 → 0.132.5
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 -1
- package/components/Accordion/Accordion.svelte +4 -0
- package/components/Accordion/Accordion.svelte.d.ts +4 -0
- package/components/Accordion/AccordionItem.svelte +14 -5
- package/components/Accordion/AccordionItem.svelte.d.ts +4 -1
- package/components/ConicGradient/settings.d.ts +0 -2
- package/components/ConicGradient/settings.js +0 -1
- package/components/FileButton/FileButton.svelte +1 -1
- package/components/FileDropzone/FileDropzone.svelte +1 -1
- package/components/InputChip/InputChip.svelte +3 -3
- package/components/ListBox/ListBoxItem.svelte +3 -3
- package/components/ListBox/ListBoxItem.svelte.d.ts +2 -1
- package/components/Paginator/Paginator.svelte +3 -3
- package/components/Radio/RadioItem.svelte +2 -2
- package/components/Radio/RadioItem.svelte.d.ts +2 -1
- package/components/RangeSlider/RangeSlider.svelte.d.ts +4 -4
- package/components/Stepper/Step.svelte +3 -3
- package/components/Tab/Tab.svelte +2 -2
- package/components/Tab/Tab.svelte.d.ts +2 -1
- package/index.d.ts +4 -3
- package/index.js +10 -3
- package/package.json +10 -11
- package/styles/elements/forms.css +5 -9
- package/styles/elements/modals.css +15 -0
- package/styles/elements/popups.css +16 -0
- package/styles/elements.css +2 -2
- package/styles/typography.css +3 -3
- package/tailwind/core.cjs +1 -1
- package/tailwind/generated/intellisense-classes.cjs +1 -1
- package/tailwind/generated/intellisense-classes.d.cts +65 -208
- 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 +12 -8
- package/utilities/CodeBlock/CodeBlock.svelte.d.ts +9 -1
- package/utilities/Drawer/Drawer.svelte +50 -37
- package/utilities/Drawer/Drawer.svelte.d.ts +8 -2
- package/utilities/Drawer/types.d.ts +8 -2
- package/utilities/LightSwitch/LightSwitch.svelte +43 -53
- package/utilities/LightSwitch/LightSwitch.svelte.d.ts +18 -4
- 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 +11 -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 +5 -3
- package/utilities/Toast/stores.js +9 -26
- package/utilities/Toast/types.d.ts +6 -1
- package/styles/elements/menus.css +0 -29
- package/styles/elements/tooltips.css +0 -83
- 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 -26
- 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
|
@@ -7,77 +7,83 @@ export let position = "left";
|
|
|
7
7
|
export let duration = 150;
|
|
8
8
|
export let bgBackdrop = "bg-surface-backdrop-token";
|
|
9
9
|
export let blur = "backdrop-blur-xs";
|
|
10
|
+
export let padding = "";
|
|
10
11
|
export let bgDrawer = "bg-surface-100-800-token";
|
|
11
12
|
export let border = "";
|
|
12
13
|
export let rounded = "";
|
|
14
|
+
export let shadow = "shadow-xl";
|
|
13
15
|
export let width = "";
|
|
14
16
|
export let height = "";
|
|
15
|
-
export let
|
|
17
|
+
export let regionBackdrop = "";
|
|
18
|
+
export let regionDrawer = "";
|
|
16
19
|
export let labelledby = "";
|
|
17
20
|
export let describedby = "";
|
|
18
|
-
const
|
|
19
|
-
|
|
21
|
+
const presets = {
|
|
22
|
+
top: { alignment: "items-start", width: "w-full", height: "h-[50%]", rounded: "rounded-bl-container-token rounded-br-container-token" },
|
|
23
|
+
bottom: { alignment: "items-end", width: "w-full", height: " h-[50%]", rounded: "rounded-tl-container-token rounded-tr-container-token" },
|
|
24
|
+
left: { alignment: "justify-start", width: "w-[90%]", height: "h-full", rounded: "rounded-tr-container-token rounded-br-container-token" },
|
|
25
|
+
right: { alignment: "justify-end", width: "w-[90%]", height: "h-full", rounded: "rounded-tl-container-token rounded-bl-container-token" }
|
|
26
|
+
};
|
|
27
|
+
const cBackdrop = "fixed top-0 left-0 right-0 bottom-0 z-40 flex";
|
|
28
|
+
const cDrawer = "ox-border overflow-y-auto transition-transform";
|
|
20
29
|
let elemBackdrop;
|
|
21
|
-
let
|
|
22
|
-
let
|
|
23
|
-
let animSettings = { x: 0, y: 0 };
|
|
30
|
+
let elemDrawer;
|
|
31
|
+
let anim = { x: 0, y: 0 };
|
|
24
32
|
const propDefaults = {
|
|
25
33
|
position,
|
|
26
34
|
duration,
|
|
27
35
|
bgBackdrop,
|
|
28
36
|
blur,
|
|
37
|
+
padding,
|
|
29
38
|
bgDrawer,
|
|
30
39
|
border,
|
|
31
40
|
rounded,
|
|
41
|
+
shadow,
|
|
32
42
|
width,
|
|
33
43
|
height,
|
|
34
|
-
margin,
|
|
35
44
|
labelledby,
|
|
36
|
-
describedby
|
|
45
|
+
describedby,
|
|
46
|
+
regionBackdrop,
|
|
47
|
+
regionDrawer
|
|
37
48
|
};
|
|
38
|
-
|
|
39
|
-
if (settings.open === false)
|
|
40
|
-
return;
|
|
41
|
-
applySettings(settings);
|
|
42
|
-
setPosition();
|
|
43
|
-
});
|
|
44
|
-
function applySettings(settings) {
|
|
49
|
+
function applyPropSettings(settings) {
|
|
45
50
|
position = settings.position || propDefaults.position;
|
|
46
51
|
duration = settings.duration || propDefaults.duration;
|
|
47
52
|
bgBackdrop = settings.bgBackdrop || propDefaults.bgBackdrop;
|
|
48
53
|
blur = settings.blur || propDefaults.blur;
|
|
54
|
+
padding = settings.padding || propDefaults.padding;
|
|
49
55
|
bgDrawer = settings.bgDrawer || propDefaults.bgDrawer;
|
|
50
56
|
border = settings.border || propDefaults.border;
|
|
51
57
|
rounded = settings.rounded || propDefaults.rounded;
|
|
58
|
+
shadow = settings.shadow || propDefaults.shadow;
|
|
52
59
|
width = settings.width || propDefaults.width;
|
|
53
60
|
height = settings.height || propDefaults.height;
|
|
54
|
-
|
|
61
|
+
regionBackdrop = settings.regionBackdrop || propDefaults.regionBackdrop;
|
|
62
|
+
regionDrawer = settings.regionDrawer || propDefaults.regionDrawer;
|
|
55
63
|
labelledby = settings.labelledby || propDefaults.labelledby;
|
|
56
64
|
describedby = settings.describedby || propDefaults.describedby;
|
|
57
65
|
}
|
|
58
|
-
function
|
|
66
|
+
function applyAnimationSettings() {
|
|
67
|
+
if (window === void 0)
|
|
68
|
+
return;
|
|
59
69
|
switch (position) {
|
|
60
70
|
case "top":
|
|
61
|
-
|
|
62
|
-
animSettings = { x: 0, y: -percentage(40, windowSettings.height) };
|
|
71
|
+
anim = { x: 0, y: -window.innerWidth };
|
|
63
72
|
break;
|
|
64
73
|
case "bottom":
|
|
65
|
-
|
|
66
|
-
|
|
74
|
+
anim = { x: 0, y: window.innerWidth };
|
|
75
|
+
break;
|
|
76
|
+
case "left":
|
|
77
|
+
anim = { x: -window.innerHeight, y: 0 };
|
|
67
78
|
break;
|
|
68
79
|
case "right":
|
|
69
|
-
|
|
70
|
-
animSettings = { x: percentage(90, windowSettings.width), y: 0 };
|
|
80
|
+
anim = { x: window.innerHeight, y: 0 };
|
|
71
81
|
break;
|
|
72
82
|
default:
|
|
73
|
-
|
|
74
|
-
animSettings = { x: -percentage(90, windowSettings.width), y: 0 };
|
|
83
|
+
console.error("Error: unknown position property value.");
|
|
75
84
|
break;
|
|
76
85
|
}
|
|
77
86
|
}
|
|
78
|
-
function percentage(percent, amount) {
|
|
79
|
-
return amount / 100 * percent;
|
|
80
|
-
}
|
|
81
87
|
function onBackdropInteraction(event) {
|
|
82
88
|
if (event.target === elemBackdrop)
|
|
83
89
|
drawerStore.close();
|
|
@@ -89,18 +95,24 @@ function onKeydownWindow(event) {
|
|
|
89
95
|
if (event.code === "Escape")
|
|
90
96
|
drawerStore.close();
|
|
91
97
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
98
|
+
drawerStore.subscribe((settings) => {
|
|
99
|
+
if (settings.open !== true)
|
|
100
|
+
return;
|
|
101
|
+
applyPropSettings(settings);
|
|
102
|
+
applyAnimationSettings();
|
|
95
103
|
});
|
|
96
104
|
$:
|
|
97
|
-
|
|
105
|
+
classesPosition = presets[position].alignment;
|
|
106
|
+
$:
|
|
107
|
+
classesWidth = width ? width : presets[position].width;
|
|
98
108
|
$:
|
|
99
|
-
classesHeight = height ? height :
|
|
109
|
+
classesHeight = height ? height : presets[position].height;
|
|
100
110
|
$:
|
|
101
|
-
|
|
111
|
+
classesRounded = rounded ? rounded : presets[position].rounded;
|
|
102
112
|
$:
|
|
103
|
-
|
|
113
|
+
classesBackdrop = `${cBackdrop} ${bgBackdrop} ${padding} ${blur} ${classesPosition} ${regionBackdrop} ${$$props.class ?? ""}`;
|
|
114
|
+
$:
|
|
115
|
+
classesDrawer = `${cDrawer} ${bgDrawer} ${border} ${rounded} ${shadow} ${classesWidth} ${classesHeight} ${classesRounded} ${regionDrawer}`;
|
|
104
116
|
</script>
|
|
105
117
|
|
|
106
118
|
<svelte:window on:keydown={onKeydownWindow} />
|
|
@@ -111,21 +123,22 @@ $:
|
|
|
111
123
|
bind:this={elemBackdrop}
|
|
112
124
|
class="drawer-backdrop {classesBackdrop}"
|
|
113
125
|
data-testid="drawer-backdrop"
|
|
114
|
-
transition:fade|local={{ duration }}
|
|
115
126
|
on:mousedown={onBackdropInteraction}
|
|
116
127
|
on:touchstart={onBackdropInteraction}
|
|
117
128
|
on:keypress
|
|
129
|
+
transition:fade|local={{ duration }}
|
|
118
130
|
use:focusTrap={true}
|
|
119
131
|
>
|
|
120
132
|
<!-- Drawer -->
|
|
121
133
|
<div
|
|
134
|
+
bind:this={elemDrawer}
|
|
122
135
|
class="drawer {classesDrawer}"
|
|
123
136
|
data-testid="drawer"
|
|
124
|
-
transition:fly|local={{ x: animSettings.x, y: animSettings.y, duration }}
|
|
125
137
|
role="dialog"
|
|
126
138
|
aria-modal="true"
|
|
127
139
|
aria-labelledby={labelledby}
|
|
128
140
|
aria-describedby={describedby}
|
|
141
|
+
transition:fly|local={{ x: anim.x, y: anim.y, duration }}
|
|
129
142
|
>
|
|
130
143
|
<!-- Slot: Default -->
|
|
131
144
|
<slot />
|
|
@@ -10,18 +10,24 @@ declare const __propDef: {
|
|
|
10
10
|
bgBackdrop?: string | undefined;
|
|
11
11
|
/** Backdrop - Provide classes to set the blur style.*/
|
|
12
12
|
blur?: string | undefined;
|
|
13
|
+
/** Drawer - Provide classes to set padding.*/
|
|
14
|
+
padding?: string | undefined;
|
|
13
15
|
/** Drawer - Provide classes to set the drawer background color.*/
|
|
14
16
|
bgDrawer?: string | undefined;
|
|
15
17
|
/** Drawer - Provide classes to set border color.*/
|
|
16
18
|
border?: string | undefined;
|
|
17
19
|
/** Drawer - Provide classes to set border radius.*/
|
|
18
20
|
rounded?: string | undefined;
|
|
21
|
+
/** Drawer - Provide classes to set the box shadow.*/
|
|
22
|
+
shadow?: string | undefined;
|
|
19
23
|
/** Drawer - Provide classes to override the width.*/
|
|
20
24
|
width?: string | undefined;
|
|
21
25
|
/** Drawer - Provide classes to override the height.*/
|
|
22
26
|
height?: string | undefined;
|
|
23
|
-
/**
|
|
24
|
-
|
|
27
|
+
/** Provide abitrary classes to the backdrop region.*/
|
|
28
|
+
regionBackdrop?: string | undefined;
|
|
29
|
+
/** Provide abitrary classes to the drawer region.*/
|
|
30
|
+
regionDrawer?: string | undefined;
|
|
25
31
|
/** Provide an ID of the element labeling the drawer.*/
|
|
26
32
|
labelledby?: string | undefined;
|
|
27
33
|
/** Provide an ID of the element describing the drawer.*/
|
|
@@ -14,18 +14,24 @@ export interface DrawerSettings {
|
|
|
14
14
|
bgBackdrop?: string;
|
|
15
15
|
/** Backdrop - Provide classes to set the blur style.*/
|
|
16
16
|
blur?: string;
|
|
17
|
+
/** Drawer - Provide classes to set padding.*/
|
|
18
|
+
padding?: string;
|
|
17
19
|
/** Drawer - Provide classes to set the drawer background color.*/
|
|
18
20
|
bgDrawer?: string;
|
|
19
21
|
/** Drawer - Provide classes to set border color.*/
|
|
20
22
|
border?: string;
|
|
21
23
|
/** Drawer - Provide classes to set border radius.*/
|
|
22
24
|
rounded?: string;
|
|
25
|
+
/** Drawer - Provide classes to set box shadow.*/
|
|
26
|
+
shadow?: string;
|
|
23
27
|
/** Drawer - Provide classes to override the width.*/
|
|
24
28
|
width?: string;
|
|
25
29
|
/** Drawer - Provide classes to override the height.*/
|
|
26
30
|
height?: string;
|
|
27
|
-
/**
|
|
28
|
-
|
|
31
|
+
/** Provide abitrary classes to the backdrop region. */
|
|
32
|
+
regionBackdrop?: string;
|
|
33
|
+
/** Provide abitrary classes to the drawer region. */
|
|
34
|
+
regionDrawer?: string;
|
|
29
35
|
/** Provide an ID of the element labeling the drawer.*/
|
|
30
36
|
labelledby?: string;
|
|
31
37
|
/** Provide an ID of the element describing the drawer.*/
|
|
@@ -1,80 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} else {
|
|
23
|
-
document.documentElement.classList.remove("dark");
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
function onClick(event) {
|
|
27
|
-
storeLightSwitch.set($storeLightSwitch = !$storeLightSwitch);
|
|
28
|
-
setElemHtmlClass();
|
|
29
|
-
dispatch("click", event);
|
|
1
|
+
<script>import { modeCurrent, setModeUserPrefers, setModeCurrent, setInitialClassState } from "./lightswitch";
|
|
2
|
+
export let bgLight = "bg-surface-50";
|
|
3
|
+
export let bgDark = "bg-surface-900";
|
|
4
|
+
export let fillLight = "fill-surface-50";
|
|
5
|
+
export let fillDark = "fill-surface-900";
|
|
6
|
+
export let width = "w-12";
|
|
7
|
+
export let height = "w-6";
|
|
8
|
+
export let ring = "ring-[1px] ring-surface-500/30";
|
|
9
|
+
export let rounded = "rounded-token";
|
|
10
|
+
const cTransition = `transition-all duration-[200ms]`;
|
|
11
|
+
const cTrack = "cursor-pointer";
|
|
12
|
+
const cThumb = "aspect-square scale-[0.8] flex justify-center items-center";
|
|
13
|
+
const cIcon = "w-[70%] aspect-square";
|
|
14
|
+
const svgPath = {
|
|
15
|
+
sun: "M361.5 1.2c5 2.1 8.6 6.6 9.6 11.9L391 121l107.9 19.8c5.3 1 9.8 4.6 11.9 9.6s1.5 10.7-1.6 15.2L446.9 256l62.3 90.3c3.1 4.5 3.7 10.2 1.6 15.2s-6.6 8.6-11.9 9.6L391 391 371.1 498.9c-1 5.3-4.6 9.8-9.6 11.9s-10.7 1.5-15.2-1.6L256 446.9l-90.3 62.3c-4.5 3.1-10.2 3.7-15.2 1.6s-8.6-6.6-9.6-11.9L121 391 13.1 371.1c-5.3-1-9.8-4.6-11.9-9.6s-1.5-10.7 1.6-15.2L65.1 256 2.8 165.7c-3.1-4.5-3.7-10.2-1.6-15.2s6.6-8.6 11.9-9.6L121 121 140.9 13.1c1-5.3 4.6-9.8 9.6-11.9s10.7-1.5 15.2 1.6L256 65.1 346.3 2.8c4.5-3.1 10.2-3.7 15.2-1.6zM352 256c0 53-43 96-96 96s-96-43-96-96s43-96 96-96s96 43 96 96zm32 0c0-70.7-57.3-128-128-128s-128 57.3-128 128s57.3 128 128 128s128-57.3 128-128z",
|
|
16
|
+
moon: "M223.5 32C100 32 0 132.3 0 256S100 480 223.5 480c60.6 0 115.5-24.2 155.8-63.4c5-4.9 6.3-12.5 3.1-18.7s-10.1-9.7-17-8.5c-9.8 1.7-19.8 2.6-30.1 2.6c-96.9 0-175.5-78.8-175.5-176c0-65.8 36-123.1 89.3-153.3c6.1-3.5 9.2-10.5 7.7-17.3s-7.3-11.9-14.3-12.5c-6.3-.5-12.6-.8-19-.8z"
|
|
17
|
+
};
|
|
18
|
+
function onToggleHandler() {
|
|
19
|
+
$modeCurrent = !$modeCurrent;
|
|
20
|
+
setModeUserPrefers($modeCurrent);
|
|
21
|
+
setModeCurrent($modeCurrent);
|
|
30
22
|
}
|
|
31
23
|
function onKeyDown(event) {
|
|
32
24
|
if (["Enter", "Space"].includes(event.code)) {
|
|
33
25
|
event.preventDefault();
|
|
34
26
|
event.currentTarget.click();
|
|
35
27
|
}
|
|
36
|
-
dispatch("keydown", event);
|
|
37
28
|
}
|
|
38
|
-
onMount(() => {
|
|
39
|
-
setPrefersDarkScheme();
|
|
40
|
-
});
|
|
41
29
|
$:
|
|
42
|
-
|
|
30
|
+
trackBg = $modeCurrent === true ? bgLight : bgDark;
|
|
31
|
+
$:
|
|
32
|
+
thumbBg = $modeCurrent === true ? bgDark : bgLight;
|
|
33
|
+
$:
|
|
34
|
+
thumbPosition = $modeCurrent === true ? "translate-x-[100%]" : "";
|
|
35
|
+
$:
|
|
36
|
+
iconFill = $modeCurrent === true ? fillLight : fillDark;
|
|
37
|
+
$:
|
|
38
|
+
classesTrack = `${cTrack} ${cTransition} ${width} ${height} ${ring} ${rounded} ${trackBg} ${$$props.class ?? ""}`;
|
|
43
39
|
$:
|
|
44
|
-
|
|
40
|
+
classesThumb = `${cThumb} ${cTransition} ${height} ${rounded} ${thumbBg} ${thumbPosition}`;
|
|
45
41
|
$:
|
|
46
|
-
|
|
42
|
+
classesIcon = `${cIcon} ${iconFill}`;
|
|
47
43
|
</script>
|
|
48
44
|
|
|
49
45
|
<svelte:head>
|
|
50
|
-
{@html `<script>${
|
|
46
|
+
{@html `<script>${setInitialClassState.toString()} setInitialClassState();</script>`}
|
|
51
47
|
</svelte:head>
|
|
52
48
|
|
|
53
|
-
<!-- prettier-ignore -->
|
|
54
49
|
<div
|
|
55
|
-
class="lightswitch {
|
|
56
|
-
on:click={
|
|
50
|
+
class="lightswitch-track {classesTrack}"
|
|
51
|
+
on:click={onToggleHandler}
|
|
52
|
+
on:click
|
|
57
53
|
on:keydown={onKeyDown}
|
|
54
|
+
on:keydown
|
|
58
55
|
on:keyup
|
|
59
56
|
on:keypress
|
|
60
57
|
role="switch"
|
|
61
58
|
aria-label="Light Switch"
|
|
62
|
-
aria-checked={$
|
|
63
|
-
title="Toggle {$
|
|
59
|
+
aria-checked={$modeCurrent}
|
|
60
|
+
title="Toggle {$modeCurrent === true ? 'Dark' : 'Light'} Mode"
|
|
64
61
|
tabindex="0"
|
|
65
62
|
>
|
|
66
63
|
<!-- Thumb -->
|
|
67
64
|
<div class="lightswitch-thumb {classesThumb}">
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
<
|
|
71
|
-
|
|
72
|
-
</svg>
|
|
73
|
-
{:else}
|
|
74
|
-
<!-- Icon Dark -->
|
|
75
|
-
<svg class="lightswitch-icon fill-white {cIcon}" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512">
|
|
76
|
-
<path d="M223.5 32C100 32 0 132.3 0 256S100 480 223.5 480c60.6 0 115.5-24.2 155.8-63.4c5-4.9 6.3-12.5 3.1-18.7s-10.1-9.7-17-8.5c-9.8 1.7-19.8 2.6-30.1 2.6c-96.9 0-175.5-78.8-175.5-176c0-65.8 36-123.1 89.3-153.3c6.1-3.5 9.2-10.5 7.7-17.3s-7.3-11.9-14.3-12.5c-6.3-.5-12.6-.8-19-.8z"/>
|
|
77
|
-
</svg>
|
|
78
|
-
{/if}
|
|
65
|
+
<!-- SVG -->
|
|
66
|
+
<svg class="lightswitch-icon {classesIcon}" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
|
|
67
|
+
<path d={$modeCurrent ? svgPath.sun : svgPath.moon} />
|
|
68
|
+
</svg>
|
|
79
69
|
</div>
|
|
80
70
|
</div>
|
|
@@ -2,14 +2,28 @@ import { SvelteComponentTyped } from "svelte";
|
|
|
2
2
|
declare const __propDef: {
|
|
3
3
|
props: {
|
|
4
4
|
[x: string]: any;
|
|
5
|
+
/** Provide classes to set the light background color.*/
|
|
6
|
+
bgLight?: string | undefined;
|
|
7
|
+
/** Provide classes to set the dark background color.*/
|
|
8
|
+
bgDark?: string | undefined;
|
|
9
|
+
/** Provide classes to set the light SVG fill color.*/
|
|
10
|
+
fillLight?: string | undefined;
|
|
11
|
+
/** Provide classes to set the dark SVG fill color.*/
|
|
12
|
+
fillDark?: string | undefined;
|
|
13
|
+
/** Provide classes to set width styles.*/
|
|
14
|
+
width?: string | undefined;
|
|
15
|
+
/** Provide classes to set height styles. Should be half of width.*/
|
|
16
|
+
height?: string | undefined;
|
|
17
|
+
/** Provide classes to set ring styles.*/
|
|
18
|
+
ring?: string | undefined;
|
|
19
|
+
/** Provide classes to set border radius styles.*/
|
|
20
|
+
rounded?: string | undefined;
|
|
5
21
|
};
|
|
6
22
|
events: {
|
|
23
|
+
click: MouseEvent;
|
|
24
|
+
keydown: KeyboardEvent;
|
|
7
25
|
keyup: KeyboardEvent;
|
|
8
26
|
keypress: KeyboardEvent;
|
|
9
|
-
/** {{ event }} click - Fires when the component is clicked.*/
|
|
10
|
-
click: CustomEvent<any>;
|
|
11
|
-
/** {{ event }} keydown - Fires when the component has keydown event.*/
|
|
12
|
-
keydown: CustomEvent<any>;
|
|
13
27
|
} & {
|
|
14
28
|
[evt: string]: CustomEvent<any>;
|
|
15
29
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Store: OS Preference Mode */
|
|
2
|
+
export declare const modeOsPrefers: import("svelte/store").Writable<boolean>;
|
|
3
|
+
/** Store: User Preference Mode */
|
|
4
|
+
export declare const modeUserPrefers: import("svelte/store").Writable<boolean | undefined>;
|
|
5
|
+
/** Store: Current Mode State */
|
|
6
|
+
export declare const modeCurrent: import("svelte/store").Writable<boolean>;
|
|
7
|
+
/** Get the OS Preference for light/dark mode */
|
|
8
|
+
export declare function getModeOsPrefers(): boolean;
|
|
9
|
+
/** Get the User for light/dark mode */
|
|
10
|
+
export declare function getModeUserPrefers(): boolean | undefined;
|
|
11
|
+
/** Get the Automatic Preference light/dark mode */
|
|
12
|
+
export declare function getModeAutoPrefers(): boolean;
|
|
13
|
+
/** Set the User Preference for light/dark mode */
|
|
14
|
+
export declare function setModeUserPrefers(value: boolean): void;
|
|
15
|
+
/** Set the the current light/dark mode */
|
|
16
|
+
export declare function setModeCurrent(value: boolean): void;
|
|
17
|
+
/** Set the visible light/dark mode on page load. */
|
|
18
|
+
export declare function setInitialClassState(): void;
|
|
19
|
+
/** Automatically set the visible light/dark, updates on change. */
|
|
20
|
+
export declare function autoModeWatcher(): void;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Lightswitch Service
|
|
2
|
+
import { get } from 'svelte/store';
|
|
3
|
+
import { localStorageStore } from '../LocalStorageStore/LocalStorageStore';
|
|
4
|
+
// Stores ---
|
|
5
|
+
// TRUE: light, FALSE: dark
|
|
6
|
+
/** Store: OS Preference Mode */
|
|
7
|
+
export const modeOsPrefers = localStorageStore('modeOsPrefers', false);
|
|
8
|
+
/** Store: User Preference Mode */
|
|
9
|
+
export const modeUserPrefers = localStorageStore('modeUserPrefers', undefined);
|
|
10
|
+
/** Store: Current Mode State */
|
|
11
|
+
export const modeCurrent = localStorageStore('modeCurrent', false);
|
|
12
|
+
// Get ---
|
|
13
|
+
/** Get the OS Preference for light/dark mode */
|
|
14
|
+
export function getModeOsPrefers() {
|
|
15
|
+
const prefersLightMode = window.matchMedia('(prefers-color-scheme: light)').matches;
|
|
16
|
+
modeOsPrefers.set(prefersLightMode);
|
|
17
|
+
return prefersLightMode;
|
|
18
|
+
}
|
|
19
|
+
/** Get the User for light/dark mode */
|
|
20
|
+
export function getModeUserPrefers() {
|
|
21
|
+
return get(modeUserPrefers);
|
|
22
|
+
}
|
|
23
|
+
/** Get the Automatic Preference light/dark mode */
|
|
24
|
+
export function getModeAutoPrefers() {
|
|
25
|
+
const os = getModeOsPrefers();
|
|
26
|
+
const user = getModeUserPrefers();
|
|
27
|
+
const modeValue = user !== undefined ? user : os;
|
|
28
|
+
return modeValue;
|
|
29
|
+
}
|
|
30
|
+
// Set ---
|
|
31
|
+
/** Set the User Preference for light/dark mode */
|
|
32
|
+
export function setModeUserPrefers(value) {
|
|
33
|
+
modeUserPrefers.set(value);
|
|
34
|
+
}
|
|
35
|
+
/** Set the the current light/dark mode */
|
|
36
|
+
export function setModeCurrent(value) {
|
|
37
|
+
const elemHtmlClasses = document.documentElement.classList;
|
|
38
|
+
const classDark = `dark`;
|
|
39
|
+
value === true ? elemHtmlClasses.remove(classDark) : elemHtmlClasses.add(classDark);
|
|
40
|
+
modeCurrent.set(value);
|
|
41
|
+
}
|
|
42
|
+
// Lightswitch Utility
|
|
43
|
+
/** Set the visible light/dark mode on page load. */
|
|
44
|
+
export function setInitialClassState() {
|
|
45
|
+
const elemHtmlClasses = document.documentElement.classList;
|
|
46
|
+
// Conditions
|
|
47
|
+
const condLocalStroageUserPrefs = localStorage.getItem('modeUserPrefers') === 'false';
|
|
48
|
+
const condLocalStroageUserPrefsExists = !('modeUserPrefers' in localStorage);
|
|
49
|
+
const condMatchMedia = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
50
|
+
// Add/remove `.dark` class to HTML element
|
|
51
|
+
if (condLocalStroageUserPrefs || (condLocalStroageUserPrefsExists && condMatchMedia)) {
|
|
52
|
+
elemHtmlClasses.add('dark');
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
elemHtmlClasses.remove('dark');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Auto-Switch Utility
|
|
59
|
+
/** Automatically set the visible light/dark, updates on change. */
|
|
60
|
+
export function autoModeWatcher() {
|
|
61
|
+
const mql = window.matchMedia('(prefers-color-scheme: light)');
|
|
62
|
+
function setMode(value) {
|
|
63
|
+
const elemHtmlClasses = document.documentElement.classList;
|
|
64
|
+
const classDark = `dark`;
|
|
65
|
+
value === true ? elemHtmlClasses.remove(classDark) : elemHtmlClasses.add(classDark);
|
|
66
|
+
}
|
|
67
|
+
setMode(mql.matches);
|
|
68
|
+
mql.onchange = () => {
|
|
69
|
+
setMode(mql.matches);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Source: https://github.com/joshnuss/svelte-local-storage-store
|
|
2
2
|
// https://github.com/joshnuss/svelte-local-storage-store/blob/master/index.ts
|
|
3
|
-
// Represents version v0.
|
|
3
|
+
// Represents version v0.4.0 (2023-01-18)
|
|
4
4
|
import { writable as internal, get } from 'svelte/store';
|
|
5
5
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
6
6
|
const stores = {};
|