@nuralyui/input 0.0.5 → 0.0.6
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/input.component.d.ts +23 -18
- package/input.component.d.ts.map +1 -1
- package/input.component.js +205 -139
- package/input.component.js.map +1 -1
- package/input.style.d.ts.map +1 -1
- package/input.style.js +118 -7
- package/input.style.js.map +1 -1
- package/{input.style.variable..d.ts → input.style.variable.d.ts} +1 -1
- package/input.style.variable.d.ts.map +1 -0
- package/{input.style.variable..js → input.style.variable.js} +25 -3
- package/input.style.variable.js.map +1 -0
- package/{input.constant.d.ts → input.types.d.ts} +1 -1
- package/input.types.d.ts.map +1 -0
- package/input.types.js +2 -0
- package/input.types.js.map +1 -0
- package/package.json +1 -1
- package/test/hy-input_test.js +1 -1
- package/test/hy-input_test.js.map +1 -1
- package/utils/index.d.ts +8 -0
- package/utils/index.d.ts.map +1 -0
- package/utils/index.js +8 -0
- package/utils/index.js.map +1 -0
- package/utils/input-renderers.d.ts +50 -0
- package/utils/input-renderers.d.ts.map +1 -0
- package/utils/input-renderers.js +157 -0
- package/utils/input-renderers.js.map +1 -0
- package/utils/input-validation.utils.d.ts +26 -0
- package/utils/input-validation.utils.d.ts.map +1 -0
- package/utils/input-validation.utils.js +105 -0
- package/utils/input-validation.utils.js.map +1 -0
- package/input.constant.d.ts.map +0 -1
- package/input.constant.js +0 -2
- package/input.constant.js.map +0 -1
- package/input.style.variable..d.ts.map +0 -1
- package/input.style.variable..js.map +0 -1
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2023 Google Laabidi Aymen
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import { html, nothing } from 'lit';
|
|
7
|
+
/**
|
|
8
|
+
* Rendering utilities for input component icons and elements
|
|
9
|
+
*/
|
|
10
|
+
export class InputRenderUtils {
|
|
11
|
+
/**
|
|
12
|
+
* Renders prefix slot content
|
|
13
|
+
*/
|
|
14
|
+
static renderPrefix() {
|
|
15
|
+
return html `
|
|
16
|
+
<div class="input-prefix">
|
|
17
|
+
<slot name="prefix"></slot>
|
|
18
|
+
</div>
|
|
19
|
+
`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Renders suffix slot content
|
|
23
|
+
*/
|
|
24
|
+
static renderSuffix() {
|
|
25
|
+
return html `
|
|
26
|
+
<div class="input-suffix">
|
|
27
|
+
<slot name="suffix"></slot>
|
|
28
|
+
</div>
|
|
29
|
+
`;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Renders addon before slot content (outside input borders)
|
|
33
|
+
* Only renders if hasAddonBefore is true
|
|
34
|
+
*/
|
|
35
|
+
static renderAddonBefore(hasAddonBefore, onSlotChange) {
|
|
36
|
+
if (!hasAddonBefore)
|
|
37
|
+
return nothing;
|
|
38
|
+
return html `
|
|
39
|
+
<div class="input-addon-before">
|
|
40
|
+
<slot name="addon-before" @slotchange=${onSlotChange}></slot>
|
|
41
|
+
</div>
|
|
42
|
+
`;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Renders addon after slot content (outside input borders)
|
|
46
|
+
* Only renders if hasAddonAfter is true
|
|
47
|
+
*/
|
|
48
|
+
static renderAddonAfter(hasAddonAfter, onSlotChange) {
|
|
49
|
+
if (!hasAddonAfter)
|
|
50
|
+
return nothing;
|
|
51
|
+
return html `
|
|
52
|
+
<div class="input-addon-after">
|
|
53
|
+
<slot name="addon-after" @slotchange=${onSlotChange}></slot>
|
|
54
|
+
</div>
|
|
55
|
+
`;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Renders the copy icon when withCopy is enabled
|
|
59
|
+
*/
|
|
60
|
+
static renderCopyIcon(withCopy, disabled, readonly, onCopy, onKeydown) {
|
|
61
|
+
if (!withCopy)
|
|
62
|
+
return nothing;
|
|
63
|
+
return html `<hy-icon
|
|
64
|
+
name="copy"
|
|
65
|
+
type="regular"
|
|
66
|
+
id="copy-icon"
|
|
67
|
+
role="button"
|
|
68
|
+
aria-label="Copy input value"
|
|
69
|
+
tabindex="0"
|
|
70
|
+
@click=${!disabled && !readonly ? onCopy : nothing}
|
|
71
|
+
@keydown=${onKeydown}
|
|
72
|
+
></hy-icon>`;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Renders state-based icons (warning, error)
|
|
76
|
+
*/
|
|
77
|
+
static renderStateIcon(state) {
|
|
78
|
+
switch (state) {
|
|
79
|
+
case "warning" /* INPUT_STATE.Warning */:
|
|
80
|
+
return html `<hy-icon name="warning" id="warning-icon"></hy-icon>`;
|
|
81
|
+
case "error" /* INPUT_STATE.Error */:
|
|
82
|
+
return html `<hy-icon name="exclamation-circle" id="error-icon"></hy-icon>`;
|
|
83
|
+
default:
|
|
84
|
+
return nothing;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Renders the calendar icon for calendar input type
|
|
89
|
+
*/
|
|
90
|
+
static renderCalendarIcon(state, type) {
|
|
91
|
+
if (state !== "default" /* INPUT_STATE.Default */ || type !== "calendar" /* INPUT_TYPE.CALENDAR */) {
|
|
92
|
+
return nothing;
|
|
93
|
+
}
|
|
94
|
+
return html `<hy-icon name="calendar" type="regular" id="calendar-icon"></hy-icon>`;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Renders password toggle icon
|
|
98
|
+
*/
|
|
99
|
+
static renderPasswordIcon(type, inputType, disabled, readonly, onToggle, onKeydown) {
|
|
100
|
+
if (type !== "password" /* INPUT_TYPE.PASSWORD */)
|
|
101
|
+
return nothing;
|
|
102
|
+
if (inputType === "text" /* INPUT_TYPE.TEXT */) {
|
|
103
|
+
return html `<hy-icon
|
|
104
|
+
name="eye-slash"
|
|
105
|
+
type="regular"
|
|
106
|
+
id="password-icon"
|
|
107
|
+
role="button"
|
|
108
|
+
aria-label="Hide password"
|
|
109
|
+
tabindex="0"
|
|
110
|
+
@click=${!disabled && !readonly ? onToggle : nothing}
|
|
111
|
+
@keydown=${onKeydown}
|
|
112
|
+
></hy-icon>`;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
return html `<hy-icon
|
|
116
|
+
name="eye"
|
|
117
|
+
type="regular"
|
|
118
|
+
id="password-icon"
|
|
119
|
+
role="button"
|
|
120
|
+
aria-label="Show password"
|
|
121
|
+
tabindex="0"
|
|
122
|
+
@click=${!disabled && !readonly ? onToggle : nothing}
|
|
123
|
+
@keydown=${onKeydown}
|
|
124
|
+
></hy-icon>`;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Renders number input increment/decrement icons
|
|
129
|
+
*/
|
|
130
|
+
static renderNumberIcons(type, state, disabled, readonly, onIncrement, onDecrement, onKeydown) {
|
|
131
|
+
if (type !== "number" /* INPUT_TYPE.NUMBER */)
|
|
132
|
+
return nothing;
|
|
133
|
+
return html `
|
|
134
|
+
<div id="number-icons">
|
|
135
|
+
${state !== "default" /* INPUT_STATE.Default */ ? html `<span id="icons-separator">|</span>` : nothing}
|
|
136
|
+
<hy-icon
|
|
137
|
+
name="minus"
|
|
138
|
+
aria-label="Decrease value"
|
|
139
|
+
role="button"
|
|
140
|
+
tabindex="0"
|
|
141
|
+
@click=${!disabled && !readonly ? onDecrement : nothing}
|
|
142
|
+
@keydown=${onKeydown}
|
|
143
|
+
></hy-icon>
|
|
144
|
+
<span id="icons-separator">|</span>
|
|
145
|
+
<hy-icon
|
|
146
|
+
name="plus"
|
|
147
|
+
aria-label="Increase value"
|
|
148
|
+
role="button"
|
|
149
|
+
tabindex="0"
|
|
150
|
+
@click=${!disabled && !readonly ? onIncrement : nothing}
|
|
151
|
+
@keydown=${onKeydown}
|
|
152
|
+
></hy-icon>
|
|
153
|
+
</div>
|
|
154
|
+
`;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=input-renderers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-renderers.js","sourceRoot":"","sources":["../../../../src/components/input/utils/input-renderers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAkB,OAAO,EAAE,MAAM,KAAK,CAAC;AAGpD;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAE3B;;OAEG;IACH,MAAM,CAAC,YAAY;QACjB,OAAO,IAAI,CAAA;;;;KAIV,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,YAAY;QACjB,OAAO,IAAI,CAAA;;;;KAIV,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,iBAAiB,CAAC,cAAuB,EAAE,YAAgC;QAChF,IAAI,CAAC,cAAc;YAAE,OAAO,OAAO,CAAC;QAEpC,OAAO,IAAI,CAAA;;gDAEiC,YAAY;;KAEvD,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,gBAAgB,CAAC,aAAsB,EAAE,YAAgC;QAC9E,IAAI,CAAC,aAAa;YAAE,OAAO,OAAO,CAAC;QAEnC,OAAO,IAAI,CAAA;;+CAEgC,YAAY;;KAEtD,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,cAAc,CACnB,QAAiB,EACjB,QAAiB,EACjB,QAAiB,EACjB,MAAkB,EAClB,SAAqC;QAErC,IAAI,CAAC,QAAQ;YAAE,OAAO,OAAO,CAAC;QAE9B,OAAO,IAAI,CAAA;;;;;;;eAOA,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;iBACvC,SAAS;gBACV,CAAC;IACf,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,KAAa;QAClC,QAAQ,KAAK,EAAE;YACb;gBACE,OAAO,IAAI,CAAA,sDAAsD,CAAC;YACpE;gBACE,OAAO,IAAI,CAAA,+DAA+D,CAAC;YAC7E;gBACE,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AAO;qBAC5C,SAAS;;;KAGzB,CAAC;IACJ,CAAC;CACF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google Laabidi Aymen\n * SPDX-License-Identifier: MIT\n */\n\nimport { html, TemplateResult, nothing } from 'lit';\nimport { INPUT_TYPE, INPUT_STATE } from '../input.types.js';\n\n/**\n * Rendering utilities for input component icons and elements\n */\nexport class InputRenderUtils {\n\n /**\n * Renders prefix slot content\n */\n static renderPrefix(): TemplateResult {\n return html`\n <div class=\"input-prefix\">\n <slot name=\"prefix\"></slot>\n </div>\n `;\n }\n\n /**\n * Renders suffix slot content \n */\n static renderSuffix(): TemplateResult {\n return html`\n <div class=\"input-suffix\">\n <slot name=\"suffix\"></slot>\n </div>\n `;\n }\n\n /**\n * Renders addon before slot content (outside input borders)\n * Only renders if hasAddonBefore is true\n */\n static renderAddonBefore(hasAddonBefore: boolean, onSlotChange: (e: Event) => void): TemplateResult | typeof nothing {\n if (!hasAddonBefore) return nothing;\n \n return html`\n <div class=\"input-addon-before\">\n <slot name=\"addon-before\" @slotchange=${onSlotChange}></slot>\n </div>\n `;\n }\n\n /**\n * Renders addon after slot content (outside input borders) \n * Only renders if hasAddonAfter is true\n */\n static renderAddonAfter(hasAddonAfter: boolean, onSlotChange: (e: Event) => void): TemplateResult | typeof nothing {\n if (!hasAddonAfter) return nothing;\n \n return html`\n <div class=\"input-addon-after\">\n <slot name=\"addon-after\" @slotchange=${onSlotChange}></slot>\n </div>\n `;\n }\n\n /**\n * Renders the copy icon when withCopy is enabled\n */\n static renderCopyIcon(\n withCopy: boolean,\n disabled: boolean,\n readonly: boolean,\n onCopy: () => void,\n onKeydown: (e: KeyboardEvent) => void\n ): TemplateResult | typeof nothing {\n if (!withCopy) return nothing;\n \n return html`<hy-icon\n name=\"copy\"\n type=\"regular\"\n id=\"copy-icon\"\n role=\"button\"\n aria-label=\"Copy input value\"\n tabindex=\"0\"\n @click=${!disabled && !readonly ? onCopy : nothing}\n @keydown=${onKeydown}\n ></hy-icon>`;\n }\n\n /**\n * Renders state-based icons (warning, error)\n */\n static renderStateIcon(state: string): TemplateResult | typeof nothing {\n switch (state) {\n case INPUT_STATE.Warning:\n return html`<hy-icon name=\"warning\" id=\"warning-icon\"></hy-icon>`;\n case INPUT_STATE.Error:\n return html`<hy-icon name=\"exclamation-circle\" id=\"error-icon\"></hy-icon>`;\n default:\n return nothing;\n }\n }\n\n /**\n * Renders the calendar icon for calendar input type\n */\n static renderCalendarIcon(\n state: string,\n type: string\n ): TemplateResult | typeof nothing {\n if (state !== INPUT_STATE.Default || type !== INPUT_TYPE.CALENDAR) {\n return nothing;\n }\n \n return html`<hy-icon name=\"calendar\" type=\"regular\" id=\"calendar-icon\"></hy-icon>`;\n }\n\n /**\n * Renders password toggle icon\n */\n static renderPasswordIcon(\n type: string,\n inputType: string,\n disabled: boolean,\n readonly: boolean,\n onToggle: () => void,\n onKeydown: (e: KeyboardEvent) => void\n ): TemplateResult | typeof nothing {\n if (type !== INPUT_TYPE.PASSWORD) return nothing;\n \n if (inputType === INPUT_TYPE.TEXT) {\n return html`<hy-icon\n name=\"eye-slash\"\n type=\"regular\"\n id=\"password-icon\"\n role=\"button\"\n aria-label=\"Hide password\"\n tabindex=\"0\"\n @click=${!disabled && !readonly ? onToggle : nothing}\n @keydown=${onKeydown}\n ></hy-icon>`;\n } else {\n return html`<hy-icon\n name=\"eye\"\n type=\"regular\"\n id=\"password-icon\"\n role=\"button\"\n aria-label=\"Show password\"\n tabindex=\"0\"\n @click=${!disabled && !readonly ? onToggle : nothing}\n @keydown=${onKeydown}\n ></hy-icon>`;\n }\n }\n\n /**\n * Renders number input increment/decrement icons\n */\n static renderNumberIcons(\n type: string,\n state: string,\n disabled: boolean,\n readonly: boolean,\n onIncrement: () => void,\n onDecrement: () => void,\n onKeydown: (e: KeyboardEvent) => void\n ): TemplateResult | typeof nothing {\n if (type !== INPUT_TYPE.NUMBER) return nothing;\n \n return html`\n <div id=\"number-icons\">\n ${state !== INPUT_STATE.Default ? html`<span id=\"icons-separator\">|</span>` : nothing}\n <hy-icon \n name=\"minus\" \n aria-label=\"Decrease value\"\n role=\"button\"\n tabindex=\"0\"\n @click=${!disabled && !readonly ? onDecrement : nothing}\n @keydown=${onKeydown}\n ></hy-icon>\n <span id=\"icons-separator\">|</span>\n <hy-icon \n name=\"plus\" \n aria-label=\"Increase value\"\n role=\"button\"\n tabindex=\"0\"\n @click=${!disabled && !readonly ? onIncrement : nothing}\n @keydown=${onKeydown}\n ></hy-icon>\n </div>\n `;\n }\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2023 Google Laabidi Aymen
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Validation utilities for input components
|
|
8
|
+
*/
|
|
9
|
+
export declare class InputValidationUtils {
|
|
10
|
+
/**
|
|
11
|
+
* Validates numeric properties (min, max, step) to ensure they are valid numbers
|
|
12
|
+
*/
|
|
13
|
+
static validateNumericProperties(type: string, min?: string, max?: string, step?: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* Prevents non-numeric characters from being typed in number inputs
|
|
16
|
+
*/
|
|
17
|
+
static preventNonNumericInput(keyDownEvent: KeyboardEvent, min?: string): void;
|
|
18
|
+
/**
|
|
19
|
+
* Validates a numeric value against min/max constraints
|
|
20
|
+
*/
|
|
21
|
+
static validateNumericValue(value: string, min?: string, max?: string): {
|
|
22
|
+
isValid: boolean;
|
|
23
|
+
warnings: string[];
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=input-validation.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-validation.utils.d.ts","sourceRoot":"","sources":["../../../../src/components/input/utils/input-validation.utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;GAEG;AACH,qBAAa,oBAAoB;IAE/B;;OAEG;IACH,MAAM,CAAC,yBAAyB,CAC9B,IAAI,EAAE,MAAM,EACZ,GAAG,CAAC,EAAE,MAAM,EACZ,GAAG,CAAC,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,GACZ,IAAI;IAiBP;;OAEG;IACH,MAAM,CAAC,sBAAsB,CAC3B,YAAY,EAAE,aAAa,EAC3B,GAAG,CAAC,EAAE,MAAM,GACX,IAAI;IAyDP;;OAEG;IACH,MAAM,CAAC,oBAAoB,CACzB,KAAK,EAAE,MAAM,EACb,GAAG,CAAC,EAAE,MAAM,EACZ,GAAG,CAAC,EAAE,MAAM,GACX;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;KAAE;CA0B5C"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2023 Google Laabidi Aymen
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Validation utilities for input components
|
|
8
|
+
*/
|
|
9
|
+
export class InputValidationUtils {
|
|
10
|
+
/**
|
|
11
|
+
* Validates numeric properties (min, max, step) to ensure they are valid numbers
|
|
12
|
+
*/
|
|
13
|
+
static validateNumericProperties(type, min, max, step) {
|
|
14
|
+
if (type === "number" /* INPUT_TYPE.NUMBER */) {
|
|
15
|
+
if (min && isNaN(Number(min))) {
|
|
16
|
+
console.warn(`Invalid min value: "${min}" is not a valid number`);
|
|
17
|
+
}
|
|
18
|
+
if (max && isNaN(Number(max))) {
|
|
19
|
+
console.warn(`Invalid max value: "${max}" is not a valid number`);
|
|
20
|
+
}
|
|
21
|
+
if (step && isNaN(Number(step))) {
|
|
22
|
+
console.warn(`Invalid step value: "${step}" is not a valid number`);
|
|
23
|
+
}
|
|
24
|
+
if (min && max && Number(min) >= Number(max)) {
|
|
25
|
+
console.warn(`Invalid range: min value (${min}) should be less than max value (${max})`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Prevents non-numeric characters from being typed in number inputs
|
|
31
|
+
*/
|
|
32
|
+
static preventNonNumericInput(keyDownEvent, min) {
|
|
33
|
+
const key = keyDownEvent.key;
|
|
34
|
+
const target = keyDownEvent.target;
|
|
35
|
+
const currentValue = target.value;
|
|
36
|
+
const cursorPosition = target.selectionStart || 0;
|
|
37
|
+
// Allow control keys (backspace, delete, tab, escape, enter, arrow keys, etc.)
|
|
38
|
+
const allowedControlKeys = [
|
|
39
|
+
'Backspace', 'Delete', 'Tab', 'Escape', 'Enter',
|
|
40
|
+
'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown',
|
|
41
|
+
'Home', 'End', 'PageUp', 'PageDown'
|
|
42
|
+
];
|
|
43
|
+
// Allow Ctrl/Cmd combinations (copy, paste, select all, etc.)
|
|
44
|
+
if (keyDownEvent.ctrlKey || keyDownEvent.metaKey) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// Allow control keys
|
|
48
|
+
if (allowedControlKeys.includes(key)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
// Allow digits
|
|
52
|
+
if (/^\d$/.test(key)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
// Allow decimal point (.) only once and allow it at the beginning for values like ".5"
|
|
56
|
+
if (key === '.' || key === ',') {
|
|
57
|
+
const hasDecimal = currentValue.includes('.') || currentValue.includes(',');
|
|
58
|
+
if (!hasDecimal) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Allow minus sign (-) only at the beginning and if min allows negative numbers
|
|
63
|
+
if (key === '-') {
|
|
64
|
+
const hasMinusSign = currentValue.includes('-');
|
|
65
|
+
const minAllowsNegative = !min || Number(min) < 0;
|
|
66
|
+
if (!hasMinusSign && cursorPosition === 0 && minAllowsNegative) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Allow plus sign (+) only at the beginning
|
|
71
|
+
if (key === '+') {
|
|
72
|
+
const hasPlusSign = currentValue.includes('+');
|
|
73
|
+
if (!hasPlusSign && cursorPosition === 0) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// If we reach here, prevent the key input
|
|
78
|
+
keyDownEvent.preventDefault();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Validates a numeric value against min/max constraints
|
|
82
|
+
*/
|
|
83
|
+
static validateNumericValue(value, min, max) {
|
|
84
|
+
const warnings = [];
|
|
85
|
+
if (!value) {
|
|
86
|
+
return { isValid: true, warnings };
|
|
87
|
+
}
|
|
88
|
+
const numericValue = Number(value);
|
|
89
|
+
if (isNaN(numericValue)) {
|
|
90
|
+
return {
|
|
91
|
+
isValid: false,
|
|
92
|
+
warnings: [`Invalid numeric value: "${value}"`]
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
// Check min/max constraints
|
|
96
|
+
if (min && numericValue < Number(min)) {
|
|
97
|
+
warnings.push(`Value ${numericValue} is below minimum ${min}`);
|
|
98
|
+
}
|
|
99
|
+
if (max && numericValue > Number(max)) {
|
|
100
|
+
warnings.push(`Value ${numericValue} is above maximum ${max}`);
|
|
101
|
+
}
|
|
102
|
+
return { isValid: true, warnings };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=input-validation.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-validation.utils.js","sourceRoot":"","sources":["../../../../src/components/input/utils/input-validation.utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;GAEG;AACH,MAAM,OAAO,oBAAoB;IAE/B;;OAEG;IACH,MAAM,CAAC,yBAAyB,CAC9B,IAAY,EACZ,GAAY,EACZ,GAAY,EACZ,IAAa;QAEb,IAAI,IAAI,qCAAsB,EAAE;YAC9B,IAAI,GAAG,IAAI,KAAK,CAAC,MAAM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,KAAK;gBACd,QAAQ,EAAE,CAAC,2BAA2B,KAAK,GAAG,CAAC;aAChD,CAAC;SACH;QAED,4BAA4B;QAC5B,IAAI,GAAG,IAAI,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,EAAE;YACrC,QAAQ,CAAC,IAAI,CAAC,SAAS,YAAY,qBAAqB,GAAG,EAAE,CAAC,CAAC;SAChE;QACD,IAAI,GAAG,IAAI,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,EAAE;YACrC,QAAQ,CAAC,IAAI,CAAC,SAAS,YAAY,qBAAqB,GAAG,EAAE,CAAC,CAAC;SAChE;QAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IACrC,CAAC;CACF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google Laabidi Aymen\n * SPDX-License-Identifier: MIT\n */\n\nimport { INPUT_TYPE } from '../input.types.js';\n\n/**\n * Validation utilities for input components\n */\nexport class InputValidationUtils {\n \n /**\n * Validates numeric properties (min, max, step) to ensure they are valid numbers\n */\n static validateNumericProperties(\n type: string,\n min?: string,\n max?: string,\n step?: string\n ): void {\n if (type === INPUT_TYPE.NUMBER) {\n if (min && isNaN(Number(min))) {\n console.warn(`Invalid min value: \"${min}\" is not a valid number`);\n }\n if (max && isNaN(Number(max))) {\n console.warn(`Invalid max value: \"${max}\" is not a valid number`);\n }\n if (step && isNaN(Number(step))) {\n console.warn(`Invalid step value: \"${step}\" is not a valid number`);\n }\n if (min && max && Number(min) >= Number(max)) {\n console.warn(`Invalid range: min value (${min}) should be less than max value (${max})`);\n }\n }\n }\n\n /**\n * Prevents non-numeric characters from being typed in number inputs\n */\n static preventNonNumericInput(\n keyDownEvent: KeyboardEvent,\n min?: string\n ): void {\n const key = keyDownEvent.key;\n const target = keyDownEvent.target as HTMLInputElement;\n const currentValue = target.value;\n const cursorPosition = target.selectionStart || 0;\n\n // Allow control keys (backspace, delete, tab, escape, enter, arrow keys, etc.)\n const allowedControlKeys = [\n 'Backspace', 'Delete', 'Tab', 'Escape', 'Enter',\n 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown',\n 'Home', 'End', 'PageUp', 'PageDown'\n ];\n\n // Allow Ctrl/Cmd combinations (copy, paste, select all, etc.)\n if (keyDownEvent.ctrlKey || keyDownEvent.metaKey) {\n return;\n }\n\n // Allow control keys\n if (allowedControlKeys.includes(key)) {\n return;\n }\n\n // Allow digits\n if (/^\\d$/.test(key)) {\n return;\n }\n\n // Allow decimal point (.) only once and allow it at the beginning for values like \".5\"\n if (key === '.' || key === ',') {\n const hasDecimal = currentValue.includes('.') || currentValue.includes(',');\n if (!hasDecimal) {\n return;\n }\n }\n\n // Allow minus sign (-) only at the beginning and if min allows negative numbers\n if (key === '-') {\n const hasMinusSign = currentValue.includes('-');\n const minAllowsNegative = !min || Number(min) < 0;\n if (!hasMinusSign && cursorPosition === 0 && minAllowsNegative) {\n return;\n }\n }\n\n // Allow plus sign (+) only at the beginning\n if (key === '+') {\n const hasPlusSign = currentValue.includes('+');\n if (!hasPlusSign && cursorPosition === 0) {\n return;\n }\n }\n\n // If we reach here, prevent the key input\n keyDownEvent.preventDefault();\n }\n\n /**\n * Validates a numeric value against min/max constraints\n */\n static validateNumericValue(\n value: string,\n min?: string,\n max?: string\n ): { isValid: boolean; warnings: string[] } {\n const warnings: string[] = [];\n \n if (!value) {\n return { isValid: true, warnings };\n }\n\n const numericValue = Number(value);\n \n if (isNaN(numericValue)) {\n return { \n isValid: false, \n warnings: [`Invalid numeric value: \"${value}\"`] \n };\n }\n\n // Check min/max constraints\n if (min && numericValue < Number(min)) {\n warnings.push(`Value ${numericValue} is below minimum ${min}`);\n }\n if (max && numericValue > Number(max)) {\n warnings.push(`Value ${numericValue} is above maximum ${max}`);\n }\n\n return { isValid: true, warnings };\n }\n}\n"]}
|
package/input.constant.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"input.constant.d.ts","sourceRoot":"","sources":["../../../src/components/input/input.constant.ts"],"names":[],"mappings":"AAAA,0BAAkB,WAAW;IAC3B,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,OAAO,YAAY;CACpB;AAED,0BAAkB,UAAU;IAC1B,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,KAAK,UAAU;CAChB;AAED,0BAAkB,UAAU;IAC1B,QAAQ,aAAa;IACrB,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,QAAQ,aAAa;CACtB;AAED,eAAO,MAAM,YAAY,KAAK,CAAC"}
|
package/input.constant.js
DELETED
package/input.constant.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"input.constant.js","sourceRoot":"","sources":["../../../src/components/input/input.constant.ts"],"names":[],"mappings":"AAmBA,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAC","sourcesContent":["export const enum INPUT_STATE {\n Default = 'default',\n Error = 'error',\n Warning = 'warning',\n}\n\nexport const enum INPUT_SIZE {\n Large = 'large',\n Medium = 'medium',\n Small = 'small',\n}\n\nexport const enum INPUT_TYPE {\n PASSWORD = 'password',\n TEXT = 'text',\n NUMBER = 'number',\n CALENDAR = 'calendar',\n}\n\nexport const EMPTY_STRING = '';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"input.style.variable..d.ts","sourceRoot":"","sources":["../../../src/components/input/input.style.variable..ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,yBAgG1B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"input.style.variable..js","sourceRoot":"","sources":["../../../src/components/input/input.style.variable..ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgGhC,CAAC","sourcesContent":["import {css} from 'lit';\n\nexport const styleVariables = css`\n :host {\n --hybrid-input-local-background-color: #f4f4f4;\n --hybrid-input-local-text-color: #000000;\n --hybrid-input-local-font-family: Inter, ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", Roboto, Ubuntu, Cantarell, \"Noto Sans\", sans-serif, \"system-ui\", \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, \"Noto Sans\", sans-serif, SFProLocalRange;\n --hybrid-input-local-font-size:13px;\n --hybrid-input-local-label-color: #525252;\n --hybrid-input-local-placeholder-color: #a8a8a8;\n --hybrid-input-local-border-bottom: 2px solid #a8a8a8;\n --hybrid-input-local-border-top: 2px solid transparent;\n --hybrid-input-local-border-left: 2px solid transparent;\n --hybrid-input-local-border-right: 2px solid transparent;\n --hybrid-input-local-disabled-border-bottom: none;\n --hybrid-input-local-disabled-border-top: none;\n --hybrid-input-local-disabled-border-left: none;\n --hybrid-input-local-disabled-border-right: none;\n --hybrid-input-local-focus-border: 2px solid #0f62fe;\n --hybrid-input-local-border-radius: 0px;\n --hybrid-input-local-label-font-size: 13px;\n --hybrid-input-local-helper-text-color: #525252;\n --hybrid-input-local-helper-text-font-size: 13px;\n --hybrid-input-local-placeholder-font-size: 13px;\n --hybrid-input-label-padding-bottom: 5px;\n --hybrid-input-local-helper-text-padding-top: 5px;\n --hybrid-input-local-disabled-background-color: #f4f4f4;\n --hybrid-input-local-disabled-placeholder-color: #c6c6c6;\n --hybrid-input-local-error-helper-text-color: #da1e28;\n --hybrid-input-local-error-border: 2px solid #da1e28;\n --hybrid-input-local-warning-helper-text-color: #161616;\n --hybrid-input-local-disabled-helper-text-color: #c6c6c6;\n --hybrid-input-local-disabled-label-color: #c6c6c6;\n --hybrid-input-local-warning-icon-color: #f0c300;\n --hybrid-input-local-error-icon-color: #da1e28;\n --hybrid-input-local-password-icon-color: #000000;\n --hybrid-input-local-calendar-icon-color: #000000;\n --hybrid-input-local-copy-icon-color: #000000;\n --hybrid-input-local-disabled-icon-opacity: 0.4;\n --hybrid-input-local-number-icons-color: #000000;\n --hybrid-input-local-password-icon-padding-left: 8px;\n --hybrid-input-local-password-icon-padding-right: 8px;\n --hybrid-input-local-number-icons-separator-color: #e0e0e0;\n --hybrid-input-local-number-icons-separator-padding-bottom: 4px;\n --hybrid-input-local-number-icons-separator-padding-left: 5px;\n --hybrid-input-local-number-icons-separator-padding-right: 5px;\n --hybrid-input-local-copy-icon-padding-right:5px;\n\n --hybrid-input-local-number-icons-container-width: 70px;\n --hybrid-input-local-number-icons-container-padding-left: 5px;\n --hybrid-input-local-number-icons-container-padding-right: 5px;\n --hybrid-input-local-number-icons-width: 12px;\n --hybrid-input-local-number-icons-height: 12px;\n\n --hybrid-input-local-number-icons-padding-left: 4px;\n --hybrid-input-local-number-icons-padding-right: 4px;\n\n --hybrid-input-local-large-padding-top: 10px;\n --hybrid-input-local-large-padding-bottom: 10px;\n --hybrid-input-local-large-padding-left: 9px;\n --hybrid-input-local-large-padding-right: 4px;\n\n --hybrid-input-local-medium-padding-top: 7px;\n --hybrid-input-local-medium-padding-bottom: 7px;\n --hybrid-input-local-medium-padding-left: 9px;\n --hybrid-input-local-medium-padding-right: 4px;\n\n --hybrid-input-local-small-padding-top: 4px;\n --hybrid-input-local-small-padding-bottom: 4px;\n --hybrid-input-local-small-padding-left: 9px;\n --hybrid-input-local-small-padding-right: 4px;\n }\n\n /* \n * Dark theme styles using data-theme attribute on host element\n * These override the light theme defaults when data-theme=\"dark\" is applied\n * This provides explicit theme control via JavaScript or HTML attributes\n */\n :host([data-theme=\"dark\"]) {\n --hybrid-input-local-background-color: #393939;\n --hybrid-input-local-focus-border: 2px solid #ffffff;\n --hybrid-input-local-text-color: #ffffff;\n --hybrid-input-local-error-border: 2px solid #fa4d56;\n --hybrid-input-local-error-helper-text-color: #ffb3b8;\n --hybrid-input-local-disabled-background-color: #393939;\n --hybrid-input-local-disabled-placeholder-color: #6f6f6f;\n --hybrid-input-local-disabled-helper-text-color: #6f6f6f;\n --hybrid-input-local-disabled-label-color: #6f6f6f;\n --hybrid-input-local-warning-icon-color: #f0c300;\n --hybrid-input-local-error-icon-color: #da1e28;\n --hybrid-input-local-password-icon-color: #ffffff;\n --hybrid-input-local-number-icons-color: #ffffff;\n --hybrid-input-local-label-color: #c6c6c6;\n --hybrid-input-local-helper-text-color: #c6c6c6;\n --hybrid-input-local-number-icons-separator-color: #525252;\n --hybrid-input-local-calendar-icon-color: #ffffff;\n --hybrid-input-local-copy-icon-color: #ffffff;\n }\n`;\n"]}
|