polymorph-ui-components 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (242) hide show
  1. package/README.md +354 -0
  2. package/dist/Accordion/Accordion.svelte +28 -0
  3. package/dist/Accordion/Accordion.svelte.d.ts +4 -0
  4. package/dist/Accordion/properties.d.ts +7 -0
  5. package/dist/Accordion/properties.js +1 -0
  6. package/dist/Animations/ModalAnimation.svelte +55 -0
  7. package/dist/Animations/ModalAnimation.svelte.d.ts +12 -0
  8. package/dist/Animations/OverlayAnimation.svelte +14 -0
  9. package/dist/Animations/OverlayAnimation.svelte.d.ts +7 -0
  10. package/dist/Avatar/Avatar.svelte +122 -0
  11. package/dist/Avatar/Avatar.svelte.d.ts +4 -0
  12. package/dist/Avatar/properties.d.ts +15 -0
  13. package/dist/Avatar/properties.js +1 -0
  14. package/dist/Badge/Badge.svelte +53 -0
  15. package/dist/Badge/Badge.svelte.d.ts +4 -0
  16. package/dist/Badge/properties.d.ts +6 -0
  17. package/dist/Badge/properties.js +1 -0
  18. package/dist/Banner/Banner.svelte +158 -0
  19. package/dist/Banner/Banner.svelte.d.ts +4 -0
  20. package/dist/Banner/properties.d.ts +19 -0
  21. package/dist/Banner/properties.js +1 -0
  22. package/dist/Book/Book.svelte +281 -0
  23. package/dist/Book/Book.svelte.d.ts +4 -0
  24. package/dist/Book/properties.d.ts +24 -0
  25. package/dist/Book/properties.js +1 -0
  26. package/dist/Browser/Browser.svelte +176 -0
  27. package/dist/Browser/Browser.svelte.d.ts +3 -0
  28. package/dist/Browser/properties.d.ts +14 -0
  29. package/dist/Browser/properties.js +1 -0
  30. package/dist/Button/Button.svelte +153 -0
  31. package/dist/Button/Button.svelte.d.ts +4 -0
  32. package/dist/Button/properties.d.ts +24 -0
  33. package/dist/Button/properties.js +1 -0
  34. package/dist/Calendar/Calendar.svelte +477 -0
  35. package/dist/Calendar/Calendar.svelte.d.ts +4 -0
  36. package/dist/Calendar/properties.d.ts +30 -0
  37. package/dist/Calendar/properties.js +1 -0
  38. package/dist/Carousel/Carousel.svelte +258 -0
  39. package/dist/Carousel/Carousel.svelte.d.ts +4 -0
  40. package/dist/Carousel/properties.d.ts +20 -0
  41. package/dist/Carousel/properties.js +1 -0
  42. package/dist/CheckListItem/CheckListItem.svelte +65 -0
  43. package/dist/CheckListItem/CheckListItem.svelte.d.ts +4 -0
  44. package/dist/CheckListItem/properties.d.ts +15 -0
  45. package/dist/CheckListItem/properties.js +1 -0
  46. package/dist/Checkbox/Checkbox.svelte +157 -0
  47. package/dist/Checkbox/Checkbox.svelte.d.ts +4 -0
  48. package/dist/Checkbox/properties.d.ts +17 -0
  49. package/dist/Checkbox/properties.js +1 -0
  50. package/dist/Choicebox/Choicebox.svelte +85 -0
  51. package/dist/Choicebox/Choicebox.svelte.d.ts +4 -0
  52. package/dist/Choicebox/properties.d.ts +14 -0
  53. package/dist/Choicebox/properties.js +1 -0
  54. package/dist/ColorPicker/ColorPicker.svelte +583 -0
  55. package/dist/ColorPicker/ColorPicker.svelte.d.ts +4 -0
  56. package/dist/ColorPicker/properties.d.ts +15 -0
  57. package/dist/ColorPicker/properties.js +1 -0
  58. package/dist/Combobox/Combobox.svelte +432 -0
  59. package/dist/Combobox/Combobox.svelte.d.ts +6 -0
  60. package/dist/Combobox/properties.d.ts +42 -0
  61. package/dist/Combobox/properties.js +1 -0
  62. package/dist/CommandMenu/CommandMenu.svelte +452 -0
  63. package/dist/CommandMenu/CommandMenu.svelte.d.ts +4 -0
  64. package/dist/CommandMenu/properties.d.ts +26 -0
  65. package/dist/CommandMenu/properties.js +1 -0
  66. package/dist/ContextMenu/ContextMenu.svelte +308 -0
  67. package/dist/ContextMenu/ContextMenu.svelte.d.ts +4 -0
  68. package/dist/ContextMenu/properties.d.ts +26 -0
  69. package/dist/ContextMenu/properties.js +1 -0
  70. package/dist/Gauge/Gauge.svelte +70 -0
  71. package/dist/Gauge/Gauge.svelte.d.ts +4 -0
  72. package/dist/Gauge/properties.d.ts +9 -0
  73. package/dist/Gauge/properties.js +1 -0
  74. package/dist/GridItem/GridItem.svelte +145 -0
  75. package/dist/GridItem/GridItem.svelte.d.ts +4 -0
  76. package/dist/GridItem/properties.d.ts +15 -0
  77. package/dist/GridItem/properties.js +1 -0
  78. package/dist/Icon/Icon.svelte +61 -0
  79. package/dist/Icon/Icon.svelte.d.ts +4 -0
  80. package/dist/Icon/properties.d.ts +12 -0
  81. package/dist/Icon/properties.js +1 -0
  82. package/dist/IconStack/IconStack.svelte +55 -0
  83. package/dist/IconStack/IconStack.svelte.d.ts +4 -0
  84. package/dist/IconStack/properties.d.ts +9 -0
  85. package/dist/IconStack/properties.js +1 -0
  86. package/dist/Img/Img.svelte +37 -0
  87. package/dist/Img/Img.svelte.d.ts +4 -0
  88. package/dist/Img/properties.d.ts +13 -0
  89. package/dist/Img/properties.js +1 -0
  90. package/dist/Input/Input.svelte +349 -0
  91. package/dist/Input/Input.svelte.d.ts +8 -0
  92. package/dist/Input/properties.d.ts +45 -0
  93. package/dist/Input/properties.js +1 -0
  94. package/dist/InputButton/InputButton.svelte +252 -0
  95. package/dist/InputButton/InputButton.svelte.d.ts +7 -0
  96. package/dist/InputButton/properties.d.ts +22 -0
  97. package/dist/InputButton/properties.js +1 -0
  98. package/dist/KeyboardInput/KeyboardInput.svelte +93 -0
  99. package/dist/KeyboardInput/KeyboardInput.svelte.d.ts +4 -0
  100. package/dist/KeyboardInput/properties.d.ts +12 -0
  101. package/dist/KeyboardInput/properties.js +1 -0
  102. package/dist/ListItem/ListItem.svelte +309 -0
  103. package/dist/ListItem/ListItem.svelte.d.ts +4 -0
  104. package/dist/ListItem/properties.d.ts +34 -0
  105. package/dist/ListItem/properties.js +1 -0
  106. package/dist/Loader/Loader.svelte +90 -0
  107. package/dist/Loader/Loader.svelte.d.ts +4 -0
  108. package/dist/Loader/properties.d.ts +4 -0
  109. package/dist/Loader/properties.js +1 -0
  110. package/dist/LoadingDots/LoadingDots.svelte +59 -0
  111. package/dist/LoadingDots/LoadingDots.svelte.d.ts +3 -0
  112. package/dist/LoadingDots/properties.d.ts +8 -0
  113. package/dist/LoadingDots/properties.js +1 -0
  114. package/dist/Menu/Menu.svelte +356 -0
  115. package/dist/Menu/Menu.svelte.d.ts +4 -0
  116. package/dist/Menu/properties.d.ts +28 -0
  117. package/dist/Menu/properties.js +1 -0
  118. package/dist/Modal/Modal.svelte +357 -0
  119. package/dist/Modal/Modal.svelte.d.ts +4 -0
  120. package/dist/Modal/properties.d.ts +39 -0
  121. package/dist/Modal/properties.js +1 -0
  122. package/dist/Pagination/Pagination.svelte +148 -0
  123. package/dist/Pagination/Pagination.svelte.d.ts +4 -0
  124. package/dist/Pagination/properties.d.ts +14 -0
  125. package/dist/Pagination/properties.js +1 -0
  126. package/dist/Phone/Phone.svelte +234 -0
  127. package/dist/Phone/Phone.svelte.d.ts +3 -0
  128. package/dist/Phone/properties.d.ts +11 -0
  129. package/dist/Phone/properties.js +1 -0
  130. package/dist/Pill/Pill.svelte +130 -0
  131. package/dist/Pill/Pill.svelte.d.ts +4 -0
  132. package/dist/Pill/properties.d.ts +16 -0
  133. package/dist/Pill/properties.js +1 -0
  134. package/dist/Progress/Progress.svelte +68 -0
  135. package/dist/Progress/Progress.svelte.d.ts +4 -0
  136. package/dist/Progress/properties.d.ts +10 -0
  137. package/dist/Progress/properties.js +1 -0
  138. package/dist/Radio/Radio.svelte +124 -0
  139. package/dist/Radio/Radio.svelte.d.ts +4 -0
  140. package/dist/Radio/properties.d.ts +15 -0
  141. package/dist/Radio/properties.js +1 -0
  142. package/dist/RelativeTime/RelativeTime.svelte +109 -0
  143. package/dist/RelativeTime/RelativeTime.svelte.d.ts +4 -0
  144. package/dist/RelativeTime/properties.d.ts +13 -0
  145. package/dist/RelativeTime/properties.js +1 -0
  146. package/dist/Scroller/Scroller.svelte +390 -0
  147. package/dist/Scroller/Scroller.svelte.d.ts +4 -0
  148. package/dist/Scroller/properties.d.ts +30 -0
  149. package/dist/Scroller/properties.js +1 -0
  150. package/dist/Select/Select.svelte +472 -0
  151. package/dist/Select/Select.svelte.d.ts +4 -0
  152. package/dist/Select/properties.d.ts +20 -0
  153. package/dist/Select/properties.js +1 -0
  154. package/dist/Sheet/Sheet.svelte +264 -0
  155. package/dist/Sheet/Sheet.svelte.d.ts +4 -0
  156. package/dist/Sheet/properties.d.ts +19 -0
  157. package/dist/Sheet/properties.js +1 -0
  158. package/dist/Shimmer/Shimmer.svelte +44 -0
  159. package/dist/Shimmer/Shimmer.svelte.d.ts +4 -0
  160. package/dist/Shimmer/properties.d.ts +4 -0
  161. package/dist/Shimmer/properties.js +1 -0
  162. package/dist/Slider/Slider.svelte +147 -0
  163. package/dist/Slider/Slider.svelte.d.ts +4 -0
  164. package/dist/Slider/properties.d.ts +17 -0
  165. package/dist/Slider/properties.js +1 -0
  166. package/dist/Snippet/Snippet.svelte +123 -0
  167. package/dist/Snippet/Snippet.svelte.d.ts +4 -0
  168. package/dist/Snippet/properties.d.ts +15 -0
  169. package/dist/Snippet/properties.js +1 -0
  170. package/dist/SplitButton/SplitButton.svelte +145 -0
  171. package/dist/SplitButton/SplitButton.svelte.d.ts +4 -0
  172. package/dist/SplitButton/properties.d.ts +17 -0
  173. package/dist/SplitButton/properties.js +1 -0
  174. package/dist/SplitInput/SplitInput.svelte +225 -0
  175. package/dist/SplitInput/SplitInput.svelte.d.ts +7 -0
  176. package/dist/SplitInput/properties.d.ts +20 -0
  177. package/dist/SplitInput/properties.js +1 -0
  178. package/dist/Stepper/Step.svelte +88 -0
  179. package/dist/Stepper/Step.svelte.d.ts +4 -0
  180. package/dist/Stepper/Stepper.svelte +64 -0
  181. package/dist/Stepper/Stepper.svelte.d.ts +4 -0
  182. package/dist/Stepper/properties.d.ts +27 -0
  183. package/dist/Stepper/properties.js +1 -0
  184. package/dist/Table/Table.svelte +357 -0
  185. package/dist/Table/Table.svelte.d.ts +4 -0
  186. package/dist/Table/properties.d.ts +26 -0
  187. package/dist/Table/properties.js +1 -0
  188. package/dist/Tabs/Tabs.svelte +303 -0
  189. package/dist/Tabs/Tabs.svelte.d.ts +4 -0
  190. package/dist/Tabs/properties.d.ts +30 -0
  191. package/dist/Tabs/properties.js +1 -0
  192. package/dist/ThemeSwitcher/ThemeSwitcher.svelte +249 -0
  193. package/dist/ThemeSwitcher/ThemeSwitcher.svelte.d.ts +4 -0
  194. package/dist/ThemeSwitcher/properties.d.ts +19 -0
  195. package/dist/ThemeSwitcher/properties.js +1 -0
  196. package/dist/Toast/Toast.svelte +220 -0
  197. package/dist/Toast/Toast.svelte.d.ts +4 -0
  198. package/dist/Toast/properties.d.ts +24 -0
  199. package/dist/Toast/properties.js +1 -0
  200. package/dist/Toggle/Toggle.svelte +99 -0
  201. package/dist/Toggle/Toggle.svelte.d.ts +4 -0
  202. package/dist/Toggle/properties.d.ts +9 -0
  203. package/dist/Toggle/properties.js +1 -0
  204. package/dist/Toolbar/Toolbar.svelte +142 -0
  205. package/dist/Toolbar/Toolbar.svelte.d.ts +4 -0
  206. package/dist/Toolbar/properties.d.ts +16 -0
  207. package/dist/Toolbar/properties.js +1 -0
  208. package/dist/Tooltip/Tooltip.svelte +153 -0
  209. package/dist/Tooltip/Tooltip.svelte.d.ts +4 -0
  210. package/dist/Tooltip/properties.d.ts +13 -0
  211. package/dist/Tooltip/properties.js +1 -0
  212. package/dist/assets/back.svg +3 -0
  213. package/dist/assets/battery.svg +5 -0
  214. package/dist/assets/checkmark.svg +3 -0
  215. package/dist/assets/chevron-down-sm.svg +3 -0
  216. package/dist/assets/chevron-down.svg +3 -0
  217. package/dist/assets/chevron-left-lg.svg +3 -0
  218. package/dist/assets/chevron-left.svg +3 -0
  219. package/dist/assets/chevron-right-lg.svg +3 -0
  220. package/dist/assets/chevron-right.svg +3 -0
  221. package/dist/assets/chevron-up.svg +3 -0
  222. package/dist/assets/close.svg +4 -0
  223. package/dist/assets/copy.svg +4 -0
  224. package/dist/assets/error-circle.svg +5 -0
  225. package/dist/assets/lock.svg +3 -0
  226. package/dist/assets/minus.svg +3 -0
  227. package/dist/assets/monitor.svg +5 -0
  228. package/dist/assets/moon.svg +3 -0
  229. package/dist/assets/palette.svg +7 -0
  230. package/dist/assets/search.svg +4 -0
  231. package/dist/assets/signal.svg +6 -0
  232. package/dist/assets/sort-default.svg +4 -0
  233. package/dist/assets/sun.svg +11 -0
  234. package/dist/assets/swap-vertical.svg +6 -0
  235. package/dist/assets/wifi.svg +3 -0
  236. package/dist/index.d.ts +103 -0
  237. package/dist/index.js +55 -0
  238. package/dist/types.d.ts +42 -0
  239. package/dist/types.js +1 -0
  240. package/dist/utils.d.ts +28 -0
  241. package/dist/utils.js +294 -0
  242. package/package.json +91 -0
