polymorph-ui-components 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +354 -0
- package/dist/Accordion/Accordion.svelte +28 -0
- package/dist/Accordion/Accordion.svelte.d.ts +4 -0
- package/dist/Accordion/properties.d.ts +7 -0
- package/dist/Accordion/properties.js +1 -0
- package/dist/Animations/ModalAnimation.svelte +55 -0
- package/dist/Animations/ModalAnimation.svelte.d.ts +12 -0
- package/dist/Animations/OverlayAnimation.svelte +14 -0
- package/dist/Animations/OverlayAnimation.svelte.d.ts +7 -0
- package/dist/Avatar/Avatar.svelte +122 -0
- package/dist/Avatar/Avatar.svelte.d.ts +4 -0
- package/dist/Avatar/properties.d.ts +15 -0
- package/dist/Avatar/properties.js +1 -0
- package/dist/Badge/Badge.svelte +53 -0
- package/dist/Badge/Badge.svelte.d.ts +4 -0
- package/dist/Badge/properties.d.ts +6 -0
- package/dist/Badge/properties.js +1 -0
- package/dist/Banner/Banner.svelte +158 -0
- package/dist/Banner/Banner.svelte.d.ts +4 -0
- package/dist/Banner/properties.d.ts +19 -0
- package/dist/Banner/properties.js +1 -0
- package/dist/Book/Book.svelte +281 -0
- package/dist/Book/Book.svelte.d.ts +4 -0
- package/dist/Book/properties.d.ts +24 -0
- package/dist/Book/properties.js +1 -0
- package/dist/Browser/Browser.svelte +176 -0
- package/dist/Browser/Browser.svelte.d.ts +3 -0
- package/dist/Browser/properties.d.ts +14 -0
- package/dist/Browser/properties.js +1 -0
- package/dist/Button/Button.svelte +153 -0
- package/dist/Button/Button.svelte.d.ts +4 -0
- package/dist/Button/properties.d.ts +24 -0
- package/dist/Button/properties.js +1 -0
- package/dist/Calendar/Calendar.svelte +477 -0
- package/dist/Calendar/Calendar.svelte.d.ts +4 -0
- package/dist/Calendar/properties.d.ts +30 -0
- package/dist/Calendar/properties.js +1 -0
- package/dist/Carousel/Carousel.svelte +258 -0
- package/dist/Carousel/Carousel.svelte.d.ts +4 -0
- package/dist/Carousel/properties.d.ts +20 -0
- package/dist/Carousel/properties.js +1 -0
- package/dist/CheckListItem/CheckListItem.svelte +65 -0
- package/dist/CheckListItem/CheckListItem.svelte.d.ts +4 -0
- package/dist/CheckListItem/properties.d.ts +15 -0
- package/dist/CheckListItem/properties.js +1 -0
- package/dist/Checkbox/Checkbox.svelte +157 -0
- package/dist/Checkbox/Checkbox.svelte.d.ts +4 -0
- package/dist/Checkbox/properties.d.ts +17 -0
- package/dist/Checkbox/properties.js +1 -0
- package/dist/Choicebox/Choicebox.svelte +85 -0
- package/dist/Choicebox/Choicebox.svelte.d.ts +4 -0
- package/dist/Choicebox/properties.d.ts +14 -0
- package/dist/Choicebox/properties.js +1 -0
- package/dist/ColorPicker/ColorPicker.svelte +583 -0
- package/dist/ColorPicker/ColorPicker.svelte.d.ts +4 -0
- package/dist/ColorPicker/properties.d.ts +15 -0
- package/dist/ColorPicker/properties.js +1 -0
- package/dist/Combobox/Combobox.svelte +432 -0
- package/dist/Combobox/Combobox.svelte.d.ts +6 -0
- package/dist/Combobox/properties.d.ts +42 -0
- package/dist/Combobox/properties.js +1 -0
- package/dist/CommandMenu/CommandMenu.svelte +452 -0
- package/dist/CommandMenu/CommandMenu.svelte.d.ts +4 -0
- package/dist/CommandMenu/properties.d.ts +26 -0
- package/dist/CommandMenu/properties.js +1 -0
- package/dist/ContextMenu/ContextMenu.svelte +308 -0
- package/dist/ContextMenu/ContextMenu.svelte.d.ts +4 -0
- package/dist/ContextMenu/properties.d.ts +26 -0
- package/dist/ContextMenu/properties.js +1 -0
- package/dist/Gauge/Gauge.svelte +70 -0
- package/dist/Gauge/Gauge.svelte.d.ts +4 -0
- package/dist/Gauge/properties.d.ts +9 -0
- package/dist/Gauge/properties.js +1 -0
- package/dist/GridItem/GridItem.svelte +145 -0
- package/dist/GridItem/GridItem.svelte.d.ts +4 -0
- package/dist/GridItem/properties.d.ts +15 -0
- package/dist/GridItem/properties.js +1 -0
- package/dist/Icon/Icon.svelte +61 -0
- package/dist/Icon/Icon.svelte.d.ts +4 -0
- package/dist/Icon/properties.d.ts +12 -0
- package/dist/Icon/properties.js +1 -0
- package/dist/IconStack/IconStack.svelte +55 -0
- package/dist/IconStack/IconStack.svelte.d.ts +4 -0
- package/dist/IconStack/properties.d.ts +9 -0
- package/dist/IconStack/properties.js +1 -0
- package/dist/Img/Img.svelte +37 -0
- package/dist/Img/Img.svelte.d.ts +4 -0
- package/dist/Img/properties.d.ts +13 -0
- package/dist/Img/properties.js +1 -0
- package/dist/Input/Input.svelte +349 -0
- package/dist/Input/Input.svelte.d.ts +8 -0
- package/dist/Input/properties.d.ts +45 -0
- package/dist/Input/properties.js +1 -0
- package/dist/InputButton/InputButton.svelte +252 -0
- package/dist/InputButton/InputButton.svelte.d.ts +7 -0
- package/dist/InputButton/properties.d.ts +22 -0
- package/dist/InputButton/properties.js +1 -0
- package/dist/KeyboardInput/KeyboardInput.svelte +93 -0
- package/dist/KeyboardInput/KeyboardInput.svelte.d.ts +4 -0
- package/dist/KeyboardInput/properties.d.ts +12 -0
- package/dist/KeyboardInput/properties.js +1 -0
- package/dist/ListItem/ListItem.svelte +309 -0
- package/dist/ListItem/ListItem.svelte.d.ts +4 -0
- package/dist/ListItem/properties.d.ts +34 -0
- package/dist/ListItem/properties.js +1 -0
- package/dist/Loader/Loader.svelte +90 -0
- package/dist/Loader/Loader.svelte.d.ts +4 -0
- package/dist/Loader/properties.d.ts +4 -0
- package/dist/Loader/properties.js +1 -0
- package/dist/LoadingDots/LoadingDots.svelte +59 -0
- package/dist/LoadingDots/LoadingDots.svelte.d.ts +3 -0
- package/dist/LoadingDots/properties.d.ts +8 -0
- package/dist/LoadingDots/properties.js +1 -0
- package/dist/Menu/Menu.svelte +356 -0
- package/dist/Menu/Menu.svelte.d.ts +4 -0
- package/dist/Menu/properties.d.ts +28 -0
- package/dist/Menu/properties.js +1 -0
- package/dist/Modal/Modal.svelte +357 -0
- package/dist/Modal/Modal.svelte.d.ts +4 -0
- package/dist/Modal/properties.d.ts +39 -0
- package/dist/Modal/properties.js +1 -0
- package/dist/Pagination/Pagination.svelte +148 -0
- package/dist/Pagination/Pagination.svelte.d.ts +4 -0
- package/dist/Pagination/properties.d.ts +14 -0
- package/dist/Pagination/properties.js +1 -0
- package/dist/Phone/Phone.svelte +234 -0
- package/dist/Phone/Phone.svelte.d.ts +3 -0
- package/dist/Phone/properties.d.ts +11 -0
- package/dist/Phone/properties.js +1 -0
- package/dist/Pill/Pill.svelte +130 -0
- package/dist/Pill/Pill.svelte.d.ts +4 -0
- package/dist/Pill/properties.d.ts +16 -0
- package/dist/Pill/properties.js +1 -0
- package/dist/Progress/Progress.svelte +68 -0
- package/dist/Progress/Progress.svelte.d.ts +4 -0
- package/dist/Progress/properties.d.ts +10 -0
- package/dist/Progress/properties.js +1 -0
- package/dist/Radio/Radio.svelte +124 -0
- package/dist/Radio/Radio.svelte.d.ts +4 -0
- package/dist/Radio/properties.d.ts +15 -0
- package/dist/Radio/properties.js +1 -0
- package/dist/RelativeTime/RelativeTime.svelte +109 -0
- package/dist/RelativeTime/RelativeTime.svelte.d.ts +4 -0
- package/dist/RelativeTime/properties.d.ts +13 -0
- package/dist/RelativeTime/properties.js +1 -0
- package/dist/Scroller/Scroller.svelte +390 -0
- package/dist/Scroller/Scroller.svelte.d.ts +4 -0
- package/dist/Scroller/properties.d.ts +30 -0
- package/dist/Scroller/properties.js +1 -0
- package/dist/Select/Select.svelte +472 -0
- package/dist/Select/Select.svelte.d.ts +4 -0
- package/dist/Select/properties.d.ts +20 -0
- package/dist/Select/properties.js +1 -0
- package/dist/Sheet/Sheet.svelte +264 -0
- package/dist/Sheet/Sheet.svelte.d.ts +4 -0
- package/dist/Sheet/properties.d.ts +19 -0
- package/dist/Sheet/properties.js +1 -0
- package/dist/Shimmer/Shimmer.svelte +44 -0
- package/dist/Shimmer/Shimmer.svelte.d.ts +4 -0
- package/dist/Shimmer/properties.d.ts +4 -0
- package/dist/Shimmer/properties.js +1 -0
- package/dist/Slider/Slider.svelte +147 -0
- package/dist/Slider/Slider.svelte.d.ts +4 -0
- package/dist/Slider/properties.d.ts +17 -0
- package/dist/Slider/properties.js +1 -0
- package/dist/Snippet/Snippet.svelte +123 -0
- package/dist/Snippet/Snippet.svelte.d.ts +4 -0
- package/dist/Snippet/properties.d.ts +15 -0
- package/dist/Snippet/properties.js +1 -0
- package/dist/SplitButton/SplitButton.svelte +145 -0
- package/dist/SplitButton/SplitButton.svelte.d.ts +4 -0
- package/dist/SplitButton/properties.d.ts +17 -0
- package/dist/SplitButton/properties.js +1 -0
- package/dist/SplitInput/SplitInput.svelte +225 -0
- package/dist/SplitInput/SplitInput.svelte.d.ts +7 -0
- package/dist/SplitInput/properties.d.ts +20 -0
- package/dist/SplitInput/properties.js +1 -0
- package/dist/Stepper/Step.svelte +88 -0
- package/dist/Stepper/Step.svelte.d.ts +4 -0
- package/dist/Stepper/Stepper.svelte +64 -0
- package/dist/Stepper/Stepper.svelte.d.ts +4 -0
- package/dist/Stepper/properties.d.ts +27 -0
- package/dist/Stepper/properties.js +1 -0
- package/dist/Table/Table.svelte +357 -0
- package/dist/Table/Table.svelte.d.ts +4 -0
- package/dist/Table/properties.d.ts +26 -0
- package/dist/Table/properties.js +1 -0
- package/dist/Tabs/Tabs.svelte +303 -0
- package/dist/Tabs/Tabs.svelte.d.ts +4 -0
- package/dist/Tabs/properties.d.ts +30 -0
- package/dist/Tabs/properties.js +1 -0
- package/dist/ThemeSwitcher/ThemeSwitcher.svelte +249 -0
- package/dist/ThemeSwitcher/ThemeSwitcher.svelte.d.ts +4 -0
- package/dist/ThemeSwitcher/properties.d.ts +19 -0
- package/dist/ThemeSwitcher/properties.js +1 -0
- package/dist/Toast/Toast.svelte +220 -0
- package/dist/Toast/Toast.svelte.d.ts +4 -0
- package/dist/Toast/properties.d.ts +24 -0
- package/dist/Toast/properties.js +1 -0
- package/dist/Toggle/Toggle.svelte +99 -0
- package/dist/Toggle/Toggle.svelte.d.ts +4 -0
- package/dist/Toggle/properties.d.ts +9 -0
- package/dist/Toggle/properties.js +1 -0
- package/dist/Toolbar/Toolbar.svelte +142 -0
- package/dist/Toolbar/Toolbar.svelte.d.ts +4 -0
- package/dist/Toolbar/properties.d.ts +16 -0
- package/dist/Toolbar/properties.js +1 -0
- package/dist/Tooltip/Tooltip.svelte +153 -0
- package/dist/Tooltip/Tooltip.svelte.d.ts +4 -0
- package/dist/Tooltip/properties.d.ts +13 -0
- package/dist/Tooltip/properties.js +1 -0
- package/dist/assets/back.svg +3 -0
- package/dist/assets/battery.svg +5 -0
- package/dist/assets/checkmark.svg +3 -0
- package/dist/assets/chevron-down-sm.svg +3 -0
- package/dist/assets/chevron-down.svg +3 -0
- package/dist/assets/chevron-left-lg.svg +3 -0
- package/dist/assets/chevron-left.svg +3 -0
- package/dist/assets/chevron-right-lg.svg +3 -0
- package/dist/assets/chevron-right.svg +3 -0
- package/dist/assets/chevron-up.svg +3 -0
- package/dist/assets/close.svg +4 -0
- package/dist/assets/copy.svg +4 -0
- package/dist/assets/error-circle.svg +5 -0
- package/dist/assets/lock.svg +3 -0
- package/dist/assets/minus.svg +3 -0
- package/dist/assets/monitor.svg +5 -0
- package/dist/assets/moon.svg +3 -0
- package/dist/assets/palette.svg +7 -0
- package/dist/assets/search.svg +4 -0
- package/dist/assets/signal.svg +6 -0
- package/dist/assets/sort-default.svg +4 -0
- package/dist/assets/sun.svg +11 -0
- package/dist/assets/swap-vertical.svg +6 -0
- package/dist/assets/wifi.svg +3 -0
- package/dist/index.d.ts +103 -0
- package/dist/index.js +55 -0
- package/dist/types.d.ts +42 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +28 -0
- package/dist/utils.js +294 -0
- package/package.json +91 -0
|
@@ -0,0 +1,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 @@
|
|
|
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,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 {};
|