@flightlesslabs/dodo-ui 0.8.0 → 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.
Files changed (54) hide show
  1. package/dist/index.d.ts +13 -2
  2. package/dist/index.js +8 -0
  3. package/dist/stories/components/Form/NumericInput/Events/Events.stories.svelte +126 -0
  4. package/dist/stories/components/Form/NumericInput/Events/Events.stories.svelte.d.ts +18 -0
  5. package/dist/stories/components/Form/NumericInput/NumericInput.stories.svelte +79 -0
  6. package/dist/stories/components/Form/NumericInput/NumericInput.stories.svelte.d.ts +21 -0
  7. package/dist/stories/components/Form/NumericInput/NumericInput.svelte +161 -0
  8. package/dist/stories/components/Form/NumericInput/NumericInput.svelte.d.ts +69 -0
  9. package/dist/stories/components/Form/NumericInput/Validation/Validation.stories.svelte +84 -0
  10. package/dist/stories/components/Form/NumericInput/Validation/Validation.stories.svelte.d.ts +18 -0
  11. package/dist/stories/components/Form/PasswordInput/Events/Events.stories.svelte +27 -6
  12. package/dist/stories/components/Form/PasswordInput/PasswordInput.svelte +5 -3
  13. package/dist/stories/components/Form/PasswordInput/PasswordInput.svelte.d.ts +7 -1
  14. package/dist/stories/components/Form/Select/Events/Events.stories.svelte +27 -0
  15. package/dist/stories/components/Form/Select/Select.svelte +4 -1
  16. package/dist/stories/components/Form/Select/Select.svelte.d.ts +7 -1
  17. package/dist/stories/components/Form/TextInput/Events/Events.stories.svelte +27 -0
  18. package/dist/stories/components/Form/TextInput/TextInput.svelte +5 -3
  19. package/dist/stories/components/Form/TextInput/TextInput.svelte.d.ts +10 -1
  20. package/dist/stories/components/Layout/Menu/DynamicMenu/DynamicMenu.svelte +1 -1
  21. package/dist/stories/developer tools/components/DynamicInput/DynamicInput.svelte +23 -5
  22. package/dist/stories/developer tools/components/DynamicInput/DynamicInput.svelte.d.ts +13 -2
  23. package/dist/stories/developer tools/components/DynamicInput/Events/Events.stories.svelte +115 -0
  24. package/dist/stories/developer tools/components/DynamicInput/Events/Events.stories.svelte.d.ts +18 -0
  25. package/dist/stories/developer tools/helpers/Numbers/cleanNumericString/cleanNumericString.d.ts +13 -0
  26. package/dist/stories/developer tools/helpers/Numbers/cleanNumericString/cleanNumericString.js +26 -0
  27. package/dist/stories/developer tools/helpers/Numbers/cleanNumericString/index.mdx +20 -0
  28. package/dist/stories/developer tools/helpers/Numbers/isValidNumberValue/index.mdx +71 -0
  29. package/dist/stories/developer tools/helpers/Numbers/isValidNumberValue/isValidNumberValue.d.ts +51 -0
  30. package/dist/stories/developer tools/helpers/Numbers/isValidNumberValue/isValidNumberValue.js +96 -0
  31. package/dist/stories/developer tools/helpers/logger/index.mdx +63 -0
  32. package/dist/stories/developer tools/helpers/logger/logger.d.ts +24 -0
  33. package/dist/stories/developer tools/helpers/logger/logger.js +31 -0
  34. package/package.json +1 -1
  35. package/src/lib/index.ts +20 -0
  36. package/src/lib/stories/components/Form/NumericInput/Events/Events.stories.svelte +134 -0
  37. package/src/lib/stories/components/Form/NumericInput/NumericInput.stories.svelte +84 -0
  38. package/src/lib/stories/components/Form/NumericInput/NumericInput.svelte +286 -0
  39. package/src/lib/stories/components/Form/NumericInput/Validation/Validation.stories.svelte +87 -0
  40. package/src/lib/stories/components/Form/PasswordInput/Events/Events.stories.svelte +28 -6
  41. package/src/lib/stories/components/Form/PasswordInput/PasswordInput.svelte +15 -3
  42. package/src/lib/stories/components/Form/Select/Events/Events.stories.svelte +31 -1
  43. package/src/lib/stories/components/Form/Select/Select.svelte +13 -0
  44. package/src/lib/stories/components/Form/TextInput/Events/Events.stories.svelte +28 -0
  45. package/src/lib/stories/components/Form/TextInput/TextInput.svelte +18 -3
  46. package/src/lib/stories/components/Layout/Menu/DynamicMenu/DynamicMenu.svelte +1 -1
  47. package/src/lib/stories/developer tools/components/DynamicInput/DynamicInput.svelte +43 -4
  48. package/src/lib/stories/developer tools/components/DynamicInput/Events/Events.stories.svelte +121 -0
  49. package/src/lib/stories/developer tools/helpers/Numbers/cleanNumericString/cleanNumericString.ts +27 -0
  50. package/src/lib/stories/developer tools/helpers/Numbers/cleanNumericString/index.mdx +20 -0
  51. package/src/lib/stories/developer tools/helpers/Numbers/isValidNumberValue/index.mdx +71 -0
  52. package/src/lib/stories/developer tools/helpers/Numbers/isValidNumberValue/isValidNumberValue.ts +156 -0
  53. package/src/lib/stories/developer tools/helpers/logger/index.mdx +63 -0
  54. package/src/lib/stories/developer tools/helpers/logger/logger.ts +46 -0