@@ -0,0 +1,55 @@
1
+ <script lang="ts">
2
+ import type { IconStackProperties } from './properties';
3
+
4
+ let { icons, testId, classes }: IconStackProperties = $props();
5
+ </script>
6
+
7
+ <div class="stack-container {classes ?? ''}" data-pw={testId}>
8
+ {#each icons as icon, i (i)}
9
+ <div class="stack-icon" style:z-index={icons.length - i}>
10
+ {#if icon.type === 'image'}
11
+ <img src={icon.content} alt="icon" />
12
+ {:else}
13
+ <div class="text-container">
14
+ <span>{icon.content}</span>
15
+ </div>
16
+ {/if}
17
+ </div>
18
+ {/each}
19
+ </div>
20
+
21
+ <style>
22
+ .stack-container {
23
+ display: flex;
24
+ margin: var(--icon-stack-container-margin, 0px);
25
+ }
26
+ .stack-icon {
27
+ display: flex;
28
+ width: var(--icon-stack-icon-width, 36px);
29
+ height: var(--icon-stack-icon-height, 36px);
30
+ background: var(--icon-stack-icon-bg, white);
31
+ border-radius: var(--icon-stack-icon-radius, 50%);
32
+ margin: var(--icon-stack-icon-margin, 0px 0px 0px -14px);
33
+ align-items: var(--icon-stack-icon-align-items, center);
34
+ border: var(--icon-stack-icon-border, 1px solid currentColor);
35
+ justify-content: var(--icon-stack-icon-justify-content, center);
36
+ box-shadow: var(--icon-stack-icon-shadow, 0 2px 4px #00000026);
37
+ }
38
+ .stack-icon img {
39
+ width: var(--icon-stack-img-width, 36px);
40
+ height: var(--icon-stack-img-height, 36px);
41
+ }
42
+ .text-container {
43
+ display: flex;
44
+ width: var(--icon-stack-text-container-width, 36px);
45
+ height: var(--icon-stack-text-container-height, 36px);
46
+ align-items: var(--icon-stack-text-container-align-items, center);
47
+ justify-content: var(--icon-stack-text-container-justify-content, center);
48
+ }
49
+ .text-container span {
50
+ color: var(--icon-stack-text-color, inherit);
51
+ font-size: var(--icon-stack-text-size, inherit);
52
+ font-weight: var(--icon-stack-text-weight, inherit);
53
+ text-align: var(--icon-stack-text-align, center);
54
+ }
55
+ </style>
@@ -0,0 +1,4 @@
1
+ import type { IconStackProperties } from './properties';
2
+ declare const IconStack: import("svelte").Component<IconStackProperties, {}, "">;
3
+ type IconStack = ReturnType<typeof IconStack>;
4
+ export default IconStack;
@@ -0,0 +1,9 @@
1
+ export type IconStackItem = {
2
+ type: 'image' | 'text';
3
+ content: string;
4
+ };
5
+ export type IconStackProperties = {
6
+ icons: IconStackItem[];
7
+ testId?: string;
8
+ classes?: string;
9
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,37 @@
1
+ <script lang="ts">
2
+ import type { ImgProperties } from './properties';
3
+
4
+ let { src, alt, fallback, onerror, testId, classes }: ImgProperties = $props();
5
+
6
+ let currentSrc = $derived(src);
7
+
8
+ function handleFallback(): void {
9
+ if (typeof fallback === 'string' && fallback.length > 0 && currentSrc !== fallback) {
10
+ currentSrc = fallback;
11
+ } else {
12
+ onerror?.();
13
+ }
14
+ }
15
+ </script>
16
+
17
+ <img class={classes ?? ''} src={currentSrc} {alt} onerror={handleFallback} data-pw={testId} />
18
+
19
+ <style>
20
+ img {
21
+ object-fit: var(--image-object-fit);
22
+ height: var(--image-height, 24px);
23
+ width: var(--image-width, 24px);
24
+ padding: var(--image-padding, 0px);
25
+ border-radius: var(--image-border-radius, 0px);
26
+ margin: var(--image-margin, 0px);
27
+ filter: var(--image-filter, none);
28
+ background: var(--image-background);
29
+ border: var(--image-border);
30
+ transition: var(--image-transition);
31
+ }
32
+
33
+ img:hover {
34
+ background: var(--image-hover-background, var(--image-background));
35
+ border: var(--image-hover-border, var(--image-border));
36
+ }
37
+ </style>
@@ -0,0 +1,4 @@
1
+ import type { ImgProperties } from './properties';
2
+ declare const Img: import("svelte").Component<ImgProperties, {}, "">;
3
+ type Img = ReturnType<typeof Img>;
4
+ export default Img;
@@ -0,0 +1,13 @@
1
+ export type ImgProperties = MandatoryImgProperties & OptionalImgProperties & ImgEventProperties;
2
+ export type MandatoryImgProperties = {
3
+ src: string;
4
+ alt: string;
5
+ };
6
+ export type OptionalImgProperties = {
7
+ fallback?: string | null;
8
+ testId?: string;
9
+ classes?: string;
10
+ };
11
+ export type ImgEventProperties = {
12
+ onerror?: () => void;
13
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,349 @@
1
+ <script lang="ts">
2
+ import { validateInput } from '../utils';
3
+ import type { InputProperties } from './properties';
4
+ import type { ValidationState } from '../types';
5
+
6
+ let {
7
+ value = $bindable(''),
8
+ placeholder = '',
9
+ dataType = 'text',
10
+ label = '',
11
+ onErrorMessage = '',
12
+ infoMessage = '',
13
+ validators = [],
14
+ disable = false,
15
+ validationPattern = null,
16
+ inProgressPattern = null,
17
+ addFocusColor = false,
18
+ maxLength = 1000,
19
+ minLength = 0,
20
+ min,
21
+ max,
22
+ actionInput = false,
23
+ useTextArea = false,
24
+ autoComplete = 'on',
25
+ name = '',
26
+ testId = '',
27
+ textTransformers = [],
28
+ textViewPresentation = [],
29
+ onfocus = () => {},
30
+ onfocusout = () => {},
31
+ onblur = () => {},
32
+ oninput = () => {},
33
+ onpaste = () => {},
34
+ onstatechange = () => {},
35
+ onclick = () => {},
36
+ onkeydown = () => {},
37
+ classes,
38
+ role,
39
+ ariaExpanded,
40
+ ariaAutocomplete,
41
+ ariaControls,
42
+ ariaActivedescendant
43
+ }: InputProperties = $props();
44
+
45
+ export function focus() {
46
+ try {
47
+ inputElement?.focus();
48
+ inputElement?.scrollIntoView({ behavior: 'smooth', block: 'center' });
49
+ } catch (error) {
50
+ console.error('Error focusing or scrolling inputElement:', error);
51
+ }
52
+ }
53
+
54
+ export function blur() {
55
+ try {
56
+ inputElement?.blur();
57
+ } catch (error) {
58
+ console.error('Error blurring inputElement:', error);
59
+ }
60
+ }
61
+
62
+ export function getInputRef(): HTMLInputElement | HTMLTextAreaElement | null {
63
+ return inputElement;
64
+ }
65
+
66
+ let inputElement: HTMLInputElement | HTMLTextAreaElement | null = $state(null);
67
+
68
+ let validationState = $derived.by(() => {
69
+ const valueValidation: ValidationState = validateInput(
70
+ value,
71
+ dataType,
72
+ validationPattern,
73
+ inProgressPattern,
74
+ validators
75
+ );
76
+ if (
77
+ valueValidation === 'InProgress' &&
78
+ value.length > 0 &&
79
+ inputElement !== null &&
80
+ inputElement !== document.activeElement
81
+ ) {
82
+ return 'Invalid';
83
+ }
84
+ return valueValidation;
85
+ });
86
+
87
+ // eslint-disable-next-line no-restricted-syntax
88
+ $effect(() => {
89
+ onstatechange(validationState);
90
+ });
91
+
92
+ const showErrorMessage = $derived(validationState === 'Invalid');
93
+
94
+ function handleOnInput(event: Event) {
95
+ if (inputElement === null) {
96
+ return;
97
+ }
98
+
99
+ let currentValue = inputElement.value;
100
+ if (dataType === 'tel' && currentValue.length > 0) {
101
+ currentValue = textTransformers.reduce((prevValue, currIndexFunction) => {
102
+ let newValue = currIndexFunction(prevValue);
103
+ return newValue;
104
+ }, currentValue);
105
+ currentValue = currentValue.replace(/\D+|\D/gm, '');
106
+ const numberLength = currentValue.length;
107
+ if (numberLength === 0) {
108
+ inputElement.value = value;
109
+ return;
110
+ }
111
+ if (numberLength > maxLength) {
112
+ const existingInput = value;
113
+ if (existingInput.length === maxLength) {
114
+ inputElement.value = applyTextPresentation(value);
115
+ return;
116
+ }
117
+ /**
118
+ * choose last max length number of digits if length is bigger than max length passed in props
119
+ */
120
+ currentValue = currentValue.substring(numberLength - maxLength);
121
+ }
122
+ currentValue = applyTextPresentation(currentValue);
123
+ inputElement.value = currentValue;
124
+ }
125
+ value = inputElement.value;
126
+ oninput(inputElement.value, event);
127
+ }
128
+
129
+ /**
130
+ *
131
+ * @param event
132
+ * ENABLED ONLY FOR 'dataType = tel'
133
+ */
134
+ function handleOnPaste(event: ClipboardEvent) {
135
+ if (inputElement === null) {
136
+ return;
137
+ }
138
+
139
+ if (event.clipboardData) {
140
+ if (dataType === 'tel') {
141
+ let unfilteredNumber = event.clipboardData.getData('text');
142
+ unfilteredNumber = textTransformers.reduce((prevValue, currIndexFunction) => {
143
+ let newValue = currIndexFunction(prevValue);
144
+ return newValue;
145
+ }, unfilteredNumber);
146
+ /**
147
+ * removes everything except numbers
148
+ */
149
+ const filteredNumber = unfilteredNumber.replace(/\D+|\D/gm, '');
150
+ const filteredNumberLength = filteredNumber.length;
151
+ /**
152
+ * pasted text is non numeric
153
+ */
154
+ if (filteredNumber.length === 0) {
155
+ event.preventDefault();
156
+ }
157
+ /**
158
+ * user pasted 10+ digit number , overrides all cases
159
+ */
160
+ if (filteredNumber.length > maxLength) {
161
+ /**
162
+ * choose last max length number of digits if length is bigger than max length passed in props
163
+ */
164
+ const finalValue = applyTextPresentation(
165
+ filteredNumber.substring(filteredNumberLength - maxLength)
166
+ );
167
+ // Adding reactivity
168
+ value = finalValue;
169
+ onpaste(event);
170
+ event.preventDefault(); // prevent bubble and let finalValue be entered
171
+ }
172
+ /**
173
+ * if numeric pasted text has length less than max length, bubble to oninput.
174
+ */
175
+ }
176
+ }
177
+ }
178
+
179
+ function applyTextPresentation(currentValue: string): string {
180
+ return textViewPresentation.reduce((prevValue, currIndexFunction) => {
181
+ let newValue = currIndexFunction(prevValue);
182
+ return newValue;
183
+ }, currentValue);
184
+ }
185
+
186
+ function _onFocusOut(event: FocusEvent) {
187
+ if (validationState === 'InProgress' && value.length > 0) {
188
+ validationState = 'Invalid';
189
+ }
190
+ onfocusout(event);
191
+ onblur(event);
192
+ }
193
+ </script>
194
+
195
+ <div class="input-container {classes ?? ''}" class:input-error={showErrorMessage && !actionInput}>
196
+ {#if typeof label === 'string' && label !== '' && !actionInput}
197
+ <label class="label" for={name}>
198
+ {label}
199
+ </label>
200
+ {/if}
201
+
202
+ {#if useTextArea}
203
+ <!-- svelte-ignore element_invalid_self_closing_tag -->
204
+ <textarea
205
+ {value}
206
+ {placeholder}
207
+ autocomplete={autoComplete}
208
+ {name}
209
+ {role}
210
+ aria-expanded={ariaExpanded}
211
+ aria-autocomplete={ariaAutocomplete}
212
+ aria-controls={ariaControls}
213
+ aria-activedescendant={ariaActivedescendant}
214
+ {onfocus}
215
+ onfocusout={_onFocusOut}
216
+ oninput={handleOnInput}
217
+ onpaste={handleOnPaste}
218
+ {onclick}
219
+ {onkeydown}
220
+ class:action-input={actionInput}
221
+ style="--input-focus-border-width: {addFocusColor ? 1 : 0}px;"
222
+ disabled={disable}
223
+ bind:this={inputElement}
224
+ maxlength={dataType === 'tel' ? null : maxLength}
225
+ minlength={minLength}
226
+ />
227
+ {:else}
228
+ <input
229
+ type={dataType}
230
+ {value}
231
+ {placeholder}
232
+ autocomplete={autoComplete}
233
+ {name}
234
+ {role}
235
+ aria-expanded={ariaExpanded}
236
+ aria-autocomplete={ariaAutocomplete}
237
+ aria-controls={ariaControls}
238
+ aria-activedescendant={ariaActivedescendant}
239
+ {onfocus}
240
+ onfocusout={_onFocusOut}
241
+ oninput={handleOnInput}
242
+ onpaste={handleOnPaste}
243
+ {onclick}
244
+ {onkeydown}
245
+ data-pw={testId}
246
+ class:action-input={actionInput}
247
+ disabled={disable}
248
+ bind:this={inputElement}
249
+ maxlength={dataType === 'tel' ? null : maxLength}
250
+ minlength={minLength}
251
+ {min}
252
+ {max}
253
+ />
254
+ {/if}
255
+
256
+ {#if onErrorMessage !== '' && showErrorMessage && !actionInput}
257
+ <div class="error-message">
258
+ {onErrorMessage}
259
+ </div>
260
+ {/if}
261
+ {#if infoMessage !== '' && !actionInput}
262
+ <div class="info-message">
263
+ {infoMessage}
264
+ </div>
265
+ {/if}
266
+ </div>
267
+
268
+ <style>
269
+ textarea,
270
+ input {
271
+ box-sizing: var(--input-box-sizing, border-box);
272
+ height: var(--input-height, fit-content);
273
+ background-color: var(--input-background, transparent);
274
+ font-size: var(--input-font-size, 16px) !important;
275
+ font-family: var(--input-font-family, inherit);
276
+ border-radius: var(--input-radius, 6px);
277
+ outline: none;
278
+ padding: var(--input-padding, 10px 12px);
279
+ font-weight: var(--input-font-weight, 500);
280
+ width: var(--input-width, fit-content);
281
+ margin: var(--input-margin, 0px 0px 12px 0px);
282
+ appearance: none !important;
283
+ -webkit-appearance: none !important; /* For Safari MWeb */
284
+ box-shadow: var(--input-box-shadow, none);
285
+ border: var(--input-border, 1px solid currentColor);
286
+ resize: none;
287
+ visibility: var(--input-visibility, visible);
288
+ text-align: var(--input-text-align, left);
289
+ color: var(--input-text-color);
290
+ }
291
+
292
+ textarea:focus,
293
+ input:focus {
294
+ border: var(--input-focus-border, 1px solid currentColor);
295
+ }
296
+
297
+ .input-error {
298
+ --input-focus-border: var(
299
+ --input-error-border,
300
+ 1px solid var(--input-error-msg-text-color, currentColor)
301
+ ) !important;
302
+ --input-border: var(
303
+ --input-error-border,
304
+ 1px solid var(--input-error-msg-text-color, currentColor)
305
+ ) !important;
306
+ }
307
+
308
+ .action-input {
309
+ border-radius: var(--input-radius, 6px 0px 0px 6px);
310
+ box-shadow: var(--input-box-shadow, none);
311
+ margin-bottom: 0;
312
+ }
313
+
314
+ .input-container {
315
+ display: flex;
316
+ flex-direction: column;
317
+ margin: var(--input-container-margin, 0);
318
+ padding: var(--input-container-padding, 0);
319
+ width: var(--input-container-width, fit-content);
320
+ }
321
+
322
+ .label {
323
+ font-weight: var(--input-label-msg-text-weight, 400);
324
+ font-size: var(--input-label-msg-text-size, 12px);
325
+ color: var(--input-label-msg-text-color, currentColor);
326
+ margin: var(--input-label-msg-margin, 0px 0px 6px 0px);
327
+ padding: var(--input-label-msg-padding);
328
+ }
329
+
330
+ .error-message {
331
+ font-weight: var(--input-error-msg-text-weight, 400);
332
+ font-size: var(--input-error-msg-text-size, 12px);
333
+ color: var(--input-error-msg-text-color, currentColor);
334
+ margin: var(--input-error-msg-margin);
335
+ padding: var(--input-error-msg-padding);
336
+ }
337
+
338
+ .info-message {
339
+ font-weight: var(--input-info-msg-text-weight, 400);
340
+ font-size: var(--input-info-msg-text-size, 12px);
341
+ color: var(--input-info-msg-text-color, currentColor);
342
+ margin: var(--input-info-msg-margin);
343
+ padding: var(--input-info-msg-padding);
344
+ }
345
+
346
+ ::placeholder {
347
+ color: var(--input-placeholder-color, #a1a1aa);
348
+ }
349
+ </style>
@@ -0,0 +1,8 @@
1
+ import type { InputProperties } from './properties';
2
+ declare const Input: import("svelte").Component<InputProperties, {
3
+ focus: () => void;
4
+ blur: () => void;
5
+ getInputRef: () => HTMLInputElement | HTMLTextAreaElement | null;
6
+ }, "value">;
7
+ type Input = ReturnType<typeof Input>;
8
+ export default Input;
@@ -0,0 +1,45 @@
1
+ import type { CustomValidator, InputDataType, TextTransformer, ValidationState } from '../types';
2
+ import type { HTMLInputAttributes } from 'svelte/elements';
3
+ export type InputProperties = OptionalInputProperties & InputEventProperties & MandatoryInputProperties;
4
+ export type MandatoryInputProperties = {
5
+ value: string;
6
+ };
7
+ export type OptionalInputProperties = {
8
+ placeholder?: string | null;
9
+ dataType?: InputDataType;
10
+ label?: string | null;
11
+ onErrorMessage?: string | null;
12
+ infoMessage?: string | null;
13
+ validators?: CustomValidator[];
14
+ disable?: boolean;
15
+ validationPattern?: RegExp | null;
16
+ inProgressPattern?: RegExp | null;
17
+ addFocusColor?: boolean;
18
+ maxLength?: number;
19
+ minLength?: number;
20
+ min?: number;
21
+ max?: number;
22
+ actionInput?: boolean;
23
+ useTextArea?: boolean;
24
+ autoComplete?: HTMLInputAttributes['autocomplete'];
25
+ name?: string;
26
+ textTransformers?: TextTransformer[];
27
+ textViewPresentation?: TextTransformer[];
28
+ testId?: string;
29
+ classes?: string;
30
+ role?: string;
31
+ ariaExpanded?: boolean;
32
+ ariaAutocomplete?: 'none' | 'inline' | 'list' | 'both';
33
+ ariaControls?: string | null;
34
+ ariaActivedescendant?: string | null;
35
+ };
36
+ export type InputEventProperties = {
37
+ oninput?: (value: string, event: Event) => void;
38
+ onfocus?: (event: FocusEvent) => void;
39
+ onfocusout?: (event: FocusEvent) => void;
40
+ onblur?: (event: FocusEvent) => void;
41
+ onpaste?: (event: ClipboardEvent) => void;
42
+ onclick?: (event: MouseEvent) => void;
43
+ onstatechange?: (state: ValidationState) => void;
44
+ onkeydown?: (event: KeyboardEvent) => void;
45
+ };
@@ -0,0 +1 @@
1
+ export {};