@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 CHANGED
@@ -1,50 +1,111 @@
1
- import { default as React_2 } from 'react';
1
+ import { JSX } from 'react/jsx-runtime';
2
2
 
3
- declare type Size = "xs" | "sm" | "md" | "lg" | "xl";
4
-
5
- export declare const TEXT_INPUT_CLASSNAME = "av-text-input";
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<React_2.InputHTMLAttributes<HTMLInputElement>, "size"> & React_2.RefAttributes<HTMLInputElement>>;
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 TextInputMask: React_2.ForwardRefExoticComponent<{
32
- rightElement: React_2.ReactElement;
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
- label: string;
37
- name: string;
38
- error?: boolean;
39
- focusMode?: "dark" | "light" | "system" | "alt-system";
40
- helperText?: string;
41
- inputClassName?: string;
42
- labelHidden?: boolean;
43
- labelId?: string;
44
- mode?: "dark" | "light" | "system" | "alt-system";
45
- noBorder?: boolean;
46
- raw?: boolean;
47
- size?: Size;
48
- } & Omit<React_2.InputHTMLAttributes<HTMLInputElement>, "size"> & React_2.RefAttributes<HTMLInputElement>>;
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.1.1
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
- const TextInput = /*#__PURE__*/ react.forwardRef(({ 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", ...extraProps }, ref)=>{
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
- * - 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);
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
- * This effect sets the label and helper text position based on
228
- * the size of the input.
229
- */ useLayoutEffect(()=>{
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
- const TextInputMask = /*#__PURE__*/ react.forwardRef(({ name, disabled, label, labelHidden, onMaskChange, onChange, onBlur, onFocus, onTextInputMaskBlur, rightElement, ...otherProps }, ref)=>{
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
- * Callback that can be used to generate
332
- * show/hide analytics.
333
- */ onMaskChange && onMaskChange(true);
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
- * Callback that can be used to generate
350
- * show/hide analytics.
351
- */ onMaskChange && onMaskChange(newHiddenState);
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
- * If the related target is not a child of the input,
357
- * then the blur is leaving the input
358
- * and not going to a child of the input.
359
- * This is the case when the user blurs from the show/hide button.
360
- * In this case, we want to call the onTextInputMaskBlur callback.
361
- */ const parent = inputRef.current?.parentElement;
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
- * TextInputMask rules.
386
- *
387
- * If button label is "Show", then characters must be masked.
388
- * - Type is set to password e.g. <input type="password">.
389
- * - Once button is clicked, toggle the input text to show characters
390
- * (type="text") and live region (aria-live="assertive") should
391
- * announce, "showing characters" or similar.
392
- * If button label is "Hide", then characters must be unmasked.
393
- * Type is set to password e.g. <input type="text">.
394
- * - Once button is clicked, toggle the input text to hide characters
395
- * (type="password") and live region (aria-live="assertive") should
396
- * announce, "hiding characters" or similar.
397
- * If 20 seconds have passed and text input mask field has no focus-in nor
398
- * keystrokes while text input mask characters are shown, then hide characters,
399
- * toggle control label back to "Show", and use aria-live="polite" to announce
400
- * "[text input mask label] hiding characters" or similar.
401
- */ return /*#__PURE__*/ jsxs(Fragment, {
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.1.1",
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.1.1"
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.1",
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": "a3730974df8fcea3c016bd83844c4243dbb10208"
53
+ "gitHead": "5cc3c9aaf61ca3843f16a3d6b322a92f7fb210ca"
54
54
  }