@versini/ui-textinput 6.1.1 → 6.3.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 +93 -32
- package/dist/index.js +43 -45
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,50 +1,111 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JSX } from 'react/jsx-runtime';
|
|
2
2
|
|
|
3
|
-
declare type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare const TEXT_INPUT_HELPER_TEXT_CLASSNAME = "av-text-input-helper-text";
|
|
8
|
-
|
|
9
|
-
export declare const TEXT_INPUT_SIMPLE_CLASSNAME = "av-text-input-simple";
|
|
10
|
-
|
|
11
|
-
export declare const TEXT_INPUT_WRAPPER_CLASSNAME = "av-text-input-wrapper";
|
|
12
|
-
|
|
13
|
-
export declare const TextInput: React_2.ForwardRefExoticComponent<{
|
|
14
|
-
rightElement?: React_2.ReactElement;
|
|
15
|
-
rightElementClassName?: string;
|
|
16
|
-
} & {
|
|
3
|
+
declare type CommonTextInputProps = {
|
|
4
|
+
/**
|
|
5
|
+
* The label of the TextInput.
|
|
6
|
+
*/
|
|
17
7
|
label: string;
|
|
8
|
+
/**
|
|
9
|
+
* The name of the TextInput.
|
|
10
|
+
*/
|
|
18
11
|
name: string;
|
|
12
|
+
/**
|
|
13
|
+
* Whether or not the TextInput is in error state.
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
19
16
|
error?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* The type of focus for the TextInput. This will change the color
|
|
19
|
+
* of the focus ring around the TextInput.
|
|
20
|
+
*/
|
|
20
21
|
focusMode?: "dark" | "light" | "system" | "alt-system";
|
|
22
|
+
/**
|
|
23
|
+
* Text to add to the bottom of the TextInput.
|
|
24
|
+
*/
|
|
21
25
|
helperText?: string;
|
|
26
|
+
/**
|
|
27
|
+
* CSS class(es) to add to the actual textarea element.
|
|
28
|
+
*/
|
|
22
29
|
inputClassName?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Hides the label visually but retain accessible relationship with the TextInput.
|
|
32
|
+
*/
|
|
23
33
|
labelHidden?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Id to use for the TextInput label.
|
|
36
|
+
*/
|
|
24
37
|
labelId?: string;
|
|
38
|
+
/**
|
|
39
|
+
* The mode of TextInput. This will change the color of the TextInput.
|
|
40
|
+
*/
|
|
25
41
|
mode?: "dark" | "light" | "system" | "alt-system";
|
|
42
|
+
/**
|
|
43
|
+
* Whether or not the TextInput has a border.
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
26
46
|
noBorder?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Whether or not to render the TextInput with styles or not.
|
|
49
|
+
* @default false
|
|
50
|
+
*/
|
|
27
51
|
raw?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Controls input height and horizontal padding, 'md' by default
|
|
54
|
+
*/
|
|
28
55
|
size?: Size;
|
|
29
|
-
} & Omit<
|
|
56
|
+
} & Omit<React.InputHTMLAttributes<HTMLInputElement>, "size">;
|
|
57
|
+
|
|
58
|
+
declare type Size = "xs" | "sm" | "md" | "lg" | "xl";
|
|
59
|
+
|
|
60
|
+
export declare const TEXT_INPUT_CLASSNAME = "av-text-input";
|
|
61
|
+
|
|
62
|
+
export declare const TEXT_INPUT_HELPER_TEXT_CLASSNAME = "av-text-input-helper-text";
|
|
63
|
+
|
|
64
|
+
export declare const TEXT_INPUT_SIMPLE_CLASSNAME = "av-text-input-simple";
|
|
30
65
|
|
|
31
|
-
export declare const
|
|
32
|
-
|
|
66
|
+
export declare const TEXT_INPUT_WRAPPER_CLASSNAME = "av-text-input-wrapper";
|
|
67
|
+
|
|
68
|
+
export declare function TextInput({ id, name, label, error, raw, className, inputClassName, mode, focusMode, disabled, noBorder, labelId, labelHidden, type, helperText, rightElement, rightElementClassName, size, ref, ...extraProps }: TextInputProps): JSX.Element;
|
|
69
|
+
|
|
70
|
+
export declare function TextInputMask({ name, disabled, label, labelHidden, onMaskChange, onChange, onBlur, onFocus, onTextInputMaskBlur, rightElement, ref, ...otherProps }: TextInputMaskProps): JSX.Element;
|
|
71
|
+
|
|
72
|
+
declare type TextInputMaskProps = {
|
|
73
|
+
/**
|
|
74
|
+
* A ref to the input element.
|
|
75
|
+
*/
|
|
76
|
+
ref?: React.Ref<HTMLInputElement>;
|
|
77
|
+
/**
|
|
78
|
+
* This prop allows you to pass in a React element to render on the right
|
|
79
|
+
* side of the TextInput. This is useful for adding icons or actionable
|
|
80
|
+
* elements, such a Button.
|
|
81
|
+
*/
|
|
82
|
+
rightElement: React.ReactElement;
|
|
83
|
+
/**
|
|
84
|
+
* Callback fired when the value changes.
|
|
85
|
+
* @param masked whether or not the value is masked
|
|
86
|
+
*/
|
|
33
87
|
onMaskChange?: (masked: boolean) => void;
|
|
88
|
+
/**
|
|
89
|
+
* Callback fired when the user blurs out of the TextInputMask.
|
|
90
|
+
*/
|
|
34
91
|
onTextInputMaskBlur?: () => void;
|
|
35
|
-
} &
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
92
|
+
} & CommonTextInputProps;
|
|
93
|
+
|
|
94
|
+
declare type TextInputProps = {
|
|
95
|
+
/**
|
|
96
|
+
* A ref to the input element.
|
|
97
|
+
*/
|
|
98
|
+
ref?: React.Ref<HTMLInputElement>;
|
|
99
|
+
/**
|
|
100
|
+
* This prop allows you to pass in a React element to render on the right
|
|
101
|
+
* side of the TextInput. This is useful for adding icons or actionable
|
|
102
|
+
* elements, such a Button.
|
|
103
|
+
*/
|
|
104
|
+
rightElement?: React.ReactElement;
|
|
105
|
+
/**
|
|
106
|
+
* Extra classes to add to the right element container.
|
|
107
|
+
*/
|
|
108
|
+
rightElementClassName?: string;
|
|
109
|
+
} & CommonTextInputProps;
|
|
49
110
|
|
|
50
111
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
@versini/ui-textinput v6.
|
|
2
|
+
@versini/ui-textinput v6.3.0
|
|
3
3
|
© 2025 gizmette.com
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -166,7 +166,7 @@ const getTextInputClasses = ({ className, inputClassName, raw, disabled, noBorde
|
|
|
166
166
|
|
|
167
167
|
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
function TextInput({ id, name, label, error = false, raw = false, className, inputClassName, mode = "system", focusMode = "system", disabled = false, noBorder = false, labelId, labelHidden = false, type = "text", helperText = "", rightElement, rightElementClassName, size = "md", ref, ...extraProps }) {
|
|
170
170
|
const [rightElementRef, rect] = useResizeObserver();
|
|
171
171
|
const [inputPaddingRight, setInputPaddingRight] = useState(0);
|
|
172
172
|
const inputId = useUniqueId({
|
|
@@ -213,20 +213,20 @@ const TextInput = /*#__PURE__*/ react.forwardRef(({ id, name, label, error = fal
|
|
|
213
213
|
/* c8 ignore start - ResizeObserver is tough to test... */ useLayoutEffect(()=>{
|
|
214
214
|
if (rect && rect.width) {
|
|
215
215
|
/**
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
216
|
+
* - rect.width is the width of the right element (Button, Icon, etc.)
|
|
217
|
+
* - The main input field has default left/right paddings of
|
|
218
|
+
* 16px (px-4) + 2px border (border-2) = 18px
|
|
219
|
+
* - We add 10px to the right padding to give some space between the right
|
|
220
|
+
* element and the input field.
|
|
221
|
+
*/ setInputPaddingRight(rect.width + 18 + 10);
|
|
222
222
|
}
|
|
223
223
|
}, [
|
|
224
224
|
rect
|
|
225
225
|
]);
|
|
226
226
|
/* c8 ignore end */ /**
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
227
|
+
* This effect sets the label and helper text position based on
|
|
228
|
+
* the size of the input.
|
|
229
|
+
*/ useLayoutEffect(()=>{
|
|
230
230
|
const { label, helperText } = sizeStyles[size];
|
|
231
231
|
labelRef?.current?.style.setProperty("--av-text-input-label", label);
|
|
232
232
|
helperTextRef?.current?.style.setProperty("--av-text-input-helper-text", helperText);
|
|
@@ -288,8 +288,7 @@ const TextInput = /*#__PURE__*/ react.forwardRef(({ id, name, label, error = fal
|
|
|
288
288
|
})
|
|
289
289
|
]
|
|
290
290
|
});
|
|
291
|
-
}
|
|
292
|
-
TextInput.displayName = "TextInput";
|
|
291
|
+
}
|
|
293
292
|
|
|
294
293
|
;// CONCATENATED MODULE: external "@versini/ui-hooks/use-merge-refs"
|
|
295
294
|
|
|
@@ -302,7 +301,7 @@ TextInput.displayName = "TextInput";
|
|
|
302
301
|
const CLEAR_ANNOUNCEMENT_TIMEOUT = 500;
|
|
303
302
|
const AUTO_HIDE_CLEAR_ANNOUNCEMENT_TIMEOUT = 5000;
|
|
304
303
|
const AUTO_HIDE_TIMEOUT = 20000;
|
|
305
|
-
|
|
304
|
+
function TextInputMask({ name, disabled, label, labelHidden, onMaskChange, onChange, onBlur, onFocus, onTextInputMaskBlur, rightElement, ref, ...otherProps }) {
|
|
306
305
|
const [masked, setMasked] = useState(true);
|
|
307
306
|
const [liveRegionStatus, setLiveRegionStatus] = useState({
|
|
308
307
|
message: null,
|
|
@@ -328,9 +327,9 @@ const TextInputMask = /*#__PURE__*/ react.forwardRef(({ name, disabled, label, l
|
|
|
328
327
|
message: `${label} hiding characters`
|
|
329
328
|
});
|
|
330
329
|
/**
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
330
|
+
* Callback that can be used to generate
|
|
331
|
+
* show/hide analytics.
|
|
332
|
+
*/ onMaskChange && onMaskChange(true);
|
|
334
333
|
}, AUTO_HIDE_TIMEOUT);
|
|
335
334
|
}
|
|
336
335
|
};
|
|
@@ -346,19 +345,19 @@ const TextInputMask = /*#__PURE__*/ react.forwardRef(({ name, disabled, label, l
|
|
|
346
345
|
message: newHiddenState ? "Characters hidden" : "Characters showing"
|
|
347
346
|
});
|
|
348
347
|
/**
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
348
|
+
* Callback that can be used to generate
|
|
349
|
+
* show/hide analytics.
|
|
350
|
+
*/ onMaskChange && onMaskChange(newHiddenState);
|
|
352
351
|
};
|
|
353
352
|
const handleTextInputMaskBlur = (e)=>{
|
|
354
353
|
const { relatedTarget } = e;
|
|
355
354
|
/**
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
355
|
+
* If the related target is not a child of the input,
|
|
356
|
+
* then the blur is leaving the input
|
|
357
|
+
* and not going to a child of the input.
|
|
358
|
+
* This is the case when the user blurs from the show/hide button.
|
|
359
|
+
* In this case, we want to call the onTextInputMaskBlur callback.
|
|
360
|
+
*/ const parent = inputRef.current?.parentElement;
|
|
362
361
|
if (!parent?.contains(relatedTarget)) {
|
|
363
362
|
onTextInputMaskBlur && onTextInputMaskBlur();
|
|
364
363
|
}
|
|
@@ -382,23 +381,23 @@ const TextInputMask = /*#__PURE__*/ react.forwardRef(({ name, disabled, label, l
|
|
|
382
381
|
};
|
|
383
382
|
}, []);
|
|
384
383
|
/**
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
384
|
+
* TextInputMask rules.
|
|
385
|
+
*
|
|
386
|
+
* If button label is "Show", then characters must be masked.
|
|
387
|
+
* - Type is set to password e.g. <input type="password">.
|
|
388
|
+
* - Once button is clicked, toggle the input text to show characters
|
|
389
|
+
* (type="text") and live region (aria-live="assertive") should
|
|
390
|
+
* announce, "showing characters" or similar.
|
|
391
|
+
* If button label is "Hide", then characters must be unmasked.
|
|
392
|
+
* Type is set to password e.g. <input type="text">.
|
|
393
|
+
* - Once button is clicked, toggle the input text to hide characters
|
|
394
|
+
* (type="password") and live region (aria-live="assertive") should
|
|
395
|
+
* announce, "hiding characters" or similar.
|
|
396
|
+
* If 20 seconds have passed and text input mask field has no focus-in nor
|
|
397
|
+
* keystrokes while text input mask characters are shown, then hide characters,
|
|
398
|
+
* toggle control label back to "Show", and use aria-live="polite" to announce
|
|
399
|
+
* "[text input mask label] hiding characters" or similar.
|
|
400
|
+
*/ return /*#__PURE__*/ jsxs(Fragment, {
|
|
402
401
|
children: [
|
|
403
402
|
/*#__PURE__*/ jsx(TextInput, {
|
|
404
403
|
ref: mergedInputRef,
|
|
@@ -427,8 +426,7 @@ const TextInputMask = /*#__PURE__*/ react.forwardRef(({ name, disabled, label, l
|
|
|
427
426
|
})
|
|
428
427
|
]
|
|
429
428
|
});
|
|
430
|
-
}
|
|
431
|
-
TextInputMask.displayName = "TextInputMask";
|
|
429
|
+
}
|
|
432
430
|
|
|
433
431
|
;// CONCATENATED MODULE: ./src/components/index.ts
|
|
434
432
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/ui-textinput",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"publishConfig": {
|
|
@@ -38,17 +38,17 @@
|
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@testing-library/jest-dom": "6.9.1",
|
|
41
|
-
"@versini/ui-types": "8.
|
|
41
|
+
"@versini/ui-types": "8.2.0"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@tailwindcss/typography": "0.5.19",
|
|
45
45
|
"@versini/ui-hooks": "6.1.1",
|
|
46
|
-
"@versini/ui-liveregion": "3.2.
|
|
46
|
+
"@versini/ui-liveregion": "3.2.2",
|
|
47
47
|
"clsx": "2.1.1",
|
|
48
48
|
"tailwindcss": "4.1.18"
|
|
49
49
|
},
|
|
50
50
|
"sideEffects": [
|
|
51
51
|
"**/*.css"
|
|
52
52
|
],
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "5cc3c9aaf61ca3843f16a3d6b322a92f7fb210ca"
|
|
54
54
|
}
|