lutra 0.0.33 → 0.1.4

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 (274) hide show
  1. package/README.md +4 -24
  2. package/dist/components/AspectRatio.svelte +26 -0
  3. package/dist/components/AspectRatio.svelte.d.ts +8 -0
  4. package/dist/components/Avatar.svelte +105 -0
  5. package/dist/components/Avatar.svelte.d.ts +14 -0
  6. package/dist/{display → components}/Close.svelte +25 -7
  7. package/dist/components/Close.svelte.d.ts +7 -0
  8. package/dist/components/ContextTip.svelte +41 -0
  9. package/dist/components/ContextTip.svelte.d.ts +7 -0
  10. package/dist/components/Dialog.svelte +78 -0
  11. package/dist/components/Dialog.svelte.d.ts +14 -0
  12. package/dist/components/Icon.svelte +62 -0
  13. package/dist/components/Icon.svelte.d.ts +8 -0
  14. package/dist/{display → components}/IconButton.svelte +43 -14
  15. package/dist/components/IconButton.svelte.d.ts +16 -0
  16. package/dist/components/Image.svelte +172 -0
  17. package/dist/components/Image.svelte.d.ts +56 -0
  18. package/dist/{display → components}/Indicator.svelte +44 -9
  19. package/dist/components/Indicator.svelte.d.ts +12 -0
  20. package/dist/{display → components}/Inset.svelte +8 -3
  21. package/dist/components/Inset.svelte.d.ts +7 -0
  22. package/dist/components/Layout.svelte +33 -0
  23. package/dist/components/Layout.svelte.d.ts +11 -0
  24. package/dist/components/MenuDropdown.svelte +195 -0
  25. package/dist/components/MenuDropdown.svelte.d.ts +16 -0
  26. package/dist/{nav → components}/MenuItem.svelte +46 -38
  27. package/dist/components/MenuItem.svelte.d.ts +11 -0
  28. package/dist/components/MenuItemContent.svelte +25 -0
  29. package/dist/components/MenuItemContent.svelte.d.ts +10 -0
  30. package/dist/{nav → components}/MenuTypes.d.ts +19 -5
  31. package/dist/components/Modal.svelte +149 -0
  32. package/dist/components/Modal.svelte.d.ts +16 -0
  33. package/dist/{display → components}/Notification.svelte +33 -22
  34. package/dist/components/Notification.svelte.d.ts +12 -0
  35. package/dist/components/Overlay.svelte +31 -0
  36. package/dist/components/Overlay.svelte.d.ts +14 -0
  37. package/dist/{layout → components}/OverlayContainer.svelte +6 -3
  38. package/dist/{layout → components}/OverlayContainer.svelte.d.ts +4 -1
  39. package/dist/components/OverlayLayer.svelte +168 -0
  40. package/dist/components/OverlayLayer.svelte.d.ts +8 -0
  41. package/dist/components/PageContent.svelte +108 -0
  42. package/dist/components/PageContent.svelte.d.ts +38 -0
  43. package/dist/components/TabbedContent.svelte +74 -0
  44. package/dist/components/TabbedContent.svelte.d.ts +11 -0
  45. package/dist/components/TabbedContentItem.svelte +33 -0
  46. package/dist/components/TabbedContentItem.svelte.d.ts +10 -0
  47. package/dist/components/Table.svelte +41 -0
  48. package/dist/components/Table.svelte.d.ts +13 -0
  49. package/dist/{nav → components}/Tabs.svelte +99 -41
  50. package/dist/components/Tabs.svelte.d.ts +20 -0
  51. package/dist/components/Tag.svelte +120 -0
  52. package/dist/components/Tag.svelte.d.ts +21 -0
  53. package/dist/components/Theme.svelte +105 -0
  54. package/dist/components/Theme.svelte.d.ts +17 -0
  55. package/dist/{display → components}/Tooltip.svelte +41 -16
  56. package/dist/components/Tooltip.svelte.d.ts +12 -0
  57. package/dist/components/UIContent.svelte +19 -0
  58. package/dist/components/UIContent.svelte.d.ts +7 -0
  59. package/dist/components/index.d.ts +28 -0
  60. package/dist/components/index.js +29 -0
  61. package/dist/{display → components}/notifications.svelte.d.ts +1 -1
  62. package/dist/{display → components}/notifications.svelte.js +3 -4
  63. package/dist/{layout → components}/overlays.svelte.d.ts +4 -2
  64. package/dist/config.d.ts +30 -0
  65. package/dist/config.js +18 -0
  66. package/dist/css/1-props.css +440 -0
  67. package/dist/css/2-base.css +343 -0
  68. package/dist/css/3-typo.css +106 -0
  69. package/dist/css/4-layout.css +368 -0
  70. package/dist/css/5-media.css +116 -0
  71. package/dist/css/lutra.css +7 -0
  72. package/dist/css/themes/DefaultTheme.css +209 -0
  73. package/dist/form/Button.svelte +35 -16
  74. package/dist/form/Button.svelte.d.ts +8 -19
  75. package/dist/form/Datepicker.svelte +311 -0
  76. package/dist/form/Datepicker.svelte.d.ts +9 -0
  77. package/dist/form/FieldContent.svelte +69 -44
  78. package/dist/form/FieldContent.svelte.d.ts +7 -17
  79. package/dist/form/FieldError.svelte +16 -6
  80. package/dist/form/FieldError.svelte.d.ts +4 -15
  81. package/dist/form/Fieldset.svelte +48 -13
  82. package/dist/form/Fieldset.svelte.d.ts +5 -16
  83. package/dist/form/Form.svelte +158 -74
  84. package/dist/form/Form.svelte.d.ts +17 -17
  85. package/dist/form/{FieldActions.svelte → FormActions.svelte} +29 -17
  86. package/dist/form/FormActions.svelte.d.ts +9 -0
  87. package/dist/form/FormSection.svelte +96 -0
  88. package/dist/form/FormSection.svelte.d.ts +9 -0
  89. package/dist/form/ImageUpload.svelte +134 -94
  90. package/dist/form/ImageUpload.svelte.d.ts +5 -16
  91. package/dist/form/Input.svelte +254 -136
  92. package/dist/form/Input.svelte.d.ts +12 -21
  93. package/dist/form/InputLength.svelte +15 -5
  94. package/dist/form/InputLength.svelte.d.ts +4 -15
  95. package/dist/form/Label.svelte +55 -11
  96. package/dist/form/Label.svelte.d.ts +6 -15
  97. package/dist/form/LogoUpload.svelte +36 -21
  98. package/dist/form/LogoUpload.svelte.d.ts +4 -15
  99. package/dist/form/Select.svelte +100 -50
  100. package/dist/form/Select.svelte.d.ts +5 -16
  101. package/dist/form/Textarea.svelte +200 -98
  102. package/dist/form/Textarea.svelte.d.ts +11 -24
  103. package/dist/form/Toggle.svelte +3 -1
  104. package/dist/form/Toggle.svelte.d.ts +4 -1
  105. package/dist/form/client.svelte.d.ts +1 -0
  106. package/dist/form/client.svelte.js +6 -2
  107. package/dist/form/form.d.ts +10 -9
  108. package/dist/form/form.js +37 -32
  109. package/dist/form/index.d.ts +3 -4
  110. package/dist/form/index.js +3 -4
  111. package/dist/form/types.d.ts +9 -16
  112. package/dist/icons/IconAlert.svelte.d.ts +4 -1
  113. package/dist/icons/IconCopy.svelte.d.ts +4 -1
  114. package/dist/icons/IconDone.svelte.d.ts +4 -1
  115. package/dist/icons/IconError.svelte.d.ts +4 -1
  116. package/dist/icons/IconHelp.svelte.d.ts +4 -1
  117. package/dist/icons/IconHide.svelte.d.ts +4 -1
  118. package/dist/icons/IconInfo.svelte.d.ts +4 -1
  119. package/dist/icons/IconLink.svelte.d.ts +4 -1
  120. package/dist/icons/IconMenuBurger.svelte.d.ts +4 -1
  121. package/dist/icons/IconMenuDots.svelte.d.ts +4 -1
  122. package/dist/icons/IconSearch.svelte.d.ts +4 -1
  123. package/dist/icons/IconShow.svelte.d.ts +4 -1
  124. package/dist/icons/IconSuccess.svelte.d.ts +4 -1
  125. package/dist/icons/IconWarning.svelte.d.ts +4 -1
  126. package/dist/index.d.ts +3 -1
  127. package/dist/index.js +3 -2
  128. package/dist/types.d.ts +39 -0
  129. package/dist/types.js +25 -0
  130. package/dist/util/StringOrComponent.svelte +20 -0
  131. package/dist/util/StringOrComponent.svelte.d.ts +8 -0
  132. package/dist/util/StringOrSnippet.svelte +16 -0
  133. package/dist/util/StringOrSnippet.svelte.d.ts +8 -0
  134. package/dist/{utils → util}/dom.js +1 -2
  135. package/dist/util/locale.d.ts +1 -0
  136. package/dist/util/locale.js +47 -0
  137. package/dist/util/settings.d.ts +4 -0
  138. package/package.json +35 -79
  139. package/dist/color.css +0 -0
  140. package/dist/display/Avatar.svelte +0 -61
  141. package/dist/display/Avatar.svelte.d.ts +0 -19
  142. package/dist/display/Badge.svelte +0 -91
  143. package/dist/display/Badge.svelte.d.ts +0 -30
  144. package/dist/display/Callout.svelte +0 -109
  145. package/dist/display/Callout.svelte.d.ts +0 -28
  146. package/dist/display/Close.svelte.d.ts +0 -18
  147. package/dist/display/Code.svelte +0 -190
  148. package/dist/display/Code.svelte.d.ts +0 -32
  149. package/dist/display/ContextTip.svelte +0 -23
  150. package/dist/display/ContextTip.svelte.d.ts +0 -18
  151. package/dist/display/DataList.svelte +0 -16
  152. package/dist/display/DataList.svelte.d.ts +0 -21
  153. package/dist/display/Details.svelte +0 -49
  154. package/dist/display/Details.svelte.d.ts +0 -27
  155. package/dist/display/Hero.svelte +0 -50
  156. package/dist/display/Hero.svelte.d.ts +0 -26
  157. package/dist/display/Icon.svelte +0 -39
  158. package/dist/display/Icon.svelte.d.ts +0 -19
  159. package/dist/display/IconButton.svelte.d.ts +0 -27
  160. package/dist/display/Image.svelte +0 -91
  161. package/dist/display/Image.svelte.d.ts +0 -26
  162. package/dist/display/Indicator.svelte.d.ts +0 -23
  163. package/dist/display/Inset.svelte.d.ts +0 -18
  164. package/dist/display/LineChart.svelte +0 -385
  165. package/dist/display/LineChart.svelte.d.ts +0 -24
  166. package/dist/display/LoadingIndicator.svelte +0 -33
  167. package/dist/display/LoadingIndicator.svelte.d.ts +0 -15
  168. package/dist/display/Modal.svelte +0 -116
  169. package/dist/display/Modal.svelte.d.ts +0 -27
  170. package/dist/display/Notification.svelte.d.ts +0 -23
  171. package/dist/display/Panel.svelte +0 -23
  172. package/dist/display/Panel.svelte.d.ts +0 -19
  173. package/dist/display/Popup.svelte +0 -111
  174. package/dist/display/Popup.svelte.d.ts +0 -25
  175. package/dist/display/Stat.svelte +0 -81
  176. package/dist/display/Stat.svelte.d.ts +0 -30
  177. package/dist/display/Table.svelte +0 -28
  178. package/dist/display/Table.svelte.d.ts +0 -24
  179. package/dist/display/TablePaginator.svelte +0 -51
  180. package/dist/display/TablePaginator.svelte.d.ts +0 -21
  181. package/dist/display/Tag.svelte +0 -90
  182. package/dist/display/Tag.svelte.d.ts +0 -32
  183. package/dist/display/Tooltip.svelte.d.ts +0 -23
  184. package/dist/display/chart.d.ts +0 -78
  185. package/dist/display/chart.js +0 -212
  186. package/dist/display/index.d.ts +0 -24
  187. package/dist/display/index.js +0 -24
  188. package/dist/form/FieldActions.svelte.d.ts +0 -20
  189. package/dist/form/FieldContainer.svelte +0 -37
  190. package/dist/form/FieldContainer.svelte.d.ts +0 -19
  191. package/dist/form/FieldSection.svelte +0 -86
  192. package/dist/form/FieldSection.svelte.d.ts +0 -20
  193. package/dist/layout/Layout.svelte +0 -47
  194. package/dist/layout/Layout.svelte.d.ts +0 -22
  195. package/dist/layout/LayoutFooter.svelte +0 -21
  196. package/dist/layout/LayoutFooter.svelte.d.ts +0 -18
  197. package/dist/layout/LayoutGrid.svelte +0 -51
  198. package/dist/layout/LayoutGrid.svelte.d.ts +0 -27
  199. package/dist/layout/LayoutHeader.svelte +0 -97
  200. package/dist/layout/LayoutHeader.svelte.d.ts +0 -34
  201. package/dist/layout/LayoutSideMenu.svelte +0 -55
  202. package/dist/layout/LayoutSideMenu.svelte.d.ts +0 -21
  203. package/dist/layout/LayoutTypes.d.ts +0 -15
  204. package/dist/layout/LayoutTypes.js +0 -9
  205. package/dist/layout/Overlay.svelte +0 -20
  206. package/dist/layout/Overlay.svelte.d.ts +0 -25
  207. package/dist/layout/OverlayLayer.svelte +0 -140
  208. package/dist/layout/OverlayLayer.svelte.d.ts +0 -19
  209. package/dist/layout/PageContent.svelte +0 -82
  210. package/dist/layout/PageContent.svelte.d.ts +0 -25
  211. package/dist/layout/Theme.svelte +0 -243
  212. package/dist/layout/Theme.svelte.d.ts +0 -19
  213. package/dist/layout/UIContent.svelte +0 -15
  214. package/dist/layout/UIContent.svelte.d.ts +0 -18
  215. package/dist/layout/index.d.ts +0 -11
  216. package/dist/layout/index.js +0 -11
  217. package/dist/nav/Breadcrumb.svelte +0 -82
  218. package/dist/nav/Breadcrumb.svelte.d.ts +0 -28
  219. package/dist/nav/Menu.svelte +0 -170
  220. package/dist/nav/Menu.svelte.d.ts +0 -27
  221. package/dist/nav/MenuItem.svelte.d.ts +0 -22
  222. package/dist/nav/NavMenu.svelte +0 -181
  223. package/dist/nav/NavMenu.svelte.d.ts +0 -19
  224. package/dist/nav/TabbedContent.svelte +0 -43
  225. package/dist/nav/TabbedContent.svelte.d.ts +0 -23
  226. package/dist/nav/Tabs.svelte.d.ts +0 -25
  227. package/dist/nav/index.d.ts +0 -7
  228. package/dist/nav/index.js +0 -6
  229. package/dist/style.css +0 -950
  230. package/dist/typo/Clamp.svelte +0 -25
  231. package/dist/typo/Clamp.svelte.d.ts +0 -24
  232. package/dist/typo/H.svelte +0 -52
  233. package/dist/typo/H.svelte.d.ts +0 -28
  234. package/dist/typo/H1.svelte +0 -14
  235. package/dist/typo/H1.svelte.d.ts +0 -26
  236. package/dist/typo/H2.svelte +0 -14
  237. package/dist/typo/H2.svelte.d.ts +0 -26
  238. package/dist/typo/H3.svelte +0 -14
  239. package/dist/typo/H3.svelte.d.ts +0 -26
  240. package/dist/typo/H4.svelte +0 -14
  241. package/dist/typo/H4.svelte.d.ts +0 -26
  242. package/dist/typo/H5.svelte +0 -14
  243. package/dist/typo/H5.svelte.d.ts +0 -26
  244. package/dist/typo/H6.svelte +0 -14
  245. package/dist/typo/H6.svelte.d.ts +0 -26
  246. package/dist/typo/P.svelte +0 -34
  247. package/dist/typo/P.svelte.d.ts +0 -26
  248. package/dist/typo/index.d.ts +0 -9
  249. package/dist/typo/index.js +0 -9
  250. package/dist/utils/StringOrComponent.svelte +0 -14
  251. package/dist/utils/StringOrComponent.svelte.d.ts +0 -19
  252. package/dist/utils/StringOrSnippet.svelte +0 -11
  253. package/dist/utils/StringOrSnippet.svelte.d.ts +0 -19
  254. package/dist/utils/defaults.d.ts +0 -4
  255. package/dist/utils/hooks.server.d.ts +0 -2
  256. package/dist/utils/hooks.server.js +0 -16
  257. package/dist/utils/id.d.ts +0 -1
  258. package/dist/utils/id.js +0 -3
  259. package/dist/utils/index.d.ts +0 -9
  260. package/dist/utils/index.js +0 -6
  261. package/dist/utils/isSnippet.d.ts +0 -3
  262. package/dist/utils/isSnippet.js +0 -11
  263. /package/dist/{nav → components}/MenuTypes.js +0 -0
  264. /package/dist/{layout → components}/overlays.svelte.js +0 -0
  265. /package/dist/{utils → util}/attr.d.ts +0 -0
  266. /package/dist/{utils → util}/attr.js +0 -0
  267. /package/dist/{utils → util}/color.d.ts +0 -0
  268. /package/dist/{utils → util}/color.js +0 -0
  269. /package/dist/{utils → util}/dom.d.ts +0 -0
  270. /package/dist/{utils → util}/keyboard.svelte.d.ts +0 -0
  271. /package/dist/{utils → util}/keyboard.svelte.js +0 -0
  272. /package/dist/{utils/defaults.js → util/settings.js} +0 -0
  273. /package/dist/{utils → util}/transitions.d.ts +0 -0
  274. /package/dist/{utils → util}/transitions.js +0 -0
