@giro-ds/react 3.0.0 → 3.0.2
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/components/TextField/TextField.types.d.ts +1 -1
- package/dist/index.cjs +16 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +16 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ export type TextFieldType = 'text' | 'email' | 'password' | 'number' | 'tel' | '
|
|
|
3
3
|
export type TooltipPosition = 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
|
|
4
4
|
export interface TextFieldProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'value' | 'type'> {
|
|
5
5
|
/** Controlled value */
|
|
6
|
-
value?: string;
|
|
6
|
+
value?: string | number;
|
|
7
7
|
/** Change handler - receives string value */
|
|
8
8
|
onChange?: (value: string) => void;
|
|
9
9
|
/** Label text */
|
package/dist/index.cjs
CHANGED
|
@@ -678,11 +678,17 @@ const validateInput = ({ value, maxLength, errorMessage, required }) => {
|
|
|
678
678
|
};
|
|
679
679
|
|
|
680
680
|
const TextField$1 = React.forwardRef(({ className, value = '', label, placeholder, type = 'text', onChange, disabled = false, maxLength = 30, required = false, helperText, tooltip = false, tooltipText = '', side = 'bottom', align = 'start', errorMessage = '', id, icon, onBlur, onFocus, name, ...inputProps }, ref) => {
|
|
681
|
-
const
|
|
681
|
+
const normalizeValue = (val) => {
|
|
682
|
+
return val === undefined || val === null ? '' : String(val);
|
|
683
|
+
};
|
|
684
|
+
const [inputValue, setInputValue] = React.useState(normalizeValue(value));
|
|
682
685
|
const [inputError, setInputError] = React.useState('');
|
|
683
686
|
const [isFocused, setIsFocused] = React.useState(false);
|
|
684
687
|
const generatedId = React.useId();
|
|
685
688
|
const componentId = id || generatedId;
|
|
689
|
+
React.useEffect(() => {
|
|
690
|
+
setInputValue(normalizeValue(value));
|
|
691
|
+
}, [value]);
|
|
686
692
|
const handleChange = React.useCallback((e) => {
|
|
687
693
|
const newValue = e.target.value;
|
|
688
694
|
if (!disabled && (!maxLength || newValue.length <= maxLength)) {
|
|
@@ -826,11 +832,13 @@ function parseDate(dateString, locale = 'pt-br') {
|
|
|
826
832
|
return date;
|
|
827
833
|
}
|
|
828
834
|
|
|
829
|
-
var styles$e = {"zds-date-picker":"DatePicker-module__zds-date-picker___FjFTb","zds-date-picker__calendar-popup":"DatePicker-module__zds-date-picker__calendar-popup___hEkq7","zds-calendar--left":"DatePicker-module__zds-calendar--left___5z2UM","zds-calendar--right":"DatePicker-module__zds-calendar--right___NCJtd"};
|
|
835
|
+
var styles$e = {"zds-date-picker":"DatePicker-module__zds-date-picker___FjFTb","zds-date-picker__calendar-popup":"DatePicker-module__zds-date-picker__calendar-popup___hEkq7","zds-calendar--left":"DatePicker-module__zds-calendar--left___5z2UM","zds-calendar--right":"DatePicker-module__zds-calendar--right___NCJtd","zds-date-picker__icon":"DatePicker-module__zds-date-picker__icon___nYEnv","zds-date-picker__icon--disabled":"DatePicker-module__zds-date-picker__icon--disabled___p4Rr2"};
|
|
830
836
|
|
|
831
837
|
const DatePicker = ({ locale = 'pt-br', calendarPosition = 'left', helperText = '', required = false, label = 'Data', value, defaultValue, onChange, disabled = false, error: externalError, minDate, maxDate, className = '', 'data-testid': testId, }) => {
|
|
832
838
|
// ✅ IDs únicos para acessibilidade
|
|
833
839
|
const fieldId = React.useId();
|
|
840
|
+
const calendarId = `${fieldId}-calendar`;
|
|
841
|
+
const errorId = `${fieldId}-error`;
|
|
834
842
|
const helperTextId = `${fieldId}-help`;
|
|
835
843
|
// ✅ Suporte controlled/uncontrolled adequado
|
|
836
844
|
const isControlled = value !== undefined;
|
|
@@ -1008,9 +1016,12 @@ const DatePicker = ({ locale = 'pt-br', calendarPosition = 'left', helperText =
|
|
|
1008
1016
|
setTempInputValue(formatDate(currentSelectedDate, locale));
|
|
1009
1017
|
}
|
|
1010
1018
|
}, [locale, currentSelectedDate, isEditing]);
|
|
1011
|
-
return (jsxRuntime.jsx("div", { ref: wrapperRef, children: jsxRuntime.jsxs("div", { className: clsx(styles$e['zds-date-picker']), children: [jsxRuntime.jsx(
|
|
1012
|
-
|
|
1013
|
-
|
|
1019
|
+
return (jsxRuntime.jsx("div", { ref: wrapperRef, children: jsxRuntime.jsxs("div", { className: clsx(styles$e['zds-date-picker']), children: [jsxRuntime.jsx(TextField, { type: "tel", icon: jsxRuntime.jsx(reactIcons.Calendar16Regular, { onClick: !disabled ? handleIconClick : undefined, className: clsx(styles$e['zds-date-picker__icon'], disabled && styles$e['zds-date-picker__icon--disabled']) }), onChange: (e) => {
|
|
1020
|
+
handleTextFieldChange(String(e));
|
|
1021
|
+
}, onClick: !disabled ? handleFieldClick : undefined, onFocus: !disabled ? handleFieldFocus : undefined, onKeyDown: handleKeyDown, value: displayValue, helperText: combinedHelperText, maxLength: 10, required: required, label: label, disabled: disabled, id: fieldId, className: className, "data-testid": testId, placeholder: locale === 'en-us' ? 'MM/DD/YYYY' : 'DD/MM/YYYY', "aria-label": "Open calendar", "aria-expanded": showCalendar, "aria-controls": calendarId, "aria-invalid": !!currentError, "aria-describedby": currentError ? errorId : (helperText ? helperTextId : undefined) }), jsxRuntime.jsx("div", { className: clsx(styles$e['zds-date-picker__calendar-popup'], calendarPosition === 'left' && styles$e['zds-calendar--left'], calendarPosition === 'right' && styles$e['zds-calendar--right']), children: showCalendar && (jsxRuntime.jsx(MemoizedCalendar, { selectedDate: currentSelectedDate, currentDate: currentDate, onDateChange: setCurrentDate, onDaySelect: handleDaySelect, locale: locale, format: locale === 'en-us' ? 'mm/dd/yyyy' : 'dd/mm/yyyy', minDate: minDate, maxDate: maxDate, id: calendarId, onClear: () => {
|
|
1022
|
+
handleDateChange(null);
|
|
1023
|
+
setCurrentDate(new Date());
|
|
1024
|
+
} })) })] }) }));
|
|
1014
1025
|
};
|
|
1015
1026
|
var DatePicker_default = React.memo(DatePicker);
|
|
1016
1027
|
|