@marianmeres/stuic 1.125.0 → 2.0.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (252) hide show
  1. package/README.md +2 -8
  2. package/dist/_shared.css +2 -0
  3. package/dist/actions/autogrow.svelte.d.ts +6 -0
  4. package/dist/actions/autogrow.svelte.js +19 -0
  5. package/dist/actions/highlight-dragover.svelte.d.ts +7 -0
  6. package/dist/actions/highlight-dragover.svelte.js +38 -0
  7. package/dist/actions/index.d.ts +7 -0
  8. package/dist/actions/index.js +7 -0
  9. package/dist/actions/on-submit-validity-check.svelte.d.ts +15 -0
  10. package/dist/actions/on-submit-validity-check.svelte.js +58 -0
  11. package/dist/actions/tooltip/index.css +34 -0
  12. package/dist/actions/tooltip/tooltip.svelte.d.ts +13 -0
  13. package/dist/actions/tooltip/tooltip.svelte.js +203 -0
  14. package/dist/actions/trim.svelte.d.ts +4 -0
  15. package/dist/actions/trim.svelte.js +17 -0
  16. package/dist/actions/{validate.d.ts → validate.svelte.d.ts} +8 -8
  17. package/dist/actions/validate.svelte.js +90 -0
  18. package/dist/components/AlertConfirmPrompt/AlertConfirmPrompt.svelte +59 -385
  19. package/dist/components/AlertConfirmPrompt/AlertConfirmPrompt.svelte.d.ts +9 -101
  20. package/dist/components/AlertConfirmPrompt/Current.svelte +202 -0
  21. package/dist/components/AlertConfirmPrompt/Current.svelte.d.ts +22 -0
  22. package/dist/components/AlertConfirmPrompt/acp-icons.d.ts +7 -2
  23. package/dist/components/AlertConfirmPrompt/acp-icons.js +8 -8
  24. package/dist/components/AlertConfirmPrompt/alert-confirm-prompt-stack.svelte.d.ts +63 -0
  25. package/dist/components/AlertConfirmPrompt/alert-confirm-prompt-stack.svelte.js +144 -0
  26. package/dist/components/AlertConfirmPrompt/index.d.ts +2 -0
  27. package/dist/components/AlertConfirmPrompt/index.js +2 -0
  28. package/dist/components/AnimatedElipsis/AnimatedEllipsis.svelte +47 -0
  29. package/dist/components/AnimatedElipsis/AnimatedEllipsis.svelte.d.ts +7 -0
  30. package/dist/components/AnimatedElipsis/index.d.ts +1 -0
  31. package/dist/components/AnimatedElipsis/index.js +1 -0
  32. package/dist/components/AppShell/AppShell.svelte +188 -127
  33. package/dist/components/AppShell/AppShell.svelte.d.ts +62 -43
  34. package/dist/components/AppShell/index.d.ts +1 -0
  35. package/dist/components/AppShell/index.js +1 -0
  36. package/dist/components/Backdrop/Backdrop.svelte +149 -49
  37. package/dist/components/Backdrop/Backdrop.svelte.d.ts +22 -37
  38. package/dist/components/Backdrop/index.d.ts +1 -0
  39. package/dist/components/Backdrop/index.js +1 -0
  40. package/dist/components/Button/Button.svelte +122 -146
  41. package/dist/components/Button/Button.svelte.d.ts +22 -80
  42. package/dist/components/Button/index.css +16 -0
  43. package/dist/components/Button/index.d.ts +1 -0
  44. package/dist/components/Button/index.js +1 -0
  45. package/dist/components/ColResize/ColResize.svelte +0 -0
  46. package/dist/components/ColResize/ColResize.svelte.d.ts +26 -0
  47. package/dist/components/ColorScheme/{LocalColorScheme.svelte → ColorSchemeLocal.svelte} +2 -2
  48. package/dist/components/ColorScheme/ColorSchemeLocal.svelte.d.ts +26 -0
  49. package/dist/components/ColorScheme/{SystemAwareColorScheme.svelte → ColorSchemeSystemAware.svelte} +4 -4
  50. package/dist/components/ColorScheme/ColorSchemeSystemAware.svelte.d.ts +26 -0
  51. package/dist/components/ColorScheme/color-scheme.d.ts +26 -8
  52. package/dist/components/ColorScheme/color-scheme.js +40 -16
  53. package/dist/components/ColorScheme/index.d.ts +3 -0
  54. package/dist/components/ColorScheme/index.js +3 -0
  55. package/dist/components/DismissibleMessage/DismissibleMessage.svelte +76 -83
  56. package/dist/components/DismissibleMessage/DismissibleMessage.svelte.d.ts +16 -37
  57. package/dist/components/DismissibleMessage/index.css +13 -0
  58. package/dist/components/DismissibleMessage/index.d.ts +1 -0
  59. package/dist/components/DismissibleMessage/index.js +1 -0
  60. package/dist/components/Drawer/Drawer.svelte +155 -84
  61. package/dist/components/Drawer/Drawer.svelte.d.ts +24 -35
  62. package/dist/components/Drawer/index.d.ts +1 -0
  63. package/dist/components/Drawer/index.js +1 -0
  64. package/dist/components/HoverExpandableWidth/HoverExpandableWidth.svelte +150 -111
  65. package/dist/components/HoverExpandableWidth/HoverExpandableWidth.svelte.d.ts +16 -29
  66. package/dist/components/HoverExpandableWidth/index.d.ts +1 -0
  67. package/dist/components/HoverExpandableWidth/index.js +1 -0
  68. package/dist/components/Input/FieldCheckbox.svelte +174 -132
  69. package/dist/components/Input/FieldCheckbox.svelte.d.ts +28 -64
  70. package/dist/components/Input/FieldFile.svelte +166 -0
  71. package/dist/components/Input/FieldFile.svelte.d.ts +41 -0
  72. package/dist/components/Input/FieldInput.svelte +143 -0
  73. package/dist/components/Input/FieldInput.svelte.d.ts +41 -0
  74. package/dist/components/Input/FieldLikeButton.svelte +206 -0
  75. package/dist/components/Input/FieldLikeButton.svelte.d.ts +41 -0
  76. package/dist/components/Input/FieldOptions.svelte +646 -0
  77. package/dist/components/Input/FieldOptions.svelte.d.ts +58 -0
  78. package/dist/components/Input/FieldRadios.svelte +126 -77
  79. package/dist/components/Input/FieldRadios.svelte.d.ts +23 -61
  80. package/dist/components/Input/FieldSelect.svelte +160 -239
  81. package/dist/components/Input/FieldSelect.svelte.d.ts +40 -88
  82. package/dist/components/Input/FieldSwitch.svelte +132 -0
  83. package/dist/components/Input/FieldSwitch.svelte.d.ts +41 -0
  84. package/dist/components/Input/FieldTextarea.svelte +146 -0
  85. package/dist/components/Input/FieldTextarea.svelte.d.ts +44 -0
  86. package/dist/components/Input/Fieldset.svelte +21 -17
  87. package/dist/components/Input/Fieldset.svelte.d.ts +10 -27
  88. package/dist/components/Input/_internal/FieldRadioInternal.svelte +186 -0
  89. package/dist/components/Input/_internal/FieldRadioInternal.svelte.d.ts +30 -0
  90. package/dist/components/Input/_internal/InputWrap.svelte +216 -0
  91. package/dist/components/Input/_internal/InputWrap.svelte.d.ts +36 -0
  92. package/dist/components/Input/index.css +134 -0
  93. package/dist/components/Input/index.d.ts +11 -0
  94. package/dist/components/Input/index.js +11 -0
  95. package/dist/components/Input/types.d.ts +11 -0
  96. package/dist/components/KbdShortcut/KbdShortcut.svelte +89 -0
  97. package/dist/components/KbdShortcut/KbdShortcut.svelte.d.ts +17 -0
  98. package/dist/components/KbdShortcut/index.d.ts +1 -0
  99. package/dist/components/KbdShortcut/index.js +1 -0
  100. package/dist/components/Modal/Modal.svelte +127 -0
  101. package/dist/components/Modal/Modal.svelte.d.ts +32 -0
  102. package/dist/components/Modal/index.d.ts +1 -0
  103. package/dist/components/Modal/index.js +1 -0
  104. package/dist/components/ModalDialog/ModalDialog.svelte +137 -81
  105. package/dist/components/ModalDialog/ModalDialog.svelte.d.ts +17 -38
  106. package/dist/components/ModalDialog/index.d.ts +1 -0
  107. package/dist/components/ModalDialog/index.js +1 -0
  108. package/dist/components/Notifications/Notifications.svelte +259 -173
  109. package/dist/components/Notifications/Notifications.svelte.d.ts +32 -60
  110. package/dist/components/Notifications/index.css +12 -0
  111. package/dist/components/Notifications/index.d.ts +2 -0
  112. package/dist/components/Notifications/index.js +2 -0
  113. package/dist/components/Notifications/notifications-icons.d.ts +1 -1
  114. package/dist/components/Notifications/notifications-icons.js +4 -4
  115. package/dist/components/Notifications/notifications-stack.svelte.d.ts +89 -0
  116. package/dist/components/Notifications/notifications-stack.svelte.js +161 -0
  117. package/dist/components/Progress/Progress.svelte +26 -0
  118. package/dist/components/Progress/Progress.svelte.d.ts +10 -0
  119. package/dist/components/Progress/_internal/Bar.svelte +31 -0
  120. package/dist/components/Progress/_internal/Bar.svelte.d.ts +10 -0
  121. package/dist/components/Progress/_internal/Circle.svelte +10 -0
  122. package/dist/components/Progress/_internal/Circle.svelte.d.ts +7 -0
  123. package/dist/components/Progress/index.css +7 -0
  124. package/dist/components/Progress/index.d.ts +1 -0
  125. package/dist/components/Progress/index.js +1 -0
  126. package/dist/components/Spinner/Spinner.svelte +52 -37
  127. package/dist/components/Spinner/Spinner.svelte.d.ts +10 -22
  128. package/dist/components/Spinner/index.d.ts +1 -0
  129. package/dist/components/Spinner/index.js +1 -0
  130. package/dist/components/Switch/Switch.svelte +158 -118
  131. package/dist/components/Switch/Switch.svelte.d.ts +25 -66
  132. package/dist/components/Switch/SwitchButton.svelte +131 -0
  133. package/dist/components/Switch/SwitchButton.svelte.d.ts +21 -0
  134. package/dist/components/Switch/index.css +7 -0
  135. package/dist/components/Switch/index.d.ts +2 -0
  136. package/dist/components/Switch/index.js +2 -0
  137. package/dist/components/Thc/Thc.svelte +67 -10
  138. package/dist/components/Thc/Thc.svelte.d.ts +18 -22
  139. package/dist/components/Thc/index.d.ts +1 -0
  140. package/dist/components/Thc/index.js +1 -0
  141. package/dist/components/TwCheck/TwCheck.svelte +34 -0
  142. package/dist/components/TwCheck/TwCheck.svelte.d.ts +10 -0
  143. package/dist/components/TwCheck/index.css +5 -0
  144. package/dist/components/TwCheck/index.d.ts +1 -0
  145. package/dist/components/TwCheck/index.js +1 -0
  146. package/dist/components/X/X.svelte +12 -5
  147. package/dist/components/X/X.svelte.d.ts +6 -18
  148. package/dist/components/X/index.d.ts +1 -0
  149. package/dist/components/X/index.js +1 -0
  150. package/dist/index.css +26 -0
  151. package/dist/index.d.ts +21 -39
  152. package/dist/index.js +23 -54
  153. package/dist/types.d.ts +251 -2
  154. package/dist/types.js +248 -0
  155. package/dist/utils/breakpoint.svelte.d.ts +19 -0
  156. package/dist/utils/breakpoint.svelte.js +42 -0
  157. package/dist/utils/debounce.d.ts +13 -0
  158. package/dist/utils/debounce.js +22 -0
  159. package/dist/utils/device-pointer.svelte.d.ts +11 -0
  160. package/dist/utils/device-pointer.svelte.js +26 -0
  161. package/dist/utils/event-modifiers.d.ts +4 -0
  162. package/dist/utils/event-modifiers.js +29 -0
  163. package/dist/utils/get-id.d.ts +1 -1
  164. package/dist/utils/get-id.js +3 -1
  165. package/dist/utils/index.d.ts +21 -0
  166. package/dist/utils/index.js +21 -0
  167. package/dist/utils/is-browser.d.ts +1 -0
  168. package/dist/utils/is-browser.js +5 -0
  169. package/dist/utils/is-mac.d.ts +1 -0
  170. package/dist/utils/is-mac.js +11 -0
  171. package/dist/utils/maybe-json-parse.d.ts +1 -0
  172. package/dist/utils/maybe-json-parse.js +12 -0
  173. package/dist/utils/maybe-json-stringify.d.ts +1 -0
  174. package/dist/utils/maybe-json-stringify.js +11 -0
  175. package/dist/utils/move-array-item.d.ts +4 -0
  176. package/dist/utils/move-array-item.js +20 -0
  177. package/dist/utils/omit-pick.d.ts +2 -2
  178. package/dist/utils/omit-pick.js +10 -8
  179. package/dist/utils/paint.d.ts +18 -0
  180. package/dist/utils/paint.js +32 -0
  181. package/dist/utils/persistent-state.svelte.d.ts +23 -0
  182. package/dist/utils/persistent-state.svelte.js +48 -0
  183. package/dist/utils/prefers-reduced-motion.svelte.d.ts +2 -0
  184. package/dist/utils/prefers-reduced-motion.svelte.js +4 -0
  185. package/dist/utils/qsa.d.ts +1 -0
  186. package/dist/utils/qsa.js +3 -0
  187. package/dist/utils/sleep.d.ts +28 -0
  188. package/dist/utils/sleep.js +33 -0
  189. package/dist/utils/storage-abstraction.d.ts +35 -0
  190. package/dist/utils/storage-abstraction.js +136 -0
  191. package/dist/utils/str-hash.d.ts +7 -0
  192. package/dist/utils/str-hash.js +35 -0
  193. package/dist/utils/throttle.d.ts +1 -0
  194. package/dist/utils/throttle.js +47 -0
  195. package/dist/utils/to-integer.d.ts +1 -0
  196. package/dist/utils/to-integer.js +11 -0
  197. package/dist/utils/tr.d.ts +5 -0
  198. package/dist/utils/tr.js +13 -0
  199. package/dist/utils/tw-merge.d.ts +10 -0
  200. package/dist/utils/tw-merge.js +16 -0
  201. package/dist/utils/ucfirst.d.ts +1 -0
  202. package/dist/utils/ucfirst.js +6 -0
  203. package/package.json +66 -73
  204. package/dist/actions/autogrow.d.ts +0 -8
  205. package/dist/actions/autogrow.js +0 -22
  206. package/dist/actions/autoscroll.d.ts +0 -21
  207. package/dist/actions/autoscroll.js +0 -60
  208. package/dist/actions/drag-drop.d.ts +0 -28
  209. package/dist/actions/drag-drop.js +0 -152
  210. package/dist/actions/on-outside.d.ts +0 -9
  211. package/dist/actions/on-outside.js +0 -27
  212. package/dist/actions/pre-submit-validity-check.d.ts +0 -3
  213. package/dist/actions/pre-submit-validity-check.js +0 -21
  214. package/dist/actions/tooltip/_make-visible.d.ts +0 -3
  215. package/dist/actions/tooltip/_make-visible.js +0 -25
  216. package/dist/actions/tooltip/_maybe-pick-safe-placement.d.ts +0 -3
  217. package/dist/actions/tooltip/_maybe-pick-safe-placement.js +0 -86
  218. package/dist/actions/tooltip/_set-position.d.ts +0 -2
  219. package/dist/actions/tooltip/_set-position.js +0 -125
  220. package/dist/actions/tooltip/tooltip.d.ts +0 -42
  221. package/dist/actions/tooltip/tooltip.js +0 -299
  222. package/dist/actions/trim.d.ts +0 -4
  223. package/dist/actions/trim.js +0 -18
  224. package/dist/actions/validate.js +0 -80
  225. package/dist/components/AlertConfirmPrompt/alert-confirm-prompt.d.ts +0 -58
  226. package/dist/components/AlertConfirmPrompt/alert-confirm-prompt.js +0 -141
  227. package/dist/components/ColorScheme/LocalColorScheme.svelte.d.ts +0 -25
  228. package/dist/components/ColorScheme/SystemAwareColorScheme.svelte.d.ts +0 -25
  229. package/dist/components/Input/Field.svelte +0 -315
  230. package/dist/components/Input/Field.svelte.d.ts +0 -102
  231. package/dist/components/Input/PinInput.svelte +0 -151
  232. package/dist/components/Input/PinInput.svelte.d.ts +0 -51
  233. package/dist/components/Input/XFieldRadioInternal.svelte +0 -143
  234. package/dist/components/Input/XFieldRadioInternal.svelte.d.ts +0 -45
  235. package/dist/components/Notifications/notifications.d.ts +0 -78
  236. package/dist/components/Notifications/notifications.js +0 -215
  237. package/dist/components/Popover/Popover.svelte +0 -24
  238. package/dist/components/Popover/Popover.svelte.d.ts +0 -22
  239. package/dist/components/Spinner/Spinner.v5.svelte +0 -114
  240. package/dist/components/Spinner/Spinner.v5.svelte.d.ts +0 -16
  241. package/dist/utils/calculate-alignment.d.ts +0 -68
  242. package/dist/utils/calculate-alignment.js +0 -183
  243. package/dist/utils/device-pointer.d.ts +0 -5
  244. package/dist/utils/device-pointer.js +0 -10
  245. package/dist/utils/prefers-reduced-motion.d.ts +0 -6
  246. package/dist/utils/prefers-reduced-motion.js +0 -26
  247. package/dist/utils/tw-merge2.d.ts +0 -3
  248. package/dist/utils/tw-merge2.js +0 -9
  249. package/dist/utils/tw-types.d.ts +0 -1
  250. package/dist/utils/window-size.d.ts +0 -22
  251. package/dist/utils/window-size.js +0 -35
  252. /package/dist/{utils/tw-types.js → components/Input/types.js} +0 -0