@@ -1,138 +1,255 @@
1
- <script lang="ts">import { getContext, onMount } from "svelte";
2
- import { createId } from "../utils/id.js";
3
- import Copy from "../icons/IconCopy.svelte";
4
- import Done from "../icons/IconDone.svelte";
5
- import Show from "../icons/IconShow.svelte";
6
- import Hide from "../icons/IconHide.svelte";
7
- import Tooltip from "../display/Tooltip.svelte";
8
- import IconButton from "../display/IconButton.svelte";
9
- import { fieldChange, fieldKeydown, ignoreKeys } from "./client.svelte.js";
10
- import FieldError from "./FieldError.svelte";
11
- import { getFromObjWithStringPath } from "./form.js";
12
- import { ZodType } from "zod";
13
- import FieldContent from "./FieldContent.svelte";
14
- import { on } from "svelte/events";
15
- import { fade } from "svelte/transition";
16
- import Theme from "../layout/Theme.svelte";
17
- let {
18
- alt,
19
- autofocus,
20
- autocapitalize,
21
- autocomplete,
22
- autocorrect,
23
- capture,
24
- checked,
25
- contained,
26
- copyable,
27
- defaultValue,
28
- disabled,
29
- enterkeyhint,
30
- height,
31
- help,
32
- id = $bindable(createId()),
33
- indeterminate,
34
- inputmode,
35
- label,
36
- labelTip,
37
- list,
38
- maxlength,
39
- minlength,
40
- max,
41
- min,
42
- multiple,
43
- name,
44
- pattern,
45
- placeholder,
46
- suffix,
47
- onblur,
48
- onchange,
49
- onclick,
50
- onfocus,
51
- onkeydown,
52
- onkeyup,
53
- onkeypress,
54
- prefix,
55
- readonly,
56
- required,
57
- shape = "rounded",
58
- size,
59
- src,
60
- step,
61
- title,
62
- type,
63
- unit,
64
- value = $bindable(""),
65
- viewable,
66
- webkitdirectory,
67
- ...rest
68
- } = $props();
69
- let el = $state();
70
- let copyTitle = $state("Copy");
71
- let viewTitle = $state("Show");
72
- let copyTooltipOpen = $state(false);
73
- let copyBtnIcon = $state(Copy);
74
- let viewBtnIcon = $state(Show);
75
- const form = getContext("form");
76
- const field = $derived(form?.fields[name]);
77
- const issue = $derived(form?.issues?.find((issue2) => issue2.name === name));
78
- $effect(() => {
79
- console.log("issue", issue);
80
- });
81
- const validator = getContext("form.validators")?.[name];
82
- const data = form?.data;
83
- const originalData = form?.originalData;
84
- function view(e) {
85
- e.preventDefault();
86
- if (!el) return;
87
- if (el.type === "password") {
88
- el.type = "text";
89
- viewBtnIcon = Hide;
90
- viewTitle = "Hide";
91
- } else {
92
- el.type = "password";
93
- viewBtnIcon = Show;
94
- viewTitle = "Show";
95
- }
96
- el.focus();
97
- }
98
- function copy(e) {
99
- e.preventDefault();
100
- if (!el) return;
101
- if (navigator.clipboard) {
102
- navigator.clipboard.writeText(value.toString());
103
- } else {
104
- el.focus();
105
- el.select();
106
- document.execCommand("copy");
107
- }
108
- copyBtnIcon = Done;
109
- copyTitle = "Copied!";
110
- copyTooltipOpen = true;
111
- setTimeout(() => {
112
- copyBtnIcon = Copy;
113
- copyTitle = "Copy";
114
- copyTooltipOpen = false;
115
- }, 1500);
116
- el.focus();
117
- }
118
- if (!value) value = form ? getFromObjWithStringPath(Object.assign(originalData ?? {}, data ?? {}), name) || form?.fields?.[name]?.defaultValue : "";
119
- onMount(() => {
120
- if (value) fieldChange(form, name, () => el)({});
121
- });
122
- let focused = $state(false);
123
- let rangeValueLeft = $derived.by(() => {
124
- if (!el) return 0;
125
- value;
126
- return (el.valueAsNumber - min) / (max - min) * 100;
127
- });
128
- function focus(e) {
129
- focused = true;
130
- if (onfocus) return onfocus(e);
131
- }
132
- function blur(e) {
133
- focused = false;
134
- if (onblur) return onblur(e);
135
- }
1
+ <script lang="ts">
2
+ import { getContext, onMount, type Snippet } from "svelte";
3
+ import type { Autocomplete } from "./types.js";
4
+ import Copy from "../icons/IconCopy.svelte";
5
+ import Done from "../icons/IconDone.svelte";
6
+ import Show from "../icons/IconShow.svelte";
7
+ import Hide from "../icons/IconHide.svelte";
8
+ import Tooltip from "../components/Tooltip.svelte";
9
+ import IconButton from "../components/IconButton.svelte";
10
+ import type { LutraForm } from "./types.js";
11
+ import { fieldChange, fieldKeydown, ignoreKeys } from "./client.svelte.js";
12
+ import FieldError from "./FieldError.svelte";
13
+ import { getFromObjWithStringPath } from "./form.js";
14
+ import { ZodType } from "zod";
15
+ import FieldContent from "./FieldContent.svelte";
16
+ import { on } from "svelte/events";
17
+ import { fade } from "svelte/transition";
18
+ import Theme from "../components/Theme.svelte";
19
+
20
+ let {
21
+ alt,
22
+ autofocus,
23
+ autocapitalize,
24
+ autocomplete,
25
+ autocorrect,
26
+ capture,
27
+ checked,
28
+ contained,
29
+ copyable,
30
+ defaultValue,
31
+ disabled,
32
+ enterkeyhint,
33
+ height,
34
+ help,
35
+ id = $bindable(crypto.randomUUID()),
36
+ indeterminate,
37
+ inputmode,
38
+ label,
39
+ labelHelp,
40
+ labelTip,
41
+ list,
42
+ maxlength,
43
+ minlength,
44
+ max,
45
+ min,
46
+ multiple,
47
+ name,
48
+ pattern,
49
+ placeholder,
50
+ suffix,
51
+ onblur,
52
+ onchange,
53
+ onclick,
54
+ onfocus,
55
+ onkeydown,
56
+ onkeyup,
57
+ onkeypress,
58
+ prefix,
59
+ readonly,
60
+ required,
61
+ shape = 'rounded',
62
+ size,
63
+ src,
64
+ step,
65
+ title,
66
+ type,
67
+ unit,
68
+ value = $bindable(''),
69
+ viewable,
70
+ webkitdirectory,
71
+ ...rest
72
+ }: {
73
+ /** alt attribute for the image type. Required for accessibility */
74
+ alt?: string;
75
+ /** Whether the input should be autofocused. */
76
+ autofocus?: boolean;
77
+ /** Whether the input should be autocapitalized. */
78
+ autocapitalize?: boolean | 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters';
79
+ /** Specifies whether autocomplete is enabled for the input. */
80
+ autocomplete?: Autocomplete;
81
+ /** Whether the input should be autocorrected. (Safari only) */
82
+ autocorrect?: boolean;
83
+ /** A hint to the browser for which capture method to use. */
84
+ capture?: 'user' | 'environment';
85
+ /** Whether the input should be checked. */
86
+ checked?: boolean;
87
+ /** Whether the input should be contained. */
88
+ contained?: boolean;
89
+ /** Whether the input should be copyable. */
90
+ copyable?: boolean;
91
+ /** The default value of the input element. */
92
+ defaultValue?: string;
93
+ /** Whether the input should be disabled. */
94
+ disabled?: boolean;
95
+ /** A hint to the browser for which enter key to display for the input. */
96
+ enterkeyhint?: 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send';
97
+ /** The height of the input element. Valid for image inputs. */
98
+ height?: number;
99
+ /** Help text to display below the input. */
100
+ help?: string | Snippet;
101
+ /** A random id is generated if not provided. */
102
+ id?: string;
103
+ /** Whether the input should be indeterminate. */
104
+ indeterminate?: boolean;
105
+ /** A hint to the browser for which keyboard to display. This is only used for type="text" inputs. Strongly consider using type="email" or type="url" etc. instead */
106
+ inputmode?: 'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search';
107
+ /** The label for the input */
108
+ label?: string | Snippet
109
+ /** Help text to display below the input. */
110
+ labelHelp?: string | Snippet;
111
+ /** Context tooltip for a label. Renders with a questionmark using ContextTip. */
112
+ labelTip?: string | Snippet;
113
+ /** The id of a datalist element that contains pre-defined options for the input element. */
114
+ list?: string;
115
+ /** The maximum number of characters (as UTF-16 code units) the user can enter into the input. Valid for text, search, url, tel, email, and password. */
116
+ maxlength?: number;
117
+ /** The minimum number of characters (as UTF-16 code units) the user can enter into the input. Valid for text, search, url, tel, email, and password. */
118
+ minlength?: number;
119
+ /** Allow multiple f
120
+ /** The maximum value of the input element. Valid for date, month, week, time, datetime-local, number, and range. */
121
+ max?: number
122
+ /** The minimum value of the input element. Valid for date, month, week, time, datetime-local, number, and range. */
123
+ min?: number;
124
+ /** Whether the input should allow multiple values. Valid for email and file inputs. */
125
+ multiple?: boolean;
126
+ /** The name of the input element. */
127
+ name: string;
128
+ /** The onblur event handler */
129
+ onblur?: (e: FocusEvent) => void;
130
+ /** Onchange event handler */
131
+ onchange?: (e: Event) => void;
132
+ /** Onclick event handler */
133
+ onclick?: (e: MouseEvent) => void;
134
+ /** Onfocus event handler */
135
+ onfocus?: (e: FocusEvent) => void;
136
+ /** Keyup event handler */
137
+ onkeyup?: (e: KeyboardEvent) => void;
138
+ /** Keydown event handler */
139
+ onkeydown?: (e: KeyboardEvent) => void;
140
+ /** Keypress event handler */
141
+ onkeypress?: (e: KeyboardEvent) => void;
142
+ /** A regular expression that the input's value is checked against. Valid for text, search, url, tel, email, and password. */
143
+ pattern?: string;
144
+ /** Placeholder text to display when the input is empty. */
145
+ placeholder?: string;
146
+ /** Suffix content, to display after the input. */
147
+ suffix?: string | Snippet;
148
+ /** Prefix content, to display before the input. */
149
+ prefix?: string | Snippet;
150
+ /** Whether the input should be read-only. */
151
+ readonly?: boolean;
152
+ /** Whether the input should be required. */
153
+ required?: boolean;
154
+ /** The shape of the input element. */
155
+ shape?: 'default' | 'rounded' | 'pill' | 'circle';
156
+ /** The size of the input element. */
157
+ size?: number;
158
+ /** Source URL for the image type. */
159
+ src?: string;
160
+ /** A number that specifies the granularity that the value must adhere to. Valid for date, month, week, time, datetime-local, number, and range. */
161
+ step?: number;
162
+ /** A string that defines the title of the input element. */
163
+ title?: string;
164
+ /** The type of input to display. */
165
+ type?: 'button' | 'checkbox' | 'color' | 'date' | 'datetime-local' | 'email' | 'file' | 'hidden' | 'image' | 'month' | 'number' | 'password' | 'radio' | 'range' | 'search' | 'submit' | 'tel' | 'text' | 'time' | 'url' | 'week';
166
+ /** Unit of measurement for range inputs. */
167
+ unit?: string;
168
+ /** The value of the input element. */
169
+ value?: string | number | boolean | null;
170
+ /** Whether the input should be viewable. Valid for password inputs. */
171
+ viewable?: boolean;
172
+ /** Whether the input should only accept directory uploads. */
173
+ webkitdirectory?: boolean;
174
+ } = $props();
175
+
176
+ if(contained === undefined) { contained = getContext('lutra.form.input.contained') ?? getContext('lutra.form.contained') ?? getContext('lutra.contained') ?? false; }
177
+
178
+ let el: HTMLInputElement | undefined = $state();
179
+ let copyTitle = $state('Copy');
180
+ let viewTitle = $state('Show');
181
+ let copyTooltipOpen = $state(false);
182
+ let copyBtnIcon = $state(Copy);
183
+ let viewBtnIcon = $state(Show);
184
+
185
+ // Set defaults from form context
186
+ const form = getContext<LutraForm<any>>('form');
187
+ const field = $derived(form?.fields[name]);
188
+ const issue = $derived(form?.issues?.find((issue) => issue.name === name));
189
+ const validator = getContext<Record<string, ZodType>>('form.validators')?.[name];
190
+ const data = form?.data;
191
+ const originalData = form?.originalData;
192
+
193
+ function view(e: MouseEvent) {
194
+ e.preventDefault();
195
+ if(!el) return;
196
+ if(el.type === 'password') {
197
+ el.type = 'text';
198
+ viewBtnIcon = Hide;
199
+ viewTitle = 'Hide';
200
+ } else {
201
+ el.type = 'password';
202
+ viewBtnIcon = Show;
203
+ viewTitle = 'Show';
204
+ }
205
+ el.focus();
206
+ }
207
+
208
+ function copy(e: MouseEvent) {
209
+ e.preventDefault();
210
+ if(!el) return;
211
+ // try with navigator.clipboard
212
+ if(navigator.clipboard) {
213
+ navigator.clipboard.writeText(value!.toString());
214
+ } else {
215
+ el.focus();
216
+ el.select();
217
+ document.execCommand('copy');
218
+ }
219
+ copyBtnIcon = Done;
220
+ copyTitle = 'Copied!';
221
+ copyTooltipOpen = true;
222
+ setTimeout(() => {
223
+ copyBtnIcon = Copy;
224
+ copyTitle = 'Copy';
225
+ copyTooltipOpen = false;
226
+ }, 1500);
227
+ el!.focus();
228
+ }
229
+
230
+ if(!value) value = form ? (getFromObjWithStringPath(Object.assign(originalData ?? {}, data ?? {}), name) as string) || form?.fields?.[name]?.defaultValue as string : '';
231
+
232
+ onMount(() => {
233
+ if(value) fieldChange(form, name, () => el)({} as any);
234
+ });
235
+
236
+ let focused = $state(false);
237
+ let rangeValueLeft = $derived.by(() => {
238
+ if(!el) return 0;
239
+ value;
240
+ return (el.valueAsNumber - min!) / (max! - min!) * 100;
241
+ });
242
+
243
+ function focus(e: FocusEvent) {
244
+ focused = true;
245
+ if(onfocus) return onfocus(e);
246
+ }
247
+
248
+ function blur(e: FocusEvent) {
249
+ focused = false;
250
+ if(onblur) return onblur(e);
251
+ }
252
+
136
253
  </script>