package/dist/index.d.ts CHANGED
@@ -4,6 +4,14 @@ export type { ComponentRoundness } from './types/roundness.js';
4
4
  export type { ComponentSize } from './types/size.js';
5
5
  export type { ComponentWeight } from './types/weight.js';
6
6
  export type { PositionY, PositionX } from './types/position.js';
7
+ /** developer tools: helpers: logger */
8
+ export { default as createLogger } from './stories/developer tools/helpers/logger/logger.js';
9
+ export type { LogLevel, LoggerOptions, } from './stories/developer tools/helpers/logger/logger.js';
10
+ /** developer tools: helpers: Numbers: isValidNumberValue */
11
+ export { default as isValidNumberValue } from './stories/developer tools/helpers/Numbers/isValidNumberValue/isValidNumberValue.js';
12
+ export type { IsValidNumberValueSettings } from './stories/developer tools/helpers/Numbers/isValidNumberValue/isValidNumberValue.js';
13
+ /** developer tools: helpers: Numbers: cleanNumericString */
14
+ export { default as cleanNumericString } from './stories/developer tools/helpers/Numbers/cleanNumericString/cleanNumericString.js';
7
15
  /** developer tools: directives: clickOutside */
8
16
  export { clickOutside } from './stories/developer tools/directives/clickOutside/clickOutside.js';
9
17
  /** developer tools: components: UtilityButton */
@@ -14,7 +22,7 @@ export { default as InputEnclosure } from './stories/developer tools/components/
14
22
  export type { InputEnclosureProps } from './stories/developer tools/components/InputEnclosure/InputEnclosure.svelte';
15
23
  /** developer tools: components: DynamicInput */
16
24
  export { default as DynamicInput } from './stories/developer tools/components/DynamicInput/DynamicInput.svelte';
17
- export type { DynamicInputVariant, DynamicInputProps, DynamicInputClickEvent, DynamicInputFocusEvent, } from './stories/developer tools/components/DynamicInput/DynamicInput.svelte';
25
+ export type { DynamicInputVariant, DynamicInputProps, DynamicInputClickEvent, DynamicInputFocusEvent, DynamicInputKeyboardEvent, } from './stories/developer tools/components/DynamicInput/DynamicInput.svelte';
18
26
  /** developer tools: components: Popper */
