polymorph-ui-components 0.1.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/README.md +354 -0
- package/dist/Accordion/Accordion.svelte +28 -0
- package/dist/Accordion/Accordion.svelte.d.ts +4 -0
- package/dist/Accordion/properties.d.ts +7 -0
- package/dist/Accordion/properties.js +1 -0
- package/dist/Animations/ModalAnimation.svelte +55 -0
- package/dist/Animations/ModalAnimation.svelte.d.ts +12 -0
- package/dist/Animations/OverlayAnimation.svelte +14 -0
- package/dist/Animations/OverlayAnimation.svelte.d.ts +7 -0
- package/dist/Avatar/Avatar.svelte +122 -0
- package/dist/Avatar/Avatar.svelte.d.ts +4 -0
- package/dist/Avatar/properties.d.ts +15 -0
- package/dist/Avatar/properties.js +1 -0
- package/dist/Badge/Badge.svelte +53 -0
- package/dist/Badge/Badge.svelte.d.ts +4 -0
- package/dist/Badge/properties.d.ts +6 -0
- package/dist/Badge/properties.js +1 -0
- package/dist/Banner/Banner.svelte +158 -0
- package/dist/Banner/Banner.svelte.d.ts +4 -0
- package/dist/Banner/properties.d.ts +19 -0
- package/dist/Banner/properties.js +1 -0
- package/dist/Book/Book.svelte +281 -0
- package/dist/Book/Book.svelte.d.ts +4 -0
- package/dist/Book/properties.d.ts +24 -0
- package/dist/Book/properties.js +1 -0
- package/dist/Browser/Browser.svelte +176 -0
- package/dist/Browser/Browser.svelte.d.ts +3 -0
- package/dist/Browser/properties.d.ts +14 -0
- package/dist/Browser/properties.js +1 -0
- package/dist/Button/Button.svelte +153 -0
- package/dist/Button/Button.svelte.d.ts +4 -0
- package/dist/Button/properties.d.ts +24 -0
- package/dist/Button/properties.js +1 -0
- package/dist/Calendar/Calendar.svelte +477 -0
- package/dist/Calendar/Calendar.svelte.d.ts +4 -0
- package/dist/Calendar/properties.d.ts +30 -0
- package/dist/Calendar/properties.js +1 -0
- package/dist/Carousel/Carousel.svelte +258 -0
- package/dist/Carousel/Carousel.svelte.d.ts +4 -0
- package/dist/Carousel/properties.d.ts +20 -0
- package/dist/Carousel/properties.js +1 -0
- package/dist/CheckListItem/CheckListItem.svelte +65 -0
- package/dist/CheckListItem/CheckListItem.svelte.d.ts +4 -0
- package/dist/CheckListItem/properties.d.ts +15 -0
- package/dist/CheckListItem/properties.js +1 -0
- package/dist/Checkbox/Checkbox.svelte +157 -0
- package/dist/Checkbox/Checkbox.svelte.d.ts +4 -0
- package/dist/Checkbox/properties.d.ts +17 -0
- package/dist/Checkbox/properties.js +1 -0
- package/dist/Choicebox/Choicebox.svelte +85 -0
- package/dist/Choicebox/Choicebox.svelte.d.ts +4 -0
- package/dist/Choicebox/properties.d.ts +14 -0
- package/dist/Choicebox/properties.js +1 -0
- package/dist/ColorPicker/ColorPicker.svelte +583 -0
- package/dist/ColorPicker/ColorPicker.svelte.d.ts +4 -0
- package/dist/ColorPicker/properties.d.ts +15 -0
- package/dist/ColorPicker/properties.js +1 -0
- package/dist/Combobox/Combobox.svelte +432 -0
- package/dist/Combobox/Combobox.svelte.d.ts +6 -0
- package/dist/Combobox/properties.d.ts +42 -0
- package/dist/Combobox/properties.js +1 -0
- package/dist/CommandMenu/CommandMenu.svelte +452 -0
- package/dist/CommandMenu/CommandMenu.svelte.d.ts +4 -0
- package/dist/CommandMenu/properties.d.ts +26 -0
- package/dist/CommandMenu/properties.js +1 -0
- package/dist/ContextMenu/ContextMenu.svelte +308 -0
- package/dist/ContextMenu/ContextMenu.svelte.d.ts +4 -0
- package/dist/ContextMenu/properties.d.ts +26 -0
- package/dist/ContextMenu/properties.js +1 -0
- package/dist/Gauge/Gauge.svelte +70 -0
- package/dist/Gauge/Gauge.svelte.d.ts +4 -0
- package/dist/Gauge/properties.d.ts +9 -0
- package/dist/Gauge/properties.js +1 -0
- package/dist/GridItem/GridItem.svelte +145 -0
- package/dist/GridItem/GridItem.svelte.d.ts +4 -0
- package/dist/GridItem/properties.d.ts +15 -0
- package/dist/GridItem/properties.js +1 -0
- package/dist/Icon/Icon.svelte +61 -0
- package/dist/Icon/Icon.svelte.d.ts +4 -0
- package/dist/Icon/properties.d.ts +12 -0
- package/dist/Icon/properties.js +1 -0
- package/dist/IconStack/IconStack.svelte +55 -0
- package/dist/IconStack/IconStack.svelte.d.ts +4 -0
- package/dist/IconStack/properties.d.ts +9 -0
- package/dist/IconStack/properties.js +1 -0
- package/dist/Img/Img.svelte +37 -0
- package/dist/Img/Img.svelte.d.ts +4 -0
- package/dist/Img/properties.d.ts +13 -0
- package/dist/Img/properties.js +1 -0
- package/dist/Input/Input.svelte +349 -0
- package/dist/Input/Input.svelte.d.ts +8 -0
- package/dist/Input/properties.d.ts +45 -0
- package/dist/Input/properties.js +1 -0
- package/dist/InputButton/InputButton.svelte +252 -0
- package/dist/InputButton/InputButton.svelte.d.ts +7 -0
- package/dist/InputButton/properties.d.ts +22 -0
- package/dist/InputButton/properties.js +1 -0
- package/dist/KeyboardInput/KeyboardInput.svelte +93 -0
- package/dist/KeyboardInput/KeyboardInput.svelte.d.ts +4 -0
- package/dist/KeyboardInput/properties.d.ts +12 -0
- package/dist/KeyboardInput/properties.js +1 -0
- package/dist/ListItem/ListItem.svelte +309 -0
- package/dist/ListItem/ListItem.svelte.d.ts +4 -0
- package/dist/ListItem/properties.d.ts +34 -0
- package/dist/ListItem/properties.js +1 -0
- package/dist/Loader/Loader.svelte +90 -0
- package/dist/Loader/Loader.svelte.d.ts +4 -0
- package/dist/Loader/properties.d.ts +4 -0
- package/dist/Loader/properties.js +1 -0
- package/dist/LoadingDots/LoadingDots.svelte +59 -0
- package/dist/LoadingDots/LoadingDots.svelte.d.ts +3 -0
- package/dist/LoadingDots/properties.d.ts +8 -0
- package/dist/LoadingDots/properties.js +1 -0
- package/dist/Menu/Menu.svelte +356 -0
- package/dist/Menu/Menu.svelte.d.ts +4 -0
- package/dist/Menu/properties.d.ts +28 -0
- package/dist/Menu/properties.js +1 -0
- package/dist/Modal/Modal.svelte +357 -0
- package/dist/Modal/Modal.svelte.d.ts +4 -0
- package/dist/Modal/properties.d.ts +39 -0
- package/dist/Modal/properties.js +1 -0
- package/dist/Pagination/Pagination.svelte +148 -0
- package/dist/Pagination/Pagination.svelte.d.ts +4 -0
- package/dist/Pagination/properties.d.ts +14 -0
- package/dist/Pagination/properties.js +1 -0
- package/dist/Phone/Phone.svelte +234 -0
- package/dist/Phone/Phone.svelte.d.ts +3 -0
- package/dist/Phone/properties.d.ts +11 -0
- package/dist/Phone/properties.js +1 -0
- package/dist/Pill/Pill.svelte +130 -0
- package/dist/Pill/Pill.svelte.d.ts +4 -0
- package/dist/Pill/properties.d.ts +16 -0
- package/dist/Pill/properties.js +1 -0
- package/dist/Progress/Progress.svelte +68 -0
- package/dist/Progress/Progress.svelte.d.ts +4 -0
- package/dist/Progress/properties.d.ts +10 -0
- package/dist/Progress/properties.js +1 -0
- package/dist/Radio/Radio.svelte +124 -0
- package/dist/Radio/Radio.svelte.d.ts +4 -0
- package/dist/Radio/properties.d.ts +15 -0
- package/dist/Radio/properties.js +1 -0
- package/dist/RelativeTime/RelativeTime.svelte +109 -0
- package/dist/RelativeTime/RelativeTime.svelte.d.ts +4 -0
- package/dist/RelativeTime/properties.d.ts +13 -0
- package/dist/RelativeTime/properties.js +1 -0
- package/dist/Scroller/Scroller.svelte +390 -0
- package/dist/Scroller/Scroller.svelte.d.ts +4 -0
- package/dist/Scroller/properties.d.ts +30 -0
- package/dist/Scroller/properties.js +1 -0
- package/dist/Select/Select.svelte +472 -0
- package/dist/Select/Select.svelte.d.ts +4 -0
- package/dist/Select/properties.d.ts +20 -0
- package/dist/Select/properties.js +1 -0
- package/dist/Sheet/Sheet.svelte +264 -0
- package/dist/Sheet/Sheet.svelte.d.ts +4 -0
- package/dist/Sheet/properties.d.ts +19 -0
- package/dist/Sheet/properties.js +1 -0
- package/dist/Shimmer/Shimmer.svelte +44 -0
- package/dist/Shimmer/Shimmer.svelte.d.ts +4 -0
- package/dist/Shimmer/properties.d.ts +4 -0
- package/dist/Shimmer/properties.js +1 -0
- package/dist/Slider/Slider.svelte +147 -0
- package/dist/Slider/Slider.svelte.d.ts +4 -0
- package/dist/Slider/properties.d.ts +17 -0
- package/dist/Slider/properties.js +1 -0
- package/dist/Snippet/Snippet.svelte +123 -0
- package/dist/Snippet/Snippet.svelte.d.ts +4 -0
- package/dist/Snippet/properties.d.ts +15 -0
- package/dist/Snippet/properties.js +1 -0
- package/dist/SplitButton/SplitButton.svelte +145 -0
- package/dist/SplitButton/SplitButton.svelte.d.ts +4 -0
- package/dist/SplitButton/properties.d.ts +17 -0
- package/dist/SplitButton/properties.js +1 -0
- package/dist/SplitInput/SplitInput.svelte +225 -0
- package/dist/SplitInput/SplitInput.svelte.d.ts +7 -0
- package/dist/SplitInput/properties.d.ts +20 -0
- package/dist/SplitInput/properties.js +1 -0
- package/dist/Stepper/Step.svelte +88 -0
- package/dist/Stepper/Step.svelte.d.ts +4 -0
- package/dist/Stepper/Stepper.svelte +64 -0
- package/dist/Stepper/Stepper.svelte.d.ts +4 -0
- package/dist/Stepper/properties.d.ts +27 -0
- package/dist/Stepper/properties.js +1 -0
- package/dist/Table/Table.svelte +357 -0
- package/dist/Table/Table.svelte.d.ts +4 -0
- package/dist/Table/properties.d.ts +26 -0
- package/dist/Table/properties.js +1 -0
- package/dist/Tabs/Tabs.svelte +303 -0
- package/dist/Tabs/Tabs.svelte.d.ts +4 -0
- package/dist/Tabs/properties.d.ts +30 -0
- package/dist/Tabs/properties.js +1 -0
- package/dist/ThemeSwitcher/ThemeSwitcher.svelte +249 -0
- package/dist/ThemeSwitcher/ThemeSwitcher.svelte.d.ts +4 -0
- package/dist/ThemeSwitcher/properties.d.ts +19 -0
- package/dist/ThemeSwitcher/properties.js +1 -0
- package/dist/Toast/Toast.svelte +220 -0
- package/dist/Toast/Toast.svelte.d.ts +4 -0
- package/dist/Toast/properties.d.ts +24 -0
- package/dist/Toast/properties.js +1 -0
- package/dist/Toggle/Toggle.svelte +99 -0
- package/dist/Toggle/Toggle.svelte.d.ts +4 -0
- package/dist/Toggle/properties.d.ts +9 -0
- package/dist/Toggle/properties.js +1 -0
- package/dist/Toolbar/Toolbar.svelte +142 -0
- package/dist/Toolbar/Toolbar.svelte.d.ts +4 -0
- package/dist/Toolbar/properties.d.ts +16 -0
- package/dist/Toolbar/properties.js +1 -0
- package/dist/Tooltip/Tooltip.svelte +153 -0
- package/dist/Tooltip/Tooltip.svelte.d.ts +4 -0
- package/dist/Tooltip/properties.d.ts +13 -0
- package/dist/Tooltip/properties.js +1 -0
- package/dist/assets/back.svg +3 -0
- package/dist/assets/battery.svg +5 -0
- package/dist/assets/checkmark.svg +3 -0
- package/dist/assets/chevron-down-sm.svg +3 -0
- package/dist/assets/chevron-down.svg +3 -0
- package/dist/assets/chevron-left-lg.svg +3 -0
- package/dist/assets/chevron-left.svg +3 -0
- package/dist/assets/chevron-right-lg.svg +3 -0
- package/dist/assets/chevron-right.svg +3 -0
- package/dist/assets/chevron-up.svg +3 -0
- package/dist/assets/close.svg +4 -0
- package/dist/assets/copy.svg +4 -0
- package/dist/assets/error-circle.svg +5 -0
- package/dist/assets/lock.svg +3 -0
- package/dist/assets/minus.svg +3 -0
- package/dist/assets/monitor.svg +5 -0
- package/dist/assets/moon.svg +3 -0
- package/dist/assets/palette.svg +7 -0
- package/dist/assets/search.svg +4 -0
- package/dist/assets/signal.svg +6 -0
- package/dist/assets/sort-default.svg +4 -0
- package/dist/assets/sun.svg +11 -0
- package/dist/assets/swap-vertical.svg +6 -0
- package/dist/assets/wifi.svg +3 -0
- package/dist/index.d.ts +103 -0
- package/dist/index.js +55 -0
- package/dist/types.d.ts +42 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +28 -0
- package/dist/utils.js +294 -0
- package/package.json +91 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
export type TabItem = {
|
|
3
|
+
key: string;
|
|
4
|
+
label: string;
|
|
5
|
+
testId?: string;
|
|
6
|
+
subtitle?: string;
|
|
7
|
+
};
|
|
8
|
+
export type TabsProperties = MandatoryTabsProperties & OptionalTabsProperties & TabsEventProperties;
|
|
9
|
+
export type MandatoryTabsProperties = {
|
|
10
|
+
items: string[] | TabItem[];
|
|
11
|
+
};
|
|
12
|
+
export type OptionalTabsProperties = {
|
|
13
|
+
activeIndex?: number;
|
|
14
|
+
activeKey?: string;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
testId?: string;
|
|
17
|
+
scrollLeftIcon?: Snippet;
|
|
18
|
+
scrollRightIcon?: Snippet;
|
|
19
|
+
tab?: Snippet<[{
|
|
20
|
+
label: string;
|
|
21
|
+
index: number;
|
|
22
|
+
active: boolean;
|
|
23
|
+
subtitle?: string;
|
|
24
|
+
}]>;
|
|
25
|
+
classes?: string;
|
|
26
|
+
};
|
|
27
|
+
export type TabsEventProperties = {
|
|
28
|
+
onchange?: (index: number, label: string) => void;
|
|
29
|
+
onkeychange?: (key: string) => void;
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount, tick, untrack } from 'svelte';
|
|
3
|
+
import type { ThemeSwitcherOption, ThemeSwitcherProperties } from './properties';
|
|
4
|
+
import { getStorageItem, setStorageItem } from '../utils';
|
|
5
|
+
import sunSvg from '../assets/sun.svg?raw';
|
|
6
|
+
import moonSvg from '../assets/moon.svg?raw';
|
|
7
|
+
import monitorSvg from '../assets/monitor.svg?raw';
|
|
8
|
+
import paletteSvg from '../assets/palette.svg?raw';
|
|
9
|
+
|
|
10
|
+
const DEFAULT_OPTIONS: ThemeSwitcherOption[] = [
|
|
11
|
+
{ value: 'light', label: 'Light theme' },
|
|
12
|
+
{ value: 'dark', label: 'Dark theme' },
|
|
13
|
+
{ value: 'system', label: 'System theme' }
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
const KNOWN_ICONS: Record<string, string> = {
|
|
17
|
+
light: sunSvg,
|
|
18
|
+
dark: moonSvg,
|
|
19
|
+
system: monitorSvg
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function getDefaultIcon(value: string): string {
|
|
23
|
+
return KNOWN_ICONS[value] ?? paletteSvg;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let {
|
|
27
|
+
options = DEFAULT_OPTIONS,
|
|
28
|
+
value,
|
|
29
|
+
mode,
|
|
30
|
+
storageKey = 'theme-preference',
|
|
31
|
+
testId,
|
|
32
|
+
classes,
|
|
33
|
+
onchange
|
|
34
|
+
}: ThemeSwitcherProperties = $props();
|
|
35
|
+
|
|
36
|
+
let currentValue: string = $state(untrack(() => value) ?? 'system');
|
|
37
|
+
let systemPreference: string = $state('light');
|
|
38
|
+
|
|
39
|
+
let hasSystemOption = $derived(options.some((o) => o.value === 'system'));
|
|
40
|
+
let effectiveMode = $derived(mode ?? (options.length <= 2 ? 'toggle' : 'segment'));
|
|
41
|
+
let currentIndex = $derived(options.findIndex((o) => o.value === currentValue));
|
|
42
|
+
|
|
43
|
+
let segmentButtons: HTMLButtonElement[] = $state([]);
|
|
44
|
+
let indicatorLeft: number = $state(0);
|
|
45
|
+
let indicatorWidth: number = $state(0);
|
|
46
|
+
|
|
47
|
+
function updateIndicator(): void {
|
|
48
|
+
const btn = segmentButtons.at(currentIndex);
|
|
49
|
+
if (btn instanceof HTMLButtonElement) {
|
|
50
|
+
indicatorLeft = btn.offsetLeft;
|
|
51
|
+
indicatorWidth = btn.offsetWidth;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function applyValue(newValue: string): void {
|
|
56
|
+
currentValue = newValue;
|
|
57
|
+
if (typeof storageKey === 'string' && storageKey.length > 0) {
|
|
58
|
+
setStorageItem(storageKey, newValue);
|
|
59
|
+
}
|
|
60
|
+
const resolved = newValue === 'system' ? systemPreference : newValue;
|
|
61
|
+
onchange?.(newValue, resolved);
|
|
62
|
+
tick().then(updateIndicator);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function handleToggle(): void {
|
|
66
|
+
const nextIndex = (currentIndex + 1) % options.length;
|
|
67
|
+
const nextOption = options.at(nextIndex);
|
|
68
|
+
if (typeof nextOption === 'object' && nextOption !== null) {
|
|
69
|
+
applyValue(nextOption.value);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
onMount(() => {
|
|
74
|
+
systemPreference = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
75
|
+
|
|
76
|
+
if (typeof storageKey === 'string' && storageKey.length > 0) {
|
|
77
|
+
const stored = getStorageItem(storageKey);
|
|
78
|
+
if (
|
|
79
|
+
typeof stored === 'string' &&
|
|
80
|
+
stored.length > 0 &&
|
|
81
|
+
options.some((o) => o.value === stored)
|
|
82
|
+
) {
|
|
83
|
+
currentValue = stored;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (typeof value === 'string' && value !== '') {
|
|
88
|
+
currentValue = value;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
onchange?.(currentValue, currentValue === 'system' ? systemPreference : currentValue);
|
|
92
|
+
tick().then(updateIndicator);
|
|
93
|
+
|
|
94
|
+
if (hasSystemOption) {
|
|
95
|
+
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
96
|
+
const handler = (e: MediaQueryListEvent) => {
|
|
97
|
+
systemPreference = e.matches ? 'dark' : 'light';
|
|
98
|
+
if (currentValue === 'system') {
|
|
99
|
+
onchange?.(currentValue, systemPreference);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
mediaQuery.addEventListener('change', handler);
|
|
103
|
+
return () => {
|
|
104
|
+
mediaQuery.removeEventListener('change', handler);
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
</script>
|
|
109
|
+
|
|
110
|
+
{#if effectiveMode === 'toggle'}
|
|
111
|
+
<button
|
|
112
|
+
class="toggle-button {classes ?? ''}"
|
|
113
|
+
onclick={handleToggle}
|
|
114
|
+
aria-label="Switch theme"
|
|
115
|
+
data-pw={testId}
|
|
116
|
+
>
|
|
117
|
+
{#each options as option, i (option.value)}
|
|
118
|
+
<span class="icon" class:active={i === currentIndex}>
|
|
119
|
+
{#if typeof option.icon === 'function'}
|
|
120
|
+
{@render option.icon()}
|
|
121
|
+
{:else}
|
|
122
|
+
<!-- eslint-disable svelte/no-at-html-tags -->
|
|
123
|
+
{@html getDefaultIcon(option.value)}
|
|
124
|
+
{/if}
|
|
125
|
+
</span>
|
|
126
|
+
{/each}
|
|
127
|
+
</button>
|
|
128
|
+
{:else}
|
|
129
|
+
<div class="segment-control {classes ?? ''}" data-pw={testId}>
|
|
130
|
+
<div
|
|
131
|
+
class="segment-indicator"
|
|
132
|
+
style="left: {indicatorLeft}px; width: {indicatorWidth}px;"
|
|
133
|
+
></div>
|
|
134
|
+
{#each options as option, i (option.value)}
|
|
135
|
+
<button
|
|
136
|
+
bind:this={segmentButtons[i]}
|
|
137
|
+
class="segment-button"
|
|
138
|
+
class:selected={currentValue === option.value}
|
|
139
|
+
onclick={() => applyValue(option.value)}
|
|
140
|
+
aria-label={option.label ?? option.value}
|
|
141
|
+
>
|
|
142
|
+
<span class="icon">
|
|
143
|
+
{#if typeof option.icon === 'function'}
|
|
144
|
+
{@render option.icon()}
|
|
145
|
+
{:else}
|
|
146
|
+
<!-- eslint-disable svelte/no-at-html-tags -->
|
|
147
|
+
{@html getDefaultIcon(option.value)}
|
|
148
|
+
{/if}
|
|
149
|
+
</span>
|
|
150
|
+
</button>
|
|
151
|
+
{/each}
|
|
152
|
+
</div>
|
|
153
|
+
{/if}
|
|
154
|
+
|
|
155
|
+
<style>
|
|
156
|
+
.toggle-button {
|
|
157
|
+
position: relative;
|
|
158
|
+
display: inline-flex;
|
|
159
|
+
align-items: center;
|
|
160
|
+
justify-content: center;
|
|
161
|
+
width: var(--theme-switcher-size, 36px);
|
|
162
|
+
height: var(--theme-switcher-size, 36px);
|
|
163
|
+
padding: 0;
|
|
164
|
+
border: none;
|
|
165
|
+
border-radius: var(--theme-switcher-border-radius, 6px);
|
|
166
|
+
background-color: var(--theme-switcher-bg, transparent);
|
|
167
|
+
cursor: pointer;
|
|
168
|
+
color: var(--theme-switcher-icon-color, currentColor);
|
|
169
|
+
transition: background-color var(--theme-switcher-transition-duration, 0.3s);
|
|
170
|
+
font-family: inherit;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.toggle-button:hover {
|
|
174
|
+
background-color: var(--theme-switcher-bg-hover, transparent);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.icon {
|
|
178
|
+
display: inline-flex;
|
|
179
|
+
align-items: center;
|
|
180
|
+
justify-content: center;
|
|
181
|
+
width: var(--theme-switcher-icon-size, 18px);
|
|
182
|
+
height: var(--theme-switcher-icon-size, 18px);
|
|
183
|
+
transition:
|
|
184
|
+
opacity var(--theme-switcher-transition-duration, 0.3s),
|
|
185
|
+
transform var(--theme-switcher-transition-duration, 0.3s);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.icon :global(svg) {
|
|
189
|
+
width: 100%;
|
|
190
|
+
height: 100%;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.toggle-button .icon {
|
|
194
|
+
position: absolute;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.toggle-button .icon:not(.active) {
|
|
198
|
+
opacity: 0;
|
|
199
|
+
transform: scale(0.5) rotate(90deg);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.toggle-button .icon.active {
|
|
203
|
+
opacity: 1;
|
|
204
|
+
transform: scale(1) rotate(0deg);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.segment-control {
|
|
208
|
+
position: relative;
|
|
209
|
+
display: inline-flex;
|
|
210
|
+
align-items: center;
|
|
211
|
+
gap: var(--theme-switcher-segment-gap, 2px);
|
|
212
|
+
padding: var(--theme-switcher-segment-padding, 4px);
|
|
213
|
+
background-color: var(--theme-switcher-segment-bg, transparent);
|
|
214
|
+
border-radius: var(--theme-switcher-border-radius, 6px);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.segment-indicator {
|
|
218
|
+
position: absolute;
|
|
219
|
+
top: var(--theme-switcher-segment-padding, 4px);
|
|
220
|
+
bottom: var(--theme-switcher-segment-padding, 4px);
|
|
221
|
+
border-radius: var(--theme-switcher-segment-border-radius, 6px);
|
|
222
|
+
background-color: var(--theme-switcher-segment-active-bg, #ffffff);
|
|
223
|
+
box-shadow: var(--theme-switcher-segment-shadow, 0 1px 2px rgba(0, 0, 0, 0.1));
|
|
224
|
+
transition:
|
|
225
|
+
left var(--theme-switcher-transition-duration, 0.3s),
|
|
226
|
+
width var(--theme-switcher-transition-duration, 0.3s);
|
|
227
|
+
z-index: 0;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
.segment-button {
|
|
231
|
+
position: relative;
|
|
232
|
+
z-index: 1;
|
|
233
|
+
display: inline-flex;
|
|
234
|
+
align-items: center;
|
|
235
|
+
justify-content: center;
|
|
236
|
+
padding: var(--theme-switcher-segment-button-padding, 6px 10px);
|
|
237
|
+
border: none;
|
|
238
|
+
border-radius: var(--theme-switcher-segment-border-radius, 6px);
|
|
239
|
+
background: transparent;
|
|
240
|
+
cursor: pointer;
|
|
241
|
+
color: var(--theme-switcher-icon-color, currentColor);
|
|
242
|
+
transition: color var(--theme-switcher-transition-duration, 0.3s);
|
|
243
|
+
font-family: inherit;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
.segment-button.selected {
|
|
247
|
+
color: var(--theme-switcher-icon-color-active, currentColor);
|
|
248
|
+
}
|
|
249
|
+
</style>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
export type ThemeSwitcherOption = {
|
|
3
|
+
value: string;
|
|
4
|
+
label?: string;
|
|
5
|
+
icon?: Snippet;
|
|
6
|
+
};
|
|
7
|
+
export type ThemeSwitcherMode = 'toggle' | 'segment';
|
|
8
|
+
export type ThemeSwitcherProperties = OptionalThemeSwitcherProperties & ThemeSwitcherEventProperties;
|
|
9
|
+
export type OptionalThemeSwitcherProperties = {
|
|
10
|
+
options?: ThemeSwitcherOption[];
|
|
11
|
+
value?: string;
|
|
12
|
+
mode?: ThemeSwitcherMode;
|
|
13
|
+
storageKey?: string;
|
|
14
|
+
testId?: string;
|
|
15
|
+
classes?: string;
|
|
16
|
+
};
|
|
17
|
+
export type ThemeSwitcherEventProperties = {
|
|
18
|
+
onchange?: (value: string, resolvedValue: string) => void;
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { fly } from 'svelte/transition';
|
|
3
|
+
import type { ToastDirection, ToastProperties } from './properties';
|
|
4
|
+
import type { FlyAnimationConfig } from '../types';
|
|
5
|
+
import { onMount } from 'svelte';
|
|
6
|
+
import Img from '../Img/Img.svelte';
|
|
7
|
+
|
|
8
|
+
let {
|
|
9
|
+
duration = 2000,
|
|
10
|
+
leftIcon,
|
|
11
|
+
message = '',
|
|
12
|
+
subtext,
|
|
13
|
+
rightIcon,
|
|
14
|
+
direction,
|
|
15
|
+
overlapPage = true,
|
|
16
|
+
inAnimationOffset,
|
|
17
|
+
inAnimationDuration,
|
|
18
|
+
outAnimationOffset,
|
|
19
|
+
outAnimationDuration,
|
|
20
|
+
testId,
|
|
21
|
+
messageTestId,
|
|
22
|
+
subTextTestId,
|
|
23
|
+
closeIconTestId,
|
|
24
|
+
ontoasthide,
|
|
25
|
+
bottomContent,
|
|
26
|
+
classes
|
|
27
|
+
}: ToastProperties = $props();
|
|
28
|
+
|
|
29
|
+
const animationConfig: FlyAnimationConfig = $derived(getAnimationConfig(overlapPage, direction));
|
|
30
|
+
|
|
31
|
+
let showToast = $state(false);
|
|
32
|
+
let timeoutId = $state<ReturnType<typeof setTimeout> | null>(null);
|
|
33
|
+
|
|
34
|
+
function hideToast() {
|
|
35
|
+
showToast = false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function handleAnimationEnd() {
|
|
39
|
+
ontoasthide?.();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getAnimationConfig(
|
|
43
|
+
overlapPage: boolean,
|
|
44
|
+
toastDirection?: ToastDirection
|
|
45
|
+
): FlyAnimationConfig {
|
|
46
|
+
let inX: number = 0;
|
|
47
|
+
let inY: number = 0;
|
|
48
|
+
let outX: number = 0;
|
|
49
|
+
let outY: number = 0;
|
|
50
|
+
|
|
51
|
+
switch (toastDirection) {
|
|
52
|
+
case 'left-to-right':
|
|
53
|
+
inX = -1 * (inAnimationOffset ?? 500);
|
|
54
|
+
outX = -1 * (outAnimationOffset ?? 500);
|
|
55
|
+
break;
|
|
56
|
+
case 'right-to-left':
|
|
57
|
+
inX = inAnimationOffset ?? 500;
|
|
58
|
+
outX = outAnimationOffset ?? 500;
|
|
59
|
+
break;
|
|
60
|
+
case 'bottom-to-top':
|
|
61
|
+
inY = inAnimationOffset ?? (overlapPage ? 500 : 20);
|
|
62
|
+
outY = outAnimationOffset ?? (overlapPage ? 500 : 20);
|
|
63
|
+
break;
|
|
64
|
+
case 'top-to-bottom':
|
|
65
|
+
default:
|
|
66
|
+
inY = -1 * (inAnimationOffset ?? (overlapPage ? 500 : 20));
|
|
67
|
+
outY = -1 * (outAnimationOffset ?? (overlapPage ? 100 : 20));
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
in: {
|
|
73
|
+
x: inX,
|
|
74
|
+
y: inY,
|
|
75
|
+
duration: inAnimationDuration ?? 400
|
|
76
|
+
},
|
|
77
|
+
out: {
|
|
78
|
+
x: outX,
|
|
79
|
+
y: outY,
|
|
80
|
+
duration: outAnimationDuration ?? 800
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
onMount(() => {
|
|
86
|
+
showToast = true;
|
|
87
|
+
timeoutId = setTimeout(hideToast, duration);
|
|
88
|
+
|
|
89
|
+
return () => {
|
|
90
|
+
if (timeoutId !== null) {
|
|
91
|
+
clearTimeout(timeoutId);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
</script>
|
|
96
|
+
|
|
97
|
+
{#if showToast}
|
|
98
|
+
<div
|
|
99
|
+
class="toast {classes ?? ''}"
|
|
100
|
+
class:no-page-overlap={!overlapPage}
|
|
101
|
+
role="alert"
|
|
102
|
+
aria-live="assertive"
|
|
103
|
+
in:fly={animationConfig.in}
|
|
104
|
+
out:fly={animationConfig.out}
|
|
105
|
+
onoutroend={handleAnimationEnd}
|
|
106
|
+
data-pw={testId}
|
|
107
|
+
>
|
|
108
|
+
{#if typeof leftIcon === 'string' && leftIcon.length > 0}
|
|
109
|
+
<div class="toast-icon-wrapper">
|
|
110
|
+
<Img src={leftIcon} alt="" />
|
|
111
|
+
</div>
|
|
112
|
+
{/if}
|
|
113
|
+
|
|
114
|
+
<div class="toast-message" data-pw={messageTestId}>
|
|
115
|
+
{message}
|
|
116
|
+
{#if typeof subtext === 'string' && subtext.length > 0}
|
|
117
|
+
<div class="toast-subtext" data-pw={subTextTestId}>{subtext}</div>
|
|
118
|
+
{/if}
|
|
119
|
+
|
|
120
|
+
{#if typeof bottomContent === 'function'}
|
|
121
|
+
{@render bottomContent()}
|
|
122
|
+
{/if}
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
{#if typeof rightIcon === 'string' && rightIcon.length > 0}
|
|
126
|
+
<div
|
|
127
|
+
class="close-button"
|
|
128
|
+
tabindex="0"
|
|
129
|
+
role="button"
|
|
130
|
+
onclick={hideToast}
|
|
131
|
+
onkeypress={(e) => {
|
|
132
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
133
|
+
e.preventDefault();
|
|
134
|
+
hideToast();
|
|
135
|
+
}
|
|
136
|
+
}}
|
|
137
|
+
data-pw={closeIconTestId}
|
|
138
|
+
>
|
|
139
|
+
<Img src={rightIcon} alt="Close" />
|
|
140
|
+
</div>
|
|
141
|
+
{/if}
|
|
142
|
+
</div>
|
|
143
|
+
{/if}
|
|
144
|
+
|
|
145
|
+
<style>
|
|
146
|
+
.toast {
|
|
147
|
+
padding: var(--toast-padding, 10px);
|
|
148
|
+
font-size: var(--toast-font-size, 14px);
|
|
149
|
+
font-family: var(--toast-font-family, inherit);
|
|
150
|
+
font-weight: var(--toast-font-weight);
|
|
151
|
+
height: var(--toast-height, fit-content);
|
|
152
|
+
border-radius: var(--toast-border-radius, 8px);
|
|
153
|
+
border: var(--toast-border, none);
|
|
154
|
+
border-style: var(--toast-border-style);
|
|
155
|
+
width: var(--toast-width, fit-content);
|
|
156
|
+
align-items: var(--toast-align-items, center);
|
|
157
|
+
margin: var(--toast-margin, 0px 10px 10px 10px);
|
|
158
|
+
justify-content: var(--toast-justify-content, space-between);
|
|
159
|
+
z-index: var(--toast-z-index, 1000);
|
|
160
|
+
display: var(--toast-display, flex);
|
|
161
|
+
position: var(--toast-position, absolute);
|
|
162
|
+
top: var(--toast-top, 10px);
|
|
163
|
+
left: var(--toast-left, 0);
|
|
164
|
+
right: var(--toast-right, 0);
|
|
165
|
+
background-color: var(--toast-background-color, #18181b);
|
|
166
|
+
color: var(--toast-color, #fff);
|
|
167
|
+
box-shadow: var(--toast-box-shadow, 0 4px 12px rgba(0, 0, 0, 0.15));
|
|
168
|
+
opacity: var(--toast-opacity, 1);
|
|
169
|
+
box-sizing: var(--toast-box-sizing);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.no-page-overlap {
|
|
173
|
+
position: var(--toast-position, relative);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.toast-icon-wrapper {
|
|
177
|
+
display: flex;
|
|
178
|
+
width: var(--toast-icon-wrapper-width, 20px);
|
|
179
|
+
height: var(--toast-icon-wrapper-height, 20px);
|
|
180
|
+
margin: var(--toast-icon-margin, 0px 6px 0px 0px);
|
|
181
|
+
padding: var(--toast-icon-wrapper-padding, 1px);
|
|
182
|
+
align-items: center;
|
|
183
|
+
|
|
184
|
+
--image-height: var(--toast-icon-height, 100%);
|
|
185
|
+
--image-width: fit-content;
|
|
186
|
+
--image-filter: var(--toast-icon-filter, none);
|
|
187
|
+
--image-border-radius: var(--toast-icon-border-radius, 50%);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.toast-message {
|
|
191
|
+
display: var(--toast-message-display, flex);
|
|
192
|
+
flex: var(--toast-message-flex, 1);
|
|
193
|
+
padding: var(--toast-message-padding, 1px);
|
|
194
|
+
flex-direction: column;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.toast-subtext {
|
|
198
|
+
color: var(--toast-subtext-color, inherit);
|
|
199
|
+
font-size: var(--toast-subtext-font-size, inherit);
|
|
200
|
+
font-weight: var(--toast-subtext-font-weight, inherit);
|
|
201
|
+
margin: var(--toast-subtext-margin, 10px 0px 0px 0px);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.close-button {
|
|
205
|
+
width: var(--toast-close-button-width, 20px);
|
|
206
|
+
height: var(--toast-close-button-height, 20px);
|
|
207
|
+
cursor: var(--toast-close-button-cursor, pointer);
|
|
208
|
+
gap: var(--toast-close-button-gap, 6px);
|
|
209
|
+
margin: var(--toast-close-button-margin, 0px 0px 0px 10px);
|
|
210
|
+
display: var(--toast-close-button-display, flex);
|
|
211
|
+
align-items: var(--toast-close-button-align-items, center);
|
|
212
|
+
justify-content: var(--toast-close-button-justify-content, center);
|
|
213
|
+
padding: var(--toast-close-button-padding, 1px);
|
|
214
|
+
|
|
215
|
+
--image-height: var(--toast-icon-height, 100%);
|
|
216
|
+
--image-width: fit-content;
|
|
217
|
+
--image-filter: var(--toast-icon-filter, none);
|
|
218
|
+
--image-border-radius: var(--toast-icon-border-radius, 50%);
|
|
219
|
+
}
|
|
220
|
+
</style>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
export type ToastDirection = 'left-to-right' | 'right-to-left' | 'top-to-bottom' | 'bottom-to-top';
|
|
3
|
+
export type ToastProperties = ToastEventProperties & {
|
|
4
|
+
duration?: number;
|
|
5
|
+
leftIcon?: string | null;
|
|
6
|
+
message: string;
|
|
7
|
+
subtext?: string | null;
|
|
8
|
+
rightIcon?: string | null;
|
|
9
|
+
direction?: ToastDirection;
|
|
10
|
+
overlapPage?: boolean;
|
|
11
|
+
inAnimationOffset?: number | null;
|
|
12
|
+
inAnimationDuration?: number | null;
|
|
13
|
+
outAnimationOffset?: number | null;
|
|
14
|
+
outAnimationDuration?: number | null;
|
|
15
|
+
testId?: string | null;
|
|
16
|
+
messageTestId?: string;
|
|
17
|
+
subTextTestId?: string;
|
|
18
|
+
closeIconTestId?: string;
|
|
19
|
+
bottomContent?: Snippet;
|
|
20
|
+
classes?: string;
|
|
21
|
+
};
|
|
22
|
+
export type ToastEventProperties = {
|
|
23
|
+
ontoasthide?: () => void;
|
|
24
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ToggleProperties } from './properties';
|
|
3
|
+
|
|
4
|
+
let { checked = false, text = '', testId, classes, onclick }: ToggleProperties = $props();
|
|
5
|
+
|
|
6
|
+
function handleCheckboxClick(e: MouseEvent): void {
|
|
7
|
+
if (e.target instanceof HTMLInputElement && typeof e.target.checked === 'boolean') {
|
|
8
|
+
checked = e.target.checked;
|
|
9
|
+
}
|
|
10
|
+
onclick?.(checked);
|
|
11
|
+
}
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<div class="container {classes ?? ''}" data-pw={testId}>
|
|
15
|
+
<div class="text" hidden={text.length === 0}>{text}</div>
|
|
16
|
+
<label class="switch">
|
|
17
|
+
<input class="input-checkbox" type="checkbox" {checked} onclick={handleCheckboxClick} />
|
|
18
|
+
<span class="slider round"></span>
|
|
19
|
+
</label>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<style>
|
|
23
|
+
.container {
|
|
24
|
+
display: var(--toggle-container-display, flex);
|
|
25
|
+
align-items: var(--toggle-container-align-items, center);
|
|
26
|
+
gap: var(--toggle-container-gap, 8px);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.text {
|
|
30
|
+
font-size: var(--toggle-text-font-size, 14px);
|
|
31
|
+
font-weight: var(--toggle-text-font-weight, 400);
|
|
32
|
+
color: var(--toggle-text-color, inherit);
|
|
33
|
+
margin: var(--toggle-text-margin, 0px 8px 0px 0px);
|
|
34
|
+
order: var(--toggle-text-order, 0);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.switch {
|
|
38
|
+
position: relative;
|
|
39
|
+
display: inline-block;
|
|
40
|
+
width: var(--toggle-switch-width, 46px);
|
|
41
|
+
height: var(--toggle-switch-height, 25px);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.switch .input-checkbox {
|
|
45
|
+
opacity: 0;
|
|
46
|
+
width: 0;
|
|
47
|
+
height: 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.slider {
|
|
51
|
+
position: absolute;
|
|
52
|
+
cursor: pointer;
|
|
53
|
+
top: var(--toggle-slider-top, 0);
|
|
54
|
+
left: var(--toggle-slider-left, 0);
|
|
55
|
+
right: var(--toggle-slider-right, 0);
|
|
56
|
+
bottom: var(--toggle-slider-bottom, 0);
|
|
57
|
+
background-color: var(--toggle-slider-unchecked-color, #e4e4e7);
|
|
58
|
+
border: var(--toggle-slider-border, none);
|
|
59
|
+
box-sizing: border-box;
|
|
60
|
+
-webkit-transition: var(--toggle-slider-transition, 0.4s);
|
|
61
|
+
transition: var(--toggle-slider-transition, 0.4s);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.slider:before {
|
|
65
|
+
position: absolute;
|
|
66
|
+
content: '';
|
|
67
|
+
height: var(--toggle-ball-height, 23px);
|
|
68
|
+
width: var(--toggle-ball-width, 23px);
|
|
69
|
+
left: var(--toggle-slider-before-left, 2px);
|
|
70
|
+
bottom: var(--toggle-slider-before-bottom, 1px);
|
|
71
|
+
top: var(--toggle-slider-before-top, 1px);
|
|
72
|
+
background-color: var(--toggle-slider-before-background-color, #ffffff);
|
|
73
|
+
box-shadow: var(--toggle-knob-shadow, 0 1px 2px rgba(0, 0, 0, 0.3));
|
|
74
|
+
-webkit-transition: var(--toggle-slider-transition, 0.4s);
|
|
75
|
+
transition: var(--toggle-slider-transition, 0.4s);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.input-checkbox:checked + .slider {
|
|
79
|
+
background-color: var(--toggle-slider-checked-color, #18181b);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.input-checkbox:focus + .slider {
|
|
83
|
+
box-shadow: var(--toggle-slider-focus-shadow, 0 0 1px currentColor);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.input-checkbox:checked + .slider:before {
|
|
87
|
+
-webkit-transform: translateX(19px);
|
|
88
|
+
-ms-transform: translateX(19px);
|
|
89
|
+
transform: translateX(19px);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.slider.round {
|
|
93
|
+
border-radius: var(--toggle-slider-border-radius, 23px);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.slider.round:before {
|
|
97
|
+
border-radius: var(--toggle-slider-border-radius-before, 50%);
|
|
98
|
+
}
|
|
99
|
+
</style>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|