@@ -1,156 +1,198 @@
1
- <script context="module">import { slide } from "svelte/transition";
2
- import { validate as validateAction } from "../../actions/validate.js";
3
- import { getId } from "../../utils/get-id.js";
4
- import { twMerge2 } from "../../utils/tw-merge2.js";
5
- import Thc from "../Thc/Thc.svelte";
6
- const _emptyClasses = () => ({
7
- box: "",
8
- label: "",
9
- input: "",
10
- invalid: "",
11
- validationMessage: "",
12
- description: ""
13
- });
14
- const _PRESET = {
15
- box: "flex items-start mb-4",
16
- label: "block w-full",
17
- input: `
18
- size-4 rounded
19
- bg-neutral-100
20
- border-neutral-300
21
- shadow-sm
22
- text-stuic-primary dark:text-stuic-primary-dark
23
- cursor-pointer
24
- focus:border-stuic-primary
25
- focus:ring-4
26
- focus:ring-offset-0
27
- focus:ring-stuic-primary
28
- focus:ring-opacity-20
29
- disabled:cursor-not-allowed
30
- `,
31
- validationMessage: "text-xs text-stuic-primary tracking-tight",
32
- description: "text-sm opacity-50"
33
- };
34
- const _PRESET_BY_SIZE = {
35
- sm: { label: "text-sm" },
36
- md: { label: "text-base" },
37
- lg: { label: "text-base font-bold" }
38
- };
39
- export class FieldCheckboxConfig {
40
- static class = _emptyClasses();
41
- static classBySize = {
42
- sm: _emptyClasses(),
43
- md: _emptyClasses(),
44
- lg: _emptyClasses()
45
- };
46
- }
47
- </script>
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte";
3
+ import type { HTMLInputAttributes } from "svelte/elements";
4
+ import { slide } from "svelte/transition";
5
+ import {
6
+ validate as validateAction,
7
+ type ValidateOptions,
8
+ type ValidationResult,
9
+ } from "../../actions/validate.svelte.js";
10
+ import { getId } from "../../utils/get-id.js";
11
+ import { twMerge } from "../../utils/tw-merge.js";
12
+ import { Thc } from "../Thc/index.js";
13
+ import { isTHCNotEmpty, type THC } from "../Thc/Thc.svelte";
14
+
15
+ type SnippetWithId = Snippet<[{ id: string }]>;
16
+
17
+ interface Props extends HTMLInputAttributes {
18
+ input?: HTMLInputElement;
19
+ id?: string;
20
+ checked?: boolean;
21
+ label?: SnippetWithId | THC;
22
+ required?: boolean;
23
+ disabled?: boolean;
24
+ renderSize?: "sm" | "md" | "lg" | string;
25
+ description?: SnippetWithId | THC;
26
+ //
27
+ validate?: boolean | Omit<ValidateOptions, "setValidationResult">;
28
+ //
29
+ class?: string;
30
+ classInputBox?: string;
31
+ classInput?: string;
32
+ classLabelBox?: string;
33
+ classLabel?: string;
34
+ classDescBox?: string;
35
+ classValidationBox?: string;
36
+ style?: string;
37
+ }
38
+
39
+ let {
40
+ input = $bindable(),
41
+ id = getId(),
42
+ checked = $bindable(),
43
+ label,
44
+ required,
45
+ disabled,
46
+ renderSize = "md",
47
+ description,
48
+ validate,
49
+ class: classProp,
50
+ classInputBox,
51
+ classInput,
52
+ classLabelBox,
53
+ classLabel,
54
+ classDescBox,
55
+ classValidationBox,
56
+ style,
57
+ ...rest
58
+ }: Props = $props();
59
+
60
+ //
61
+ let validation: ValidationResult | undefined = $state();
62
+ const setValidationResult = (res: ValidationResult) => (validation = res);
63
+
64
+ //
65
+ let invalid = $derived(validation && !validation?.valid);
66
+ let idDesc = getId();
48
67
 