19
27
  export { default as Popper } from './stories/developer tools/components/Popper/Popper.svelte';
20
28
  export type { PopperProps } from './stories/developer tools/components/Popper/Popper.svelte';
@@ -25,7 +33,7 @@ export { default as Button } from './stories/components/Form/Button/Button.svelt
25
33
  export type { ButtonLinkTarget, ButtonLinkReferrerpolicy, ButtonType, ButtonProps, ButtonClickEvent, } from './stories/components/Form/Button/Button.svelte';
26
34
  /** Form: TextInput */
27
35
  export { default as TextInput } from './stories/components/Form/TextInput/TextInput.svelte';
28
- export type { TextInputType, TextInputFocusEvent, TextInputClipboardEvent, TextInputInputEvent, TextInputProps, } from './stories/components/Form/TextInput/TextInput.svelte';
36
+ export type { TextInputType, TextInputFocusEvent, TextInputClipboardEvent, TextInputInputEvent, TextInputKeyboardEvent, TextInputProps, } from './stories/components/Form/TextInput/TextInput.svelte';
29
37
  /** Form: PasswordInput */
30
38
  export { default as PasswordInput } from './stories/components/Form/PasswordInput/PasswordInput.svelte';
31
39
  export type { PasswordInputToggleEvent, PasswordInputProps, } from './stories/components/Form/PasswordInput/PasswordInput.svelte';
@@ -41,6 +49,9 @@ export type { MessageProps } from './stories/components/Form/Message/Message.sve
41
49
  /** Form: Select */
42
50
  export { default as Select } from './stories/components/Form/Select/Select.svelte';
43
51
  export type { SelectOption, SelectDropdownArrowPosition, SelectProps, } from './stories/components/Form/Select/Select.svelte';
52
+ /** Form: NumericInput */
53
+ export { default as NumericInput } from './stories/components/Form/NumericInput/NumericInput.svelte';
54
+ export type { NumericInputProps } from './stories/components/Form/NumericInput/NumericInput.svelte';
44
55
  /** Layout: Paper */
45
56
  export { default as Paper } from './stories/components/Layout/Paper/Paper.svelte';
46
57
  export type { PaperColor, PaperProps } from './stories/components/Layout/Paper/Paper.svelte';
package/dist/index.js CHANGED
@@ -1,4 +1,10 @@
1
1
  import './styles/global.css';
2
+ /** developer tools: helpers: logger */
3
+ export { default as createLogger } from './stories/developer tools/helpers/logger/logger.js';
4
+ /** developer tools: helpers: Numbers: isValidNumberValue */
5
+ export { default as isValidNumberValue } from './stories/developer tools/helpers/Numbers/isValidNumberValue/isValidNumberValue.js';
6
+ /** developer tools: helpers: Numbers: cleanNumericString */
7
+ export { default as cleanNumericString } from './stories/developer tools/helpers/Numbers/cleanNumericString/cleanNumericString.js';
2
8
  /** developer tools: directives: clickOutside */
3
9
  export { clickOutside } from './stories/developer tools/directives/clickOutside/clickOutside.js';
4
10
  /** developer tools: components: UtilityButton */
@@ -24,6 +30,8 @@ export { default as FormControl } from './stories/components/Form/FormControl/Fo
24
30
  export { default as Message } from './stories/components/Form/Message/Message.svelte';
25
31
  /** Form: Select */
26
32
  export { default as Select } from './stories/components/Form/Select/Select.svelte';
33
+ /** Form: NumericInput */
34
+ export { default as NumericInput } from './stories/components/Form/NumericInput/NumericInput.svelte';
27
35
  /** Layout: Paper */
28
36
  export { default as Paper } from './stories/components/Layout/Paper/Paper.svelte';
29
37
  /** Layout: Separator */
