@flightlesslabs/dodo-ui 0.7.2 → 0.9.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/dist/index.d.ts +18 -2
- package/dist/index.js +11 -0
- package/dist/stories/components/Form/NumericInput/Events/Events.stories.svelte +126 -0
- package/dist/stories/components/Form/NumericInput/Events/Events.stories.svelte.d.ts +18 -0
- package/dist/stories/components/Form/NumericInput/NumericInput.stories.svelte +79 -0
- package/dist/stories/components/Form/NumericInput/NumericInput.stories.svelte.d.ts +21 -0
- package/dist/stories/components/Form/NumericInput/NumericInput.svelte +161 -0
- package/dist/stories/components/Form/NumericInput/NumericInput.svelte.d.ts +69 -0
- package/dist/stories/components/Form/NumericInput/Validation/Validation.stories.svelte +84 -0
- package/dist/stories/components/Form/NumericInput/Validation/Validation.stories.svelte.d.ts +18 -0
- package/dist/stories/components/Form/PasswordInput/Events/Events.stories.svelte +27 -6
- package/dist/stories/components/Form/PasswordInput/PasswordInput.svelte +5 -3
- package/dist/stories/components/Form/PasswordInput/PasswordInput.svelte.d.ts +7 -1
- package/dist/stories/components/Form/Select/Customize/Customize.stories.svelte +16 -1
- package/dist/stories/components/Form/Select/DropDownArrow/DropDownArrow.stories.svelte +59 -0
- package/dist/stories/components/Form/Select/DropDownArrow/DropDownArrow.stories.svelte.d.ts +18 -0
- package/dist/stories/components/Form/Select/Events/Events.stories.svelte +27 -0
- package/dist/stories/components/Form/Select/Positions/AutoPosition/AutoPosition.stories.svelte +54 -0
- package/dist/stories/components/Form/Select/Positions/AutoPosition/AutoPosition.stories.svelte.d.ts +18 -0
- package/dist/stories/components/Form/Select/Positions/Positions.stories.svelte +83 -0
- package/dist/stories/components/Form/Select/Positions/Positions.stories.svelte.d.ts +18 -0
- package/dist/stories/components/Form/Select/Select.svelte +110 -123
- package/dist/stories/components/Form/Select/Select.svelte.d.ts +22 -3
- package/dist/stories/components/Form/TextInput/Events/Events.stories.svelte +27 -0
- package/dist/stories/components/Form/TextInput/TextInput.svelte +5 -3
- package/dist/stories/components/Form/TextInput/TextInput.svelte.d.ts +10 -1
- package/dist/stories/components/Layout/Menu/DynamicMenu/Customize/Customize.stories.svelte +28 -0
- package/dist/stories/components/Layout/Menu/DynamicMenu/Customize/Customize.stories.svelte.d.ts +18 -0
- package/dist/stories/components/Layout/Menu/DynamicMenu/DynamicMenu.stories.svelte +51 -0
- package/dist/stories/components/Layout/Menu/DynamicMenu/DynamicMenu.stories.svelte.d.ts +22 -0
- package/dist/stories/components/Layout/Menu/DynamicMenu/DynamicMenu.svelte +129 -0
- package/dist/stories/components/Layout/Menu/DynamicMenu/DynamicMenu.svelte.d.ts +81 -0
- package/dist/stories/components/Layout/Menu/DynamicMenu/Events/Events.stories.svelte +46 -0
- package/dist/stories/components/Layout/Menu/DynamicMenu/Events/Events.stories.svelte.d.ts +18 -0
- package/dist/stories/components/Layout/Menu/DynamicMenu/KeybaordNavigation/KeybaordNavigation.stories.svelte +27 -0
- package/dist/stories/components/Layout/Menu/DynamicMenu/KeybaordNavigation/KeybaordNavigation.stories.svelte.d.ts +18 -0
- package/dist/stories/components/Layout/Menu/DynamicMenu/Options/OptionFormat.mdx +72 -0
- package/dist/stories/components/Layout/Menu/MenuItem/MenuItem.svelte.d.ts +1 -1
- package/dist/stories/developer tools/components/DynamicInput/DynamicInput.svelte +23 -4
- package/dist/stories/developer tools/components/DynamicInput/DynamicInput.svelte.d.ts +13 -2
- package/dist/stories/developer tools/components/DynamicInput/Events/Events.stories.svelte +115 -0
- package/dist/stories/developer tools/components/DynamicInput/Events/Events.stories.svelte.d.ts +18 -0
- package/dist/stories/developer tools/helpers/Numbers/cleanNumericString/cleanNumericString.d.ts +13 -0
- package/dist/stories/developer tools/helpers/Numbers/cleanNumericString/cleanNumericString.js +26 -0
- package/dist/stories/developer tools/helpers/Numbers/cleanNumericString/index.mdx +20 -0
- package/dist/stories/developer tools/helpers/Numbers/isValidNumberValue/index.mdx +71 -0
- package/dist/stories/developer tools/helpers/Numbers/isValidNumberValue/isValidNumberValue.d.ts +51 -0
- package/dist/stories/developer tools/helpers/Numbers/isValidNumberValue/isValidNumberValue.js +96 -0
- package/dist/stories/developer tools/helpers/logger/index.mdx +63 -0
- package/dist/stories/developer tools/helpers/logger/logger.d.ts +24 -0
- package/dist/stories/developer tools/helpers/logger/logger.js +31 -0
- package/package.json +15 -17
- package/src/lib/index.ts +33 -0
- package/src/lib/stories/Home.mdx +59 -0
- package/src/lib/stories/assets/dark-theme-toggle.png +0 -0
- package/src/lib/stories/components/Form/Button/Button.stories.svelte +61 -0
- package/src/lib/stories/components/Form/Button/Color/Color.stories.svelte +43 -0
- package/src/lib/stories/components/Form/Button/Events/Events.stories.svelte +36 -0
- package/src/lib/stories/components/Form/Button/IconButton/IconButton.stories.svelte +43 -0
- package/src/lib/stories/components/Form/Button/Roundness/Roundness.stories.svelte +23 -0
- package/src/lib/stories/components/Form/Button/Size/Size.stories.svelte +16 -0
- package/src/lib/stories/components/Form/Button/Variant/Variant.stories.svelte +18 -0
- package/src/lib/stories/components/Form/FormControl/FormControl.stories.svelte +28 -0
- package/src/lib/stories/components/Form/Label/Label.stories.svelte +13 -0
- package/src/lib/stories/components/Form/Message/Color/Color.stories.svelte +36 -0
- package/src/lib/stories/components/Form/Message/Message.stories.svelte +27 -0
- package/src/lib/stories/components/Form/Message/Size/Size.stories.svelte +22 -0
- package/src/lib/stories/components/Form/NumericInput/Events/Events.stories.svelte +134 -0
- package/src/lib/stories/components/Form/NumericInput/NumericInput.stories.svelte +84 -0
- package/src/lib/stories/components/Form/NumericInput/NumericInput.svelte +286 -0
- package/src/lib/stories/components/Form/NumericInput/Validation/Validation.stories.svelte +87 -0
- package/src/lib/stories/components/Form/PasswordInput/Events/Events.stories.svelte +132 -0
- package/src/lib/stories/components/Form/PasswordInput/PasswordInput.stories.svelte +59 -0
- package/src/lib/stories/components/Form/PasswordInput/PasswordInput.svelte +15 -3
- package/src/lib/stories/components/Form/PasswordInput/Roundness/Roundness.stories.svelte +20 -0
- package/src/lib/stories/components/Form/PasswordInput/Size/Size.stories.svelte +16 -0
- package/src/lib/stories/components/Form/PasswordInput/WithIcon/WithIcon.stories.svelte +31 -0
- package/src/lib/stories/components/Form/Select/Customize/Customize.stories.svelte +139 -0
- package/src/lib/stories/components/Form/Select/DropDownArrow/DropDownArrow.stories.svelte +63 -0
- package/src/lib/stories/components/Form/Select/Events/Events.stories.svelte +174 -0
- package/src/lib/stories/components/Form/Select/Options/OptionFormat.mdx +40 -0
- package/src/lib/stories/components/Form/Select/Positions/AutoPosition/AutoPosition.stories.svelte +58 -0
- package/src/lib/stories/components/Form/Select/Positions/Positions.stories.svelte +87 -0
- package/src/lib/stories/components/Form/Select/Roundness/Roundness.stories.svelte +32 -0
- package/src/lib/stories/components/Form/Select/Select.stories.svelte +121 -0
- package/src/lib/stories/components/Form/Select/Select.svelte +166 -146
- package/src/lib/stories/components/Form/Select/Size/Size.stories.svelte +28 -0
- package/src/lib/stories/components/Form/Select/WithIcon/WithIcon.stories.svelte +43 -0
- package/src/lib/stories/components/Form/TextInput/Events/Events.stories.svelte +125 -0
- package/src/lib/stories/components/Form/TextInput/Roundness/Roundness.stories.svelte +21 -0
- package/src/lib/stories/components/Form/TextInput/Size/Size.stories.svelte +17 -0
- package/src/lib/stories/components/Form/TextInput/TextInput.stories.svelte +43 -0
- package/src/lib/stories/components/Form/TextInput/TextInput.svelte +18 -3
- package/src/lib/stories/components/Form/TextInput/WithIcon/WithIcon.stories.svelte +47 -0
- package/src/lib/stories/components/Layout/Menu/DynamicMenu/Customize/Customize.stories.svelte +30 -0
- package/src/lib/stories/components/Layout/Menu/DynamicMenu/DynamicMenu.stories.svelte +56 -0
- package/src/lib/stories/components/Layout/Menu/DynamicMenu/DynamicMenu.svelte +262 -0
- package/src/lib/stories/components/Layout/Menu/DynamicMenu/Events/Events.stories.svelte +48 -0
- package/src/lib/stories/components/Layout/Menu/DynamicMenu/KeybaordNavigation/KeybaordNavigation.stories.svelte +29 -0
- package/src/lib/stories/components/Layout/Menu/DynamicMenu/Options/OptionFormat.mdx +72 -0
- package/src/lib/stories/components/Layout/Menu/Menu.stories.svelte +69 -0
- package/src/lib/stories/components/Layout/Menu/MenuItem/MenuItem.stories.svelte +34 -0
- package/src/lib/stories/components/Layout/Menu/MenuItem/MenuItem.svelte +1 -1
- package/src/lib/stories/components/Layout/Menu/MenuItem/Size/Size.stories.svelte +16 -0
- package/src/lib/stories/components/Layout/Menu/MenuItem/Type/Type.stories.svelte +21 -0
- package/src/lib/stories/components/Layout/Menu/Size/Size.stories.svelte +37 -0
- package/src/lib/stories/components/Layout/Paper/Color/Color.stories.svelte +63 -0
- package/src/lib/stories/components/Layout/Paper/Paper.stories.svelte +50 -0
- package/src/lib/stories/components/Layout/Paper/Roundness/Roundness.stories.svelte +25 -0
- package/src/lib/stories/components/Layout/Paper/Shadow/Shadow.stories.svelte +24 -0
- package/src/lib/stories/components/Layout/Separator/Color/Color.stories.svelte +19 -0
- package/src/lib/stories/components/Layout/Separator/Separator.stories.svelte +30 -0
- package/src/lib/stories/developer tools/Intro.mdx +9 -0
- package/src/lib/stories/developer tools/components/DynamicInput/DynamicInput.stories.svelte +53 -0
- package/src/lib/stories/developer tools/components/DynamicInput/DynamicInput.svelte +43 -3
- package/src/lib/stories/developer tools/components/DynamicInput/Events/Events.stories.svelte +121 -0
- package/src/lib/stories/developer tools/components/DynamicInput/Size/Size.stories.svelte +17 -0
- package/src/lib/stories/developer tools/components/InputEnclosure/InputEnclosure.stories.svelte +38 -0
- package/src/lib/stories/developer tools/components/InputEnclosure/Roundness/Roundness.stories.svelte +20 -0
- package/src/lib/stories/developer tools/components/InputEnclosure/Size/Size.stories.svelte +16 -0
- package/src/lib/stories/developer tools/components/InputEnclosure/WithIcon/WithIcon.stories.svelte +47 -0
- package/src/lib/stories/developer tools/components/Popper/Popper.stories.svelte +124 -0
- package/src/lib/stories/developer tools/components/Popper/PopperPopup/PopperPopup.stories.svelte +64 -0
- package/src/lib/stories/developer tools/components/Popper/Positions/AutoPosition/AutoPosition.stories.svelte +92 -0
- package/src/lib/stories/developer tools/components/Popper/Positions/Positions.stories.svelte +114 -0
- package/src/lib/stories/developer tools/components/UtilityButton/Size/Size.stories.svelte +25 -0
- package/src/lib/stories/developer tools/components/UtilityButton/UtilityButton.stories.svelte +30 -0
- package/src/lib/stories/developer tools/directives/clickOutside/index.mdx +25 -0
- package/src/lib/stories/developer tools/helpers/Numbers/cleanNumericString/cleanNumericString.ts +27 -0
- package/src/lib/stories/developer tools/helpers/Numbers/cleanNumericString/index.mdx +20 -0
- package/src/lib/stories/developer tools/helpers/Numbers/isValidNumberValue/index.mdx +71 -0
- package/src/lib/stories/developer tools/helpers/Numbers/isValidNumberValue/isValidNumberValue.ts +156 -0
- package/src/lib/stories/developer tools/helpers/logger/index.mdx +63 -0
- package/src/lib/stories/developer tools/helpers/logger/logger.ts +46 -0
- package/src/lib/stories/developer tools/philosophy/Colors/Colors.mdx +43 -0
- package/src/lib/stories/developer tools/philosophy/Colors/Colors.stories.svelte +22 -0
- package/src/lib/stories/developer tools/philosophy/Colors/Opacity.stories.svelte +11 -0
- package/src/lib/stories/developer tools/philosophy/Themes.mdx +23 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { ComponentRoundness } from '$lib/types/roundness.js';
|
|
3
|
+
import type { ComponentSize } from '$lib/types/size.js';
|
|
4
|
+
|
|
5
|
+
import { type Snippet } from 'svelte';
|
|
6
|
+
import type {
|
|
7
|
+
ChangeEventHandler,
|
|
8
|
+
ClipboardEventHandler,
|
|
9
|
+
FocusEventHandler,
|
|
10
|
+
FormEventHandler,
|
|
11
|
+
KeyboardEventHandler,
|
|
12
|
+
} from 'svelte/elements';
|
|
13
|
+
|
|
14
|
+
export interface NumericInputProps {
|
|
15
|
+
/** min */
|
|
16
|
+
min?: number;
|
|
17
|
+
/** max */
|
|
18
|
+
max?: number;
|
|
19
|
+
/** Allow Negative Values */
|
|
20
|
+
allowNegativeValues?: boolean;
|
|
21
|
+
/** Decimal Places */
|
|
22
|
+
decimalPlaces?: number;
|
|
23
|
+
/** Log number validations */
|
|
24
|
+
log?: boolean;
|
|
25
|
+
/** Input ref */
|
|
26
|
+
ref?: HTMLInputElement;
|
|
27
|
+
/** How large should the button be? */
|
|
28
|
+
size?: ComponentSize;
|
|
29
|
+
/** How round should the border radius be? */
|
|
30
|
+
roundness?: ComponentRoundness;
|
|
31
|
+
/** Add a border around the button. Default True */
|
|
32
|
+
outline?: boolean;
|
|
33
|
+
/** Input value */
|
|
34
|
+
value?: number;
|
|
35
|
+
/** How round should the border radius be? */
|
|
36
|
+
placeholder?: string;
|
|
37
|
+
/** disabled state */
|
|
38
|
+
disabled?: boolean;
|
|
39
|
+
/** Read only ? */
|
|
40
|
+
readonly?: boolean;
|
|
41
|
+
/** is there any associated Error ? */
|
|
42
|
+
error?: boolean;
|
|
43
|
+
/** Name */
|
|
44
|
+
name?: string;
|
|
45
|
+
/** Id */
|
|
46
|
+
id?: string;
|
|
47
|
+
/** Icon before button content */
|
|
48
|
+
before?: Snippet;
|
|
49
|
+
/** Icon after button content */
|
|
50
|
+
after?: Snippet;
|
|
51
|
+
/** Custom css class*/
|
|
52
|
+
class?: string;
|
|
53
|
+
/** on Numeric Value Change */
|
|
54
|
+
onValueChange?: (value: number | undefined) => void;
|
|
55
|
+
/** oninput event handler */
|
|
56
|
+
oninput?: FormEventHandler<HTMLInputElement>;
|
|
57
|
+
/** onchange event handler */
|
|
58
|
+
onchange?: ChangeEventHandler<HTMLInputElement>;
|
|
59
|
+
/** onblur event handler */
|
|
60
|
+
onblur?: FocusEventHandler<HTMLInputElement>;
|
|
61
|
+
/** onfocus event handler */
|
|
62
|
+
onfocus?: FocusEventHandler<HTMLInputElement>;
|
|
63
|
+
/** onpaste event handler */
|
|
64
|
+
onpaste?: ClipboardEventHandler<HTMLInputElement>;
|
|
65
|
+
/** oncopy event handler */
|
|
66
|
+
oncopy?: ClipboardEventHandler<HTMLInputElement>;
|
|
67
|
+
/** oncut event handler */
|
|
68
|
+
oncut?: ClipboardEventHandler<HTMLInputElement>;
|
|
69
|
+
/** onkeydown event handler */
|
|
70
|
+
onkeydown?: KeyboardEventHandler<HTMLInputElement>;
|
|
71
|
+
/** onkeypress event handler */
|
|
72
|
+
onkeypress?: KeyboardEventHandler<HTMLInputElement>;
|
|
73
|
+
/** onkeyup event handler */
|
|
74
|
+
onkeyup?: KeyboardEventHandler<HTMLInputElement>;
|
|
75
|
+
}
|
|
76
|
+
</script>
|
|
77
|
+
|
|
78
|
+
<script lang="ts">
|
|
79
|
+
import InputEnclosure from '$lib/stories/developer tools/components/InputEnclosure/InputEnclosure.svelte';
|
|
80
|
+
import DynamicInput, {
|
|
81
|
+
type DynamicInputFocusEvent,
|
|
82
|
+
type DynamicInputKeyboardEvent,
|
|
83
|
+
} from '$lib/stories/developer tools/components/DynamicInput/DynamicInput.svelte';
|
|
84
|
+
import type { TextInputFocusEvent, TextInputKeyboardEvent } from '../TextInput/TextInput.svelte';
|
|
85
|
+
import isValidNumberValue from '$lib/stories/developer tools/helpers/Numbers/isValidNumberValue/isValidNumberValue.js';
|
|
86
|
+
|
|
87
|
+
let {
|
|
88
|
+
size = 'normal',
|
|
89
|
+
roundness = 1,
|
|
90
|
+
outline = true,
|
|
91
|
+
name,
|
|
92
|
+
id,
|
|
93
|
+
class: className = '',
|
|
94
|
+
disabled = false,
|
|
95
|
+
oninput,
|
|
96
|
+
onchange,
|
|
97
|
+
onblur,
|
|
98
|
+
onfocus,
|
|
99
|
+
onpaste,
|
|
100
|
+
oncopy,
|
|
101
|
+
oncut,
|
|
102
|
+
onkeydown,
|
|
103
|
+
onkeypress,
|
|
104
|
+
onkeyup,
|
|
105
|
+
before,
|
|
106
|
+
after,
|
|
107
|
+
error = false,
|
|
108
|
+
value: valueRaw,
|
|
109
|
+
placeholder,
|
|
110
|
+
ref = $bindable<HTMLInputElement>(),
|
|
111
|
+
readonly = false,
|
|
112
|
+
decimalPlaces = 0,
|
|
113
|
+
allowNegativeValues = false,
|
|
114
|
+
min,
|
|
115
|
+
max,
|
|
116
|
+
log = false,
|
|
117
|
+
onValueChange,
|
|
118
|
+
}: NumericInputProps = $props();
|
|
119
|
+
|
|
120
|
+
let value = $state<string>('');
|
|
121
|
+
let cachedValue = $state<string>('');
|
|
122
|
+
|
|
123
|
+
let focused: boolean = $state(false);
|
|
124
|
+
|
|
125
|
+
function onfocusMod(e: DynamicInputFocusEvent) {
|
|
126
|
+
const eTyped = e as TextInputFocusEvent;
|
|
127
|
+
|
|
128
|
+
if (onfocus) {
|
|
129
|
+
onfocus(eTyped);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function onblurMod(e: DynamicInputFocusEvent) {
|
|
134
|
+
const eTyped = e as TextInputFocusEvent;
|
|
135
|
+
|
|
136
|
+
const isValidWithoutMinMax = isValidNumberValue(`${value}`, {
|
|
137
|
+
decimalPlaces,
|
|
138
|
+
allowNegativeValues,
|
|
139
|
+
log,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const isValid = isValidNumberValue(`${value}`, {
|
|
143
|
+
decimalPlaces,
|
|
144
|
+
allowNegativeValues,
|
|
145
|
+
log,
|
|
146
|
+
min,
|
|
147
|
+
max,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
if (isValid) {
|
|
151
|
+
if (onValueChange) {
|
|
152
|
+
onValueChange(Number(value));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
value = `${Number(value)}`;
|
|
156
|
+
cachedValue = `${Number(value)}`;
|
|
157
|
+
} else if (isValidWithoutMinMax) {
|
|
158
|
+
if (min && Number(value) < min) {
|
|
159
|
+
if (onValueChange) {
|
|
160
|
+
onValueChange(min);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
value = `${min}`;
|
|
164
|
+
cachedValue = `${min}`;
|
|
165
|
+
} else if (max && Number(value) > max) {
|
|
166
|
+
if (onValueChange) {
|
|
167
|
+
onValueChange(max);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
value = `${max}`;
|
|
171
|
+
cachedValue = `${max}`;
|
|
172
|
+
}
|
|
173
|
+
} else if (value.trim() === '') {
|
|
174
|
+
if (onValueChange) {
|
|
175
|
+
onValueChange(undefined);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
value = '';
|
|
179
|
+
cachedValue = '';
|
|
180
|
+
} else if (valueRaw || valueRaw === 0) {
|
|
181
|
+
if (onValueChange) {
|
|
182
|
+
onValueChange(valueRaw);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
value = `${valueRaw}`;
|
|
186
|
+
cachedValue = `${valueRaw}`;
|
|
187
|
+
} else {
|
|
188
|
+
if (onValueChange) {
|
|
189
|
+
onValueChange(undefined);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
value = '';
|
|
193
|
+
cachedValue = '';
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (onblur) {
|
|
197
|
+
onblur(eTyped);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function onkeydownMod(e: DynamicInputKeyboardEvent) {
|
|
202
|
+
if (onkeydown) {
|
|
203
|
+
onkeydown(e as TextInputKeyboardEvent);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (e.ctrlKey && e.key.toLocaleLowerCase() === 'c') {
|
|
207
|
+
return;
|
|
208
|
+
} else if (e.ctrlKey && e.key.toLocaleLowerCase() === 'v') {
|
|
209
|
+
return;
|
|
210
|
+
} else if (e.ctrlKey && e.key.toLocaleLowerCase() === 'x') {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const valueToCheck = `${value}${e.key.length === 1 ? e.key : ''}`;
|
|
215
|
+
|
|
216
|
+
const isValid = isValidNumberValue(valueToCheck, {
|
|
217
|
+
decimalPlaces,
|
|
218
|
+
allowNegativeValues,
|
|
219
|
+
log,
|
|
220
|
+
strict: false,
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
if (!isValid) {
|
|
224
|
+
e.preventDefault();
|
|
225
|
+
value = cachedValue;
|
|
226
|
+
} else {
|
|
227
|
+
cachedValue = valueToCheck;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
$effect(() => {
|
|
232
|
+
let updatedValue = '';
|
|
233
|
+
|
|
234
|
+
const isValid = isValidNumberValue(`${valueRaw}`, {
|
|
235
|
+
decimalPlaces,
|
|
236
|
+
allowNegativeValues,
|
|
237
|
+
min,
|
|
238
|
+
max,
|
|
239
|
+
log,
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
if (valueRaw === undefined) {
|
|
243
|
+
updatedValue = '';
|
|
244
|
+
} else if (!isValid) {
|
|
245
|
+
updatedValue = '';
|
|
246
|
+
} else {
|
|
247
|
+
updatedValue = `${valueRaw}`;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
value = updatedValue;
|
|
251
|
+
cachedValue = updatedValue;
|
|
252
|
+
});
|
|
253
|
+
</script>
|
|
254
|
+
|
|
255
|
+
<div
|
|
256
|
+
class:outline
|
|
257
|
+
class:disabled
|
|
258
|
+
class:error
|
|
259
|
+
class:focused
|
|
260
|
+
class={['dodo-ui-NumericInput', `size--${size}`, `roundness--${roundness}`, className].join(' ')}
|
|
261
|
+
>
|
|
262
|
+
<InputEnclosure {outline} {disabled} {error} {focused} {size} {roundness} {before} {after}>
|
|
263
|
+
<DynamicInput
|
|
264
|
+
type="text"
|
|
265
|
+
{name}
|
|
266
|
+
{id}
|
|
267
|
+
{disabled}
|
|
268
|
+
bind:ref
|
|
269
|
+
bind:focused
|
|
270
|
+
{oninput}
|
|
271
|
+
{onchange}
|
|
272
|
+
onfocus={onfocusMod}
|
|
273
|
+
onblur={onblurMod}
|
|
274
|
+
{onpaste}
|
|
275
|
+
{oncopy}
|
|
276
|
+
{oncut}
|
|
277
|
+
onkeydown={onkeydownMod}
|
|
278
|
+
onkeypress={onkeypress ? (e) => onkeypress(e as TextInputKeyboardEvent) : undefined}
|
|
279
|
+
onkeyup={onkeyup ? (e) => onkeyup(e as TextInputKeyboardEvent) : undefined}
|
|
280
|
+
{placeholder}
|
|
281
|
+
{readonly}
|
|
282
|
+
variant="input"
|
|
283
|
+
bind:value
|
|
284
|
+
/>
|
|
285
|
+
</InputEnclosure>
|
|
286
|
+
</div>
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import NumericInput from '../NumericInput.svelte';
|
|
4
|
+
import { storyNumericInputArgTypes } from '../NumericInput.stories.svelte';
|
|
5
|
+
|
|
6
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
7
|
+
const { Story } = defineMeta({
|
|
8
|
+
component: NumericInput,
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
argTypes: storyNumericInputArgTypes,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
let value = $state<undefined | number>(0);
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<!-- NumericInput with default style -->
|
|
17
|
+
<Story
|
|
18
|
+
name="Default"
|
|
19
|
+
args={{
|
|
20
|
+
value,
|
|
21
|
+
onValueChange: (val) => {
|
|
22
|
+
value = val;
|
|
23
|
+
},
|
|
24
|
+
}}
|
|
25
|
+
/>
|
|
26
|
+
|
|
27
|
+
<!-- Min, In this case min is set to 25 -->
|
|
28
|
+
<Story
|
|
29
|
+
name="Min"
|
|
30
|
+
args={{
|
|
31
|
+
value,
|
|
32
|
+
onValueChange: (val) => {
|
|
33
|
+
console.log(val);
|
|
34
|
+
|
|
35
|
+
value = val;
|
|
36
|
+
},
|
|
37
|
+
min: 25,
|
|
38
|
+
}}
|
|
39
|
+
/>
|
|
40
|
+
|
|
41
|
+
<!-- Max, In this case max is set to 25 -->
|
|
42
|
+
<Story
|
|
43
|
+
name="Max"
|
|
44
|
+
args={{
|
|
45
|
+
value,
|
|
46
|
+
onValueChange: (val) => {
|
|
47
|
+
value = val;
|
|
48
|
+
},
|
|
49
|
+
max: 25,
|
|
50
|
+
}}
|
|
51
|
+
/>
|
|
52
|
+
|
|
53
|
+
<!-- Allow Negative values -->
|
|
54
|
+
<Story
|
|
55
|
+
name="AllowNegativeValues"
|
|
56
|
+
args={{
|
|
57
|
+
value,
|
|
58
|
+
onValueChange: (val) => {
|
|
59
|
+
value = val;
|
|
60
|
+
},
|
|
61
|
+
allowNegativeValues: true,
|
|
62
|
+
}}
|
|
63
|
+
/>
|
|
64
|
+
|
|
65
|
+
<!-- Decimal Places -->
|
|
66
|
+
<Story
|
|
67
|
+
name="DecimalPlaces"
|
|
68
|
+
args={{
|
|
69
|
+
value,
|
|
70
|
+
onValueChange: (val) => {
|
|
71
|
+
value = val;
|
|
72
|
+
},
|
|
73
|
+
decimalPlaces: 2,
|
|
74
|
+
}}
|
|
75
|
+
/>
|
|
76
|
+
|
|
77
|
+
<!-- Log validations, check console -->
|
|
78
|
+
<Story
|
|
79
|
+
name="LogValidations"
|
|
80
|
+
args={{
|
|
81
|
+
value,
|
|
82
|
+
onValueChange: (val) => {
|
|
83
|
+
value = val;
|
|
84
|
+
},
|
|
85
|
+
log: true,
|
|
86
|
+
}}
|
|
87
|
+
/>
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import { storyPasswordInputArgTypes } from '../PasswordInput.stories.svelte';
|
|
4
|
+
import PasswordInput, { type PasswordInputToggleEvent } from '../PasswordInput.svelte';
|
|
5
|
+
import type {
|
|
6
|
+
TextInputFocusEvent,
|
|
7
|
+
TextInputClipboardEvent,
|
|
8
|
+
TextInputKeyboardEvent,
|
|
9
|
+
} from '../../TextInput/TextInput.svelte';
|
|
10
|
+
|
|
11
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
12
|
+
const { Story } = defineMeta({
|
|
13
|
+
component: PasswordInput,
|
|
14
|
+
tags: ['autodocs'],
|
|
15
|
+
argTypes: storyPasswordInputArgTypes,
|
|
16
|
+
});
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<Story
|
|
20
|
+
name="Input"
|
|
21
|
+
args={{
|
|
22
|
+
oninput: (e: Event) => {
|
|
23
|
+
const target = e.target as HTMLInputElement;
|
|
24
|
+
|
|
25
|
+
console.log('Input Event', target.value);
|
|
26
|
+
},
|
|
27
|
+
}}
|
|
28
|
+
/>
|
|
29
|
+
|
|
30
|
+
<Story
|
|
31
|
+
name="Change"
|
|
32
|
+
args={{
|
|
33
|
+
onchange: (e: Event) => {
|
|
34
|
+
const target = e.target as HTMLInputElement;
|
|
35
|
+
|
|
36
|
+
console.log('onChange Event', target.value);
|
|
37
|
+
},
|
|
38
|
+
}}
|
|
39
|
+
/>
|
|
40
|
+
|
|
41
|
+
<Story
|
|
42
|
+
name="Toggle"
|
|
43
|
+
args={{
|
|
44
|
+
ontoggle: (e: PasswordInputToggleEvent) => {
|
|
45
|
+
const target = e.event.target as HTMLButtonElement;
|
|
46
|
+
|
|
47
|
+
console.log('ontoggle Event', e, target);
|
|
48
|
+
},
|
|
49
|
+
}}
|
|
50
|
+
/>
|
|
51
|
+
|
|
52
|
+
<Story
|
|
53
|
+
name="Focus"
|
|
54
|
+
args={{
|
|
55
|
+
onfocus: (e: TextInputFocusEvent) => {
|
|
56
|
+
const target = e.target as HTMLInputElement;
|
|
57
|
+
|
|
58
|
+
console.log('onfocus Event', target);
|
|
59
|
+
},
|
|
60
|
+
}}
|
|
61
|
+
/>
|
|
62
|
+
|
|
63
|
+
<Story
|
|
64
|
+
name="Blur"
|
|
65
|
+
args={{
|
|
66
|
+
onblur: (e: TextInputFocusEvent) => {
|
|
67
|
+
const target = e.target as HTMLInputElement;
|
|
68
|
+
|
|
69
|
+
console.log('onblur Event', target);
|
|
70
|
+
},
|
|
71
|
+
}}
|
|
72
|
+
/>
|
|
73
|
+
|
|
74
|
+
<Story
|
|
75
|
+
name="Copy"
|
|
76
|
+
args={{
|
|
77
|
+
oncopy: (e: TextInputClipboardEvent) => {
|
|
78
|
+
const target = e.target as HTMLInputElement;
|
|
79
|
+
|
|
80
|
+
console.log('oncopy Event', target);
|
|
81
|
+
},
|
|
82
|
+
}}
|
|
83
|
+
/>
|
|
84
|
+
|
|
85
|
+
<Story
|
|
86
|
+
name="Cut"
|
|
87
|
+
args={{
|
|
88
|
+
oncut: (e: TextInputClipboardEvent) => {
|
|
89
|
+
const target = e.target as HTMLInputElement;
|
|
90
|
+
|
|
91
|
+
console.log('oncut Event', target);
|
|
92
|
+
},
|
|
93
|
+
}}
|
|
94
|
+
/>
|
|
95
|
+
|
|
96
|
+
<Story
|
|
97
|
+
name="Paste"
|
|
98
|
+
args={{
|
|
99
|
+
onpaste: (e: TextInputClipboardEvent) => {
|
|
100
|
+
const target = e.target as HTMLInputElement;
|
|
101
|
+
|
|
102
|
+
console.log('onpaste Event', target);
|
|
103
|
+
},
|
|
104
|
+
}}
|
|
105
|
+
/>
|
|
106
|
+
|
|
107
|
+
<Story
|
|
108
|
+
name="KeyDown"
|
|
109
|
+
args={{
|
|
110
|
+
onkeydown: (e: TextInputKeyboardEvent) => {
|
|
111
|
+
console.log('onkeydown Event', e.key);
|
|
112
|
+
},
|
|
113
|
+
}}
|
|
114
|
+
/>
|
|
115
|
+
|
|
116
|
+
<Story
|
|
117
|
+
name="KeyPress"
|
|
118
|
+
args={{
|
|
119
|
+
onkeypress: (e: TextInputKeyboardEvent) => {
|
|
120
|
+
console.log('onkeypress Event', e.key);
|
|
121
|
+
},
|
|
122
|
+
}}
|
|
123
|
+
/>
|
|
124
|
+
|
|
125
|
+
<Story
|
|
126
|
+
name="KeyUp"
|
|
127
|
+
args={{
|
|
128
|
+
onkeyup: (e: TextInputKeyboardEvent) => {
|
|
129
|
+
console.log('onkeyup Event', e.key);
|
|
130
|
+
},
|
|
131
|
+
}}
|
|
132
|
+
/>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import PasswordInput from './PasswordInput.svelte';
|
|
4
|
+
import type { StoryBookArgTypes } from '$lib/storybook-types.js';
|
|
5
|
+
import Icon from '@iconify/svelte';
|
|
6
|
+
import { componentRoundnessArray } from '$lib/types/roundness.js';
|
|
7
|
+
import { componentSizeArray } from '$lib/types/size.js';
|
|
8
|
+
|
|
9
|
+
export const storyPasswordInputArgTypes: StoryBookArgTypes = {
|
|
10
|
+
roundness: {
|
|
11
|
+
control: { type: 'select' },
|
|
12
|
+
options: componentRoundnessArray,
|
|
13
|
+
},
|
|
14
|
+
size: {
|
|
15
|
+
control: { type: 'select' },
|
|
16
|
+
options: componentSizeArray,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
21
|
+
const { Story } = defineMeta({
|
|
22
|
+
component: PasswordInput,
|
|
23
|
+
tags: ['autodocs'],
|
|
24
|
+
argTypes: storyPasswordInputArgTypes,
|
|
25
|
+
args: { value: 'Hello world!' },
|
|
26
|
+
});
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<!-- PasswordInput with default style -->
|
|
30
|
+
<Story name="Default" />
|
|
31
|
+
|
|
32
|
+
<Story name="Placeholder" args={{ value: '', placeholder: 'Type something...' }} />
|
|
33
|
+
|
|
34
|
+
<Story name="No Outline" args={{ outline: false }} />
|
|
35
|
+
|
|
36
|
+
<Story name="Error" args={{ error: true }} />
|
|
37
|
+
|
|
38
|
+
<Story name="Disabled" args={{ disabled: true }} />
|
|
39
|
+
|
|
40
|
+
<!-- Disable password toggle -->
|
|
41
|
+
<Story name="No toggle" args={{ passwordToggle: false }} />
|
|
42
|
+
|
|
43
|
+
<!-- Show Password by default -->
|
|
44
|
+
<Story name="Show Password" args={{ passwordToggleState: true }} />
|
|
45
|
+
|
|
46
|
+
<Story name="Read only" args={{ readonly: true }} />
|
|
47
|
+
|
|
48
|
+
<!-- Show Password by default -->
|
|
49
|
+
<Story name="Custom toggle icon" asChild>
|
|
50
|
+
<PasswordInput value="Hello world!">
|
|
51
|
+
{#snippet customPasswordToggleIcon(toggle)}
|
|
52
|
+
{#if toggle}
|
|
53
|
+
<Icon icon="mingcute:eye-close-line" width="24" height="24" />
|
|
54
|
+
{:else}
|
|
55
|
+
<Icon icon="mingcute:eye-2-line" width="24" height="24" />
|
|
56
|
+
{/if}
|
|
57
|
+
{/snippet}
|
|
58
|
+
</PasswordInput>
|
|
59
|
+
</Story>
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
ClipboardEventHandler,
|
|
8
8
|
FocusEventHandler,
|
|
9
9
|
FormEventHandler,
|
|
10
|
+
KeyboardEventHandler,
|
|
10
11
|
} from 'svelte/elements';
|
|
11
12
|
|
|
12
13
|
export type PasswordInputToggleEvent = {
|
|
@@ -65,6 +66,12 @@
|
|
|
65
66
|
oncut?: ClipboardEventHandler<HTMLInputElement>;
|
|
66
67
|
/** ontoggle event handler */
|
|
67
68
|
ontoggle?: (e: PasswordInputToggleEvent) => void;
|
|
69
|
+
/** onkeydown event handler */
|
|
70
|
+
onkeydown?: KeyboardEventHandler<HTMLInputElement>;
|
|
71
|
+
/** onkeypress event handler */
|
|
72
|
+
onkeypress?: KeyboardEventHandler<HTMLInputElement>;
|
|
73
|
+
/** onkeyup event handler */
|
|
74
|
+
onkeyup?: KeyboardEventHandler<HTMLInputElement>;
|
|
68
75
|
}
|
|
69
76
|
</script>
|
|
70
77
|
|
|
@@ -72,7 +79,7 @@
|
|
|
72
79
|
import Icon from '@iconify/svelte';
|
|
73
80
|
import UtilityButton from '$lib/stories/developer tools/components/UtilityButton/UtilityButton.svelte';
|
|
74
81
|
import InputEnclosure from '$lib/stories/developer tools/components/InputEnclosure/InputEnclosure.svelte';
|
|
75
|
-
import type { TextInputFocusEvent } from '../TextInput/TextInput.svelte';
|
|
82
|
+
import type { TextInputFocusEvent, TextInputKeyboardEvent } from '../TextInput/TextInput.svelte';
|
|
76
83
|
import { DynamicInput, type DynamicInputFocusEvent } from '$lib/index.js';
|
|
77
84
|
|
|
78
85
|
let {
|
|
@@ -90,6 +97,9 @@
|
|
|
90
97
|
onpaste,
|
|
91
98
|
oncopy,
|
|
92
99
|
oncut,
|
|
100
|
+
onkeydown,
|
|
101
|
+
onkeypress,
|
|
102
|
+
onkeyup,
|
|
93
103
|
before,
|
|
94
104
|
after,
|
|
95
105
|
customPasswordToggleIcon,
|
|
@@ -111,7 +121,6 @@
|
|
|
111
121
|
|
|
112
122
|
function onfocusMod(e: DynamicInputFocusEvent) {
|
|
113
123
|
const eTyped = e as TextInputFocusEvent;
|
|
114
|
-
focused = true;
|
|
115
124
|
|
|
116
125
|
if (onfocus) {
|
|
117
126
|
onfocus(eTyped);
|
|
@@ -120,7 +129,6 @@
|
|
|
120
129
|
|
|
121
130
|
function onblurMod(e: DynamicInputFocusEvent) {
|
|
122
131
|
const eTyped = e as TextInputFocusEvent;
|
|
123
|
-
focused = false;
|
|
124
132
|
|
|
125
133
|
if (onblur) {
|
|
126
134
|
onblur(eTyped);
|
|
@@ -156,6 +164,7 @@
|
|
|
156
164
|
{id}
|
|
157
165
|
{disabled}
|
|
158
166
|
bind:ref
|
|
167
|
+
bind:focused
|
|
159
168
|
{oninput}
|
|
160
169
|
{onchange}
|
|
161
170
|
onfocus={onfocusMod}
|
|
@@ -163,6 +172,9 @@
|
|
|
163
172
|
{onpaste}
|
|
164
173
|
{oncopy}
|
|
165
174
|
{oncut}
|
|
175
|
+
onkeydown={onkeydown ? (e) => onkeydown(e as TextInputKeyboardEvent) : undefined}
|
|
176
|
+
onkeypress={onkeypress ? (e) => onkeypress(e as TextInputKeyboardEvent) : undefined}
|
|
177
|
+
onkeyup={onkeyup ? (e) => onkeyup(e as TextInputKeyboardEvent) : undefined}
|
|
166
178
|
{placeholder}
|
|
167
179
|
bind:value
|
|
168
180
|
{readonly}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script module>
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import PasswordInput from '../PasswordInput.svelte';
|
|
4
|
+
import { storyPasswordInputArgTypes } from '../PasswordInput.stories.svelte';
|
|
5
|
+
|
|
6
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
7
|
+
const { Story } = defineMeta({
|
|
8
|
+
component: PasswordInput,
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
argTypes: storyPasswordInputArgTypes,
|
|
11
|
+
});
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<Story name="Roundness 1" />
|
|
15
|
+
|
|
16
|
+
<Story name="Roundness 2" args={{ roundness: 2 }} />
|
|
17
|
+
|
|
18
|
+
<Story name="Roundness 3" args={{ roundness: 3 }} />
|
|
19
|
+
|
|
20
|
+
<Story name="Roundness 0" args={{ roundness: 0 }} />
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script module>
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import PasswordInput from '../PasswordInput.svelte';
|
|
4
|
+
import { storyPasswordInputArgTypes } from '../PasswordInput.stories.svelte';
|
|
5
|
+
|
|
6
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
7
|
+
const { Story } = defineMeta({
|
|
8
|
+
component: PasswordInput,
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
argTypes: storyPasswordInputArgTypes,
|
|
11
|
+
});
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<Story name="Normal" />
|
|
15
|
+
<Story name="Small" args={{ size: 'small' }} />
|
|
16
|
+
<Story name="Large" args={{ size: 'large' }} />
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<script module>
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import PasswordInput from '../PasswordInput.svelte';
|
|
4
|
+
import { storyPasswordInputArgTypes } from '../PasswordInput.stories.svelte';
|
|
5
|
+
import Icon from '@iconify/svelte';
|
|
6
|
+
|
|
7
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
8
|
+
const { Story } = defineMeta({
|
|
9
|
+
component: PasswordInput,
|
|
10
|
+
tags: ['autodocs'],
|
|
11
|
+
argTypes: storyPasswordInputArgTypes,
|
|
12
|
+
});
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<!-- PasswordInput icon in front. -->
|
|
16
|
+
<Story name="Icon Before" asChild>
|
|
17
|
+
<PasswordInput>
|
|
18
|
+
{#snippet before()}
|
|
19
|
+
<Icon icon="material-symbols:content-copy" />
|
|
20
|
+
{/snippet}
|
|
21
|
+
</PasswordInput>
|
|
22
|
+
</Story>
|
|
23
|
+
|
|
24
|
+
<!-- PasswordInput icon in front. -->
|
|
25
|
+
<Story name="Icon After" asChild>
|
|
26
|
+
<PasswordInput>
|
|
27
|
+
{#snippet after()}
|
|
28
|
+
<Icon icon="material-symbols:download-2" />
|
|
29
|
+
{/snippet}
|
|
30
|
+
</PasswordInput>
|
|
31
|
+
</Story>
|