@juspay/svelte-ui-components 1.0.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 +115 -0
- package/dist/Accordion/Accordion.svelte +35 -0
- package/dist/Accordion/Accordion.svelte.d.ts +18 -0
- package/dist/Animations/ModalAnimation.svelte +28 -0
- package/dist/Animations/ModalAnimation.svelte.d.ts +20 -0
- package/dist/Animations/OverlayAnimation.svelte +7 -0
- package/dist/Animations/OverlayAnimation.svelte.d.ts +27 -0
- package/dist/Badge/Badge.svelte +45 -0
- package/dist/Badge/Badge.svelte.d.ts +17 -0
- package/dist/Badge/properties.d.ts +4 -0
- package/dist/Badge/properties.js +1 -0
- package/dist/Banner/Banner.svelte +61 -0
- package/dist/Banner/Banner.svelte.d.ts +20 -0
- package/dist/Banner/properties.d.ts +5 -0
- package/dist/Banner/properties.js +1 -0
- package/dist/BrandLoader/BrandLoader.svelte +125 -0
- package/dist/BrandLoader/BrandLoader.svelte.d.ts +18 -0
- package/dist/BrandLoader/properties.d.ts +8 -0
- package/dist/BrandLoader/properties.js +7 -0
- package/dist/Button/Button.svelte +87 -0
- package/dist/Button/Button.svelte.d.ts +21 -0
- package/dist/Button/properties.d.ts +9 -0
- package/dist/Button/properties.js +7 -0
- package/dist/Carousel/Carousel.svelte +219 -0
- package/dist/Carousel/Carousel.svelte.d.ts +19 -0
- package/dist/Carousel/properties.d.ts +18 -0
- package/dist/Carousel/properties.js +7 -0
- package/dist/CheckListItem/CheckListItem.svelte +40 -0
- package/dist/CheckListItem/CheckListItem.svelte.d.ts +19 -0
- package/dist/Icon/Icon.svelte +32 -0
- package/dist/Icon/Icon.svelte.d.ts +20 -0
- package/dist/Icon/properties.d.ts +5 -0
- package/dist/Icon/properties.js +4 -0
- package/dist/Input/Input.svelte +218 -0
- package/dist/Input/Input.svelte.d.ts +26 -0
- package/dist/Input/properties.d.ts +25 -0
- package/dist/Input/properties.js +23 -0
- package/dist/InputButton/InputButton.svelte +157 -0
- package/dist/InputButton/InputButton.svelte.d.ts +27 -0
- package/dist/InputButton/properties.d.ts +8 -0
- package/dist/InputButton/properties.js +17 -0
- package/dist/ListItem/ListItem.svelte +196 -0
- package/dist/ListItem/ListItem.svelte.d.ts +32 -0
- package/dist/ListItem/properties.d.ts +8 -0
- package/dist/ListItem/properties.js +7 -0
- package/dist/Loader/Loader.svelte +89 -0
- package/dist/Loader/Loader.svelte.d.ts +15 -0
- package/dist/Modal/Modal.svelte +200 -0
- package/dist/Modal/Modal.svelte.d.ts +25 -0
- package/dist/Modal/properties.d.ts +15 -0
- package/dist/Modal/properties.js +12 -0
- package/dist/Select/Select.svelte +271 -0
- package/dist/Select/Select.svelte.d.ts +21 -0
- package/dist/Select/properties.d.ts +9 -0
- package/dist/Select/properties.js +1 -0
- package/dist/Status/Status.svelte +64 -0
- package/dist/Status/Status.svelte.d.ts +20 -0
- package/dist/Status/properties.d.ts +8 -0
- package/dist/Status/properties.js +6 -0
- package/dist/Table/Table.svelte +147 -0
- package/dist/Table/Table.svelte.d.ts +19 -0
- package/dist/Table/properties.d.ts +8 -0
- package/dist/Table/properties.js +1 -0
- package/dist/Toggle/Toggle.svelte +86 -0
- package/dist/Toggle/Toggle.svelte.d.ts +17 -0
- package/dist/Toolbar/Toolbar.svelte +95 -0
- package/dist/Toolbar/Toolbar.svelte.d.ts +25 -0
- package/dist/Toolbar/properties.d.ts +6 -0
- package/dist/Toolbar/properties.js +5 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +30 -0
- package/dist/types.d.ts +19 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +11 -0
- package/dist/utils.js +147 -0
- package/package.json +162 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type LoaderType = 'Circular' | 'ProgressBar';
|
|
2
|
+
export type ButtonProperties = {
|
|
3
|
+
text: string;
|
|
4
|
+
enable: boolean;
|
|
5
|
+
showLoader: boolean;
|
|
6
|
+
loaderType: LoaderType | null;
|
|
7
|
+
type: 'submit' | 'reset' | 'button';
|
|
8
|
+
};
|
|
9
|
+
export declare const defaultButtonProperties: ButtonProperties;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
<script>import { onMount, onDestroy } from "svelte";
|
|
2
|
+
import { defaultCarouselProperties } from "./properties";
|
|
3
|
+
export let properties = defaultCarouselProperties;
|
|
4
|
+
let slidesDiv;
|
|
5
|
+
let intervalId;
|
|
6
|
+
let endTouch;
|
|
7
|
+
let startTouch;
|
|
8
|
+
let startMouse;
|
|
9
|
+
let endMouse;
|
|
10
|
+
let carouselWidth;
|
|
11
|
+
let carouselDiv;
|
|
12
|
+
let activeSlideIndex = 0;
|
|
13
|
+
let widthUnits;
|
|
14
|
+
function nextSlide() {
|
|
15
|
+
if (activeSlideIndex != properties.views.length - 1 || properties.isScrollableLast) {
|
|
16
|
+
activeSlideIndex++;
|
|
17
|
+
changeCurrentSlide();
|
|
18
|
+
if (properties.autoplay) {
|
|
19
|
+
resetInterval();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function previousSlide() {
|
|
24
|
+
if (activeSlideIndex != 0 || properties.isScrollableLast) {
|
|
25
|
+
activeSlideIndex--;
|
|
26
|
+
changeCurrentSlide();
|
|
27
|
+
if (properties.autoplay) {
|
|
28
|
+
resetInterval();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function changeCurrentSlide() {
|
|
33
|
+
if (activeSlideIndex > properties.views.length - 1) {
|
|
34
|
+
activeSlideIndex = 0;
|
|
35
|
+
} else if (activeSlideIndex < 0) {
|
|
36
|
+
activeSlideIndex = properties.views.length - 1;
|
|
37
|
+
}
|
|
38
|
+
if (slidesDiv) {
|
|
39
|
+
slidesDiv.style.transform = `translateX(${-activeSlideIndex * parseInt(carouselWidth)}${widthUnits})`;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function moveSlideToIndex(index) {
|
|
43
|
+
activeSlideIndex = index;
|
|
44
|
+
changeCurrentSlide();
|
|
45
|
+
}
|
|
46
|
+
function resetInterval() {
|
|
47
|
+
clearInterval(intervalId);
|
|
48
|
+
intervalId = window.setInterval(nextSlide, properties.autoplayInterval);
|
|
49
|
+
}
|
|
50
|
+
function handleTouchStart(event) {
|
|
51
|
+
if (event.touches && Object.keys(event.touches).length > 0) {
|
|
52
|
+
if (event.touches[0] && typeof event.changedTouches[0].clientX !== "undefined") {
|
|
53
|
+
startTouch = event.touches[0].clientX;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function handleTouchEnd(event) {
|
|
58
|
+
if (event.changedTouches && Object.keys(event.changedTouches).length > 0) {
|
|
59
|
+
if (event.changedTouches[0] && typeof event.changedTouches[0].clientX !== "undefined") {
|
|
60
|
+
endTouch = event.changedTouches[0].clientX;
|
|
61
|
+
if (startTouch - endTouch > 20) {
|
|
62
|
+
nextSlide();
|
|
63
|
+
} else {
|
|
64
|
+
if (endTouch - startTouch > 20) {
|
|
65
|
+
previousSlide();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function handleMouseDown(event) {
|
|
72
|
+
if (event && Object.keys(event).length > 0 && typeof event.clientX !== "undefined") {
|
|
73
|
+
startMouse = event.clientX;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function handeMouseUp(event) {
|
|
77
|
+
if (event && Object.keys(event).length > 0 && typeof event.clientX !== "undefined") {
|
|
78
|
+
endMouse = event.clientX;
|
|
79
|
+
if (startMouse - endMouse > 20) {
|
|
80
|
+
nextSlide();
|
|
81
|
+
} else {
|
|
82
|
+
if (endMouse - startMouse > 20) {
|
|
83
|
+
previousSlide();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function setWidthUnit(carouselWidth2) {
|
|
89
|
+
widthUnits = carouselWidth2.slice(-3);
|
|
90
|
+
if (/^-?\d+$/.test(widthUnits[0])) {
|
|
91
|
+
widthUnits = widthUnits.slice(-2);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
onMount(() => {
|
|
95
|
+
if (carouselDiv) {
|
|
96
|
+
carouselWidth = getComputedStyle(carouselDiv).getPropertyValue("--carousel-width");
|
|
97
|
+
setWidthUnit(carouselWidth);
|
|
98
|
+
carouselDiv.addEventListener("touchstart", handleTouchStart);
|
|
99
|
+
carouselDiv.addEventListener("touchend", handleTouchEnd);
|
|
100
|
+
carouselDiv.addEventListener("mousedown", handleMouseDown);
|
|
101
|
+
carouselDiv.addEventListener("mouseup", handeMouseUp);
|
|
102
|
+
}
|
|
103
|
+
if (properties.autoplay) {
|
|
104
|
+
intervalId = window.setInterval(nextSlide, properties.autoplayInterval);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
onDestroy(() => {
|
|
108
|
+
if (properties.autoplay) {
|
|
109
|
+
clearInterval(intervalId);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
</script>
|
|
113
|
+
|
|
114
|
+
<div class="carousel-container">
|
|
115
|
+
{#if properties.views.length}
|
|
116
|
+
<div class="carousel" bind:this={carouselDiv}>
|
|
117
|
+
<div class="slidesDiv" bind:this={slidesDiv}>
|
|
118
|
+
{#each properties.views as view}
|
|
119
|
+
<div class="current-slide">
|
|
120
|
+
{#if view.properties}
|
|
121
|
+
<svelte:component this={view.component} properties={view.properties} />
|
|
122
|
+
{:else}
|
|
123
|
+
<svelte:component this={view.component} />
|
|
124
|
+
{/if}
|
|
125
|
+
</div>
|
|
126
|
+
{/each}
|
|
127
|
+
</div>
|
|
128
|
+
</div>
|
|
129
|
+
{/if}
|
|
130
|
+
{#if properties.showDots}
|
|
131
|
+
<div class="dots-wrapper">
|
|
132
|
+
<!-- eslint-disable-next-line -->
|
|
133
|
+
{#each properties.views as _, index}
|
|
134
|
+
<div
|
|
135
|
+
class={activeSlideIndex == index ? 'active-dot' : 'dot'}
|
|
136
|
+
on:click={() => moveSlideToIndex(index)}
|
|
137
|
+
on:keydown
|
|
138
|
+
role="none"
|
|
139
|
+
/>
|
|
140
|
+
{/each}
|
|
141
|
+
</div>
|
|
142
|
+
{/if}
|
|
143
|
+
</div>
|
|
144
|
+
|
|
145
|
+
<style>
|
|
146
|
+
.carousel-container {
|
|
147
|
+
width: var(--carousel-width);
|
|
148
|
+
}
|
|
149
|
+
.current-slide {
|
|
150
|
+
width: var(--carousel-width, 300px);
|
|
151
|
+
height: var(--carousel-height, 100px);
|
|
152
|
+
flex-shrink: 0;
|
|
153
|
+
}
|
|
154
|
+
.carousel {
|
|
155
|
+
box-shadow: var(--carousel-shadow);
|
|
156
|
+
height: var(--carousel-height, 100px);
|
|
157
|
+
width: var(--carousel-width, 300px);
|
|
158
|
+
overflow: hidden;
|
|
159
|
+
border-radius: var(--carousel-border-radius, 0%);
|
|
160
|
+
}
|
|
161
|
+
.carousel:active {
|
|
162
|
+
cursor: grabbing;
|
|
163
|
+
}
|
|
164
|
+
.slidesDiv {
|
|
165
|
+
display: flex;
|
|
166
|
+
transform: translateX(0);
|
|
167
|
+
transition: transform 0.5s ease-in-out;
|
|
168
|
+
}
|
|
169
|
+
.dots-wrapper {
|
|
170
|
+
gap: var(--dot-gap, 10px);
|
|
171
|
+
padding-top: var(--dot-padding-top, 10px);
|
|
172
|
+
display: flex;
|
|
173
|
+
justify-content: center;
|
|
174
|
+
}
|
|
175
|
+
.dot {
|
|
176
|
+
width: var(--dot-width, 5px);
|
|
177
|
+
height: var(--dot-height, 5px);
|
|
178
|
+
border-radius: 50%;
|
|
179
|
+
background: #c4c4c4;
|
|
180
|
+
cursor: pointer;
|
|
181
|
+
transition: 0.3s ease;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.active-dot {
|
|
185
|
+
width: var(--dot-width, 5px);
|
|
186
|
+
height: var(--dot-height, 5px);
|
|
187
|
+
border-radius: 50%;
|
|
188
|
+
cursor: pointer;
|
|
189
|
+
background: #000000;
|
|
190
|
+
transition: 0.3s ease;
|
|
191
|
+
}
|
|
192
|
+
/*
|
|
193
|
+
@media only screen and (max-width: 324px) {
|
|
194
|
+
|
|
195
|
+
.carousel-container {
|
|
196
|
+
width:270px;
|
|
197
|
+
|
|
198
|
+
}
|
|
199
|
+
.current-slide {
|
|
200
|
+
width: 270px;
|
|
201
|
+
}
|
|
202
|
+
.carousel {
|
|
203
|
+
width:270px;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
@media only screen and (max-width: 269px) {
|
|
208
|
+
.carousel-container {
|
|
209
|
+
width:240px;
|
|
210
|
+
}
|
|
211
|
+
.current-slide {
|
|
212
|
+
width: 240px;
|
|
213
|
+
}
|
|
214
|
+
.carousel {
|
|
215
|
+
width:240px;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
} */
|
|
219
|
+
</style>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { CarouselProperties } from './properties';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
properties?: CarouselProperties | undefined;
|
|
6
|
+
};
|
|
7
|
+
events: {
|
|
8
|
+
keydown: KeyboardEvent;
|
|
9
|
+
} & {
|
|
10
|
+
[evt: string]: CustomEvent<any>;
|
|
11
|
+
};
|
|
12
|
+
slots: {};
|
|
13
|
+
};
|
|
14
|
+
export type CarouselProps = typeof __propDef.props;
|
|
15
|
+
export type CarouselEvents = typeof __propDef.events;
|
|
16
|
+
export type CarouselSlots = typeof __propDef.slots;
|
|
17
|
+
export default class Carousel extends SvelteComponent<CarouselProps, CarouselEvents, CarouselSlots> {
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SvelteComponent } from 'svelte';
|
|
2
|
+
export type CarouselProperties = {
|
|
3
|
+
autoplay: boolean;
|
|
4
|
+
views: {
|
|
5
|
+
properties: Record<string, unknown> | null;
|
|
6
|
+
component: typeof SvelteComponent;
|
|
7
|
+
}[];
|
|
8
|
+
autoplayInterval: number;
|
|
9
|
+
showDots: boolean;
|
|
10
|
+
isScrollableLast: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare const defaultCarouselProperties: {
|
|
13
|
+
autoplay: boolean;
|
|
14
|
+
views: never[];
|
|
15
|
+
autoplayInterval: number;
|
|
16
|
+
showDots: boolean;
|
|
17
|
+
isScrollableLast: boolean;
|
|
18
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<script>import { createEventDispatcher } from "svelte";
|
|
2
|
+
export let text;
|
|
3
|
+
export let checked;
|
|
4
|
+
const dispatch = createEventDispatcher();
|
|
5
|
+
function handleCheckboxClick(e) {
|
|
6
|
+
if (e.target instanceof HTMLInputElement && typeof e.target.checked === "boolean") {
|
|
7
|
+
checked = e.target.checked;
|
|
8
|
+
}
|
|
9
|
+
dispatch("click");
|
|
10
|
+
}
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<div class="container">
|
|
14
|
+
<input type="checkbox" class="checkbox" bind:checked on:click={handleCheckboxClick} />
|
|
15
|
+
<span class="text">
|
|
16
|
+
<!-- eslint-disable-next-line -->
|
|
17
|
+
{@html text}
|
|
18
|
+
</span>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<style>
|
|
22
|
+
.container {
|
|
23
|
+
display: var(--check-list-item-display, flex);
|
|
24
|
+
align-items: var(--check-list-item-align-items, center);
|
|
25
|
+
width: var(--check-list-item-width, 100%);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.text {
|
|
29
|
+
margin: var(--check-list-item-margin, 0px 0px 0px 8px);
|
|
30
|
+
font-size: var(--check-list-item-text-size, 12px);
|
|
31
|
+
color: var(--check-list-item-text-color);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
input.checkbox {
|
|
35
|
+
accent-color: var(--checkbox-accent-color, #000);
|
|
36
|
+
border: 5px solid red;
|
|
37
|
+
height: var(--checkbox-height, 24px);
|
|
38
|
+
width: var(--checkbox-width, 24px);
|
|
39
|
+
}
|
|
40
|
+
</style>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
text: string;
|
|
5
|
+
checked: boolean;
|
|
6
|
+
};
|
|
7
|
+
events: {
|
|
8
|
+
click: CustomEvent<any>;
|
|
9
|
+
} & {
|
|
10
|
+
[evt: string]: CustomEvent<any>;
|
|
11
|
+
};
|
|
12
|
+
slots: {};
|
|
13
|
+
};
|
|
14
|
+
export type CheckListItemProps = typeof __propDef.props;
|
|
15
|
+
export type CheckListItemEvents = typeof __propDef.events;
|
|
16
|
+
export type CheckListItemSlots = typeof __propDef.slots;
|
|
17
|
+
export default class CheckListItem extends SvelteComponent<CheckListItemProps, CheckListItemEvents, CheckListItemSlots> {
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<script>import { defaultIconProperties } from "./properties";
|
|
2
|
+
export let properties = defaultIconProperties;
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<div class="icon-container" on:click on:keydown role="button" tabindex="0">
|
|
6
|
+
<img src={properties.icon} alt="" />
|
|
7
|
+
{#if properties.text !== ''}
|
|
8
|
+
<div class="icon-text">{properties.text}</div>
|
|
9
|
+
{/if}
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
<style>
|
|
13
|
+
.icon-container {
|
|
14
|
+
display: flex;
|
|
15
|
+
padding: var(--icon-container-paddding, 4px);
|
|
16
|
+
flex-direction: var(--icon-container-direction, column);
|
|
17
|
+
align-items: center;
|
|
18
|
+
cursor: pointer;
|
|
19
|
+
}
|
|
20
|
+
.icon-container img {
|
|
21
|
+
height: var(--icon-height, 20px);
|
|
22
|
+
width: var(--icon-width, 20px);
|
|
23
|
+
padding: var(--icon-padding, 4px);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.icon-text {
|
|
27
|
+
display: flex;
|
|
28
|
+
padding: var(--icon-text-padding, 4px);
|
|
29
|
+
flex-direction: var(--icon-text-direction, column);
|
|
30
|
+
font-size: var(--icon-text-font-size, 12px);
|
|
31
|
+
}
|
|
32
|
+
</style>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { IconProperties } from './properties';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
properties?: IconProperties | undefined;
|
|
6
|
+
};
|
|
7
|
+
events: {
|
|
8
|
+
click: MouseEvent;
|
|
9
|
+
keydown: KeyboardEvent;
|
|
10
|
+
} & {
|
|
11
|
+
[evt: string]: CustomEvent<any>;
|
|
12
|
+
};
|
|
13
|
+
slots: {};
|
|
14
|
+
};
|
|
15
|
+
export type IconProps = typeof __propDef.props;
|
|
16
|
+
export type IconEvents = typeof __propDef.events;
|
|
17
|
+
export type IconSlots = typeof __propDef.slots;
|
|
18
|
+
export default class Icon extends SvelteComponent<IconProps, IconEvents, IconSlots> {
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
<script>import { validateInput } from "../utils";
|
|
2
|
+
import { createEventDispatcher, onMount } from "svelte";
|
|
3
|
+
import { defaultInputProperties } from "./properties";
|
|
4
|
+
const dispatch = createEventDispatcher();
|
|
5
|
+
export let properties = defaultInputProperties;
|
|
6
|
+
let inputElement;
|
|
7
|
+
$:
|
|
8
|
+
state = getValidationState(properties);
|
|
9
|
+
function getValidationState(prop) {
|
|
10
|
+
const valueValidation = validateInput(
|
|
11
|
+
prop.value,
|
|
12
|
+
prop.dataType,
|
|
13
|
+
prop.validationPattern,
|
|
14
|
+
prop.inProgressPattern,
|
|
15
|
+
prop.validators
|
|
16
|
+
);
|
|
17
|
+
if (valueValidation === "InProgress" && prop.value.length > 0 && inputElement && inputElement !== document.activeElement) {
|
|
18
|
+
return "Invalid";
|
|
19
|
+
} else {
|
|
20
|
+
return valueValidation;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
$:
|
|
24
|
+
showErrorMessage = state === "Invalid";
|
|
25
|
+
function onInput(event) {
|
|
26
|
+
let currentValue = inputElement.value;
|
|
27
|
+
if (properties.dataType === "tel" && currentValue.length > 0) {
|
|
28
|
+
currentValue = properties.textTransformers.reduce((prevValue, currIndexFunction) => {
|
|
29
|
+
let newValue = currIndexFunction(prevValue);
|
|
30
|
+
return newValue;
|
|
31
|
+
}, currentValue);
|
|
32
|
+
currentValue = currentValue.replace(/\D+|\D/gm, "");
|
|
33
|
+
const numberLength = currentValue.length;
|
|
34
|
+
if (numberLength === 0) {
|
|
35
|
+
inputElement.value = properties.value;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (numberLength > properties.maxLength) {
|
|
39
|
+
const existingInput = properties.value;
|
|
40
|
+
if (existingInput.length == properties.maxLength) {
|
|
41
|
+
inputElement.value = properties.value;
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
currentValue = currentValue.substring(numberLength - properties.maxLength);
|
|
45
|
+
}
|
|
46
|
+
inputElement.value = currentValue;
|
|
47
|
+
}
|
|
48
|
+
properties.value = currentValue;
|
|
49
|
+
properties = properties;
|
|
50
|
+
dispatch("input", event);
|
|
51
|
+
}
|
|
52
|
+
function onPaste(event) {
|
|
53
|
+
if (event.clipboardData) {
|
|
54
|
+
if (properties.dataType === "tel") {
|
|
55
|
+
let unfilteredNumber = event.clipboardData.getData("text");
|
|
56
|
+
unfilteredNumber = properties.textTransformers.reduce((prevValue, currIndexFunction) => {
|
|
57
|
+
let newValue = currIndexFunction(prevValue);
|
|
58
|
+
return newValue;
|
|
59
|
+
}, unfilteredNumber);
|
|
60
|
+
const filteredNumber = unfilteredNumber.replace(/\D+|\D/gm, "");
|
|
61
|
+
const filteredNumberLength = filteredNumber.length;
|
|
62
|
+
if (filteredNumber.length === 0) {
|
|
63
|
+
properties = properties;
|
|
64
|
+
event.preventDefault();
|
|
65
|
+
}
|
|
66
|
+
if (filteredNumber.length > properties.maxLength) {
|
|
67
|
+
const finalValue = filteredNumber.substring(filteredNumberLength - properties.maxLength);
|
|
68
|
+
properties.value = finalValue;
|
|
69
|
+
properties = properties;
|
|
70
|
+
dispatch("paste", event);
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function onFocusOut(event) {
|
|
77
|
+
if (state === "InProgress" && properties.value.length > 0) {
|
|
78
|
+
state = "Invalid";
|
|
79
|
+
}
|
|
80
|
+
dispatch("focusout", event);
|
|
81
|
+
}
|
|
82
|
+
onMount(() => {
|
|
83
|
+
if (properties.focus) {
|
|
84
|
+
inputElement.focus();
|
|
85
|
+
}
|
|
86
|
+
dispatch("stateChange", { state });
|
|
87
|
+
});
|
|
88
|
+
$: {
|
|
89
|
+
dispatch("stateChange", { state });
|
|
90
|
+
}
|
|
91
|
+
</script>
|
|
92
|
+
|
|
93
|
+
<div class="input-container">
|
|
94
|
+
{#if properties.label && properties.label !== '' && !properties.actionInput}
|
|
95
|
+
<label class="label" for={properties.name}>
|
|
96
|
+
{properties.label}
|
|
97
|
+
</label>
|
|
98
|
+
{/if}
|
|
99
|
+
|
|
100
|
+
{#if properties.useTextArea}
|
|
101
|
+
<textarea
|
|
102
|
+
value={properties.value}
|
|
103
|
+
placeholder={properties.placeholder}
|
|
104
|
+
autocomplete={properties.autoComplete}
|
|
105
|
+
name={properties.name}
|
|
106
|
+
on:keydown
|
|
107
|
+
on:keyup
|
|
108
|
+
on:keypress
|
|
109
|
+
on:focus
|
|
110
|
+
on:focusout={onFocusOut}
|
|
111
|
+
on:input={onInput}
|
|
112
|
+
on:paste={onPaste}
|
|
113
|
+
class="
|
|
114
|
+
{properties.actionInput ? 'action-input' : ''}
|
|
115
|
+
"
|
|
116
|
+
style="--focus-border: {properties.addFocusColor ? 1 : 0}px;"
|
|
117
|
+
disabled={properties.disable}
|
|
118
|
+
bind:this={inputElement}
|
|
119
|
+
maxlength={properties.dataType === 'tel' ? undefined : properties.maxLength}
|
|
120
|
+
minlength={properties.minLength}
|
|
121
|
+
/>
|
|
122
|
+
{:else}
|
|
123
|
+
<input
|
|
124
|
+
type={properties.dataType}
|
|
125
|
+
value={properties.value}
|
|
126
|
+
placeholder={properties.placeholder}
|
|
127
|
+
autocomplete={properties.autoComplete}
|
|
128
|
+
name={properties.name}
|
|
129
|
+
on:keydown
|
|
130
|
+
on:keyup
|
|
131
|
+
on:keypress
|
|
132
|
+
on:focus
|
|
133
|
+
on:focusout={onFocusOut}
|
|
134
|
+
on:input={onInput}
|
|
135
|
+
on:paste={onPaste}
|
|
136
|
+
class="
|
|
137
|
+
{properties.actionInput ? 'action-input' : ''}
|
|
138
|
+
"
|
|
139
|
+
disabled={properties.disable}
|
|
140
|
+
bind:this={inputElement}
|
|
141
|
+
maxlength={properties.dataType === 'tel' ? undefined : properties.maxLength}
|
|
142
|
+
minlength={properties.minLength}
|
|
143
|
+
/>
|
|
144
|
+
{/if}
|
|
145
|
+
|
|
146
|
+
{#if properties.message.onError !== '' && showErrorMessage && !properties.actionInput}
|
|
147
|
+
<div class="error-message">
|
|
148
|
+
{properties.message.onError}
|
|
149
|
+
</div>
|
|
150
|
+
{/if}
|
|
151
|
+
{#if properties.message.info !== '' && !properties.actionInput}
|
|
152
|
+
<div class="info-message">
|
|
153
|
+
{properties.message.info}
|
|
154
|
+
</div>
|
|
155
|
+
{/if}
|
|
156
|
+
</div>
|
|
157
|
+
|
|
158
|
+
<style>
|
|
159
|
+
textarea,
|
|
160
|
+
input {
|
|
161
|
+
box-sizing: border-box;
|
|
162
|
+
height: var(--input-height, fit-content);
|
|
163
|
+
background-color: var(--input-background, white);
|
|
164
|
+
font-size: var(--input-font-size, 16px) !important;
|
|
165
|
+
font-family: var(--input-font-family, Euclid Circular A);
|
|
166
|
+
border-radius: var(--input-radius, 4px);
|
|
167
|
+
outline: none;
|
|
168
|
+
padding: var(--input-padding, 16px);
|
|
169
|
+
font-weight: var(--input-font-weight, 500);
|
|
170
|
+
width: var(--input-width, fit-content);
|
|
171
|
+
margin: var(--input-margin, 0px 0px 12px 0px);
|
|
172
|
+
-webkit-appearance: none !important; /* For Safari MWeb */
|
|
173
|
+
box-shadow: var(--input-box-shadow, 0px 1px 8px #2f537733);
|
|
174
|
+
border: var(--input-border, none);
|
|
175
|
+
resize: none;
|
|
176
|
+
visibility: var(--input-visibility, visible);
|
|
177
|
+
text-align: var(--input-text-align, left);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
textarea:focus,
|
|
181
|
+
input:focus {
|
|
182
|
+
border: var(--input-focus-border);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.action-input {
|
|
186
|
+
border-radius: var(--input-radius, 4px 0px 0px 4px);
|
|
187
|
+
box-shadow: 0px 0px 0px #ffffff;
|
|
188
|
+
margin-bottom: 0;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.input-container {
|
|
192
|
+
display: flex;
|
|
193
|
+
flex-direction: column;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.label {
|
|
197
|
+
font-weight: var(--input-label-msg-text-weight, 400);
|
|
198
|
+
font-size: var(--input-label-msg-text-size, 12px);
|
|
199
|
+
color: var(--input-label-msg-text-color, #637c95);
|
|
200
|
+
margin-bottom: 6px;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.error-message {
|
|
204
|
+
font-weight: var(--input-error-msg-text-weight, 400);
|
|
205
|
+
font-size: var(--input-error-msg-text-size, 12px);
|
|
206
|
+
color: var(--input-error-msg-text-color, #fa1405);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.info-message {
|
|
210
|
+
font-weight: var(--input-info-msg-text-weight, 400);
|
|
211
|
+
font-size: var(--input-info-msg-text-size, 12px);
|
|
212
|
+
color: var(--input-info-msg-text-color, #fa1405);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
::placeholder {
|
|
216
|
+
color: var(--input-placeholder-color);
|
|
217
|
+
}
|
|
218
|
+
</style>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import { type InputProperties } from './properties';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
properties?: InputProperties | undefined;
|
|
6
|
+
};
|
|
7
|
+
events: {
|
|
8
|
+
keydown: KeyboardEvent;
|
|
9
|
+
keyup: KeyboardEvent;
|
|
10
|
+
keypress: KeyboardEvent;
|
|
11
|
+
focus: FocusEvent;
|
|
12
|
+
input: CustomEvent<any>;
|
|
13
|
+
paste: CustomEvent<any>;
|
|
14
|
+
focusout: CustomEvent<any>;
|
|
15
|
+
stateChange: CustomEvent<any>;
|
|
16
|
+
} & {
|
|
17
|
+
[evt: string]: CustomEvent<any>;
|
|
18
|
+
};
|
|
19
|
+
slots: {};
|
|
20
|
+
};
|
|
21
|
+
export type InputProps = typeof __propDef.props;
|
|
22
|
+
export type InputEvents = typeof __propDef.events;
|
|
23
|
+
export type InputSlots = typeof __propDef.slots;
|
|
24
|
+
export default class Input extends SvelteComponent<InputProps, InputEvents, InputSlots> {
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AutoCompleteType, CustomValidator, InputDataType, TextTransformer } from '../types';
|
|
2
|
+
export type InputProperties = {
|
|
3
|
+
value: string;
|
|
4
|
+
placeholder: string;
|
|
5
|
+
dataType: InputDataType;
|
|
6
|
+
label: string | null;
|
|
7
|
+
message: {
|
|
8
|
+
onError: string;
|
|
9
|
+
info: string;
|
|
10
|
+
};
|
|
11
|
+
validators: CustomValidator[];
|
|
12
|
+
focus: boolean;
|
|
13
|
+
disable: boolean;
|
|
14
|
+
validationPattern: RegExp | null;
|
|
15
|
+
inProgressPattern: RegExp | null;
|
|
16
|
+
addFocusColor: boolean;
|
|
17
|
+
maxLength: number;
|
|
18
|
+
minLength: number;
|
|
19
|
+
actionInput: boolean;
|
|
20
|
+
useTextArea: boolean;
|
|
21
|
+
autoComplete: AutoCompleteType;
|
|
22
|
+
name: string;
|
|
23
|
+
textTransformers: TextTransformer[];
|
|
24
|
+
};
|
|
25
|
+
export declare const defaultInputProperties: InputProperties;
|