49
- <script>let _class = {};
50
- export { _class as class };
51
- export let classBySize = {};
52
- export let size = "md";
53
- export let id = getId();
54
- export let checked = false;
55
- export let label = "";
56
- export let name = "";
57
- export let description = "";
58
- export let tabindex = 0;
59
- export let disabled = void 0;
60
- export let readonly = void 0;
61
- export let required = void 0;
62
- export let validate = void 0;
63
- let validation;
64
- const setValidationResult = (res) => validation = res;
65
- let idDesc = getId();
66
- const _collectClasses = (k, extra = "") => [
67
- _PRESET?.[k] || "",
68
- _PRESET_BY_SIZE?.[size]?.[k] || "",
69
- FieldCheckboxConfig?.class?.[k] || "",
70
- FieldCheckboxConfig?.classBySize?.[size]?.[k] || "",
71
- extra || "",
72
- _class?.[k] || "",
73
- classBySize?.[size]?.[k] || ""
74
- ].join(" ");
75
- $:
76
- _boxClass = twMerge2(_collectClasses("box"));
77
- $:
78
- _inputClass = twMerge2(
79
- _collectClasses(
80
- "input",
81
- validation && !validation.valid ? _collectClasses("invalid") : ""
82
- )
83
- );
84
- $:
85
- _labelClass = twMerge2(_collectClasses("label"));
86
- $:
87
- _validationMessageClass = twMerge2(_collectClasses("validationMessage"));
88
- $:
89
- _descriptionClass = twMerge2(_collectClasses("description"));
68
+ // $inspect(33333, invalid, validation);
69
+
70
+ //
71
+ let _classCommon = $derived(
72
+ [invalid && "invalid", disabled && "disabled", required && "required", renderSize]
73
+ .filter(Boolean)
74
+ .join(" ")
75
+ );
76
+
77
+ const _preset = {
78
+ labelBox: {
79
+ label: {
80
+ size: {
81
+ sm: "text-sm mt-0.5",
82
+ lg: "font-bold",
83
+ } as any,
84
+ },
85
+ },
86
+ };
90
87
  </script>