@@ -0,0 +1,126 @@
1
+ <script module lang="ts">import { defineMeta } from '@storybook/addon-svelte-csf';
2
+ import { storyNumericInputArgTypes } from '../NumericInput.stories.svelte';
3
+ import NumericInput from '../NumericInput.svelte';
4
+ // More on how to set up stories at: https://storybook.js.org/docs/writing-stories
5
+ const { Story } = defineMeta({
6
+ component: NumericInput,
7
+ tags: ['autodocs'],
8
+ argTypes: storyNumericInputArgTypes,
9
+ });
10
+ let value = $state(0);
11
+ </script>
12
+
13
+ <!-- Use this event to get filtered numeric value -->
14
+ <Story
15
+ name="NumericValueChange"
16
+ args={{
17
+ value,
18
+ onValueChange: (val: number | undefined) => {
19
+ value = val;
20
+ },
21
+ }}
22
+ />
23
+
24
+ <Story
25
+ name="Input"
26
+ args={{
27
+ oninput: (e: Event) => {
28
+ const target = e.target as HTMLInputElement;
29
+
30
+ console.log('Input Event', target.value);
31
+ },
32
+ }}
33
+ />
34
+
35
+ <Story
36
+ name="Change"
37
+ args={{
38
+ onchange: (e: Event) => {
39
+ const target = e.target as HTMLInputElement;
40
+
41
+ console.log('onChange Event', target.value);
42
+ },
43
+ }}
44
+ />
45
+
46
+ <Story
47
+ name="Focus"
48
+ args={{
49
+ onfocus: (e: TextInputFocusEvent) => {
50
+ const target = e.target as HTMLInputElement;
51
+
52
+ console.log('onfocus Event', target);
53
+ },
54
+ }}
55
+ />
56
+
57
+ <Story
58
+ name="Blur"
59
+ args={{
60
+ onblur: (e: TextInputFocusEvent) => {
61
+ const target = e.target as HTMLInputElement;
62
+
63
+ console.log('onblur Event', target);
64
+ },
65
+ }}
66
+ />
67
+
68
+ <Story
69
+ name="Copy"
70
+ args={{
71
+ oncopy: (e: TextInputClipboardEvent) => {
72
+ const target = e.target as HTMLInputElement;
73
+
74
+ console.log('oncopy Event', target);
75
+ },
76
+ }}
77
+ />
78
+
79
+ <Story
80
+ name="Cut"
81
+ args={{
82
+ oncut: (e: TextInputClipboardEvent) => {
83
+ const target = e.target as HTMLInputElement;
84
+
85
+ console.log('oncut Event', target);
86
+ },
87
+ }}
88
+ />
89
+
90
+ <Story
91
+ name="Paste"
92
+ args={{
93
+ onpaste: (e: TextInputClipboardEvent) => {
94
+ const target = e.target as HTMLInputElement;
95
+
96
+ console.log('onpaste Event', target);
97
+ },
98
+ }}
99
+ />
100
+
101
+ <Story
102
+ name="KeyDown"
103
+ args={{
104
+ onkeydown: (e: TextInputKeyboardEvent) => {
105
+ console.log('onkeydown Event', e.key);
106
+ },
107
+ }}
108
+ />
109
+
110
+ <Story
111
+ name="KeyPress"
112
+ args={{
113
+ onkeypress: (e: TextInputKeyboardEvent) => {
114
+ console.log('onkeypress Event', e.key);
115
+ },
116
+ }}
117
+ />
118
+
119
+ <Story
120
+ name="KeyUp"
121
+ args={{
122
+ onkeyup: (e: TextInputKeyboardEvent) => {
123
+ console.log('onkeyup Event', e.key);
124
+ },
125
+ }}
126
+ />
@@ -0,0 +1,18 @@
1
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
2
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
+ $$bindings?: Bindings;
4
+ } & Exports;
5
+ (internal: unknown, props: {
6
+ $$events?: Events;
7
+ $$slots?: Slots;
8
+ }): Exports & {
9
+ $set?: any;
10
+ $on?: any;
11
+ };
12
+ z_$$bindings?: Bindings;
13
+ }
14
+ declare const Events: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
15
+ [evt: string]: CustomEvent<any>;
16
+ }, {}, {}, string>;
17
+ type Events = InstanceType<typeof Events>;
18
+ export default Events;
@@ -0,0 +1,79 @@
1
+ <script module lang="ts">import { defineMeta } from '@storybook/addon-svelte-csf';
2
+ import NumericInput from './NumericInput.svelte';
3
+ import { componentRoundnessArray } from '../../../../types/roundness.js';
4
+ import { componentSizeArray } from '../../../../types/size.js';
5
+ export const storyNumericInputArgTypes = {
6
+ roundness: {
7
+ control: { type: 'select' },
8
+ options: componentRoundnessArray,
9
+ },
10
+ size: {
11
+ control: { type: 'select' },
12
+ options: componentSizeArray,
13
+ },
14
+ };
15
+ // More on how to set up stories at: https://storybook.js.org/docs/writing-stories
16
+ const { Story } = defineMeta({
17
+ component: NumericInput,
18
+ tags: ['autodocs'],
19
+ argTypes: storyNumericInputArgTypes,
20
+ });
21
+ let value = $state(0);
22
+ </script>
23
+
24
+ <!-- NumericInput with default style -->
25
+ <Story
26
+ name="Default"
27
+ args={{
28
+ value,
29
+ onValueChange: (val) => {
30
+ value = val;
31
+ },
32
+ }}
33
+ />
34
+
35
+ <Story name="Placeholder" args={{ value: undefined, placeholder: 'Type something...' }} />
36
+
37
+ <Story
38
+ name="No Outline"
39
+ args={{
40
+ outline: false,
41
+ value,
42
+ onValueChange: (val) => {
43
+ value = val;
44
+ },
45
+ }}
46
+ />
47
+
48
+ <Story
49
+ name="Error"
50
+ args={{
51
+ error: true,
52
+ value,
53
+ onValueChange: (val) => {
54
+ value = val;
55
+ },
56
+ }}
57
+ />
58
+
59
+ <Story
60
+ name="Disabled"
61
+ args={{
62
+ disabled: true,
63
+ value,
64
+ onValueChange: (val) => {
65
+ value = val;
66
+ },
67
+ }}
68
+ />
69
+
70
+ <Story
71
+ name="Read only"
72
+ args={{
73
+ readonly: true,
74
+ value,
75
+ onValueChange: (val) => {
76
+ value = val;
77
+ },
78
+ }}
79
+ />
@@ -0,0 +1,21 @@
1
+ import NumericInput from './NumericInput.svelte';
2
+ import type { StoryBookArgTypes } from '../../../../storybook-types.js';
3
+ export declare const storyNumericInputArgTypes: StoryBookArgTypes;
4
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
5
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
6
+ $$bindings?: Bindings;
7
+ } & Exports;
8
+ (internal: unknown, props: {
9
+ $$events?: Events;
10
+ $$slots?: Slots;
11
+ }): Exports & {
12
+ $set?: any;
13
+ $on?: any;
14
+ };
15
+ z_$$bindings?: Bindings;
16
+ }
17
+ declare const NumericInput: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
18
+ [evt: string]: CustomEvent<any>;
19
+ }, {}, {}, string>;
20
+ type NumericInput = InstanceType<typeof NumericInput>;
21
+ export default NumericInput;
@@ -0,0 +1,161 @@
1
+ <script lang="ts" module>import {} from 'svelte';
2
+ </script>
3
+
4
+ <script lang="ts">import InputEnclosure from '../../../developer tools/components/InputEnclosure/InputEnclosure.svelte';
5
+ import DynamicInput, {} from '../../../developer tools/components/DynamicInput/DynamicInput.svelte';
6
+ import isValidNumberValue from '../../../developer tools/helpers/Numbers/isValidNumberValue/isValidNumberValue.js';
7
+ let { size = 'normal', roundness = 1, outline = true, name, id, class: className = '', disabled = false, oninput, onchange, onblur, onfocus, onpaste, oncopy, oncut, onkeydown, onkeypress, onkeyup, before, after, error = false, value: valueRaw, placeholder, ref = $bindable(), readonly = false, decimalPlaces = 0, allowNegativeValues = false, min, max, log = false, onValueChange, } = $props();
8
+ let value = $state('');
9
+ let cachedValue = $state('');
10
+ let focused = $state(false);
11
+ function onfocusMod(e) {
12
+ const eTyped = e;
13
+ if (onfocus) {
14
+ onfocus(eTyped);
15
+ }
16
+ }
17
+ function onblurMod(e) {
18
+ const eTyped = e;
19
+ const isValidWithoutMinMax = isValidNumberValue(`${value}`, {
20
+ decimalPlaces,
21
+ allowNegativeValues,
22
+ log,
23
+ });
24
+ const isValid = isValidNumberValue(`${value}`, {
25
+ decimalPlaces,
26
+ allowNegativeValues,
27
+ log,
28
+ min,
29
+ max,
30
+ });
31
+ if (isValid) {
32
+ if (onValueChange) {
33
+ onValueChange(Number(value));
34
+ }
35
+ value = `${Number(value)}`;
36
+ cachedValue = `${Number(value)}`;
37
+ }
38
+ else if (isValidWithoutMinMax) {
39
+ if (min && Number(value) < min) {
40
+ if (onValueChange) {
41
+ onValueChange(min);
42
+ }
43
+ value = `${min}`;
44
+ cachedValue = `${min}`;
45
+ }
46
+ else if (max && Number(value) > max) {
47
+ if (onValueChange) {
48
+ onValueChange(max);
49
+ }
50
+ value = `${max}`;
51
+ cachedValue = `${max}`;
52
+ }
53
+ }
54
+ else if (value.trim() === '') {
55
+ if (onValueChange) {
56
+ onValueChange(undefined);
57
+ }
58
+ value = '';
59
+ cachedValue = '';
60
+ }
61
+ else if (valueRaw || valueRaw === 0) {
62
+ if (onValueChange) {
63
+ onValueChange(valueRaw);
64
+ }
65
+ value = `${valueRaw}`;
66
+ cachedValue = `${valueRaw}`;
67
+ }
68
+ else {
69
+ if (onValueChange) {
70
+ onValueChange(undefined);
71
+ }
72
+ value = '';
73
+ cachedValue = '';
74
+ }
75
+ if (onblur) {
76
+ onblur(eTyped);
77
+ }
78
+ }
79
+ function onkeydownMod(e) {
80
+ if (onkeydown) {
81
+ onkeydown(e);
82
+ }
83
+ if (e.ctrlKey && e.key.toLocaleLowerCase() === 'c') {
84
+ return;
85
+ }
86
+ else if (e.ctrlKey && e.key.toLocaleLowerCase() === 'v') {
87
+ return;
88
+ }
89
+ else if (e.ctrlKey && e.key.toLocaleLowerCase() === 'x') {
90
+ return;
91
+ }
92
+ const valueToCheck = `${value}${e.key.length === 1 ? e.key : ''}`;
93
+ const isValid = isValidNumberValue(valueToCheck, {
94
+ decimalPlaces,
95
+ allowNegativeValues,
96
+ log,
97
+ strict: false,
98
+ });
99
+ if (!isValid) {
100
+ e.preventDefault();
101
+ value = cachedValue;
102
+ }
103
+ else {
104
+ cachedValue = valueToCheck;
105
+ }
106
+ }
107
+ $effect(() => {
108
+ let updatedValue = '';
109
+ const isValid = isValidNumberValue(`${valueRaw}`, {
110
+ decimalPlaces,
111
+ allowNegativeValues,
112
+ min,
113
+ max,
114
+ log,
115
+ });
116
+ if (valueRaw === undefined) {
117
+ updatedValue = '';
118
+ }
119
+ else if (!isValid) {
120
+ updatedValue = '';
121
+ }
122
+ else {
123
+ updatedValue = `${valueRaw}`;
124
+ }
125
+ value = updatedValue;
126
+ cachedValue = updatedValue;
127
+ });
128
+ </script>
129
+
130
+ <div
131
+ class:outline
132
+ class:disabled
133
+ class:error
134
+ class:focused
135
+ class={['dodo-ui-NumericInput', `size--${size}`, `roundness--${roundness}`, className].join(' ')}
136
+ >
137
+ <InputEnclosure {outline} {disabled} {error} {focused} {size} {roundness} {before} {after}>
138
+ <DynamicInput
139
+ type="text"
140
+ {name}
141
+ {id}
142
+ {disabled}
143
+ bind:ref
144
+ bind:focused
145
+ {oninput}
146
+ {onchange}
147
+ onfocus={onfocusMod}
148
+ onblur={onblurMod}
149
+ {onpaste}
150
+ {oncopy}
151
+ {oncut}
152
+ onkeydown={onkeydownMod}
153
+ onkeypress={onkeypress ? (e) => onkeypress(e as TextInputKeyboardEvent) : undefined}
154
+ onkeyup={onkeyup ? (e) => onkeyup(e as TextInputKeyboardEvent) : undefined}
155
+ {placeholder}
156
+ {readonly}
157
+ variant="input"
158
+ bind:value
159
+ />
160
+ </InputEnclosure>
161
+ </div>
@@ -0,0 +1,69 @@
1
+ import type { ComponentRoundness } from '../../../../types/roundness.js';
2
+ import type { ComponentSize } from '../../../../types/size.js';
3
+ import { type Snippet } from 'svelte';
4
+ import type { ChangeEventHandler, ClipboardEventHandler, FocusEventHandler, FormEventHandler, KeyboardEventHandler } from 'svelte/elements';
5
+ export interface NumericInputProps {
6
+ /** min */
7
+ min?: number;
8
+ /** max */
9
+ max?: number;
10
+ /** Allow Negative Values */
11
+ allowNegativeValues?: boolean;
12
+ /** Decimal Places */
13
+ decimalPlaces?: number;
14
+ /** Log number validations */
15
+ log?: boolean;
16
+ /** Input ref */
17
+ ref?: HTMLInputElement;
18
+ /** How large should the button be? */
19
+ size?: ComponentSize;
20
+ /** How round should the border radius be? */
21
+ roundness?: ComponentRoundness;
22
+ /** Add a border around the button. Default True */
23
+ outline?: boolean;
24
+ /** Input value */
25
+ value?: number;
26
+ /** How round should the border radius be? */
27
+ placeholder?: string;
28
+ /** disabled state */
29
+ disabled?: boolean;
30
+ /** Read only ? */
31
+ readonly?: boolean;
32
+ /** is there any associated Error ? */
33
+ error?: boolean;
34
+ /** Name */
35
+ name?: string;
36
+ /** Id */
37
+ id?: string;
38
+ /** Icon before button content */
39
+ before?: Snippet;
40
+ /** Icon after button content */
41
+ after?: Snippet;
42
+ /** Custom css class*/
43
+ class?: string;
44
+ /** on Numeric Value Change */
45
+ onValueChange?: (value: number | undefined) => void;
46
+ /** oninput event handler */
47
+ oninput?: FormEventHandler<HTMLInputElement>;
48
+ /** onchange event handler */
49
+ onchange?: ChangeEventHandler<HTMLInputElement>;
50
+ /** onblur event handler */
51
+ onblur?: FocusEventHandler<HTMLInputElement>;
52
+ /** onfocus event handler */
53
+ onfocus?: FocusEventHandler<HTMLInputElement>;
54
+ /** onpaste event handler */
55
+ onpaste?: ClipboardEventHandler<HTMLInputElement>;
56
+ /** oncopy event handler */
57
+ oncopy?: ClipboardEventHandler<HTMLInputElement>;
58
+ /** oncut event handler */
59
+ oncut?: ClipboardEventHandler<HTMLInputElement>;
60
+ /** onkeydown event handler */
61
+ onkeydown?: KeyboardEventHandler<HTMLInputElement>;
62
+ /** onkeypress event handler */
63
+ onkeypress?: KeyboardEventHandler<HTMLInputElement>;
64
+ /** onkeyup event handler */
65
+ onkeyup?: KeyboardEventHandler<HTMLInputElement>;
66
+ }
67
+ declare const NumericInput: import("svelte").Component<NumericInputProps, {}, "ref">;
68
+ type NumericInput = ReturnType<typeof NumericInput>;
69
+ export default NumericInput;
@@ -0,0 +1,84 @@
1
+ <script module lang="ts">import { defineMeta } from '@storybook/addon-svelte-csf';
2
+ import NumericInput from '../NumericInput.svelte';
3
+ import { storyNumericInputArgTypes } from '../NumericInput.stories.svelte';
4
+ // More on how to set up stories at: https://storybook.js.org/docs/writing-stories
5
+ const { Story } = defineMeta({
6
+ component: NumericInput,
7
+ tags: ['autodocs'],
8
+ argTypes: storyNumericInputArgTypes,
9
+ });
10
+ let value = $state(0);
11
+ </script>
12
+
13
+ <!-- NumericInput with default style -->
14
+ <Story
15
+ name="Default"
16
+ args={{
17
+ value,
18
+ onValueChange: (val) => {
19
+ value = val;
20
+ },
21
+ }}
22
+ />
23
+
24
+ <!-- Min, In this case min is set to 25 -->
25
+ <Story
26
+ name="Min"
27
+ args={{
28
+ value,
29
+ onValueChange: (val) => {
30
+ console.log(val);
31
+
32
+ value = val;
33
+ },
34
+ min: 25,
35
+ }}
36
+ />
37
+
38
+ <!-- Max, In this case max is set to 25 -->
39
+ <Story
40
+ name="Max"
41
+ args={{
42
+ value,
43
+ onValueChange: (val) => {
44
+ value = val;
45
+ },
46
+ max: 25,
47
+ }}
48
+ />
49
+
50
+ <!-- Allow Negative values -->
51
+ <Story
52
+ name="AllowNegativeValues"
53
+ args={{
54
+ value,
55
+ onValueChange: (val) => {
56
+ value = val;
57
+ },
58
+ allowNegativeValues: true,
59
+ }}
60
+ />
61
+
62
+ <!-- Decimal Places -->
63
+ <Story
64
+ name="DecimalPlaces"
65
+ args={{
66
+ value,
67
+ onValueChange: (val) => {
68
+ value = val;
69
+ },
70
+ decimalPlaces: 2,
71
+ }}
72
+ />
73
+
74
+ <!-- Log validations, check console -->
75
+ <Story
76
+ name="LogValidations"
77
+ args={{
78
+ value,
79
+ onValueChange: (val) => {
80
+ value = val;
81
+ },
82
+ log: true,
83
+ }}
84
+ />
@@ -0,0 +1,18 @@
1
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
2
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
+ $$bindings?: Bindings;
4
+ } & Exports;
5
+ (internal: unknown, props: {
6
+ $$events?: Events;
7
+ $$slots?: Slots;
8
+ }): Exports & {
9
+ $set?: any;
10
+ $on?: any;
11
+ };
12
+ z_$$bindings?: Bindings;
13
+ }
14
+ declare const Validation: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
15
+ [evt: string]: CustomEvent<any>;
16
+ }, {}, {}, string>;
17
+ type Validation = InstanceType<typeof Validation>;
18
+ export default Validation;