@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.
- package/dist/index.d.ts +13 -2
- package/dist/index.js +8 -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/Events/Events.stories.svelte +27 -0
- package/dist/stories/components/Form/Select/Select.svelte +4 -1
- package/dist/stories/components/Form/Select/Select.svelte.d.ts +7 -1
- 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/DynamicMenu.svelte +1 -1
- package/dist/stories/developer tools/components/DynamicInput/DynamicInput.svelte +23 -5
- 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 +1 -1
- package/src/lib/index.ts +20 -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 +28 -6
- package/src/lib/stories/components/Form/PasswordInput/PasswordInput.svelte +15 -3
- package/src/lib/stories/components/Form/Select/Events/Events.stories.svelte +31 -1
- package/src/lib/stories/components/Form/Select/Select.svelte +13 -0
- package/src/lib/stories/components/Form/TextInput/Events/Events.stories.svelte +28 -0
- package/src/lib/stories/components/Form/TextInput/TextInput.svelte +18 -3
- package/src/lib/stories/components/Layout/Menu/DynamicMenu/DynamicMenu.svelte +1 -1
- package/src/lib/stories/developer tools/components/DynamicInput/DynamicInput.svelte +43 -4
- package/src/lib/stories/developer tools/components/DynamicInput/Events/Events.stories.svelte +121 -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
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Source } from '@storybook/blocks';
|
|
2
|
+
|
|
3
|
+
# isValidNumberValue
|
|
4
|
+
|
|
5
|
+
Utility function to validate whether a string is a valid number based on customizable settings including minimum, maximum, decimal places, and allowance of negative numbers.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Basic Usage
|
|
10
|
+
|
|
11
|
+
Validates a string as a number with default settings (no decimals allowed, no negatives allowed, strict checking):
|
|
12
|
+
|
|
13
|
+
<Source
|
|
14
|
+
dark
|
|
15
|
+
language="ts"
|
|
16
|
+
code={`
|
|
17
|
+
import { isValidNumberValue } from '@flightlesslabs/dodo-ui';
|
|
18
|
+
|
|
19
|
+
const result = isValidNumberValue("123");
|
|
20
|
+
console.log(result); // true
|
|
21
|
+
`}
|
|
22
|
+
/>
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## With Settings
|
|
27
|
+
|
|
28
|
+
Customize validation rules:
|
|
29
|
+
|
|
30
|
+
- `min` — minimum allowed value (inclusive)
|
|
31
|
+
- `max` — maximum allowed value (inclusive)
|
|
32
|
+
- `allowNegativeValues` — whether negatives are allowed
|
|
33
|
+
- `decimalPlaces` — max decimal places allowed
|
|
34
|
+
- `log` — enable detailed logging
|
|
35
|
+
- `strict` — Strict checking, Full text - keep it enabled, Partial text - keep it disabled
|
|
36
|
+
|
|
37
|
+
<Source
|
|
38
|
+
dark
|
|
39
|
+
language="ts"
|
|
40
|
+
code={`
|
|
41
|
+
import { isValidNumberValue } from '@flightlesslabs/dodo-ui';
|
|
42
|
+
|
|
43
|
+
const result1 = isValidNumberValue("123.456", { decimalPlaces: 3, log: true });
|
|
44
|
+
const result2 = isValidNumberValue("-50", { allowNegativeValues: true, min: -100 });
|
|
45
|
+
const result3 = isValidNumberValue("200", { max: 150 });
|
|
46
|
+
|
|
47
|
+
const result4 = isValidNumberValue("-", { allowNegativeValues: true });
|
|
48
|
+
const result5 = isValidNumberValue("-", { allowNegativeValues: true, strict: false });
|
|
49
|
+
|
|
50
|
+
console.log(result1); // true
|
|
51
|
+
console.log(result2); // true
|
|
52
|
+
console.log(result3); // false (exceeds max)
|
|
53
|
+
console.log(result4); // false (fails in strict check)
|
|
54
|
+
console.log(result5); // true (pass in strict check)
|
|
55
|
+
`}
|
|
56
|
+
/>
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Type Definition
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
export type IsValidNumberValueSettings = {
|
|
64
|
+
min?: number;
|
|
65
|
+
max?: number;
|
|
66
|
+
allowNegativeValues?: boolean;
|
|
67
|
+
decimalPlaces?: number;
|
|
68
|
+
log?: boolean;
|
|
69
|
+
strict?: boolean;
|
|
70
|
+
};
|
|
71
|
+
```
|
package/dist/stories/developer tools/helpers/Numbers/isValidNumberValue/isValidNumberValue.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type IsValidNumberValueSettings = {
|
|
2
|
+
/**
|
|
3
|
+
* Minimum allowed numeric value (inclusive).
|
|
4
|
+
*/
|
|
5
|
+
min?: number;
|
|
6
|
+
/**
|
|
7
|
+
* Maximum allowed numeric value (inclusive).
|
|
8
|
+
*/
|
|
9
|
+
max?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Whether negative numbers are allowed.
|
|
12
|
+
* Defaults to false.
|
|
13
|
+
*/
|
|
14
|
+
allowNegativeValues?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Maximum allowed decimal places.
|
|
17
|
+
* Defaults to 0 (no decimals allowed).
|
|
18
|
+
*/
|
|
19
|
+
decimalPlaces?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Whether to enable logging.
|
|
22
|
+
* Defaults to false.
|
|
23
|
+
*/
|
|
24
|
+
log?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Strict checking, Full text - keep it enabled, Partial text - keep it disabled
|
|
27
|
+
* Defaults to true.
|
|
28
|
+
*/
|
|
29
|
+
strict?: boolean;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Validates whether a string represents a valid number based on provided settings.
|
|
33
|
+
*
|
|
34
|
+
* @param value - The string to validate as a number.
|
|
35
|
+
* @param settings - Optional validation settings.
|
|
36
|
+
* @param settings.min - Minimum allowed value (inclusive).
|
|
37
|
+
* @param settings.max - Maximum allowed value (inclusive).
|
|
38
|
+
* @param settings.allowNegativeValues - Whether negative numbers are allowed.
|
|
39
|
+
* @param settings.decimalPlaces - Maximum allowed decimal places.
|
|
40
|
+
* @param settings.log - Whether to enable detailed logging.
|
|
41
|
+
* @param settings.strict - Whether to enable Strict checking, Full text - keep it enabled, Partial text - keep it disabled
|
|
42
|
+
*
|
|
43
|
+
* @returns True if the value is a valid number according to the settings; otherwise false.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* isValidNumberValue("123.45", { decimalPlaces: 2, log: true });
|
|
48
|
+
* isValidNumberValue("-50", { allowNegativeValues: true, min: -100 });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export default function isValidNumberValue(value: string, settings?: IsValidNumberValueSettings): boolean;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import createLogger from '../../logger/logger.js';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the input string is a valid numeric string.
|
|
4
|
+
* Allows integers, decimals, negative numbers, and scientific notation.
|
|
5
|
+
*
|
|
6
|
+
* @param str - Input string to validate.
|
|
7
|
+
* @returns True if string is numeric, false otherwise.
|
|
8
|
+
*/
|
|
9
|
+
function isNumericString(str) {
|
|
10
|
+
if (typeof str !== 'string')
|
|
11
|
+
return false;
|
|
12
|
+
const trimmed = str.trim();
|
|
13
|
+
if (trimmed === '')
|
|
14
|
+
return false;
|
|
15
|
+
const num = Number(trimmed);
|
|
16
|
+
return !isNaN(num) && isFinite(num);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Validates whether a string represents a valid number based on provided settings.
|
|
20
|
+
*
|
|
21
|
+
* @param value - The string to validate as a number.
|
|
22
|
+
* @param settings - Optional validation settings.
|
|
23
|
+
* @param settings.min - Minimum allowed value (inclusive).
|
|
24
|
+
* @param settings.max - Maximum allowed value (inclusive).
|
|
25
|
+
* @param settings.allowNegativeValues - Whether negative numbers are allowed.
|
|
26
|
+
* @param settings.decimalPlaces - Maximum allowed decimal places.
|
|
27
|
+
* @param settings.log - Whether to enable detailed logging.
|
|
28
|
+
* @param settings.strict - Whether to enable Strict checking, Full text - keep it enabled, Partial text - keep it disabled
|
|
29
|
+
*
|
|
30
|
+
* @returns True if the value is a valid number according to the settings; otherwise false.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* isValidNumberValue("123.45", { decimalPlaces: 2, log: true });
|
|
35
|
+
* isValidNumberValue("-50", { allowNegativeValues: true, min: -100 });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export default function isValidNumberValue(value, settings) {
|
|
39
|
+
const allowNegativeValues = settings?.allowNegativeValues || false;
|
|
40
|
+
const decimalPlaces = settings?.decimalPlaces || 0;
|
|
41
|
+
const valueFormatted = value.trim();
|
|
42
|
+
const log = settings?.log || false;
|
|
43
|
+
const logger = createLogger({
|
|
44
|
+
label: 'isValidNumberValue',
|
|
45
|
+
show: log,
|
|
46
|
+
});
|
|
47
|
+
const min = settings?.min;
|
|
48
|
+
const max = settings?.max;
|
|
49
|
+
const strict = settings?.strict === false ? false : true;
|
|
50
|
+
logger.info(`Validating value: "${valueFormatted}"`);
|
|
51
|
+
if (strict && !isNumericString(valueFormatted)) {
|
|
52
|
+
logger.warn('Invalid input: strict checking is enaabled and the text failed the checks');
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
if (valueFormatted === '') {
|
|
56
|
+
logger.info('Valid input: Blank value');
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
if (allowNegativeValues && valueFormatted === '-') {
|
|
60
|
+
logger.info(`Valid input: Single '-' sign allowed as a negative placeholder.`);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
if (!decimalPlaces && valueFormatted.includes('.')) {
|
|
64
|
+
logger.warn('Invalid input: Decimals not allowed');
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
const dotCount = (valueFormatted.match(/\./g) || []).length;
|
|
68
|
+
if (dotCount > 1) {
|
|
69
|
+
logger.warn('Invalid input: More than one decimal point detected.');
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
const parts = valueFormatted.split('.');
|
|
73
|
+
if (parts[1]?.length > decimalPlaces) {
|
|
74
|
+
logger.warn(`Invalid input: Number has ${parts[1].length} decimal places, exceeding the allowed limit of ${decimalPlaces}.`);
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
if (!isNumericString(valueFormatted)) {
|
|
78
|
+
logger.warn('Invalid input: String is not a valid number.');
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
const numericValue = Number(valueFormatted);
|
|
82
|
+
if (!allowNegativeValues && numericValue < 0) {
|
|
83
|
+
logger.warn('Invalid input: Negative numbers are not allowed.');
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
if (min !== undefined && numericValue < min) {
|
|
87
|
+
logger.warn(`Invalid input: Number ${numericValue} is less than the minimum allowed value of ${min}.`);
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
if (max !== undefined && numericValue > max) {
|
|
91
|
+
logger.warn(`Invalid input: Number ${numericValue} exceeds the maximum allowed value of ${max}.`);
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
logger.info('Validation passed: Input is a valid number according to the provided settings.');
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Source } from '@storybook/blocks';
|
|
2
|
+
|
|
3
|
+
# Logger Utility
|
|
4
|
+
|
|
5
|
+
A customizable logger function that supports:
|
|
6
|
+
|
|
7
|
+
- Log levels (`info`, `warn`, `error`)
|
|
8
|
+
- Optional labels
|
|
9
|
+
- A `show` flag to toggle logging
|
|
10
|
+
- Console output with timestamps
|
|
11
|
+
|
|
12
|
+
## Import
|
|
13
|
+
|
|
14
|
+
Import the logger creation function:
|
|
15
|
+
|
|
16
|
+
<Source dark language="ts" code={`import { createLogger } from '@flightlesslabs/dodo-ui';`} />
|
|
17
|
+
|
|
18
|
+
## Basic Usage
|
|
19
|
+
|
|
20
|
+
Create a logger and log different types of messages:
|
|
21
|
+
|
|
22
|
+
<Source
|
|
23
|
+
dark
|
|
24
|
+
language="ts"
|
|
25
|
+
code={`const logger = createLogger({
|
|
26
|
+
label: 'AuthService',
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
logger.info('User logged in');
|
|
30
|
+
logger.warn('Token is about to expire');
|
|
31
|
+
logger.error('Login failed', new Error('Invalid credentials'));
|
|
32
|
+
`}
|
|
33
|
+
/>
|
|
34
|
+
|
|
35
|
+
## Disable Logging
|
|
36
|
+
|
|
37
|
+
You can use the \`show\` flag to completely silence the logger (e.g., in production):
|
|
38
|
+
|
|
39
|
+
<Source
|
|
40
|
+
dark
|
|
41
|
+
language="ts"
|
|
42
|
+
code={`const logger = createLogger({
|
|
43
|
+
show: false,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
logger.info('This will not be logged');
|
|
47
|
+
`}
|
|
48
|
+
/>
|
|
49
|
+
|
|
50
|
+
## Level Filtering
|
|
51
|
+
|
|
52
|
+
The logger will only show messages **at or above** the configured `level`:
|
|
53
|
+
|
|
54
|
+
<Source
|
|
55
|
+
dark
|
|
56
|
+
language="ts"
|
|
57
|
+
code={`const logger = createLogger();
|
|
58
|
+
|
|
59
|
+
logger.info('This will NOT show');
|
|
60
|
+
logger.warn('This WILL show');
|
|
61
|
+
logger.error('This WILL show');
|
|
62
|
+
`}
|
|
63
|
+
/>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type LogLevel = 'info' | 'warn' | 'error';
|
|
2
|
+
export interface LoggerOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Optional label to prefix log entries.
|
|
5
|
+
*/
|
|
6
|
+
label?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Whether to actually show logs.
|
|
9
|
+
* Defaults to true.
|
|
10
|
+
*/
|
|
11
|
+
show?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Formats the log message with timestamp, label, and level.
|
|
15
|
+
*/
|
|
16
|
+
export declare function formatPrefix(level: LogLevel, label?: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a logger that logs every call unless disabled by show=false.
|
|
19
|
+
*/
|
|
20
|
+
export default function createLogger(options?: LoggerOptions): {
|
|
21
|
+
info: (msg: unknown, ...optionalParams: unknown[]) => void;
|
|
22
|
+
warn: (msg: unknown, ...optionalParams: unknown[]) => void;
|
|
23
|
+
error: (msg: unknown, ...optionalParams: unknown[]) => void;
|
|
24
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats the log message with timestamp, label, and level.
|
|
3
|
+
*/
|
|
4
|
+
export function formatPrefix(level, label) {
|
|
5
|
+
const timestamp = new Date().toISOString();
|
|
6
|
+
const labelPart = label ? `[${label}]` : '';
|
|
7
|
+
return `[${timestamp}] ${labelPart} [${level.toUpperCase()}]`;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates a logger that logs every call unless disabled by show=false.
|
|
11
|
+
*/
|
|
12
|
+
export default function createLogger(options = {}) {
|
|
13
|
+
const { label, show = true } = options;
|
|
14
|
+
function shouldLog() {
|
|
15
|
+
return show;
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
info: (msg, ...optionalParams) => {
|
|
19
|
+
if (shouldLog())
|
|
20
|
+
console.info(formatPrefix('info', label), msg, ...optionalParams);
|
|
21
|
+
},
|
|
22
|
+
warn: (msg, ...optionalParams) => {
|
|
23
|
+
if (shouldLog())
|
|
24
|
+
console.warn(formatPrefix('warn', label), msg, ...optionalParams);
|
|
25
|
+
},
|
|
26
|
+
error: (msg, ...optionalParams) => {
|
|
27
|
+
if (shouldLog())
|
|
28
|
+
console.error(formatPrefix('error', label), msg, ...optionalParams);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
package/package.json
CHANGED
package/src/lib/index.ts
CHANGED
|
@@ -14,6 +14,20 @@ export type { ComponentWeight } from './types/weight.js';
|
|
|
14
14
|
|
|
15
15
|
export type { PositionY, PositionX } from './types/position.js';
|
|
16
16
|
|
|
17
|
+
/** developer tools: helpers: logger */
|
|
18
|
+
export { default as createLogger } from '$lib/stories/developer tools/helpers/logger/logger.js';
|
|
19
|
+
export type {
|
|
20
|
+
LogLevel,
|
|
21
|
+
LoggerOptions,
|
|
22
|
+
} from '$lib/stories/developer tools/helpers/logger/logger.js';
|
|
23
|
+
|
|
24
|
+
/** developer tools: helpers: Numbers: isValidNumberValue */
|
|
25
|
+
export { default as isValidNumberValue } from '$lib/stories/developer tools/helpers/Numbers/isValidNumberValue/isValidNumberValue.js';
|
|
26
|
+
export type { IsValidNumberValueSettings } from '$lib/stories/developer tools/helpers/Numbers/isValidNumberValue/isValidNumberValue.js';
|
|
27
|
+
|
|
28
|
+
/** developer tools: helpers: Numbers: cleanNumericString */
|
|
29
|
+
export { default as cleanNumericString } from '$lib/stories/developer tools/helpers/Numbers/cleanNumericString/cleanNumericString.js';
|
|
30
|
+
|
|
17
31
|
/** developer tools: directives: clickOutside */
|
|
18
32
|
export { clickOutside } from '$lib/stories/developer tools/directives/clickOutside/clickOutside.js';
|
|
19
33
|
|
|
@@ -32,6 +46,7 @@ export type {
|
|
|
32
46
|
DynamicInputProps,
|
|
33
47
|
DynamicInputClickEvent,
|
|
34
48
|
DynamicInputFocusEvent,
|
|
49
|
+
DynamicInputKeyboardEvent,
|
|
35
50
|
} from '$lib/stories/developer tools/components/DynamicInput/DynamicInput.svelte';
|
|
36
51
|
|
|
37
52
|
/** developer tools: components: Popper */
|
|
@@ -57,6 +72,7 @@ export type {
|
|
|
57
72
|
TextInputFocusEvent,
|
|
58
73
|
TextInputClipboardEvent,
|
|
59
74
|
TextInputInputEvent,
|
|
75
|
+
TextInputKeyboardEvent,
|
|
60
76
|
TextInputProps,
|
|
61
77
|
} from '$lib/stories/components/Form/TextInput/TextInput.svelte';
|
|
62
78
|
|
|
@@ -87,6 +103,10 @@ export type {
|
|
|
87
103
|
SelectProps,
|
|
88
104
|
} from '$lib/stories/components/Form/Select/Select.svelte';
|
|
89
105
|
|
|
106
|
+
/** Form: NumericInput */
|
|
107
|
+
export { default as NumericInput } from '$lib/stories/components/Form/NumericInput/NumericInput.svelte';
|
|
108
|
+
export type { NumericInputProps } from '$lib/stories/components/Form/NumericInput/NumericInput.svelte';
|
|
109
|
+
|
|
90
110
|
/** Layout: Paper */
|
|
91
111
|
export { default as Paper } from '$lib/stories/components/Layout/Paper/Paper.svelte';
|
|
92
112
|
export type { PaperColor, PaperProps } from '$lib/stories/components/Layout/Paper/Paper.svelte';
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import { storyNumericInputArgTypes } from '../NumericInput.stories.svelte';
|
|
4
|
+
import NumericInput from '../NumericInput.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: NumericInput,
|
|
14
|
+
tags: ['autodocs'],
|
|
15
|
+
argTypes: storyNumericInputArgTypes,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
let value = $state<undefined | number>(0);
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<!-- Use this event to get filtered numeric value -->
|
|
22
|
+
<Story
|
|
23
|
+
name="NumericValueChange"
|
|
24
|
+
args={{
|
|
25
|
+
value,
|
|
26
|
+
onValueChange: (val: number | undefined) => {
|
|
27
|
+
value = val;
|
|
28
|
+
},
|
|
29
|
+
}}
|
|
30
|
+
/>
|
|
31
|
+
|
|
32
|
+
<Story
|
|
33
|
+
name="Input"
|
|
34
|
+
args={{
|
|
35
|
+
oninput: (e: Event) => {
|
|
36
|
+
const target = e.target as HTMLInputElement;
|
|
37
|
+
|
|
38
|
+
console.log('Input Event', target.value);
|
|
39
|
+
},
|
|
40
|
+
}}
|
|
41
|
+
/>
|
|
42
|
+
|
|
43
|
+
<Story
|
|
44
|
+
name="Change"
|
|
45
|
+
args={{
|
|
46
|
+
onchange: (e: Event) => {
|
|
47
|
+
const target = e.target as HTMLInputElement;
|
|
48
|
+
|
|
49
|
+
console.log('onChange Event', target.value);
|
|
50
|
+
},
|
|
51
|
+
}}
|
|
52
|
+
/>
|
|
53
|
+
|
|
54
|
+
<Story
|
|
55
|
+
name="Focus"
|
|
56
|
+
args={{
|
|
57
|
+
onfocus: (e: TextInputFocusEvent) => {
|
|
58
|
+
const target = e.target as HTMLInputElement;
|
|
59
|
+
|
|
60
|
+
console.log('onfocus Event', target);
|
|
61
|
+
},
|
|
62
|
+
}}
|
|
63
|
+
/>
|
|
64
|
+
|
|
65
|
+
<Story
|
|
66
|
+
name="Blur"
|
|
67
|
+
args={{
|
|
68
|
+
onblur: (e: TextInputFocusEvent) => {
|
|
69
|
+
const target = e.target as HTMLInputElement;
|
|
70
|
+
|
|
71
|
+
console.log('onblur Event', target);
|
|
72
|
+
},
|
|
73
|
+
}}
|
|
74
|
+
/>
|
|
75
|
+
|
|
76
|
+
<Story
|
|
77
|
+
name="Copy"
|
|
78
|
+
args={{
|
|
79
|
+
oncopy: (e: TextInputClipboardEvent) => {
|
|
80
|
+
const target = e.target as HTMLInputElement;
|
|
81
|
+
|
|
82
|
+
console.log('oncopy Event', target);
|
|
83
|
+
},
|
|
84
|
+
}}
|
|
85
|
+
/>
|
|
86
|
+
|
|
87
|
+
<Story
|
|
88
|
+
name="Cut"
|
|
89
|
+
args={{
|
|
90
|
+
oncut: (e: TextInputClipboardEvent) => {
|
|
91
|
+
const target = e.target as HTMLInputElement;
|
|
92
|
+
|
|
93
|
+
console.log('oncut Event', target);
|
|
94
|
+
},
|
|
95
|
+
}}
|
|
96
|
+
/>
|
|
97
|
+
|
|
98
|
+
<Story
|
|
99
|
+
name="Paste"
|
|
100
|
+
args={{
|
|
101
|
+
onpaste: (e: TextInputClipboardEvent) => {
|
|
102
|
+
const target = e.target as HTMLInputElement;
|
|
103
|
+
|
|
104
|
+
console.log('onpaste Event', target);
|
|
105
|
+
},
|
|
106
|
+
}}
|
|
107
|
+
/>
|
|
108
|
+
|
|
109
|
+
<Story
|
|
110
|
+
name="KeyDown"
|
|
111
|
+
args={{
|
|
112
|
+
onkeydown: (e: TextInputKeyboardEvent) => {
|
|
113
|
+
console.log('onkeydown Event', e.key);
|
|
114
|
+
},
|
|
115
|
+
}}
|
|
116
|
+
/>
|
|
117
|
+
|
|
118
|
+
<Story
|
|
119
|
+
name="KeyPress"
|
|
120
|
+
args={{
|
|
121
|
+
onkeypress: (e: TextInputKeyboardEvent) => {
|
|
122
|
+
console.log('onkeypress Event', e.key);
|
|
123
|
+
},
|
|
124
|
+
}}
|
|
125
|
+
/>
|
|
126
|
+
|
|
127
|
+
<Story
|
|
128
|
+
name="KeyUp"
|
|
129
|
+
args={{
|
|
130
|
+
onkeyup: (e: TextInputKeyboardEvent) => {
|
|
131
|
+
console.log('onkeyup Event', e.key);
|
|
132
|
+
},
|
|
133
|
+
}}
|
|
134
|
+
/>
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import NumericInput from './NumericInput.svelte';
|
|
4
|
+
import type { StoryBookArgTypes } from '$lib/storybook-types.js';
|
|
5
|
+
import { componentRoundnessArray } from '$lib/types/roundness.js';
|
|
6
|
+
import { componentSizeArray } from '$lib/types/size.js';
|
|
7
|
+
|
|
8
|
+
export const storyNumericInputArgTypes: StoryBookArgTypes = {
|
|
9
|
+
roundness: {
|
|
10
|
+
control: { type: 'select' },
|
|
11
|
+
options: componentRoundnessArray,
|
|
12
|
+
},
|
|
13
|
+
size: {
|
|
14
|
+
control: { type: 'select' },
|
|
15
|
+
options: componentSizeArray,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
20
|
+
const { Story } = defineMeta({
|
|
21
|
+
component: NumericInput,
|
|
22
|
+
tags: ['autodocs'],
|
|
23
|
+
argTypes: storyNumericInputArgTypes,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
let value = $state<undefined | number>(0);
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<!-- NumericInput with default style -->
|
|
30
|
+
<Story
|
|
31
|
+
name="Default"
|
|
32
|
+
args={{
|
|
33
|
+
value,
|
|
34
|
+
onValueChange: (val) => {
|
|
35
|
+
value = val;
|
|
36
|
+
},
|
|
37
|
+
}}
|
|
38
|
+
/>
|
|
39
|
+
|
|
40
|
+
<Story name="Placeholder" args={{ value: undefined, placeholder: 'Type something...' }} />
|
|
41
|
+
|
|
42
|
+
<Story
|
|
43
|
+
name="No Outline"
|
|
44
|
+
args={{
|
|
45
|
+
outline: false,
|
|
46
|
+
value,
|
|
47
|
+
onValueChange: (val) => {
|
|
48
|
+
value = val;
|
|
49
|
+
},
|
|
50
|
+
}}
|
|
51
|
+
/>
|
|
52
|
+
|
|
53
|
+
<Story
|
|
54
|
+
name="Error"
|
|
55
|
+
args={{
|
|
56
|
+
error: true,
|
|
57
|
+
value,
|
|
58
|
+
onValueChange: (val) => {
|
|
59
|
+
value = val;
|
|
60
|
+
},
|
|
61
|
+
}}
|
|
62
|
+
/>
|
|
63
|
+
|
|
64
|
+
<Story
|
|
65
|
+
name="Disabled"
|
|
66
|
+
args={{
|
|
67
|
+
disabled: true,
|
|
68
|
+
value,
|
|
69
|
+
onValueChange: (val) => {
|
|
70
|
+
value = val;
|
|
71
|
+
},
|
|
72
|
+
}}
|
|
73
|
+
/>
|
|
74
|
+
|
|
75
|
+
<Story
|
|
76
|
+
name="Read only"
|
|
77
|
+
args={{
|
|
78
|
+
readonly: true,
|
|
79
|
+
value,
|
|
80
|
+
onValueChange: (val) => {
|
|
81
|
+
value = val;
|
|
82
|
+
},
|
|
83
|
+
}}
|
|
84
|
+
/>
|