91
88
 
92
- <div class={_boxClass}>
93
- <div class="flex h-6 items-center ml-1">
89
+ {#snippet snippetOrThc({ id, value }: { id: string; value?: SnippetWithId | THC })}
90
+ {#if typeof value === "function"}
91
+ {@render value({ id })}
92
+ {:else if value}
93
+ <Thc thc={value} forceAsHtml />
94
+ {/if}
95
+ {/snippet}
96
+
97
+ <label
98
+ class={twMerge(
99
+ `stuic-checkbox`,
100
+ _classCommon,
101
+ "flex items-start mb-4 text-base",
102
+ classProp
103
+ )}
104
+ {style}
105
+ >
106
+ <div
107
+ class={twMerge(
108
+ "input-box",
109
+ _classCommon,
110
+ "flex h-6 items-center ml-1",
111
+ classInputBox
112
+ )}
113
+ >
94
114
  <input
95
115
  {id}
96
116
  type="checkbox"
117
+ bind:this={input}
97
118
  bind:checked
98
119
  aria-checked={checked}
99
120
  aria-describedby={description ? idDesc : undefined}
100
- {name}
101
- class={_inputClass}
102
- {disabled}
103
- {readonly}
121
+ use:validateAction={() => ({
122
+ enabled: !!validate,
123
+ ...(typeof validate === "boolean" ? {} : validate),
124
+ setValidationResult,
125
+ })}
126
+ class={twMerge(
127
+ _classCommon,
128
+ `size-5 rounded
129
+ bg-neutral-100
130
+ border-neutral-300
131
+ text-input-accent dark:text-input-accent-dark
132
+ cursor-pointer
133
+
134
+ checked:border-input-accent checked:bg-input-accent
135
+ checked:dark:border-input-accent-dark checked:dark:bg-input-accent-dark
136
+
137
+ focus:border-input-accent
138
+ focus:ring-4
139
+ focus:ring-offset-0
140
+ focus:ring-input-accent/20 focus:dark:ring-input-accent-dark/20
141
+
142
+ disabled:cursor-not-allowed`,
143
+ classInput
144
+ )}
104
145
  {required}
105
- {tabindex}
106
- use:validateAction={validate
107
- ? { ...(validate === true ? {} : validate), setValidationResult }
108
- : undefined}
109
- on:blur
110
- on:change
111
- on:click
112
- on:focus
113
- on:input
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
146
+ {disabled}
147
+ {...rest}
122
148
  />
123
149
  </div>
124
- <div class="ml-3 w-full">
150
+ <div class={twMerge("label-box", _classCommon, "ml-3 w-full", classLabelBox)}>
125
151
  {#if label}
126
- <label
127
- for={id}
128
- class={_labelClass}
129
- class:cursor-pointer={!disabled}
130
- class:cursor-not-allowed={disabled}
152
+ <div
153
+ class={twMerge(
154
+ "label",
155
+ _classCommon,
156
+ "block w-full cursor-pointer",
157
+ disabled && "cursor-not-allowed",
158
+ required && "after:content-['*'] after:opacity-40 after:pl-1",
159
+ _preset.labelBox.label.size[renderSize],
160
+ classLabel
161
+ )}
131
162
  >
132
- <Thc thc={label} forceAsHtml />
133
- </label>
163
+ {#if isTHCNotEmpty(label)}
164
+ <Thc thc={label as THC} forceAsHtml />
165
+ {:else}
166
+ {@render (label as SnippetWithId)({ id })}
167
+ {/if}
168
+ </div>
134
169
  {/if}
135
170
  {#if validation && !validation?.valid}
136
- <div transition:slide={{ duration: 150 }} class={_validationMessageClass}>
171
+ <div
172
+ transition:slide={{ duration: 150 }}
173
+ class={twMerge(
174
+ "validation-box",
175
+ _classCommon,
176
+ "text-xs text-input-accent dark:text-input-accent-dark tracking-tight",
177
+ classValidationBox
178
+ )}
179
+ >
137
180
  {@html validation.message}
138
181
  </div>
139
182
  {/if}
140
- {#if description || $$slots.description}
141
- <!-- svelte-ignore a11y-click-events-have-key-events a11y-no-static-element-interactions -->
183
+ {#if description}
142
184
  <div
143
- class={_descriptionClass}
144
- class:cursor-pointer={!disabled}
145
- class:cursor-not-allowed={disabled}
146
- on:click={() => !disabled && (checked = !checked)}
185
+ id={idDesc}
186
+ class={twMerge(
187
+ "desc-box",
188
+ _classCommon,
189
+ "text-sm opacity-50 cursor-pointer font-normal",
190
+ disabled && "cursor-not-allowed",
191
+ classDescBox
192
+ )}
147
193
  >
148
- {#if $$slots.description}
149
- <slot name="description" />
150
- {:else}
151
- <Thc thc={description} forceAsHtml />
152
- {/if}
194
+ {@render snippetOrThc({ id, value: description })}
153
195
  </div>
154
196
  {/if}
155
197
  </div>
156
- </div>
198
+ </label>
@@ -1,65 +1,29 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { ValidateOptions } from '../../actions/validate.js';
3
- import type { THC } from '../Thc/Thc.svelte';
4
- export interface FieldCheckboxConfigClasses {
5
- box?: string;
6
- label?: string;
7
- input?: string;
8
- invalid?: string;
9
- validationMessage?: string;
10
- description?: string;
1
+ import type { Snippet } from "svelte";
2
+ import type { HTMLInputAttributes } from "svelte/elements";
3
+ import { type ValidateOptions } from "../../actions/validate.svelte.js";
4
+ import { type THC } from "../Thc/Thc.svelte";
5
+ type SnippetWithId = Snippet<[{
6
+ id: string;
7
+ }]>;
8
+ interface Props extends HTMLInputAttributes {
9
+ input?: HTMLInputElement;
10
+ id?: string;
11
+ checked?: boolean;
12
+ label?: SnippetWithId | THC;
13
+ required?: boolean;
14
+ disabled?: boolean;
15
+ renderSize?: "sm" | "md" | "lg" | string;
16
+ description?: SnippetWithId | THC;
17
+ validate?: boolean | Omit<ValidateOptions, "setValidationResult">;
18
+ class?: string;
19
+ classInputBox?: string;
20
+ classInput?: string;
21
+ classLabelBox?: string;
22
+ classLabel?: string;
23
+ classDescBox?: string;
24
+ classValidationBox?: string;
25
+ style?: string;
11
26
  }
12
- export interface FieldCheckboxConfigClassesBySize {
13
- sm?: FieldCheckboxConfigClasses;
14
- md?: FieldCheckboxConfigClasses;
15
- lg?: FieldCheckboxConfigClasses;
16
- }
17
- export declare class FieldCheckboxConfig {
18
- static class: FieldCheckboxConfigClasses;
19
- static classBySize: FieldCheckboxConfigClassesBySize;
20
- }
21
- declare const __propDef: {
22
- props: {
23
- class?: FieldCheckboxConfigClasses;
24
- classBySize?: FieldCheckboxConfigClassesBySize;
25
- size?: "sm" | "md" | "lg";
26
- id?: string;
27
- checked?: boolean;
28
- label?: THC;
29
- name?: string;
30
- description?: THC;
31
- tabindex?: number;
32
- disabled?: boolean | undefined;
33
- readonly?: boolean | undefined;
34
- required?: boolean | undefined;
35
- validate?: ValidateOptions | true | undefined;
36
- };
37
- events: {
38
- blur: FocusEvent;
39
- change: Event;
40
- click: MouseEvent;
41
- focus: FocusEvent;
42
- input: Event;
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
- } & {
52
- [evt: string]: CustomEvent<any>;
53
- };
54
- slots: {
55
- description: {};
56
- };
57
- exports?: {} | undefined;
58
- bindings?: string | undefined;
59
- };
60
- export type FieldCheckboxProps = typeof __propDef.props;
61
- export type FieldCheckboxEvents = typeof __propDef.events;
62
- export type FieldCheckboxSlots = typeof __propDef.slots;
63
- export default class FieldCheckbox extends SvelteComponent<FieldCheckboxProps, FieldCheckboxEvents, FieldCheckboxSlots> {
64
- }
65
- export {};
27
+ declare const FieldCheckbox: import("svelte").Component<Props, {}, "input" | "checked">;
28
+ type FieldCheckbox = ReturnType<typeof FieldCheckbox>;
29
+ export default FieldCheckbox;
@@ -0,0 +1,166 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte";
3
+ import type { HTMLInputAttributes } from "svelte/elements";
4
+ import { highlightDragover } from "../../actions/highlight-dragover.svelte.js";
5
+ import {
6
+ validate as validateAction,
7
+ type ValidateOptions,
8
+ type ValidationResult,
9
+ } from "../../actions/validate.svelte.js";
10
+ import { getId } from "../../utils/get-id.js";
11
+ import { twMerge } from "../../utils/tw-merge.js";
12
+ import type { THC } from "../Thc/Thc.svelte";
13
+ import InputWrap from "./_internal/InputWrap.svelte";
14
+
15
+ type SnippetWithId = Snippet<[{ id: string }]>;
16
+
17
+ interface Props extends HTMLInputAttributes, Record<string, any> {
18
+ input?: HTMLInputElement;
19
+ files?: FileList;
20
+ multiple?: boolean;
21
+ label?: SnippetWithId | THC;
22
+ description?: SnippetWithId | THC;
23
+ class?: string;
24
+ id?: string;
25
+ tabindex?: number; // tooShort
26
+ renderSize?: "sm" | "md" | "lg" | string;
27
+ //
28
+ required?: boolean;
29
+ disabled?: boolean;
30
+ //
31
+ validate?: boolean | Omit<ValidateOptions, "setValidationResult">;
32
+ // wrap snippets
33
+ labelAfter?: SnippetWithId | THC;
34
+ inputBefore?: SnippetWithId | THC;
35
+ inputAfter?: SnippetWithId | THC;
36
+ inputBelow?: SnippetWithId | THC;
37
+ below?: SnippetWithId | THC;
38
+ //
39
+ labelLeft?: boolean;
40
+ labelLeftWidth?: "normal" | "wide";
41
+ labelLeftBreakpoint?: number;
42
+ //
43
+ classInput?: string;
44
+ classLabel?: string;
45
+ classLabelBox?: string;
46
+ classInputBox?: string;
47
+ classInputBoxWrap?: string;
48
+ classDescBox?: string;
49
+ classBelowBox?: string;
50
+ classFileList?: string;
51
+ //
52
+ style?: string;
53
+ }
54
+
55
+ let {
56
+ input = $bindable(),
57
+ files = $bindable(),
58
+ multiple,
59
+ label = "",
60
+ id = getId(),
61
+ type = "text",
62
+ tabindex = 0,
63
+ description,
64
+ class: classProp,
65
+ renderSize,
66
+ //
67
+ required = false,
68
+ disabled = false,
69
+ //
70
+ validate,
71
+ //
72
+ labelAfter,
73
+ inputBefore,
74
+ inputAfter,
75
+ inputBelow,
76
+ below,
77
+ //
78
+ labelLeft = false,
79
+ labelLeftWidth = "normal",
80
+ labelLeftBreakpoint = 480,
81
+ //
82
+ classInput,
83
+ classLabel,
84
+ classLabelBox,
85
+ classInputBox,
86
+ classInputBoxWrap,
87
+ classDescBox,
88
+ classBelowBox,
89
+ classFileList,
90
+ style,
91
+ //
92
+ ...rest
93
+ }: Props = $props();
94
+
95
+ let validation: ValidationResult | undefined = $state();
96
+ const setValidationResult = (res: ValidationResult) => (validation = res);
97
+
98
+ // $inspect(files);
99
+ </script>
100
+
101
+ <InputWrap
102
+ {description}
103
+ class={classProp}
104
+ size={renderSize}
105
+ {id}
106
+ {label}
107
+ {labelAfter}
108
+ {inputBefore}
109
+ {inputAfter}
110
+ {below}
111
+ {required}
112
+ {disabled}
113
+ {labelLeft}
114
+ {labelLeftWidth}
115
+ {labelLeftBreakpoint}
116
+ {classLabel}
117
+ {classLabelBox}
118
+ {classInputBox}
119
+ {classInputBoxWrap}
120
+ {classDescBox}
121
+ {classBelowBox}
122
+ {validation}
123
+ {style}
124
+ >
125
+ <div class="block w-full">
126
+ <input
127
+ type="file"
128
+ bind:files
129
+ bind:this={input}
130
+ {id}
131
+ class={twMerge(
132
+ "form-input",
133
+ "block border-0 w-full !text-sm",
134
+ "file:rounded file:border-0 file:mr-4 file:bg-neutral-200",
135
+ "file:px-2 file:py-0.5 file:cursor-pointer file:text-sm",
136
+ "focus-visible:ring-0 focus:ring-0 focus:leading-0",
137
+ renderSize,
138
+ classInput
139
+ )}
140
+ use:highlightDragover={() => ({ classes: ["outline-dashed"] })}
141
+ use:validateAction={() => ({
142
+ enabled: !!validate,
143
+ ...(typeof validate === "boolean" ? {} : validate),
144
+ setValidationResult,
145
+ })}
146
+ {multiple}
147
+ {tabindex}
148
+ {required}
149
+ {disabled}
150
+ {...rest}
151
+ />
152
+ {#if (files?.length || 0) > 1}
153
+ <ul
154
+ class={twMerge(
155
+ "px-2.5 pb-2.5 pt-1 text-sm opacity-80",
156
+ "space-y-1 list-decimal list-inside",
157
+ classFileList
158
+ )}
159
+ >
160
+ {#each files || [] as f}
161
+ <li>{f.name}</li>
162
+ {/each}
163
+ </ul>
164
+ {/if}
165
+ </div>
166
+ </InputWrap>
@@ -0,0 +1,41 @@
1
+ import type { Snippet } from "svelte";
2
+ import type { HTMLInputAttributes } from "svelte/elements";
3
+ import { type ValidateOptions } from "../../actions/validate.svelte.js";
4
+ import type { THC } from "../Thc/Thc.svelte";
5
+ type SnippetWithId = Snippet<[{
6
+ id: string;
7
+ }]>;
8
+ interface Props extends HTMLInputAttributes, Record<string, any> {
9
+ input?: HTMLInputElement;
10
+ files?: FileList;
11
+ multiple?: boolean;
12
+ label?: SnippetWithId | THC;
13
+ description?: SnippetWithId | THC;
14
+ class?: string;
15
+ id?: string;
16
+ tabindex?: number;
17
+ renderSize?: "sm" | "md" | "lg" | string;
18
+ required?: boolean;
19
+ disabled?: boolean;
20
+ validate?: boolean | Omit<ValidateOptions, "setValidationResult">;
21
+ labelAfter?: SnippetWithId | THC;
22
+ inputBefore?: SnippetWithId | THC;
23
+ inputAfter?: SnippetWithId | THC;
24
+ inputBelow?: SnippetWithId | THC;
25
+ below?: SnippetWithId | THC;
26
+ labelLeft?: boolean;
27
+ labelLeftWidth?: "normal" | "wide";
28
+ labelLeftBreakpoint?: number;
29
+ classInput?: string;
30
+ classLabel?: string;
31
+ classLabelBox?: string;
32
+ classInputBox?: string;
33
+ classInputBoxWrap?: string;
34
+ classDescBox?: string;
35
+ classBelowBox?: string;
36
+ classFileList?: string;
37
+ style?: string;
38
+ }
39
+ declare const FieldFile: import("svelte").Component<Props, {}, "input" | "files">;
40
+ type FieldFile = ReturnType<typeof FieldFile>;
41
+ export default FieldFile;