react-better-html 1.1.35 → 1.1.37

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.
@@ -131,7 +131,7 @@ const InputFieldComponent = (0, react_1.forwardRef)(function InputField({ label,
131
131
  }, [withDebounce, onChangeValue, debouncedValue]);
132
132
  return ((0, jsx_runtime_1.jsxs)(Div_1.default.column, { width: "100%", gap: theme.styles.gap / 2, ...styledComponentStylesWithExcluded, children: [label && (0, jsx_runtime_1.jsx)(Label_1.default, { text: label, required: required, isError: !!errorText }), (0, jsx_runtime_1.jsxs)(Div_1.default, { position: "relative", width: "100%", children: [leftIcon && ((0, jsx_runtime_1.jsx)(Icon_1.default, { name: leftIcon, position: "absolute", top: 46 / 2, left: theme.styles.space + 1, transform: "translateY(-50%)", pointerEvents: "none", zIndex: 1002 })), (0, jsx_runtime_1.jsx)(InputElement, { theme: theme, withLeftIcon: leftIcon !== undefined, withRightIcon: rightIcon !== undefined, required: required, placeholder: placeholder ?? label, onChange: onChangeElement, ...styledComponentStylesWithoutExcluded, ...dataProps, ...ariaProps, ...restProps, ref: ref }), rightIcon ? (onClickRightIcon ? ((0, jsx_runtime_1.jsx)(Button_1.default.icon, { icon: rightIcon, position: "absolute", top: 46 / 2, right: theme.styles.space + 1 - theme.styles.space / 2, transform: "translateY(-50%)", onClick: onClickRightIcon })) : ((0, jsx_runtime_1.jsx)(Icon_1.default, { name: rightIcon, position: "absolute", top: 46 / 2, right: theme.styles.space + 1, transform: "translateY(-50%)", pointerEvents: "none" }))) : undefined, insideInputFieldComponent] }), (errorText || infoText) && ((0, jsx_runtime_1.jsx)(Text_1.default, { as: "span", display: "block", fontSize: 14, color: errorText ? theme.colors.error : theme.colors.textSecondary, children: errorText || infoText }))] }));
133
133
  });
