react-better-html 1.1.150 → 1.1.152

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.mts CHANGED
@@ -410,6 +410,10 @@ type InputFieldComponentType = {
410
410
  dateTime: (props: ComponentPropWithRef<HTMLInputElement, InputFieldProps & {
411
411
  minDate?: Date;
412
412
  maxDate?: Date;
413
+ /** @default today */
414
+ defaultDateAfterTimePick?: `${number}-${number}-${number}`;
415
+ /** @default "00:00" */
416
+ defaultTimeAfterDatePick?: `${number}:${number}`;
413
417
  }>) => React.ReactElement;
414
418
  time: (props: ComponentPropWithRef<HTMLInputElement, InputFieldProps>) => React.ReactElement;
415
419
  color: (props: ComponentPropWithRef<HTMLInputElement, InputFieldProps>) => React.ReactElement;
@@ -475,6 +479,7 @@ type DropdownProps<Value, Data = unknown> = {
475
479
  onChange?: (value: Value | undefined) => void;
476
480
  onChangeSearch?: (query: string) => void;
477
481
  renderOption?: (option: DropdownOption<Value, Data>, index: number, isSelected: boolean) => React.ReactNode;
482
+ renderOptionDivider?: (previousOption: DropdownOption<Value, Data> | undefined, nextOption: DropdownOption<Value, Data> | undefined, previousOptionIndex: number, nextOptionIndex: number) => React.ReactNode;
478
483
  } & OmitProps<DivProps, "onChange" | "defaultChecked">;
479
484
  type DropdownComponentType = {
480
485
  <Value, Data>(props: ComponentPropWithRef<HTMLDivElement, DropdownProps<Value, Data>>): React.ReactElement;
@@ -556,6 +561,7 @@ declare function useForm<FormFields extends Record<string | number, string | num
556
561
  getRadioButtonProps: <FieldName extends keyof FormFields>(field: FieldName, value: FormFields[FieldName]) => ComponentPropWithRef<ToggleInputRef, ToggleInputProps<FormFields[FieldName]>>;
557
562
  getSwitchProps: <FieldName extends keyof FormFields>(field: FieldName) => ComponentPropWithRef<ToggleInputRef, ToggleInputProps<FormFields[FieldName]>>;
558
563
  focusField: (field: keyof FormFields) => void;
564
+ validate: () => {};
559
565
  onSubmit: (event: React.FormEvent<HTMLFormElement>) => Promise<void>;
560
566
  reset: () => void;
561
567
  requiredFields: (keyof FormFields)[] | undefined;
package/dist/index.d.ts CHANGED
@@ -410,6 +410,10 @@ type InputFieldComponentType = {
410
410
  dateTime: (props: ComponentPropWithRef<HTMLInputElement, InputFieldProps & {
411
411
  minDate?: Date;
412
412
  maxDate?: Date;
413
+ /** @default today */
414
+ defaultDateAfterTimePick?: `${number}-${number}-${number}`;
415
+ /** @default "00:00" */
416
+ defaultTimeAfterDatePick?: `${number}:${number}`;
413
417
  }>) => React.ReactElement;
414
418
  time: (props: ComponentPropWithRef<HTMLInputElement, InputFieldProps>) => React.ReactElement;
415
419
  color: (props: ComponentPropWithRef<HTMLInputElement, InputFieldProps>) => React.ReactElement;
@@ -475,6 +479,7 @@ type DropdownProps<Value, Data = unknown> = {
475
479
  onChange?: (value: Value | undefined) => void;
476
480
  onChangeSearch?: (query: string) => void;
477
481
  renderOption?: (option: DropdownOption<Value, Data>, index: number, isSelected: boolean) => React.ReactNode;
482
+ renderOptionDivider?: (previousOption: DropdownOption<Value, Data> | undefined, nextOption: DropdownOption<Value, Data> | undefined, previousOptionIndex: number, nextOptionIndex: number) => React.ReactNode;
478
483
  } & OmitProps<DivProps, "onChange" | "defaultChecked">;
479
484
  type DropdownComponentType = {
480
485
  <Value, Data>(props: ComponentPropWithRef<HTMLDivElement, DropdownProps<Value, Data>>): React.ReactElement;
@@ -556,6 +561,7 @@ declare function useForm<FormFields extends Record<string | number, string | num
556
561
  getRadioButtonProps: <FieldName extends keyof FormFields>(field: FieldName, value: FormFields[FieldName]) => ComponentPropWithRef<ToggleInputRef, ToggleInputProps<FormFields[FieldName]>>;
557
562
  getSwitchProps: <FieldName extends keyof FormFields>(field: FieldName) => ComponentPropWithRef<ToggleInputRef, ToggleInputProps<FormFields[FieldName]>>;
558
563
  focusField: (field: keyof FormFields) => void;
564
+ validate: () => {};
559
565
  onSubmit: (event: React.FormEvent<HTMLFormElement>) => Promise<void>;
560
566
  reset: () => void;
561
567
  requiredFields: (keyof FormFields)[] | undefined;
package/dist/index.js CHANGED
@@ -3037,13 +3037,17 @@ function useForm(options) {
3037
3037
  const focusField = (0, import_react10.useCallback)((field) => {
3038
3038
  inputFieldRefs.current[field]?.focus();
3039
3039
  }, []);
3040
+ const validateForm = (0, import_react10.useCallback)(() => {
3041
+ const validationErrors = validate?.(values) || {};
3042
+ setErrors(validationErrors);
3043
+ return validationErrors;
3044
+ }, [validate, values]);
3040
3045
  const onSubmitFunction = (0, import_react10.useCallback)(
3041
3046
  async (event) => {
3042
3047
  event.preventDefault();
3043
3048
  setIsSubmitting.setTrue();
3044
3049
  try {
3045
- const validationErrors = validate?.(values) || {};
3046
- setErrors(validationErrors);
3050
+ const validationErrors = validateForm();
3047
3051
  if (Object.keys(validationErrors).length === 0) {
3048
3052
  await onSubmit?.(values);
3049
3053
  } else {
@@ -3054,7 +3058,7 @@ function useForm(options) {
3054
3058
  setIsSubmitting.setFalse();
3055
3059
  }
3056
3060
  },
3057
- [values, validate, onSubmit, focusField]
3061
+ [values, validateForm, onSubmit, focusField]
3058
3062
  );
3059
3063
  const reset = (0, import_react10.useCallback)(() => {
3060
3064
  setValues(defaultValues);
@@ -3085,6 +3089,7 @@ function useForm(options) {
3085
3089
  getRadioButtonProps,
3086
3090
  getSwitchProps,
3087
3091
  focusField,
3092
+ validate: validateForm,
3088
3093
  onSubmit: onSubmitFunction,
3089
3094
  reset,
3090
3095
  requiredFields,
@@ -3697,7 +3702,7 @@ var PageHeaderComponent = (0, import_react15.forwardRef)(function PageHeader({
3697
3702
  {
3698
3703
  alignItems: "center",
3699
3704
  gap: theme2.styles.space,
3700
- marginBottom: marginBottom ?? theme2.styles.space * 2,
3705
+ marginBottom: marginBottom || theme2.styles.space * 2,
3701
3706
  ref,
3702
3707
  children: [
3703
3708
  imageUrl && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Image_default.profileImage, { src: imageUrl, size: imageSize ?? (mediaQuery.size600 ? 46 : 60) }),
@@ -5508,6 +5513,7 @@ var DropdownComponent = (0, import_react18.forwardRef)(function Dropdown({
5508
5513
  onChange,
5509
5514
  onChangeSearch,
5510
5515
  renderOption,
5516
+ renderOptionDivider,
5511
5517
  id,
5512
5518
  ...props
5513
5519
  }, ref) {
@@ -5609,31 +5615,41 @@ var DropdownComponent = (0, import_react18.forwardRef)(function Dropdown({
5609
5615
  );
5610
5616
  const selectedOption = (0, import_react18.useMemo)(() => options.find((option) => option.value === value), [options, value]);
5611
5617
  const renderedOptions = (0, import_react18.useMemo)(
5612
- () => filteredOptions.map((option, index) => {
5613
- const isSelected = option.value === value;
5614
- const isDisabled = option.disabled;
5615
- const isFocused2 = index === focusedOptionIndex;
5616
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
5617
- Div_default,
5618
- {
5619
- color: isDisabled ? theme2.colors.textSecondary + "80" : isSelected ? theme2.colors.base : theme2.colors.textPrimary,
5620
- backgroundColor: isSelected ? theme2.colors.primary : theme2.colors.backgroundContent,
5621
- filter: isFocused2 ? isDisabled ? "brightness(0.95)" : "brightness(0.9)" : void 0,
5622
- filterHover: focusedOptionIndex === void 0 && !isDisabled ? "brightness(0.9)" : void 0,
5623
- cursor: isDisabled ? "not-allowed" : "pointer",
5624
- padding: `${theme2.styles.space / 2}px ${theme2.styles.space + theme2.styles.gap}px`,
5625
- value: option,
5626
- onClickWithValue: onClickOption,
5627
- onMouseMove: () => setFocusedOptionIndex(void 0),
5628
- role: "option",
5629
- "aria-selected": isSelected,
5630
- "aria-disabled": isDisabled,
5631
- children: renderOption ? renderOption(option, index, isSelected) : /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Text_default, { children: option.label })
5632
- },
5633
- JSON.stringify(option)
5634
- );
5635
- }),
5636
- [filteredOptions, value, focusedOptionIndex, theme2.colors, onClickOption, renderOption]
5618
+ () => /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_jsx_runtime16.Fragment, { children: [
5619
+ renderOptionDivider ? renderOptionDivider(void 0, filteredOptions[0], -1, 0) : void 0,
5620
+ filteredOptions.map((option, index) => {
5621
+ const isSelected = option.value === value;
5622
+ const isDisabled = option.disabled;
5623
+ const isFocused2 = index === focusedOptionIndex;
5624
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_react18.Fragment, { children: [
5625
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
5626
+ Div_default,
5627
+ {
5628
+ color: isDisabled ? theme2.colors.textSecondary + "80" : isSelected ? theme2.colors.base : theme2.colors.textPrimary,
5629
+ backgroundColor: isSelected ? theme2.colors.primary : theme2.colors.backgroundContent,
5630
+ filter: isFocused2 ? isDisabled ? "brightness(0.95)" : "brightness(0.9)" : void 0,
5631
+ filterHover: focusedOptionIndex === void 0 && !isDisabled ? "brightness(0.9)" : void 0,
5632
+ cursor: isDisabled ? "not-allowed" : "pointer",
5633
+ padding: `${theme2.styles.space / 2}px ${theme2.styles.space + theme2.styles.gap}px`,
5634
+ value: option,
5635
+ onClickWithValue: onClickOption,
5636
+ onMouseMove: () => setFocusedOptionIndex(void 0),
5637
+ role: "option",
5638
+ "aria-selected": isSelected,
5639
+ "aria-disabled": isDisabled,
5640
+ children: renderOption ? renderOption(option, index, isSelected) : /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Text_default, { children: option.label })
5641
+ }
5642
+ ),
5643
+ renderOptionDivider ? renderOptionDivider(
5644
+ option,
5645
+ filteredOptions[index + 1],
5646
+ index,
5647
+ filteredOptions[index + 1] ? index + 1 : -1
5648
+ ) : void 0
5649
+ ] }, JSON.stringify(option));
5650
+ })
5651
+ ] }),
5652
+ [filteredOptions, value, focusedOptionIndex, theme2.colors, onClickOption, renderOption, renderOptionDivider]
5637
5653
  );
5638
5654
  (0, import_react18.useEffect)(() => {
5639
5655
  if (isOpen) {
@@ -6581,7 +6597,7 @@ InputFieldComponent.date = (0, import_react20.forwardRef)(function Date2({ minDa
6581
6597
  }
6582
6598
  );
6583
6599
  });
6584
- InputFieldComponent.dateTime = (0, import_react20.forwardRef)(function DateTime({ minDate, maxDate, ...props }, ref) {
6600
+ InputFieldComponent.dateTime = (0, import_react20.forwardRef)(function DateTime({ minDate, maxDate, defaultDateAfterTimePick, defaultTimeAfterDatePick = "00:00", ...props }, ref) {
6585
6601
  const theme2 = useTheme();
6586
6602
  const holderRef = (0, import_react20.useRef)(null);
6587
6603
  const selectedHourRef = (0, import_react20.useRef)(null);
@@ -6590,31 +6606,31 @@ InputFieldComponent.dateTime = (0, import_react20.forwardRef)(function DateTime(
6590
6606
  const { internalValue, setInternalValue, inputFieldProps, insideInputFieldComponentProps, isOpen } = useComponentInputFieldDateProps(props, holderRef, isMobileIOS);
6591
6607
  const onChange = (0, import_react20.useCallback)(
6592
6608
  (date) => {
6593
- const newValue = date ? `${date}T${internalValue?.toString().split("T")[1] ?? "00:00"}` : "";
6609
+ const newValue = date ? `${date}T${internalValue?.toString().split("T")[1] ?? defaultTimeAfterDatePick}` : "";
6594
6610
  inputFieldProps.onChangeValue?.(newValue);
6595
6611
  setInternalValue(newValue);
6596
6612
  },
6597
- [internalValue, inputFieldProps.onChangeValue]
6613
+ [internalValue, defaultTimeAfterDatePick, inputFieldProps.onChangeValue]
6598
6614
  );
6599
6615
  const onClickHour = (0, import_react20.useCallback)(
6600
6616
  (hour) => {
6601
6617
  const newTime = `${hour.toString().padStart(2, "0")}:${internalValue?.toString().split(":")[1] || "00"}`;
6602
- const today = `${(/* @__PURE__ */ new Date()).getFullYear()}-${((/* @__PURE__ */ new Date()).getMonth() + 1).toString().padStart(2, "0")}-${(/* @__PURE__ */ new Date()).getDate().toString().padStart(2, "0")}`;
6618
+ const today = defaultDateAfterTimePick ?? `${(/* @__PURE__ */ new Date()).getFullYear()}-${((/* @__PURE__ */ new Date()).getMonth() + 1).toString().padStart(2, "0")}-${(/* @__PURE__ */ new Date()).getDate().toString().padStart(2, "0")}`;
6603
6619
  const newValue = `${(internalValue.trim() || today)?.toString().split("T")[0]}T${newTime}`;
6604
6620
  inputFieldProps.onChangeValue?.(newValue);
6605
6621
  setInternalValue(newValue);
6606
6622
  },
6607
- [internalValue, inputFieldProps.onChangeValue]
6623
+ [defaultDateAfterTimePick, internalValue, inputFieldProps.onChangeValue]
6608
6624
  );
6609
6625
  const onClickMinute = (0, import_react20.useCallback)(
6610
6626
  (minute) => {
6611
6627
  const newTime = `${internalValue?.toString().split("T")?.[1]?.split(":")[0] || "00"}:${minute.toString().padStart(2, "0")}`;
6612
- const today = `${(/* @__PURE__ */ new Date()).getFullYear()}-${((/* @__PURE__ */ new Date()).getMonth() + 1).toString().padStart(2, "0")}-${(/* @__PURE__ */ new Date()).getDate().toString().padStart(2, "0")}`;
6628
+ const today = defaultDateAfterTimePick ?? `${(/* @__PURE__ */ new Date()).getFullYear()}-${((/* @__PURE__ */ new Date()).getMonth() + 1).toString().padStart(2, "0")}-${(/* @__PURE__ */ new Date()).getDate().toString().padStart(2, "0")}`;
6613
6629
  const newValue = `${(internalValue.trim() || today)?.toString().split("T")[0]}T${newTime}`;
6614
6630
  inputFieldProps.onChangeValue?.(newValue);
6615
6631
  setInternalValue(newValue);
6616
6632
  },
6617
- [internalValue, inputFieldProps.onChangeValue]
6633
+ [defaultDateAfterTimePick, internalValue, inputFieldProps.onChangeValue]
6618
6634
  );
6619
6635
  (0, import_react20.useEffect)(() => {
6620
6636
  if (isOpen && selectedHourRef.current)