@bigtablet/design-system 1.11.1 → 1.11.3
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 +5 -2
- package/dist/index.js +34 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -110,7 +110,7 @@ declare const Switch: ({ checked, defaultChecked, onChange, size, disabled, clas
|
|
|
110
110
|
|
|
111
111
|
type TextFieldVariant = "outline" | "filled" | "ghost";
|
|
112
112
|
type TextFieldSize = "sm" | "md" | "lg";
|
|
113
|
-
interface TextFieldProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "size" | "onChange"> {
|
|
113
|
+
interface TextFieldProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "size" | "onChange" | "value" | "defaultValue"> {
|
|
114
114
|
label?: string;
|
|
115
115
|
helperText?: string;
|
|
116
116
|
error?: boolean;
|
|
@@ -120,7 +120,10 @@ interface TextFieldProps extends Omit<React.InputHTMLAttributes<HTMLInputElement
|
|
|
120
120
|
leftIcon?: React.ReactNode;
|
|
121
121
|
rightIcon?: React.ReactNode;
|
|
122
122
|
fullWidth?: boolean;
|
|
123
|
-
onChangeAction?: (
|
|
123
|
+
onChangeAction?: (value: string) => void;
|
|
124
|
+
value?: string;
|
|
125
|
+
defaultValue?: string;
|
|
126
|
+
transformValue?: (value: string) => string;
|
|
124
127
|
}
|
|
125
128
|
declare const TextField: React.ForwardRefExoticComponent<TextFieldProps & React.RefAttributes<HTMLInputElement>>;
|
|
126
129
|
|
package/dist/index.js
CHANGED
|
@@ -509,10 +509,23 @@ var TextField = React3.forwardRef(
|
|
|
509
509
|
fullWidth,
|
|
510
510
|
className,
|
|
511
511
|
onChangeAction,
|
|
512
|
+
value,
|
|
513
|
+
defaultValue,
|
|
514
|
+
transformValue,
|
|
512
515
|
...props
|
|
513
516
|
}, ref) => {
|
|
514
517
|
const inputId = id ?? React3.useId();
|
|
515
518
|
const helperId = helperText ? `${inputId}-help` : void 0;
|
|
519
|
+
const isControlled = value !== void 0;
|
|
520
|
+
const applyTransform = (nextValue) => transformValue ? transformValue(nextValue) : nextValue;
|
|
521
|
+
const [innerValue, setInnerValue] = React3.useState(
|
|
522
|
+
() => applyTransform(value ?? defaultValue ?? "")
|
|
523
|
+
);
|
|
524
|
+
const isComposingRef = React3.useRef(false);
|
|
525
|
+
React3.useEffect(() => {
|
|
526
|
+
if (!isControlled) return;
|
|
527
|
+
setInnerValue(applyTransform(value ?? ""));
|
|
528
|
+
}, [isControlled, value, transformValue]);
|
|
516
529
|
const rootClassName = [
|
|
517
530
|
"text_field",
|
|
518
531
|
fullWidth && "text_field_full_width",
|
|
@@ -545,7 +558,27 @@ var TextField = React3.forwardRef(
|
|
|
545
558
|
"aria-invalid": !!error,
|
|
546
559
|
"aria-describedby": helperId,
|
|
547
560
|
...props,
|
|
548
|
-
|
|
561
|
+
value: innerValue,
|
|
562
|
+
onCompositionStart: () => {
|
|
563
|
+
isComposingRef.current = true;
|
|
564
|
+
},
|
|
565
|
+
onCompositionEnd: (event) => {
|
|
566
|
+
isComposingRef.current = false;
|
|
567
|
+
const rawValue = event.currentTarget.value;
|
|
568
|
+
const nextValue = applyTransform(rawValue);
|
|
569
|
+
setInnerValue(nextValue);
|
|
570
|
+
onChangeAction?.(nextValue);
|
|
571
|
+
},
|
|
572
|
+
onChange: (event) => {
|
|
573
|
+
const rawValue = event.target.value;
|
|
574
|
+
if (isComposingRef.current) {
|
|
575
|
+
setInnerValue(rawValue);
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
const nextValue = applyTransform(rawValue);
|
|
579
|
+
setInnerValue(nextValue);
|
|
580
|
+
onChangeAction?.(nextValue);
|
|
581
|
+
}
|
|
549
582
|
}
|
|
550
583
|
),
|
|
551
584
|
rightIcon ? /* @__PURE__ */ jsx("span", { className: "text_field_icon text_field_icon_right", children: rightIcon }) : null
|