@marianmeres/stuic 1.126.0 → 2.0.0-next.3
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 +2 -8
- package/dist/_shared.css +2 -0
- package/dist/actions/autogrow.svelte.d.ts +6 -0
- package/dist/actions/autogrow.svelte.js +19 -0
- package/dist/actions/highlight-dragover.svelte.d.ts +7 -0
- package/dist/actions/highlight-dragover.svelte.js +38 -0
- package/dist/actions/index.d.ts +7 -0
- package/dist/actions/index.js +7 -0
- package/dist/actions/on-submit-validity-check.svelte.d.ts +15 -0
- package/dist/actions/on-submit-validity-check.svelte.js +58 -0
- package/dist/actions/tooltip/index.css +34 -0
- package/dist/actions/tooltip/tooltip.svelte.d.ts +13 -0
- package/dist/actions/tooltip/tooltip.svelte.js +203 -0
- package/dist/actions/trim.svelte.d.ts +4 -0
- package/dist/actions/trim.svelte.js +17 -0
- package/dist/actions/{validate.d.ts → validate.svelte.d.ts} +8 -8
- package/dist/actions/validate.svelte.js +90 -0
- package/dist/components/AlertConfirmPrompt/AlertConfirmPrompt.svelte +59 -385
- package/dist/components/AlertConfirmPrompt/AlertConfirmPrompt.svelte.d.ts +9 -101
- package/dist/components/AlertConfirmPrompt/Current.svelte +202 -0
- package/dist/components/AlertConfirmPrompt/Current.svelte.d.ts +22 -0
- package/dist/components/AlertConfirmPrompt/acp-icons.d.ts +7 -2
- package/dist/components/AlertConfirmPrompt/acp-icons.js +8 -8
- package/dist/components/AlertConfirmPrompt/alert-confirm-prompt-stack.svelte.d.ts +63 -0
- package/dist/components/AlertConfirmPrompt/alert-confirm-prompt-stack.svelte.js +144 -0
- package/dist/components/AlertConfirmPrompt/index.d.ts +2 -0
- package/dist/components/AlertConfirmPrompt/index.js +2 -0
- package/dist/components/AnimatedElipsis/AnimatedEllipsis.svelte +47 -0
- package/dist/components/AnimatedElipsis/AnimatedEllipsis.svelte.d.ts +7 -0
- package/dist/components/AnimatedElipsis/index.d.ts +1 -0
- package/dist/components/AnimatedElipsis/index.js +1 -0
- package/dist/components/AppShell/AppShell.svelte +188 -127
- package/dist/components/AppShell/AppShell.svelte.d.ts +62 -43
- package/dist/components/AppShell/index.d.ts +1 -0
- package/dist/components/AppShell/index.js +1 -0
- package/dist/components/Backdrop/Backdrop.svelte +149 -49
- package/dist/components/Backdrop/Backdrop.svelte.d.ts +22 -37
- package/dist/components/Backdrop/index.d.ts +1 -0
- package/dist/components/Backdrop/index.js +1 -0
- package/dist/components/Button/Button.svelte +122 -146
- package/dist/components/Button/Button.svelte.d.ts +22 -80
- package/dist/components/Button/index.css +16 -0
- package/dist/components/Button/index.d.ts +1 -0
- package/dist/components/Button/index.js +1 -0
- package/dist/components/ColResize/ColResize.svelte +0 -0
- package/dist/components/ColResize/ColResize.svelte.d.ts +26 -0
- package/dist/components/ColorScheme/{LocalColorScheme.svelte → ColorSchemeLocal.svelte} +2 -2
- package/dist/components/ColorScheme/ColorSchemeLocal.svelte.d.ts +26 -0
- package/dist/components/ColorScheme/{SystemAwareColorScheme.svelte → ColorSchemeSystemAware.svelte} +4 -4
- package/dist/components/ColorScheme/ColorSchemeSystemAware.svelte.d.ts +26 -0
- package/dist/components/ColorScheme/color-scheme.d.ts +26 -8
- package/dist/components/ColorScheme/color-scheme.js +40 -16
- package/dist/components/ColorScheme/index.d.ts +3 -0
- package/dist/components/ColorScheme/index.js +3 -0
- package/dist/components/DismissibleMessage/DismissibleMessage.svelte +76 -83
- package/dist/components/DismissibleMessage/DismissibleMessage.svelte.d.ts +16 -37
- package/dist/components/DismissibleMessage/index.css +13 -0
- package/dist/components/DismissibleMessage/index.d.ts +1 -0
- package/dist/components/DismissibleMessage/index.js +1 -0
- package/dist/components/Drawer/Drawer.svelte +155 -84
- package/dist/components/Drawer/Drawer.svelte.d.ts +24 -35
- package/dist/components/Drawer/index.d.ts +1 -0
- package/dist/components/Drawer/index.js +1 -0
- package/dist/components/HoverExpandableWidth/HoverExpandableWidth.svelte +150 -111
- package/dist/components/HoverExpandableWidth/HoverExpandableWidth.svelte.d.ts +16 -29
- package/dist/components/HoverExpandableWidth/index.d.ts +1 -0
- package/dist/components/HoverExpandableWidth/index.js +1 -0
- package/dist/components/Input/FieldCheckbox.svelte +174 -132
- package/dist/components/Input/FieldCheckbox.svelte.d.ts +28 -64
- package/dist/components/Input/FieldFile.svelte +166 -0
- package/dist/components/Input/FieldFile.svelte.d.ts +41 -0
- package/dist/components/Input/FieldInput.svelte +143 -0
- package/dist/components/Input/FieldInput.svelte.d.ts +41 -0
- package/dist/components/Input/FieldLikeButton.svelte +206 -0
- package/dist/components/Input/FieldLikeButton.svelte.d.ts +41 -0
- package/dist/components/Input/FieldOptions.svelte +646 -0
- package/dist/components/Input/FieldOptions.svelte.d.ts +58 -0
- package/dist/components/Input/FieldRadios.svelte +126 -77
- package/dist/components/Input/FieldRadios.svelte.d.ts +23 -61
- package/dist/components/Input/FieldSelect.svelte +160 -239
- package/dist/components/Input/FieldSelect.svelte.d.ts +40 -88
- package/dist/components/Input/FieldSwitch.svelte +132 -0
- package/dist/components/Input/FieldSwitch.svelte.d.ts +41 -0
- package/dist/components/Input/FieldTextarea.svelte +146 -0
- package/dist/components/Input/FieldTextarea.svelte.d.ts +44 -0
- package/dist/components/Input/Fieldset.svelte +21 -17
- package/dist/components/Input/Fieldset.svelte.d.ts +10 -27
- package/dist/components/Input/_internal/FieldRadioInternal.svelte +186 -0
- package/dist/components/Input/_internal/FieldRadioInternal.svelte.d.ts +30 -0
- package/dist/components/Input/_internal/InputWrap.svelte +216 -0
- package/dist/components/Input/_internal/InputWrap.svelte.d.ts +36 -0
- package/dist/components/Input/index.css +134 -0
- package/dist/components/Input/index.d.ts +11 -0
- package/dist/components/Input/index.js +11 -0
- package/dist/components/Input/types.d.ts +11 -0
- package/dist/components/KbdShortcut/KbdShortcut.svelte +89 -0
- package/dist/components/KbdShortcut/KbdShortcut.svelte.d.ts +17 -0
- package/dist/components/KbdShortcut/index.d.ts +1 -0
- package/dist/components/KbdShortcut/index.js +1 -0
- package/dist/components/Modal/Modal.svelte +127 -0
- package/dist/components/Modal/Modal.svelte.d.ts +32 -0
- package/dist/components/Modal/index.d.ts +1 -0
- package/dist/components/Modal/index.js +1 -0
- package/dist/components/ModalDialog/ModalDialog.svelte +137 -81
- package/dist/components/ModalDialog/ModalDialog.svelte.d.ts +17 -38
- package/dist/components/ModalDialog/index.d.ts +1 -0
- package/dist/components/ModalDialog/index.js +1 -0
- package/dist/components/Notifications/Notifications.svelte +259 -173
- package/dist/components/Notifications/Notifications.svelte.d.ts +32 -60
- package/dist/components/Notifications/index.css +12 -0
- package/dist/components/Notifications/index.d.ts +2 -0
- package/dist/components/Notifications/index.js +2 -0
- package/dist/components/Notifications/notifications-icons.d.ts +1 -1
- package/dist/components/Notifications/notifications-icons.js +4 -4
- package/dist/components/Notifications/notifications-stack.svelte.d.ts +89 -0
- package/dist/components/Notifications/notifications-stack.svelte.js +161 -0
- package/dist/components/Progress/Progress.svelte +26 -0
- package/dist/components/Progress/Progress.svelte.d.ts +10 -0
- package/dist/components/Progress/_internal/Bar.svelte +31 -0
- package/dist/components/Progress/_internal/Bar.svelte.d.ts +10 -0
- package/dist/components/Progress/_internal/Circle.svelte +10 -0
- package/dist/components/Progress/_internal/Circle.svelte.d.ts +7 -0
- package/dist/components/Progress/index.css +7 -0
- package/dist/components/Progress/index.d.ts +1 -0
- package/dist/components/Progress/index.js +1 -0
- package/dist/components/Spinner/Spinner.svelte +56 -41
- package/dist/components/Spinner/Spinner.svelte.d.ts +10 -22
- package/dist/components/Spinner/index.d.ts +1 -0
- package/dist/components/Spinner/index.js +1 -0
- package/dist/components/Switch/Switch.svelte +158 -118
- package/dist/components/Switch/Switch.svelte.d.ts +25 -66
- package/dist/components/Switch/SwitchButton.svelte +131 -0
- package/dist/components/Switch/SwitchButton.svelte.d.ts +21 -0
- package/dist/components/Switch/index.css +7 -0
- package/dist/components/Switch/index.d.ts +2 -0
- package/dist/components/Switch/index.js +2 -0
- package/dist/components/Thc/Thc.svelte +67 -10
- package/dist/components/Thc/Thc.svelte.d.ts +18 -22
- package/dist/components/Thc/index.d.ts +1 -0
- package/dist/components/Thc/index.js +1 -0
- package/dist/components/TwCheck/TwCheck.svelte +34 -0
- package/dist/components/TwCheck/TwCheck.svelte.d.ts +10 -0
- package/dist/components/TwCheck/index.css +5 -0
- package/dist/components/TwCheck/index.d.ts +1 -0
- package/dist/components/TwCheck/index.js +1 -0
- package/dist/components/X/X.svelte +12 -5
- package/dist/components/X/X.svelte.d.ts +6 -18
- package/dist/components/X/index.d.ts +1 -0
- package/dist/components/X/index.js +1 -0
- package/dist/index.css +26 -0
- package/dist/index.d.ts +21 -39
- package/dist/index.js +23 -54
- package/dist/types.d.ts +251 -2
- package/dist/types.js +248 -0
- package/dist/utils/breakpoint.svelte.d.ts +19 -0
- package/dist/utils/breakpoint.svelte.js +42 -0
- package/dist/utils/debounce.d.ts +13 -0
- package/dist/utils/debounce.js +22 -0
- package/dist/utils/device-pointer.svelte.d.ts +11 -0
- package/dist/utils/device-pointer.svelte.js +26 -0
- package/dist/utils/event-modifiers.d.ts +4 -0
- package/dist/utils/event-modifiers.js +29 -0
- package/dist/utils/get-id.d.ts +1 -1
- package/dist/utils/get-id.js +3 -1
- package/dist/utils/index.d.ts +21 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/is-browser.d.ts +1 -0
- package/dist/utils/is-browser.js +5 -0
- package/dist/utils/is-mac.d.ts +1 -0
- package/dist/utils/is-mac.js +11 -0
- package/dist/utils/maybe-json-parse.d.ts +1 -0
- package/dist/utils/maybe-json-parse.js +12 -0
- package/dist/utils/maybe-json-stringify.d.ts +1 -0
- package/dist/utils/maybe-json-stringify.js +11 -0
- package/dist/utils/move-array-item.d.ts +4 -0
- package/dist/utils/move-array-item.js +20 -0
- package/dist/utils/omit-pick.d.ts +2 -2
- package/dist/utils/omit-pick.js +10 -8
- package/dist/utils/paint.d.ts +18 -0
- package/dist/utils/paint.js +32 -0
- package/dist/utils/persistent-state.svelte.d.ts +23 -0
- package/dist/utils/persistent-state.svelte.js +48 -0
- package/dist/utils/prefers-reduced-motion.svelte.d.ts +2 -0
- package/dist/utils/prefers-reduced-motion.svelte.js +4 -0
- package/dist/utils/qsa.d.ts +1 -0
- package/dist/utils/qsa.js +3 -0
- package/dist/utils/sleep.d.ts +28 -0
- package/dist/utils/sleep.js +33 -0
- package/dist/utils/storage-abstraction.d.ts +35 -0
- package/dist/utils/storage-abstraction.js +136 -0
- package/dist/utils/str-hash.d.ts +7 -0
- package/dist/utils/str-hash.js +35 -0
- package/dist/utils/throttle.d.ts +1 -0
- package/dist/utils/throttle.js +47 -0
- package/dist/utils/to-integer.d.ts +1 -0
- package/dist/utils/to-integer.js +11 -0
- package/dist/utils/tr.d.ts +5 -0
- package/dist/utils/tr.js +13 -0
- package/dist/utils/tw-merge.d.ts +10 -0
- package/dist/utils/tw-merge.js +16 -0
- package/dist/utils/ucfirst.d.ts +1 -0
- package/dist/utils/ucfirst.js +6 -0
- package/package.json +66 -73
- package/dist/actions/autogrow.d.ts +0 -8
- package/dist/actions/autogrow.js +0 -22
- package/dist/actions/drag-drop.d.ts +0 -28
- package/dist/actions/drag-drop.js +0 -152
- package/dist/actions/on-outside.d.ts +0 -9
- package/dist/actions/on-outside.js +0 -27
- package/dist/actions/pre-submit-validity-check.d.ts +0 -3
- package/dist/actions/pre-submit-validity-check.js +0 -21
- package/dist/actions/tooltip/_make-visible.d.ts +0 -3
- package/dist/actions/tooltip/_make-visible.js +0 -25
- package/dist/actions/tooltip/_maybe-pick-safe-placement.d.ts +0 -3
- package/dist/actions/tooltip/_maybe-pick-safe-placement.js +0 -86
- package/dist/actions/tooltip/_set-position.d.ts +0 -2
- package/dist/actions/tooltip/_set-position.js +0 -125
- package/dist/actions/tooltip/tooltip.d.ts +0 -42
- package/dist/actions/tooltip/tooltip.js +0 -299
- package/dist/actions/trim.d.ts +0 -4
- package/dist/actions/trim.js +0 -18
- package/dist/actions/validate.js +0 -80
- package/dist/components/AlertConfirmPrompt/alert-confirm-prompt.d.ts +0 -58
- package/dist/components/AlertConfirmPrompt/alert-confirm-prompt.js +0 -141
- package/dist/components/ColorScheme/LocalColorScheme.svelte.d.ts +0 -25
- package/dist/components/ColorScheme/SystemAwareColorScheme.svelte.d.ts +0 -25
- package/dist/components/Input/Field.svelte +0 -315
- package/dist/components/Input/Field.svelte.d.ts +0 -102
- package/dist/components/Input/PinInput.svelte +0 -151
- package/dist/components/Input/PinInput.svelte.d.ts +0 -51
- package/dist/components/Input/XFieldRadioInternal.svelte +0 -143
- package/dist/components/Input/XFieldRadioInternal.svelte.d.ts +0 -45
- package/dist/components/Notifications/notifications.d.ts +0 -78
- package/dist/components/Notifications/notifications.js +0 -215
- package/dist/components/Popover/Popover.svelte +0 -24
- package/dist/components/Popover/Popover.svelte.d.ts +0 -22
- package/dist/components/Spinner/Spinner.v5.svelte +0 -114
- package/dist/components/Spinner/Spinner.v5.svelte.d.ts +0 -16
- package/dist/utils/calculate-alignment.d.ts +0 -68
- package/dist/utils/calculate-alignment.js +0 -183
- package/dist/utils/device-pointer.d.ts +0 -5
- package/dist/utils/device-pointer.js +0 -10
- package/dist/utils/prefers-reduced-motion.d.ts +0 -6
- package/dist/utils/prefers-reduced-motion.js +0 -26
- package/dist/utils/tw-merge2.d.ts +0 -3
- package/dist/utils/tw-merge2.js +0 -9
- package/dist/utils/tw-types.d.ts +0 -1
- package/dist/utils/window-size.d.ts +0 -22
- package/dist/utils/window-size.js +0 -35
- /package/dist/{utils/tw-types.js → components/Input/types.js} +0 -0
|
@@ -1,131 +1,171 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
bg-neutral-400 dark:bg-neutral-400
|
|
14
|
-
data-[checked=true]:bg-stuic-primary dark:data-[checked=true]:bg-stuic-primary-dark
|
|
15
|
-
`.trim();
|
|
16
|
-
static presetsSize = {
|
|
17
|
-
xs: "h-4 w-7",
|
|
18
|
-
sm: "h-5 w-9",
|
|
19
|
-
md: "h-6 w-11",
|
|
20
|
-
lg: "h-7 w-14",
|
|
21
|
-
xl: "h-8 w-16"
|
|
22
|
-
};
|
|
23
|
-
static class = "";
|
|
24
|
-
// to be defined at consumer level...
|
|
25
|
-
static variant = {};
|
|
26
|
-
// DOT
|
|
27
|
-
static presetBaseDot = `
|
|
28
|
-
block flex items-center justify-center
|
|
29
|
-
translate-x-1 rounded-full
|
|
30
|
-
transition-all duration-100
|
|
31
|
-
shadow
|
|
32
|
-
bg-neutral-50 dark:bg-neutral-50
|
|
33
|
-
text-neutral-950 dark:text-neutral-950
|
|
34
|
-
`.trim();
|
|
35
|
-
static presetsSizeDot = {
|
|
36
|
-
// size + translate-x = width
|
|
37
|
-
xs: "size-2 data-[checked=true]:translate-x-4",
|
|
38
|
-
sm: "size-3 data-[checked=true]:translate-x-5",
|
|
39
|
-
md: "size-4 data-[checked=true]:translate-x-6",
|
|
40
|
-
lg: "size-5 data-[checked=true]:translate-x-8",
|
|
41
|
-
xl: "size-6 data-[checked=true]:translate-x-9"
|
|
42
|
-
};
|
|
43
|
-
static classDot = "";
|
|
44
|
-
// to be defined at consumer level...
|
|
45
|
-
static variantDot = {};
|
|
46
|
-
}
|
|
47
|
-
</script>
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { tick, type Snippet } from "svelte";
|
|
3
|
+
import type { FormEventHandler, HTMLButtonAttributes } from "svelte/elements";
|
|
4
|
+
import { twMerge } from "../../utils/tw-merge.js";
|
|
5
|
+
import {
|
|
6
|
+
validate as validateAction,
|
|
7
|
+
type ValidateOptions,
|
|
8
|
+
type ValidationResult,
|
|
9
|
+
} from "../../actions/validate.svelte.js";
|
|
10
|
+
|
|
11
|
+
import "./index.css";
|
|
48
12
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
13
|
+
interface Props extends HTMLButtonAttributes {
|
|
14
|
+
button?: HTMLButtonElement;
|
|
15
|
+
checked?: boolean;
|
|
16
|
+
size?: "xs" | "sm" | "md" | "lg" | "xl" | string;
|
|
17
|
+
name?: string;
|
|
18
|
+
class?: string;
|
|
19
|
+
dotClass?: string;
|
|
20
|
+
label?: string;
|
|
21
|
+
required?: boolean;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
tabindex?: number;
|
|
24
|
+
on?: Snippet;
|
|
25
|
+
off?: Snippet;
|
|
26
|
+
onclick?: (event: MouseEvent) => void;
|
|
27
|
+
onchange?: FormEventHandler<HTMLButtonElement> | null | undefined;
|
|
28
|
+
preHook?: (current: boolean) => Promise<false | any>;
|
|
29
|
+
//
|
|
30
|
+
validate?: boolean | Omit<ValidateOptions, "setValidationResult">;
|
|
31
|
+
setValidationResult?: (res: ValidationResult) => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let {
|
|
35
|
+
button = $bindable(),
|
|
36
|
+
size = "md",
|
|
37
|
+
name,
|
|
38
|
+
class: classProp,
|
|
39
|
+
dotClass,
|
|
40
|
+
checked = $bindable(false),
|
|
41
|
+
required,
|
|
42
|
+
disabled,
|
|
43
|
+
tabindex = 0,
|
|
44
|
+
label,
|
|
45
|
+
on,
|
|
46
|
+
off,
|
|
47
|
+
onclick,
|
|
48
|
+
preHook,
|
|
49
|
+
validate,
|
|
50
|
+
setValidationResult,
|
|
51
|
+
...rest
|
|
52
|
+
}: Props = $props();
|
|
53
|
+
|
|
54
|
+
const _preset: any = {
|
|
55
|
+
size: {
|
|
56
|
+
xs: `h-4 w-7`,
|
|
57
|
+
sm: `h-5 w-9`,
|
|
58
|
+
md: `h-6 w-11`,
|
|
59
|
+
lg: `h-7 w-13`,
|
|
60
|
+
xl: `h-8 w-15`,
|
|
61
|
+
},
|
|
62
|
+
dot: {
|
|
63
|
+
size: {
|
|
64
|
+
xs: `size-2 data-[checked=true]:translate-x-4`,
|
|
65
|
+
sm: `size-3 data-[checked=true]:translate-x-5`,
|
|
66
|
+
md: `size-4 data-[checked=true]:translate-x-6`,
|
|
67
|
+
lg: `size-5 data-[checked=true]:translate-x-7`,
|
|
68
|
+
xl: `size-6 data-[checked=true]:translate-x-8`,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
//
|
|
74
|
+
let wrap = $state<HTMLLabelElement>()!;
|
|
75
|
+
let checkbox = $state<HTMLInputElement>()!;
|
|
76
|
+
|
|
77
|
+
function change() {
|
|
78
|
+
checkbox.checked = !checked;
|
|
79
|
+
checkbox.dispatchEvent(new Event("change", { bubbles: true, cancelable: true }));
|
|
80
|
+
wrap.focus();
|
|
81
|
+
}
|
|
89
82
|
</script>
|
|
90
83
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
84
|
+
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
85
|
+
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
86
|
+
<label
|
|
87
|
+
bind:this={wrap}
|
|
88
|
+
class={twMerge(
|
|
89
|
+
"stuic-switch",
|
|
90
|
+
`m-2
|
|
91
|
+
relative inline-flex flex-shrink-0 items-center
|
|
92
|
+
rounded-full cursor-pointer
|
|
93
|
+
|
|
94
|
+
transition-colors duration-100
|
|
95
|
+
|
|
96
|
+
hover:brightness-[1.05] active:brightness-[0.95]
|
|
97
|
+
data-[disabled=true]:!cursor-not-allowed data-[disabled=true]:!opacity-50 data-[disabled=true]:hover:brightness-100
|
|
98
|
+
|
|
99
|
+
bg-neutral-400 dark:bg-neutral-400
|
|
100
|
+
|
|
101
|
+
data-[checked=true]:bg-switch-accent
|
|
102
|
+
dark:data-[checked=true]:bg-switch-accent-dark
|
|
103
|
+
|
|
104
|
+
focus:outline-0
|
|
105
|
+
focus:ring-switch-accent/20 focus:dark:ring-switch-accent-dark/20
|
|
106
|
+
focus:ring-4`,
|
|
107
|
+
size,
|
|
108
|
+
_preset.size[size],
|
|
109
|
+
classProp
|
|
110
|
+
)}
|
|
97
111
|
data-checked={checked}
|
|
98
|
-
data-
|
|
99
|
-
{tabindex}
|
|
100
|
-
{
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
112
|
+
data-disabled={disabled}
|
|
113
|
+
tabindex={disabled ? -1 : tabindex}
|
|
114
|
+
onkeydown={(e: KeyboardEvent) => {
|
|
115
|
+
if (!disabled && !e.metaKey && ["Space", "Enter"].includes(e.code)) {
|
|
116
|
+
change();
|
|
117
|
+
}
|
|
118
|
+
}}
|
|
119
|
+
onclick={async (e) => {
|
|
120
|
+
e.preventDefault();
|
|
121
|
+
if (disabled) return false;
|
|
122
|
+
|
|
123
|
+
if (typeof preHook === "function" && (await preHook(checked)) === false) {
|
|
107
124
|
return false;
|
|
108
125
|
}
|
|
109
126
|
|
|
110
|
-
|
|
111
|
-
|
|
127
|
+
change();
|
|
128
|
+
|
|
129
|
+
await tick();
|
|
130
|
+
|
|
131
|
+
if (typeof onclick === "function") onclick(e);
|
|
112
132
|
}}
|
|
113
|
-
|
|
114
|
-
on:keydown
|
|
115
|
-
on:keyup
|
|
116
|
-
on:touchstart|passive
|
|
117
|
-
on:touchend|passive
|
|
118
|
-
on:touchmove|passive
|
|
119
|
-
on:touchcancel
|
|
120
|
-
on:mouseenter
|
|
121
|
-
on:mouseleave
|
|
133
|
+
{...rest}
|
|
122
134
|
>
|
|
123
|
-
|
|
124
|
-
|
|
135
|
+
<span
|
|
136
|
+
class={twMerge(
|
|
137
|
+
"dot",
|
|
138
|
+
`flex items-center justify-center
|
|
139
|
+
translate-x-1 rounded-full
|
|
140
|
+
transition-all duration-100
|
|
141
|
+
shadow
|
|
142
|
+
bg-neutral-50 dark:bg-neutral-50
|
|
143
|
+
text-neutral-950 dark:text-neutral-950`,
|
|
144
|
+
size,
|
|
145
|
+
_preset.dot.size[size],
|
|
146
|
+
dotClass
|
|
147
|
+
)}
|
|
148
|
+
data-checked={checked}
|
|
149
|
+
>
|
|
125
150
|
{#if checked}
|
|
126
|
-
|
|
151
|
+
{@render on?.()}
|
|
127
152
|
{:else}
|
|
128
|
-
|
|
153
|
+
{@render off?.()}
|
|
129
154
|
{/if}
|
|
130
155
|
</span>
|
|
131
|
-
|
|
156
|
+
<input
|
|
157
|
+
bind:checked
|
|
158
|
+
bind:this={checkbox}
|
|
159
|
+
type="checkbox"
|
|
160
|
+
class="opacity-0 size-0"
|
|
161
|
+
{disabled}
|
|
162
|
+
{required}
|
|
163
|
+
{name}
|
|
164
|
+
use:validateAction={() => ({
|
|
165
|
+
enabled: !!validate,
|
|
166
|
+
...(typeof validate === "boolean" ? {} : validate),
|
|
167
|
+
setValidationResult,
|
|
168
|
+
})}
|
|
169
|
+
tabindex="-1"
|
|
170
|
+
/>
|
|
171
|
+
</label>
|
|
@@ -1,67 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
static classDot: string;
|
|
25
|
-
static variantDot: Record<string, string>;
|
|
1
|
+
import { type Snippet } from "svelte";
|
|
2
|
+
import type { FormEventHandler, HTMLButtonAttributes } from "svelte/elements";
|
|
3
|
+
import { type ValidateOptions, type ValidationResult } from "../../actions/validate.svelte.js";
|
|
4
|
+
import "./index.css";
|
|
5
|
+
interface Props extends HTMLButtonAttributes {
|
|
6
|
+
button?: HTMLButtonElement;
|
|
7
|
+
checked?: boolean;
|
|
8
|
+
size?: "xs" | "sm" | "md" | "lg" | "xl" | string;
|
|
9
|
+
name?: string;
|
|
10
|
+
class?: string;
|
|
11
|
+
dotClass?: string;
|
|
12
|
+
label?: string;
|
|
13
|
+
required?: boolean;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
tabindex?: number;
|
|
16
|
+
on?: Snippet;
|
|
17
|
+
off?: Snippet;
|
|
18
|
+
onclick?: (event: MouseEvent) => void;
|
|
19
|
+
onchange?: FormEventHandler<HTMLButtonElement> | null | undefined;
|
|
20
|
+
preHook?: (current: boolean) => Promise<false | any>;
|
|
21
|
+
validate?: boolean | Omit<ValidateOptions, "setValidationResult">;
|
|
22
|
+
setValidationResult?: (res: ValidationResult) => void;
|
|
26
23
|
}
|
|
27
|
-
declare const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
classDot?: string;
|
|
31
|
-
label?: string;
|
|
32
|
-
checked?: boolean;
|
|
33
|
-
disabled?: boolean;
|
|
34
|
-
tabindex?: number;
|
|
35
|
-
variant?: string | undefined;
|
|
36
|
-
stopPropagation?: boolean;
|
|
37
|
-
preventDefault?: boolean;
|
|
38
|
-
preHook?: SwitchPreHook;
|
|
39
|
-
size?: "xs" | "sm" | "md" | "lg" | "xl";
|
|
40
|
-
};
|
|
41
|
-
events: {
|
|
42
|
-
click: MouseEvent;
|
|
43
|
-
keydown: KeyboardEvent;
|
|
44
|
-
keyup: KeyboardEvent;
|
|
45
|
-
touchstart: TouchEvent;
|
|
46
|
-
touchend: TouchEvent;
|
|
47
|
-
touchmove: TouchEvent;
|
|
48
|
-
touchcancel: TouchEvent;
|
|
49
|
-
mouseenter: MouseEvent;
|
|
50
|
-
mouseleave: MouseEvent;
|
|
51
|
-
change: CustomEvent<any>;
|
|
52
|
-
} & {
|
|
53
|
-
[evt: string]: CustomEvent<any>;
|
|
54
|
-
};
|
|
55
|
-
slots: {
|
|
56
|
-
on: {};
|
|
57
|
-
off: {};
|
|
58
|
-
};
|
|
59
|
-
exports?: {} | undefined;
|
|
60
|
-
bindings?: string | undefined;
|
|
61
|
-
};
|
|
62
|
-
export type SwitchProps = typeof __propDef.props;
|
|
63
|
-
export type SwitchEvents = typeof __propDef.events;
|
|
64
|
-
export type SwitchSlots = typeof __propDef.slots;
|
|
65
|
-
export default class Switch extends SvelteComponent<SwitchProps, SwitchEvents, SwitchSlots> {
|
|
66
|
-
}
|
|
67
|
-
export {};
|
|
24
|
+
declare const Switch: import("svelte").Component<Props, {}, "button" | "checked">;
|
|
25
|
+
type Switch = ReturnType<typeof Switch>;
|
|
26
|
+
export default Switch;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { tick, type Snippet } from "svelte";
|
|
3
|
+
import type { FormEventHandler, HTMLButtonAttributes } from "svelte/elements";
|
|
4
|
+
import { twMerge } from "../../utils/tw-merge.js";
|
|
5
|
+
|
|
6
|
+
import "./index.css";
|
|
7
|
+
|
|
8
|
+
interface Props extends HTMLButtonAttributes {
|
|
9
|
+
button?: HTMLButtonElement;
|
|
10
|
+
checked?: boolean;
|
|
11
|
+
size?: "xs" | "sm" | "md" | "lg" | "xl" | string;
|
|
12
|
+
class?: string;
|
|
13
|
+
dotClass?: string;
|
|
14
|
+
label?: string;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
tabindex?: number;
|
|
17
|
+
on?: Snippet;
|
|
18
|
+
off?: Snippet;
|
|
19
|
+
onclick?: (event: MouseEvent) => void;
|
|
20
|
+
onchange?: FormEventHandler<HTMLButtonElement> | null | undefined;
|
|
21
|
+
preHook?: (current: boolean) => Promise<false | any>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let {
|
|
25
|
+
button = $bindable(),
|
|
26
|
+
size = "md",
|
|
27
|
+
class: classProp,
|
|
28
|
+
dotClass,
|
|
29
|
+
checked = $bindable(false),
|
|
30
|
+
disabled,
|
|
31
|
+
tabindex = 0,
|
|
32
|
+
label,
|
|
33
|
+
on,
|
|
34
|
+
off,
|
|
35
|
+
onclick,
|
|
36
|
+
preHook,
|
|
37
|
+
...rest
|
|
38
|
+
}: Props = $props();
|
|
39
|
+
|
|
40
|
+
const _preset: any = {
|
|
41
|
+
size: {
|
|
42
|
+
xs: `h-4 w-7`,
|
|
43
|
+
sm: `h-5 w-9`,
|
|
44
|
+
md: `h-6 w-11`,
|
|
45
|
+
lg: `h-7 w-13`,
|
|
46
|
+
xl: `h-8 w-15`,
|
|
47
|
+
},
|
|
48
|
+
dot: {
|
|
49
|
+
size: {
|
|
50
|
+
xs: `size-2 data-[checked=true]:translate-x-4`,
|
|
51
|
+
sm: `size-3 data-[checked=true]:translate-x-5`,
|
|
52
|
+
md: `size-4 data-[checked=true]:translate-x-6`,
|
|
53
|
+
lg: `size-5 data-[checked=true]:translate-x-7`,
|
|
54
|
+
xl: `size-6 data-[checked=true]:translate-x-8`,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<!-- <div class="inline-block relative"> -->
|
|
61
|
+
<button
|
|
62
|
+
bind:this={button}
|
|
63
|
+
class={twMerge(
|
|
64
|
+
"stuic-switch",
|
|
65
|
+
`m-2
|
|
66
|
+
relative inline-flex flex-shrink-0 items-center
|
|
67
|
+
rounded-full cursor-pointer
|
|
68
|
+
|
|
69
|
+
transition-colors duration-100
|
|
70
|
+
|
|
71
|
+
hover:brightness-[1.05] active:brightness-[0.95]
|
|
72
|
+
disabled:!cursor-not-allowed disabled:!opacity-50 disabled:hover:brightness-100
|
|
73
|
+
|
|
74
|
+
bg-neutral-400 dark:bg-neutral-400
|
|
75
|
+
|
|
76
|
+
aria-[checked=true]:bg-switch-accent
|
|
77
|
+
dark:aria-[checked=true]:bg-switch-accent-dark
|
|
78
|
+
|
|
79
|
+
focus:outline-0
|
|
80
|
+
focus:ring-switch-accent/20 focus:dark:ring-switch-accent-dark/20
|
|
81
|
+
focus:ring-4`,
|
|
82
|
+
size,
|
|
83
|
+
_preset.size[size],
|
|
84
|
+
classProp
|
|
85
|
+
)}
|
|
86
|
+
type="button"
|
|
87
|
+
role="switch"
|
|
88
|
+
aria-checked={checked}
|
|
89
|
+
value={`${!!checked}`}
|
|
90
|
+
{tabindex}
|
|
91
|
+
{disabled}
|
|
92
|
+
onclick={async (e) => {
|
|
93
|
+
if (typeof preHook === "function" && (await preHook(checked)) === false) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
checked = !checked;
|
|
97
|
+
|
|
98
|
+
await tick();
|
|
99
|
+
|
|
100
|
+
if (typeof onclick === "function") onclick(e);
|
|
101
|
+
|
|
102
|
+
button!.dispatchEvent(
|
|
103
|
+
new CustomEvent("change", { bubbles: true, cancelable: true, detail: checked })
|
|
104
|
+
);
|
|
105
|
+
}}
|
|
106
|
+
{...rest}
|
|
107
|
+
>
|
|
108
|
+
{#if label}<span class="sr-only">{@html label}</span>{/if}
|
|
109
|
+
<span
|
|
110
|
+
aria-hidden="true"
|
|
111
|
+
data-checked={checked}
|
|
112
|
+
class={twMerge(
|
|
113
|
+
"dot",
|
|
114
|
+
`flex items-center justify-center
|
|
115
|
+
translate-x-1 rounded-full
|
|
116
|
+
transition-all duration-100
|
|
117
|
+
shadow
|
|
118
|
+
bg-neutral-50 dark:bg-neutral-50
|
|
119
|
+
text-neutral-950 dark:text-neutral-950`,
|
|
120
|
+
size,
|
|
121
|
+
_preset.dot.size[size],
|
|
122
|
+
dotClass
|
|
123
|
+
)}
|
|
124
|
+
>
|
|
125
|
+
{#if checked}
|
|
126
|
+
{@render on?.()}
|
|
127
|
+
{:else}
|
|
128
|
+
{@render off?.()}
|
|
129
|
+
{/if}
|
|
130
|
+
</span>
|
|
131
|
+
</button>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type Snippet } from "svelte";
|
|
2
|
+
import type { FormEventHandler, HTMLButtonAttributes } from "svelte/elements";
|
|
3
|
+
import "./index.css";
|
|
4
|
+
interface Props extends HTMLButtonAttributes {
|
|
5
|
+
button?: HTMLButtonElement;
|
|
6
|
+
checked?: boolean;
|
|
7
|
+
size?: "xs" | "sm" | "md" | "lg" | "xl" | string;
|
|
8
|
+
class?: string;
|
|
9
|
+
dotClass?: string;
|
|
10
|
+
label?: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
tabindex?: number;
|
|
13
|
+
on?: Snippet;
|
|
14
|
+
off?: Snippet;
|
|
15
|
+
onclick?: (event: MouseEvent) => void;
|
|
16
|
+
onchange?: FormEventHandler<HTMLButtonElement> | null | undefined;
|
|
17
|
+
preHook?: (current: boolean) => Promise<false | any>;
|
|
18
|
+
}
|
|
19
|
+
declare const SwitchButton: import("svelte").Component<Props, {}, "button" | "checked">;
|
|
20
|
+
type SwitchButton = ReturnType<typeof SwitchButton>;
|
|
21
|
+
export default SwitchButton;
|
|
@@ -1,20 +1,77 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
// THC = Text or Html or Component
|
|
3
|
+
|
|
4
|
+
interface WithComponent {
|
|
5
|
+
component: any;
|
|
6
|
+
props?: Record<string, any>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface WithText {
|
|
10
|
+
text: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface WithHtml {
|
|
14
|
+
html: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface WithSnippet {
|
|
18
|
+
snippet: Snippet;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type AsSnippet = Snippet;
|
|
22
|
+
|
|
23
|
+
//
|
|
24
|
+
export type THC =
|
|
25
|
+
| string
|
|
26
|
+
| WithText
|
|
27
|
+
| WithHtml
|
|
28
|
+
| WithComponent
|
|
29
|
+
| WithSnippet
|
|
30
|
+
| AsSnippet;
|
|
31
|
+
|
|
32
|
+
const _is = (m: any) => typeof m === "string" && m;
|
|
33
|
+
|
|
34
|
+
export function isTHCNotEmpty(m: any) {
|
|
35
|
+
return _is(m) || _is(m?.text) || _is(m?.html) || m?.component;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Will try to extract textual (or html) content from THC
|
|
40
|
+
*/
|
|
41
|
+
export function getTHCStringContent(m: any): string {
|
|
42
|
+
return m?.html || m?.text || (typeof m === "string" ? m : "") || "";
|
|
43
|
+
}
|
|
3
44
|
</script>
|
|
4
45
|
|
|
5
|
-
<script>
|
|
6
|
-
|
|
7
|
-
|
|
46
|
+
<script lang="ts">
|
|
47
|
+
import type { Snippet } from "svelte";
|
|
48
|
+
|
|
49
|
+
interface Props extends Record<string, any> {
|
|
50
|
+
thc: THC;
|
|
51
|
+
forceAsHtml?: boolean;
|
|
52
|
+
allowCastToStringFallback?: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let {
|
|
56
|
+
thc,
|
|
57
|
+
forceAsHtml = false,
|
|
58
|
+
allowCastToStringFallback = true,
|
|
59
|
+
...rest
|
|
60
|
+
}: Props = $props();
|
|
8
61
|
</script>
|
|
9
62
|
|
|
10
|
-
{#if typeof thc ===
|
|
63
|
+
{#if typeof thc === "string"}
|
|
11
64
|
{#if forceAsHtml}{@html thc}{:else}{thc}{/if}
|
|
12
|
-
{:else if thc
|
|
65
|
+
{:else if "text" in thc && thc.text}
|
|
13
66
|
{#if forceAsHtml}{@html thc.text}{:else}{thc.text}{/if}
|
|
14
|
-
{:else if thc
|
|
67
|
+
{:else if "html" in thc && thc.html}
|
|
15
68
|
{@html thc.html}
|
|
16
|
-
{:else if thc
|
|
17
|
-
|
|
69
|
+
{:else if typeof thc === "function"}
|
|
70
|
+
{@render thc()}
|
|
71
|
+
{:else if typeof thc === "object" && "snippet" in thc}
|
|
72
|
+
{@render thc.snippet()}
|
|
73
|
+
{:else if typeof thc === "object" && "component" in thc}
|
|
74
|
+
<thc.component {...thc.props || {}} {...rest || {}} />
|
|
18
75
|
{:else if allowCastToStringFallback}
|
|
19
76
|
<!-- cast to string as the last resort (if enabled) -->
|
|
20
77
|
{thc}
|