134
- InputFieldComponent.multiline = (0, react_1.forwardRef)(function Textarea({ label, errorText, infoText, onChange, onChangeValue, required, ...props }, ref) {
134
+ InputFieldComponent.multiline = (0, react_1.forwardRef)(function Multiline({ label, placeholder, errorText, infoText, onChange, onChangeValue, required, ...props }, ref) {
135
135
  const theme = (0, BetterHtmlProvider_1.useTheme)();
136
136
  const styledComponentStyles = (0, hooks_1.useStyledComponentStyles)(props, theme);
137
137
  const dataProps = (0, hooks_1.useComponentPropsWithPrefix)(props, "data");
@@ -141,19 +141,19 @@ InputFieldComponent.multiline = (0, react_1.forwardRef)(function Textarea({ labe
141
141
  onChange?.(event);
142
142
  onChangeValue?.(event.target.value);
143
143
  }, [onChange, onChangeValue]);
144
- return ((0, jsx_runtime_1.jsxs)(Div_1.default.column, { gap: theme.styles.gap / 2, children: [label && (0, jsx_runtime_1.jsx)(Label_1.default, { text: label, required: required, isError: !!errorText }), (0, jsx_runtime_1.jsx)(TextareaElement, { theme: theme, required: required, onChange: onChangeElement, ...styledComponentStyles, ...dataProps, ...ariaProps, ...restProps, ref: ref }), (errorText || infoText) && ((0, jsx_runtime_1.jsx)(Text_1.default, { as: "span", display: "block", marginTop: theme.styles.gap / 2, color: errorText ? theme.colors.error : theme.colors.textSecondary, fontSize: 14, children: errorText || infoText }))] }));
144
+ return ((0, jsx_runtime_1.jsxs)(Div_1.default.column, { gap: theme.styles.gap / 2, children: [label && (0, jsx_runtime_1.jsx)(Label_1.default, { text: label, required: required, isError: !!errorText }), (0, jsx_runtime_1.jsx)(TextareaElement, { theme: theme, required: required, placeholder: placeholder ?? label, onChange: onChangeElement, ...styledComponentStyles, ...dataProps, ...ariaProps, ...restProps, ref: ref }), (errorText || infoText) && ((0, jsx_runtime_1.jsx)(Text_1.default, { as: "span", display: "block", marginTop: theme.styles.gap / 2, color: errorText ? theme.colors.error : theme.colors.textSecondary, fontSize: 14, children: errorText || infoText }))] }));
145
145
  });
146
146
  InputFieldComponent.email = (0, react_1.forwardRef)(function Email({ ...props }, ref) {
147
147
  return ((0, jsx_runtime_1.jsx)(InputFieldComponent, { type: "email", placeholder: "your@email.here", autoComplete: "email", autoCorrect: "off", autoCapitalize: "off", ref: ref, ...props }));
148
148
  });
149
- InputFieldComponent.password = (0, react_1.forwardRef)(function Email({ ...props }, ref) {
149
+ InputFieldComponent.password = (0, react_1.forwardRef)(function Password({ ...props }, ref) {
150
150
  const [isPassword, setIsPassword] = (0, hooks_1.useBooleanState)(true);
151
151
  return ((0, jsx_runtime_1.jsx)(InputFieldComponent, { type: isPassword ? "password" : "text", placeholder: "******", rightIcon: isPassword ? "eye" : "eyeDashed", onClickRightIcon: setIsPassword.toggle, autoComplete: "current-password", autoCorrect: "off", autoCapitalize: "off", ref: ref, ...props }));
152
152
  });
153
- InputFieldComponent.search = (0, react_1.forwardRef)(function Email({ ...props }, ref) {
153
+ InputFieldComponent.search = (0, react_1.forwardRef)(function Search({ ...props }, ref) {
154
154
  return (0, jsx_runtime_1.jsx)(InputFieldComponent, { leftIcon: "magnifyingGlass", placeholder: "Search...", ref: ref, ...props });
155
155
  });
156
- InputFieldComponent.phoneNumber = (0, react_1.forwardRef)(function Email({ value, onChangeValue, ...props }, ref) {
156
+ InputFieldComponent.phoneNumber = (0, react_1.forwardRef)(function PhoneNumber({ label, value, onChangeValue, ...props }, ref) {
157
157
  const theme = (0, BetterHtmlProvider_1.useTheme)();
158
158
  const [dropdownValue, setDropdownValue] = (0, react_1.useState)();
159
159
  const [inputFieldValue, setInputFieldValue] = (0, react_1.useState)(value?.toString() ?? "");
@@ -187,7 +187,7 @@ InputFieldComponent.phoneNumber = (0, react_1.forwardRef)(function Email({ value
187
187
  setDropdownValue(country.phoneNumberExtension);
188
188
  setInputFieldValue(newValue.slice(country?.phoneNumberExtension.length + 1));
189
189
  }, [value]);
190
- return ((0, jsx_runtime_1.jsxs)(Div_1.default.row, { children: [(0, jsx_runtime_1.jsx)(Dropdown_1.default, { options: options, renderOption: renderOption, width: 130, withSearch: true, placeholder: "+00", inputFieldClassName: "react-better-html-phone-number-holder", defaultValue: defaultValue, value: dropdownValue, onChange: setDropdownValue, withoutClearButton: true }), (0, jsx_runtime_1.jsx)(InputFieldComponent, { placeholder: "Phone number", className: "react-better-html-phone-number", value: inputFieldValue, onChangeValue: onChangeValueElement, ref: ref, ...props })] }));
190
+ return ((0, jsx_runtime_1.jsxs)(Div_1.default, { children: [label && (0, jsx_runtime_1.jsx)(Label_1.default, { text: label, required: props.required, isError: !!props.errorText }), (0, jsx_runtime_1.jsxs)(Div_1.default.row, { children: [(0, jsx_runtime_1.jsx)(Dropdown_1.default, { options: options, renderOption: renderOption, width: 130, withSearch: true, placeholder: "+00", inputFieldClassName: "react-better-html-phone-number-holder", defaultValue: defaultValue, value: dropdownValue, onChange: setDropdownValue, withoutClearButton: true }), (0, jsx_runtime_1.jsx)(InputFieldComponent, { placeholder: "Phone number", className: "react-better-html-phone-number", value: inputFieldValue, onChangeValue: onChangeValueElement, ref: ref, ...props })] })] }));
191
191
  });
192
192
  const InputField = (0, react_1.memo)(InputFieldComponent);
193
193
  InputField.multiline = InputFieldComponent.multiline;
@@ -187,6 +187,7 @@ function useForm({ defaultValues, requiredFields, onSubmit, validate, }) {
187
187
  const getInputFieldProps = (0, react_1.useCallback)((field) => {
188
188
  const type = inputTypes[field] ?? "text";
189
189
  return {
190
+ required: requiredFields?.includes(field),
190
191
  value: values[field]?.toString() ?? "",
191
192
  onChangeValue: (newValue) => {
192
193
  const readyValue = type === "number" ? (newValue ? Number(newValue) : undefined) : newValue;
@@ -206,8 +207,8 @@ function useForm({ defaultValues, requiredFields, onSubmit, validate, }) {
206
207
  };
207
208
  }, [values, setFieldValue, inputTypes, errors]);
208
209
  const getTextAreaProps = (0, react_1.useCallback)((field) => {
209
- const type = inputTypes[field] ?? "text";
210
210
  return {
211
+ required: requiredFields?.includes(field),
211
212
  value: values[field]?.toString() ?? "",
212
213
  onChangeValue: (newValue) => {
213
214
  setFieldValue(field, newValue);
@@ -217,6 +218,7 @@ function useForm({ defaultValues, requiredFields, onSubmit, validate, }) {
217
218
  }, [values, setFieldValue, inputTypes, errors]);
218
219
  const getDropdownFieldProps = (0, react_1.useCallback)((field) => {
219
220
  return {
221
+ required: requiredFields?.includes(field),
220
222
  value: values[field],
221
223
  onChange: (value) => {
222
224
  setFieldValue(field, value);
@@ -226,6 +228,7 @@ function useForm({ defaultValues, requiredFields, onSubmit, validate, }) {
226
228
  }, [values, errors, setFieldValue]);
227
229
  const getCheckboxProps = (0, react_1.useCallback)((field) => {
228
230
  return {
231
+ required: requiredFields?.includes(field),
229
232
  checked: values[field],
230
233
  onChange: (checked) => {
231
234
  setFieldValue(field, checked);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-better-html",
3
- "version": "1.1.35",
3
+ "version": "1.1.37",
4
4
  "description": "A component library for react that is as close to plane html as possible",
5
5
  "main": "dist/index.js",
6
6
  "files": [