137
254
 
138
255
  {#snippet input()}
@@ -159,7 +276,7 @@ function blur(e) {
159
276
  {readonly}
160
277
  required={required || field?.required}
161
278
  {title}
162
- bind:checked={value}
279
+ bind:checked={value as boolean}
163
280
  {...rest}
164
281
  />
165
282
  {:else}
@@ -213,6 +330,7 @@ function blur(e) {
213
330
  <FieldContent
214
331
  {id}
215
332
  {label}
333
+ {labelHelp}
216
334
  {labelTip}
217
335
  contained={type === "checkbox" || type === "radio" || type === "color" || type === "range" ? false : true}
218
336
  direction={(type === "checkbox" || type === "radio") ? 'row' : 'column'}
@@ -1,28 +1,18 @@
1
1
  import { type Snippet } from "svelte";
2
2
  import type { Autocomplete } from "./types.js";
3
- interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
4
- new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
5
- $$bindings?: Bindings;
6
- } & Exports;
7
- (internal: unknown, props: Props & {
8
- $$events?: Events;
9
- $$slots?: Slots;
10
- }): Exports;
11
- z_$$bindings?: Bindings;
12
- }
13
- declare const Input: $$__sveltets_2_IsomorphicComponent<{
3
+ type $$ComponentProps = {
14
4
  /** alt attribute for the image type. Required for accessibility */
15
5
  alt?: string;
16
6
  /** Whether the input should be autofocused. */
17
7
  autofocus?: boolean;
18
8
  /** Whether the input should be autocapitalized. */
19
- autocapitalize?: boolean | "off" | "none" | "on" | "sentences" | "words" | "characters";
9
+ autocapitalize?: boolean | 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters';
20
10
  /** Specifies whether autocomplete is enabled for the input. */
21
11
  autocomplete?: Autocomplete;
22
12
  /** Whether the input should be autocorrected. (Safari only) */
23
13
  autocorrect?: boolean;
24
14
  /** A hint to the browser for which capture method to use. */
25
- capture?: "user" | "environment";
15
+ capture?: 'user' | 'environment';
26
16
  /** Whether the input should be checked. */
27
17
  checked?: boolean;
28
18
  /** Whether the input should be contained. */
@@ -34,7 +24,7 @@ declare const Input: $$__sveltets_2_IsomorphicComponent<{
34
24
  /** Whether the input should be disabled. */
35
25
  disabled?: boolean;
36
26
  /** A hint to the browser for which enter key to display for the input. */
37
- enterkeyhint?: "enter" | "done" | "go" | "next" | "previous" | "search" | "send";
27
+ enterkeyhint?: 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send';
38
28
  /** The height of the input element. Valid for image inputs. */
39
29
  height?: number;
40
30
  /** Help text to display below the input. */
@@ -44,9 +34,11 @@ declare const Input: $$__sveltets_2_IsomorphicComponent<{
44
34
  /** Whether the input should be indeterminate. */
45
35
  indeterminate?: boolean;
46
36
  /** A hint to the browser for which keyboard to display. This is only used for type="text" inputs. Strongly consider using type="email" or type="url" etc. instead */
47
- inputmode?: "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | "search";
37
+ inputmode?: 'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search';
48
38
  /** The label for the input */
49
39
  label?: string | Snippet;
40
+ /** Help text to display below the input. */
41
+ labelHelp?: string | Snippet;
50
42
  /** Context tooltip for a label. Renders with a questionmark using ContextTip. */
51
43
  labelTip?: string | Snippet;
52
44
  /** The id of a datalist element that contains pre-defined options for the input element. */
@@ -91,7 +83,7 @@ declare const Input: $$__sveltets_2_IsomorphicComponent<{
91
83
  /** Whether the input should be required. */
92
84
  required?: boolean;
93
85
  /** The shape of the input element. */
94
- shape?: "default" | "rounded" | "pill" | "circle";
86
+ shape?: 'default' | 'rounded' | 'pill' | 'circle';
95
87
  /** The size of the input element. */
96
88
  size?: number;
97
89
  /** Source URL for the image type. */
@@ -101,7 +93,7 @@ declare const Input: $$__sveltets_2_IsomorphicComponent<{
101
93
  /** A string that defines the title of the input element. */
102
94
  title?: string;
103
95
  /** The type of input to display. */
104
- type?: "button" | "submit" | "checkbox" | "radio" | "hidden" | "text" | "password" | "file" | "image" | "email" | "number" | "tel" | "url" | "range" | "search" | "date" | "time" | "datetime-local" | "month" | "week" | "color";
96
+ type?: 'button' | 'checkbox' | 'color' | 'date' | 'datetime-local' | 'email' | 'file' | 'hidden' | 'image' | 'month' | 'number' | 'password' | 'radio' | 'range' | 'search' | 'submit' | 'tel' | 'text' | 'time' | 'url' | 'week';
105
97
  /** Unit of measurement for range inputs. */
106
98
  unit?: string;
107
99
  /** The value of the input element. */
@@ -110,8 +102,7 @@ declare const Input: $$__sveltets_2_IsomorphicComponent<{
110
102
  viewable?: boolean;
111
103
  /** Whether the input should only accept directory uploads. */
112
104
  webkitdirectory?: boolean;
113
- }, {
114
- [evt: string]: CustomEvent<any>;
115
- }, {}, {}, "value" | "id">;
116
- type Input = InstanceType<typeof Input>;
105
+ };
106
+ declare const Input: import("svelte").Component<$$ComponentProps, {}, "id" | "value">;
107
+ type Input = ReturnType<typeof Input>;
117
108
  export default Input;
@@ -1,7 +1,17 @@
1
- <script lang="ts">let {
2
- value,
3
- maxlength
4
- } = $props();
1
+ <script lang="ts">
2
+ /**
3
+ * @description
4
+ * Internal: A component that displays the length of an input field. Used by the Input and Textarea components.
5
+ */
6
+ let {
7
+ value,
8
+ maxlength,
9
+ }: {
10
+ /** The value of the input. */
11
+ value: string;
12
+ /** The maximum length of the input. */
13
+ maxlength: number;
14
+ } = $props();
5
15
  </script>
6
16
 
7
17
  {#if maxlength}
@@ -27,6 +37,6 @@
27
37
  gap: 0.25rem;
28
38
  }
29
39
  .InputLength .Length.warn {
30
- color: var(--text-warn);
40
+ color: var(--text-color-warn, light-dark(red, red));
31
41
  }
32
42
  </style>
@@ -1,20 +1,9 @@
1
- interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
2
- new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
- $$bindings?: Bindings;
4
- } & Exports;
5
- (internal: unknown, props: Props & {
6
- $$events?: Events;
7
- $$slots?: Slots;
8
- }): Exports;
9
- z_$$bindings?: Bindings;
10
- }
11
- declare const InputLength: $$__sveltets_2_IsomorphicComponent<{
1
+ type $$ComponentProps = {
12
2
  /** The value of the input. */
13
3
  value: string;
14
4
  /** The maximum length of the input. */
15
5
  maxlength: number;
16
- }, {
17
- [evt: string]: CustomEvent<any>;
18
- }, {}, {}, "">;
19
- type InputLength = InstanceType<typeof InputLength>;
6
+ };
7
+ declare const InputLength: import("svelte").Component<$$ComponentProps, {}, "">;
8
+ type InputLength = ReturnType<typeof InputLength>;
20
9
  export default InputLength;
@@ -1,14 +1,40 @@
1
- <script lang="ts">import ContextTip from "../display/ContextTip.svelte";
2
- let {
3
- id,
4
- label,
5
- tip,
6
- required
7
- } = $props();
1
+ <script lang="ts">
2
+ import ContextTip from "../components/ContextTip.svelte";
3
+ import StringOrSnippet from "../util/StringOrSnippet.svelte";
4
+ import type { Snippet } from "svelte";
5
+
6
+ /**
7
+ * @description
8
+ * The label component is used to create a label for an input element.
9
+ * @example
10
+ * <Label label="Name" />
11
+ * {#snippet l()}
12
+ * <Label label={l} />
13
+ * {/snippet}
14
+ */
15
+ let {
16
+ id,
17
+ label,
18
+ help,
19
+ tip,
20
+ required,
21
+ }: {
22
+ /** The id of the input element */
23
+ id?: string;
24
+ /** The label for the input */
25
+ label?: string | Snippet;
26
+ /** The help text for the input */
27
+ tip?: string | Snippet;
28
+ /** The help text for the input */
29
+ help?: string | Snippet;
30
+ /** Whether the input is required */
31
+ required?: boolean;
32
+ } = $props();
33
+
8
34
  </script>
9
35
 
10
36
  {#if label}
11
- <label for={id} class:hasTip={!!tip}>
37
+ <label for={id} class:hasTip={!!tip} class:hasHelp={!!help}>
12
38
  {#if typeof label === 'string'}
13
39
  <span>
14
40
  {label} {#if required}<span aria-hidden="true">*</span>{/if}
@@ -18,6 +44,11 @@ let {
18
44
  {@render label()}
19
45
  </span>
20
46
  {/if}
47
+ {#if help}
48
+ <span class="Help">
49
+ <StringOrSnippet content={help} />
50
+ </span>
51
+ {/if}
21
52
  {#if tip}
22
53
  <ContextTip {tip} />
23
54
  {/if}
@@ -30,15 +61,28 @@ let {
30
61
  text-wrap: balance;
31
62
  display: inline-grid;
32
63
  grid-template-columns: 1fr;
33
- gap: 0.5em;
64
+ gap: var(--form-label-gap, var(--space-md));
34
65
  align-items: center;
35
66
  }
36
- label.hasTip {
67
+ label.hasTip,
68
+ label.hasHelp {
37
69
  grid-template-columns: 1fr auto;
38
70
  }
71
+ label.hasHelp.hasTip {
72
+ grid-template-columns: 1fr auto auto;
73
+ }
39
74
  label > span > span {
40
75
  font-weight: 600;
41
- color: var(--text-warn);
76
+ color: var(--text-color-warn, light-dark(red, red));
42
77
  padding-inline: 0.175em;
43
78
  }
79
+ .Help {
80
+ font-weight: var(--font-weight-normal);
81
+ }
82
+ .Help :global(a) {
83
+ color: var(--link-color);
84
+ }
85
+ .Help :global(a:hover) {
86
+ color: var(--link-color-hover);
87
+ }
44
88
  </style>