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,145 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { SplitButtonProperties } from './properties';
|
|
3
|
+
import type { MenuItem } from '../Menu/properties';
|
|
4
|
+
import Button from '../Button/Button.svelte';
|
|
5
|
+
import Menu from '../Menu/Menu.svelte';
|
|
6
|
+
import chevronDownSmSvg from '../assets/chevron-down-sm.svg?raw';
|
|
7
|
+
|
|
8
|
+
let {
|
|
9
|
+
text,
|
|
10
|
+
items,
|
|
11
|
+
disabled = false,
|
|
12
|
+
testId,
|
|
13
|
+
dropdownIcon,
|
|
14
|
+
classes,
|
|
15
|
+
onclick,
|
|
16
|
+
onselect
|
|
17
|
+
}: SplitButtonProperties = $props();
|
|
18
|
+
|
|
19
|
+
let menuOpen = $state(false);
|
|
20
|
+
|
|
21
|
+
function handlePrimaryClick(event: MouseEvent): void {
|
|
22
|
+
if (disabled) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
onclick?.(event);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function handleMenuSelect(item: MenuItem): void {
|
|
29
|
+
onselect?.(item);
|
|
30
|
+
}
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<div class="split-button {classes ?? ''}" class:disabled data-pw={testId}>
|
|
34
|
+
<div class="split-button-primary">
|
|
35
|
+
<Button {text} onclick={handlePrimaryClick} {disabled} />
|
|
36
|
+
</div>
|
|
37
|
+
<div class="split-button-trigger">
|
|
38
|
+
<Menu {items} bind:open={menuOpen} onselect={handleMenuSelect}>
|
|
39
|
+
{#snippet trigger()}
|
|
40
|
+
<span class="split-button-arrow">
|
|
41
|
+
{#if typeof dropdownIcon === 'function'}
|
|
42
|
+
{@render dropdownIcon()}
|
|
43
|
+
{:else}
|
|
44
|
+
<!-- eslint-disable svelte/no-at-html-tags -->
|
|
45
|
+
{@html chevronDownSmSvg}
|
|
46
|
+
{/if}
|
|
47
|
+
</span>
|
|
48
|
+
{/snippet}
|
|
49
|
+
</Menu>
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
<style>
|
|
54
|
+
.split-button {
|
|
55
|
+
display: inline-flex;
|
|
56
|
+
position: relative;
|
|
57
|
+
gap: var(--split-button-gap, 0px);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.split-button.disabled .split-button-trigger {
|
|
61
|
+
pointer-events: none;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.split-button-primary {
|
|
65
|
+
--button-color: var(--split-button-primary-background, #18181b);
|
|
66
|
+
--button-text-color: var(--split-button-primary-color, white);
|
|
67
|
+
--button-padding: var(--split-button-primary-padding, 8px 16px);
|
|
68
|
+
--button-font-size: var(--split-button-primary-font-size, 14px);
|
|
69
|
+
--button-font-weight: var(--split-button-primary-font-weight, 500);
|
|
70
|
+
--button-font-family: var(--split-button-primary-font-family);
|
|
71
|
+
--button-border: var(--split-button-primary-border, none);
|
|
72
|
+
--button-border-radius: var(--split-button-primary-border-radius, 6px 0 0 6px);
|
|
73
|
+
--button-hover-color: var(
|
|
74
|
+
--split-button-primary-hover-background,
|
|
75
|
+
var(--split-button-primary-background, #18181b)
|
|
76
|
+
);
|
|
77
|
+
--button-hover-text-color: var(
|
|
78
|
+
--split-button-primary-hover-color,
|
|
79
|
+
var(--split-button-primary-color, white)
|
|
80
|
+
);
|
|
81
|
+
--button-disabled-opacity: var(--split-button-disabled-opacity, 0.4);
|
|
82
|
+
--button-disabled-cursor: var(--split-button-disabled-cursor, not-allowed);
|
|
83
|
+
display: flex;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.split-button-trigger {
|
|
87
|
+
--menu-container-position: static;
|
|
88
|
+
--menu-container-display: flex;
|
|
89
|
+
--menu-trigger-focus-outline: none;
|
|
90
|
+
--menu-dropdown-left: 0;
|
|
91
|
+
--menu-min-width: 100%;
|
|
92
|
+
--menu-item-color: var(--split-button-menu-item-color, #18181b);
|
|
93
|
+
--menu-item-danger-color: var(--split-button-menu-item-danger-color, #18181b);
|
|
94
|
+
--menu-item-hover-background-color: var(--split-button-menu-item-hover-background, #f4f4f5);
|
|
95
|
+
--menu-item-focus-background-color: var(--split-button-menu-item-focus-background, #f4f4f5);
|
|
96
|
+
--menu-item-danger-hover-background-color: var(
|
|
97
|
+
--split-button-menu-item-danger-hover-background,
|
|
98
|
+
#f4f4f5
|
|
99
|
+
);
|
|
100
|
+
--menu-item-danger-focus-background-color: var(
|
|
101
|
+
--split-button-menu-item-danger-focus-background,
|
|
102
|
+
#f4f4f5
|
|
103
|
+
);
|
|
104
|
+
--menu-border: var(--split-button-menu-border, 1px solid #e4e4e7);
|
|
105
|
+
--menu-separator-color: var(--split-button-menu-separator-color, #e4e4e7);
|
|
106
|
+
border-left: var(--split-button-trigger-separator, 1px solid rgba(255, 255, 255, 0.3));
|
|
107
|
+
display: flex;
|
|
108
|
+
align-items: stretch;
|
|
109
|
+
background-color: var(--split-button-trigger-background, #18181b);
|
|
110
|
+
border-radius: var(--split-button-trigger-border-radius, 0 6px 6px 0);
|
|
111
|
+
color: var(--split-button-trigger-color, white);
|
|
112
|
+
cursor: pointer;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.split-button.disabled .split-button-trigger {
|
|
116
|
+
opacity: var(--split-button-disabled-opacity, 0.4);
|
|
117
|
+
cursor: var(--split-button-disabled-cursor, not-allowed);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.split-button-trigger:hover {
|
|
121
|
+
background-color: var(
|
|
122
|
+
--split-button-trigger-hover-background,
|
|
123
|
+
var(--split-button-trigger-background, #18181b)
|
|
124
|
+
);
|
|
125
|
+
color: var(--split-button-trigger-hover-color, var(--split-button-trigger-color, white));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.split-button-trigger :global(.menu-trigger) {
|
|
129
|
+
display: flex;
|
|
130
|
+
align-items: center;
|
|
131
|
+
justify-content: center;
|
|
132
|
+
padding: var(--split-button-trigger-padding, 8px);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.split-button-arrow {
|
|
136
|
+
display: inline-flex;
|
|
137
|
+
width: var(--split-button-arrow-width, 10px);
|
|
138
|
+
height: var(--split-button-arrow-height, 6px);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.split-button-arrow :global(svg) {
|
|
142
|
+
width: 100%;
|
|
143
|
+
height: 100%;
|
|
144
|
+
}
|
|
145
|
+
</style>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { MenuItem } from '../Menu/properties';
|
|
3
|
+
export type SplitButtonProperties = MandatorySplitButtonProperties & OptionalSplitButtonProperties & SplitButtonEventProperties;
|
|
4
|
+
export type MandatorySplitButtonProperties = {
|
|
5
|
+
text: string;
|
|
6
|
+
items: MenuItem[];
|
|
7
|
+
};
|
|
8
|
+
export type OptionalSplitButtonProperties = {
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
testId?: string;
|
|
11
|
+
dropdownIcon?: Snippet;
|
|
12
|
+
classes?: string;
|
|
13
|
+
};
|
|
14
|
+
export type SplitButtonEventProperties = {
|
|
15
|
+
onclick?: (event: MouseEvent) => void;
|
|
16
|
+
onselect?: (item: MenuItem) => void;
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Input from '../Input/Input.svelte';
|
|
3
|
+
import type { FieldConfig, SplitInputProperties } from './properties';
|
|
4
|
+
|
|
5
|
+
let {
|
|
6
|
+
values = $bindable([]),
|
|
7
|
+
fields,
|
|
8
|
+
length = 4,
|
|
9
|
+
disabled = false,
|
|
10
|
+
autoAdvance = false,
|
|
11
|
+
separator,
|
|
12
|
+
testId,
|
|
13
|
+
classes,
|
|
14
|
+
onchange,
|
|
15
|
+
oninput,
|
|
16
|
+
oncomplete
|
|
17
|
+
}: SplitInputProperties = $props();
|
|
18
|
+
|
|
19
|
+
let fieldCount = $derived(typeof fields !== 'undefined' ? fields.length : length);
|
|
20
|
+
|
|
21
|
+
let fieldConfigs: FieldConfig[] = $derived(
|
|
22
|
+
typeof fields !== 'undefined'
|
|
23
|
+
? fields
|
|
24
|
+
: Array.from({ length: fieldCount }, () => ({
|
|
25
|
+
dataType: 'tel' as const,
|
|
26
|
+
maxLength: 1
|
|
27
|
+
}))
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
let inputRefs: (ReturnType<typeof Input> | null)[] = $state(
|
|
31
|
+
Array.from({ length: 20 }, () => null)
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
// ── Value helpers ───────────────────────────────────────────────
|
|
35
|
+
|
|
36
|
+
function getFieldValue(index: number): string {
|
|
37
|
+
return values.at(index) ?? '';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function commitValues() {
|
|
41
|
+
const filled = values.filter((v) => v.length > 0);
|
|
42
|
+
oninput?.([...values]);
|
|
43
|
+
onchange?.([...values]);
|
|
44
|
+
if (filled.length === fieldCount) {
|
|
45
|
+
oncomplete?.([...values]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// ── Focus management ────────────────────────────────────────────
|
|
50
|
+
|
|
51
|
+
function focusField(index: number) {
|
|
52
|
+
if (index >= 0 && index < fieldCount) {
|
|
53
|
+
inputRefs.at(index)?.focus();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ── Input handler ───────────────────────────────────────────────
|
|
58
|
+
|
|
59
|
+
function handleFieldInput(index: number, inputValue: string) {
|
|
60
|
+
const config = fieldConfigs.at(index);
|
|
61
|
+
if (typeof config === 'undefined') {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const maxLen = config.maxLength ?? 1000;
|
|
65
|
+
|
|
66
|
+
if (autoAdvance && maxLen === 1 && inputValue.length > 1) {
|
|
67
|
+
const chars = inputValue.replace(/\s/g, '');
|
|
68
|
+
for (let i = 0; i < fieldCount; i++) {
|
|
69
|
+
values[i] = chars.charAt(i);
|
|
70
|
+
}
|
|
71
|
+
focusField(Math.min(chars.length, fieldCount) - 1);
|
|
72
|
+
} else {
|
|
73
|
+
values[index] = inputValue;
|
|
74
|
+
if (autoAdvance && maxLen === 1 && inputValue.length > 0 && index < fieldCount - 1) {
|
|
75
|
+
focusField(index + 1);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
commitValues();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ── Keyboard handler ────────────────────────────────────────────
|
|
82
|
+
|
|
83
|
+
function handleKeyDown(e: KeyboardEvent, index: number) {
|
|
84
|
+
if (e.key === 'Backspace') {
|
|
85
|
+
const current = getFieldValue(index);
|
|
86
|
+
if (current.length === 0 && index > 0) {
|
|
87
|
+
values[index - 1] = '';
|
|
88
|
+
focusField(index - 1);
|
|
89
|
+
commitValues();
|
|
90
|
+
}
|
|
91
|
+
} else if (e.key === 'ArrowLeft' && index > 0) {
|
|
92
|
+
focusField(index - 1);
|
|
93
|
+
} else if (e.key === 'ArrowRight' && index < fieldCount - 1) {
|
|
94
|
+
focusField(index + 1);
|
|
95
|
+
} else if (e.key === 'Tab') {
|
|
96
|
+
if (e.shiftKey && index > 0) {
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
focusField(index - 1);
|
|
99
|
+
} else if (e.shiftKey === false && index < fieldCount - 1) {
|
|
100
|
+
e.preventDefault();
|
|
101
|
+
focusField(index + 1);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// ── Paste handler ───────────────────────────────────────────────
|
|
107
|
+
|
|
108
|
+
function handlePaste(e: ClipboardEvent, index: number) {
|
|
109
|
+
if (e.clipboardData === null) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
e.preventDefault();
|
|
113
|
+
const pasted = e.clipboardData.getData('text').trim();
|
|
114
|
+
|
|
115
|
+
if (autoAdvance) {
|
|
116
|
+
const chars = pasted.replace(/\s/g, '');
|
|
117
|
+
for (let i = index; i < fieldCount; i++) {
|
|
118
|
+
const charIdx = i - index;
|
|
119
|
+
if (charIdx >= chars.length) {
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
values[i] = chars.charAt(charIdx);
|
|
123
|
+
}
|
|
124
|
+
focusField(Math.min(index + chars.length, fieldCount) - 1);
|
|
125
|
+
} else {
|
|
126
|
+
values[index] = pasted;
|
|
127
|
+
}
|
|
128
|
+
commitValues();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ── Exported methods ────────────────────────────────────────────
|
|
132
|
+
|
|
133
|
+
export function clear() {
|
|
134
|
+
for (let i = 0; i < fieldCount; i++) {
|
|
135
|
+
values[i] = '';
|
|
136
|
+
}
|
|
137
|
+
oninput?.([...values]);
|
|
138
|
+
onchange?.([...values]);
|
|
139
|
+
focusField(0);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function focus() {
|
|
143
|
+
focusField(0);
|
|
144
|
+
}
|
|
145
|
+
</script>
|
|
146
|
+
|
|
147
|
+
<div class="field-group {classes ?? ''}" data-pw={testId}>
|
|
148
|
+
{#each fieldConfigs as config, index (index)}
|
|
149
|
+
{#if typeof separator === 'string' && index > 0}
|
|
150
|
+
<span class="field-group-separator">{separator}</span>
|
|
151
|
+
{/if}
|
|
152
|
+
<div class="field-group-item">
|
|
153
|
+
<Input
|
|
154
|
+
value={getFieldValue(index)}
|
|
155
|
+
dataType={config.dataType ?? 'text'}
|
|
156
|
+
maxLength={config.maxLength ?? 1000}
|
|
157
|
+
min={config.min}
|
|
158
|
+
max={config.max}
|
|
159
|
+
placeholder={config.placeholder}
|
|
160
|
+
validationPattern={config.validationPattern ?? null}
|
|
161
|
+
validators={config.validators ?? []}
|
|
162
|
+
disable={disabled}
|
|
163
|
+
actionInput={true}
|
|
164
|
+
classes="field-group-input"
|
|
165
|
+
oninput={(v) => handleFieldInput(index, v)}
|
|
166
|
+
onkeydown={(e) => handleKeyDown(e, index)}
|
|
167
|
+
onpaste={(e) => handlePaste(e, index)}
|
|
168
|
+
bind:this={inputRefs[index]}
|
|
169
|
+
/>
|
|
170
|
+
{#if typeof config.label === 'string'}
|
|
171
|
+
<span class="field-group-label">{config.label}</span>
|
|
172
|
+
{/if}
|
|
173
|
+
</div>
|
|
174
|
+
{/each}
|
|
175
|
+
</div>
|
|
176
|
+
|
|
177
|
+
<style>
|
|
178
|
+
.field-group {
|
|
179
|
+
display: flex;
|
|
180
|
+
align-items: flex-start;
|
|
181
|
+
gap: var(--split-input-gap, 8px);
|
|
182
|
+
width: var(--split-input-width, fit-content);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.field-group-item {
|
|
186
|
+
display: flex;
|
|
187
|
+
flex-direction: column;
|
|
188
|
+
align-items: center;
|
|
189
|
+
gap: var(--split-input-label-gap, 3px);
|
|
190
|
+
flex: 1;
|
|
191
|
+
min-width: 0;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.field-group-item :global(.field-group-input) {
|
|
195
|
+
--input-border: var(--split-input-border, 1px solid currentColor);
|
|
196
|
+
--input-radius: var(--split-input-border-radius, 6px);
|
|
197
|
+
--input-focus-border: var(--split-input-focus-border, 1px solid currentColor);
|
|
198
|
+
--input-width: var(--split-input-input-width, 100%);
|
|
199
|
+
--input-height: var(--split-input-input-height, 36px);
|
|
200
|
+
--input-text-align: var(--split-input-text-align, center);
|
|
201
|
+
--input-font-size: var(--split-input-font-size, 14px);
|
|
202
|
+
--input-font-weight: var(--split-input-font-weight, 500);
|
|
203
|
+
--input-font-family: var(--split-input-font-family);
|
|
204
|
+
--input-padding: var(--split-input-input-padding, 0 6px);
|
|
205
|
+
--input-margin: 0;
|
|
206
|
+
--input-box-shadow: none;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.field-group-label {
|
|
210
|
+
font-size: var(--split-input-label-font-size, 12px);
|
|
211
|
+
font-weight: var(--split-input-label-font-weight, 500);
|
|
212
|
+
color: var(--split-input-label-color, currentColor);
|
|
213
|
+
text-transform: uppercase;
|
|
214
|
+
letter-spacing: 0.05em;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.field-group-separator {
|
|
218
|
+
display: flex;
|
|
219
|
+
align-items: center;
|
|
220
|
+
height: var(--split-input-input-height, 36px);
|
|
221
|
+
font-size: var(--split-input-separator-font-size, 16px);
|
|
222
|
+
color: var(--split-input-separator-color, currentColor);
|
|
223
|
+
flex-shrink: 0;
|
|
224
|
+
}
|
|
225
|
+
</style>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SplitInputProperties } from './properties';
|
|
2
|
+
declare const SplitInput: import("svelte").Component<SplitInputProperties, {
|
|
3
|
+
clear: () => void;
|
|
4
|
+
focus: () => void;
|
|
5
|
+
}, "values">;
|
|
6
|
+
type SplitInput = ReturnType<typeof SplitInput>;
|
|
7
|
+
export default SplitInput;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { OptionalInputProperties } from '../Input/properties';
|
|
2
|
+
export type FieldConfig = Pick<OptionalInputProperties, 'dataType' | 'maxLength' | 'min' | 'max' | 'placeholder' | 'validationPattern' | 'validators' | 'label'>;
|
|
3
|
+
export type SplitInputProperties = MandatorySplitInputProperties & OptionalSplitInputProperties & SplitInputEventProperties;
|
|
4
|
+
export type MandatorySplitInputProperties = {
|
|
5
|
+
values: string[];
|
|
6
|
+
};
|
|
7
|
+
export type OptionalSplitInputProperties = {
|
|
8
|
+
fields?: FieldConfig[];
|
|
9
|
+
length?: number;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
autoAdvance?: boolean;
|
|
12
|
+
separator?: string;
|
|
13
|
+
testId?: string;
|
|
14
|
+
classes?: string;
|
|
15
|
+
};
|
|
16
|
+
export type SplitInputEventProperties = {
|
|
17
|
+
onchange?: (values: string[]) => void;
|
|
18
|
+
oninput?: (values: string[]) => void;
|
|
19
|
+
oncomplete?: (values: string[]) => void;
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { StepProperties } from './properties';
|
|
3
|
+
|
|
4
|
+
let { stepIndex, label, icon, classes, onclick, onkeydown }: StepProperties = $props();
|
|
5
|
+
|
|
6
|
+
function handleStepClick() {
|
|
7
|
+
onclick?.({ selectedIndex: stepIndex });
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function handleKeydown(event: KeyboardEvent) {
|
|
11
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
12
|
+
event.preventDefault();
|
|
13
|
+
handleStepClick();
|
|
14
|
+
}
|
|
15
|
+
onkeydown?.(event);
|
|
16
|
+
}
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<div
|
|
20
|
+
class="step {classes ?? ''}"
|
|
21
|
+
onclick={handleStepClick}
|
|
22
|
+
onkeydown={handleKeydown}
|
|
23
|
+
role="button"
|
|
24
|
+
tabindex="0"
|
|
25
|
+
aria-label={label}
|
|
26
|
+
>
|
|
27
|
+
{#if typeof icon === 'string' && icon.length > 0}
|
|
28
|
+
<div class="step-icon-container">
|
|
29
|
+
<img class="step-icon" src={icon} alt="" />
|
|
30
|
+
</div>
|
|
31
|
+
{:else}
|
|
32
|
+
<div class="step-index-container">
|
|
33
|
+
<div class="step-index-text">
|
|
34
|
+
{stepIndex}
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
{/if}
|
|
38
|
+
<div class="step-text">
|
|
39
|
+
{label}
|
|
40
|
+
</div>
|
|
41
|
+
<div class="separator"></div>
|
|
42
|
+
</div>
|
|
43
|
+
|
|
44
|
+
<style>
|
|
45
|
+
.step {
|
|
46
|
+
display: flex;
|
|
47
|
+
flex-direction: var(--step-flex-direction, row);
|
|
48
|
+
align-items: center;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.step-index-container {
|
|
52
|
+
display: flex;
|
|
53
|
+
justify-content: center;
|
|
54
|
+
align-items: center;
|
|
55
|
+
height: var(--step-index-container-height, 30px);
|
|
56
|
+
width: var(--step-index-container-width, 30px);
|
|
57
|
+
border-radius: var(--step-index-container-radius, 50%);
|
|
58
|
+
background-color: var(--step-index-container-background-color, currentColor);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.separator {
|
|
62
|
+
display: var(--step-separator-display, block);
|
|
63
|
+
height: var(--step-separator-height, 1px);
|
|
64
|
+
width: var(--step-separator-width, 50px);
|
|
65
|
+
margin: var(--step-separator-margin, 0px 12px 0px 12px);
|
|
66
|
+
background-image: var(
|
|
67
|
+
--step-separator-background-image,
|
|
68
|
+
repeating-linear-gradient(
|
|
69
|
+
to right,
|
|
70
|
+
var(--step-separator-background-image-color, currentColor),
|
|
71
|
+
var(--step-separator-background-image-color, currentColor) 6px,
|
|
72
|
+
transparent 6px,
|
|
73
|
+
transparent 10px
|
|
74
|
+
)
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.step-text {
|
|
79
|
+
margin: var(--step-text-margin, 0px 0px 0px 12px);
|
|
80
|
+
font-size: var(--step-text-font-size, inherit);
|
|
81
|
+
color: var(--step-text-color, inherit);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.step-index-text {
|
|
85
|
+
font-size: var(--step-index-font-size, 14px);
|
|
86
|
+
color: var(--step-index-color, white);
|
|
87
|
+
}
|
|
88
|
+
</style>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { StepperProperties } from './properties';
|
|
3
|
+
import Step from './Step.svelte';
|
|
4
|
+
|
|
5
|
+
let { steps, currentStepIndex, classes, testId, onhandlestepclick }: StepperProperties = $props();
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<div class="container {classes ?? ''}" data-pw={testId}>
|
|
9
|
+
{#each steps as currentStep, stepIndex (stepIndex)}
|
|
10
|
+
<div
|
|
11
|
+
class:active-step={currentStepIndex === stepIndex}
|
|
12
|
+
class:completed-step={currentStepIndex > stepIndex}
|
|
13
|
+
class="step-container"
|
|
14
|
+
>
|
|
15
|
+
<Step
|
|
16
|
+
onclick={onhandlestepclick}
|
|
17
|
+
label={currentStep.label}
|
|
18
|
+
icon={currentStep.icon}
|
|
19
|
+
stepIndex={stepIndex + 1}
|
|
20
|
+
/>
|
|
21
|
+
</div>
|
|
22
|
+
{/each}
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
<style>
|
|
26
|
+
.container {
|
|
27
|
+
display: flex;
|
|
28
|
+
flex-direction: var(--stepper-flex-direction, row);
|
|
29
|
+
align-items: center;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.step-container:last-child {
|
|
33
|
+
--step-separator-display: none;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.step-container {
|
|
37
|
+
display: flex;
|
|
38
|
+
align-items: center;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.active-step {
|
|
42
|
+
--step-text-color: var(--step-text-active-color, currentColor);
|
|
43
|
+
--step-separator-background-image-color: var(
|
|
44
|
+
--step-separator-background-image-active-color,
|
|
45
|
+
currentColor
|
|
46
|
+
);
|
|
47
|
+
--step-index-container-background-color: var(
|
|
48
|
+
--step-index-container-active-background-color,
|
|
49
|
+
currentColor
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.completed-step {
|
|
54
|
+
--step-text-color: var(--step-text-completed-color, currentColor);
|
|
55
|
+
--step-separator-background-image-color: var(
|
|
56
|
+
--step-separator-background-image-completed-color,
|
|
57
|
+
currentColor
|
|
58
|
+
);
|
|
59
|
+
--step-index-container-background-color: var(
|
|
60
|
+
--step-index-container-completed-background-color,
|
|
61
|
+
currentColor
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
</style>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type StepperProperties = {
|
|
2
|
+
steps: Array<Step>;
|
|
3
|
+
currentStepIndex: number;
|
|
4
|
+
classes?: string;
|
|
5
|
+
testId?: string;
|
|
6
|
+
onhandlestepclick?: (event: {
|
|
7
|
+
selectedIndex: number;
|
|
8
|
+
}) => void;
|
|
9
|
+
};
|
|
10
|
+
export type Step = {
|
|
11
|
+
label: string;
|
|
12
|
+
icon?: string;
|
|
13
|
+
};
|
|
14
|
+
export type StepProperties = OptionalStepProperties & StepEventProperties & {
|
|
15
|
+
stepIndex: number;
|
|
16
|
+
label: string;
|
|
17
|
+
};
|
|
18
|
+
export type OptionalStepProperties = {
|
|
19
|
+
icon?: string;
|
|
20
|
+
classes?: string;
|
|
21
|
+
};
|
|
22
|
+
export type StepEventProperties = {
|
|
23
|
+
onclick?: (event: {
|
|
24
|
+
selectedIndex: number;
|
|
25
|
+
}) => void;
|
|
26
|
+
onkeydown?: (event: KeyboardEvent) => void;
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|