react-better-html 1.1.92 → 1.1.94

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.mjs CHANGED
@@ -1803,7 +1803,7 @@ function useComponentInputFieldDateProps(props, holderRef, disabled) {
1803
1803
  }, [isOpen]);
1804
1804
  useEffect2(() => {
1805
1805
  const handleClickOutside = (event) => {
1806
- if (holderRef.current && !holderRef.current.contains(event.target)) {
1806
+ if (holderRef && holderRef.current && !holderRef.current.contains(event.target)) {
1807
1807
  setIsOpen.setFalse();
1808
1808
  }
1809
1809
  };
@@ -4846,6 +4846,7 @@ function Label({ text, required, isError, color, htmlFor }) {
4846
4846
  Text_default,
4847
4847
  {
4848
4848
  as: "label",
4849
+ width: "fit-content",
4849
4850
  height: 16,
4850
4851
  fontSize: 14,
4851
4852
  color: isError ? theme2.colors.error : color ?? theme2.colors.textSecondary,
@@ -4865,7 +4866,7 @@ var Label_default = memo13(Label);
4865
4866
 
4866
4867
  // src/components/Dropdown.tsx
4867
4868
  import { forwardRef as forwardRef7, memo as memo14, useCallback as useCallback6, useEffect as useEffect5, useMemo as useMemo3, useRef as useRef3, useState as useState4 } from "react";
4868
- import { jsx as jsx13, jsxs as jsxs8 } from "react/jsx-runtime";
4869
+ import { Fragment as Fragment3, jsx as jsx13, jsxs as jsxs8 } from "react/jsx-runtime";
4869
4870
  var DropdownComponent = forwardRef7(function Dropdown({
4870
4871
  label,
4871
4872
  labelColor,
@@ -4886,6 +4887,7 @@ var DropdownComponent = forwardRef7(function Dropdown({
4886
4887
  debounceIsLoading,
4887
4888
  debounceMinimumSymbolsRequired,
4888
4889
  withoutClearButton,
4890
+ withoutRenderingOptionsWhenClosed,
4889
4891
  onChange,
4890
4892
  onChangeSearch,
4891
4893
  renderOption,
@@ -4894,6 +4896,7 @@ var DropdownComponent = forwardRef7(function Dropdown({
4894
4896
  }, ref) {
4895
4897
  const theme2 = useTheme();
4896
4898
  const inputFieldHolderRef = useRef3(null);
4899
+ const buttonsRef = useRef3(null);
4897
4900
  const inputRef = useRef3(null);
4898
4901
  const [isOpen, setIsOpen] = useBooleanState();
4899
4902
  const [isOpenLate, setIsOpenLate] = useBooleanState();
@@ -4988,6 +4991,33 @@ var DropdownComponent = forwardRef7(function Dropdown({
4988
4991
  [withDebounce, onChangeSearch]
4989
4992
  );
4990
4993
  const selectedOption = useMemo3(() => options.find((option) => option.value === value), [options, value]);
4994
+ const renderedOptions = useMemo3(
4995
+ () => filteredOptions.map((option, index) => {
4996
+ const isSelected = option.value === value;
4997
+ const isDisabled = option.disabled;
4998
+ const isFocused2 = index === focusedOptionIndex;
4999
+ return /* @__PURE__ */ jsx13(
5000
+ Div_default,
5001
+ {
5002
+ color: isDisabled ? theme2.colors.textSecondary + "80" : isSelected ? theme2.colors.base : theme2.colors.textPrimary,
5003
+ backgroundColor: isSelected ? theme2.colors.primary : theme2.colors.backgroundContent,
5004
+ filter: isFocused2 ? isDisabled ? "brightness(0.95)" : "brightness(0.9)" : void 0,
5005
+ filterHover: focusedOptionIndex === void 0 && !isDisabled ? "brightness(0.9)" : void 0,
5006
+ cursor: isDisabled ? "not-allowed" : "pointer",
5007
+ padding: `${theme2.styles.space / 2}px ${theme2.styles.space + theme2.styles.gap}px`,
5008
+ value: option,
5009
+ onClickWithValue: onClickOption,
5010
+ onMouseMove: () => setFocusedOptionIndex(void 0),
5011
+ role: "option",
5012
+ "aria-selected": isSelected,
5013
+ "aria-disabled": isDisabled,
5014
+ children: renderOption ? renderOption(option, index, isSelected) : /* @__PURE__ */ jsx13(Text_default, { children: option.label })
5015
+ },
5016
+ JSON.stringify(option)
5017
+ );
5018
+ }),
5019
+ [filteredOptions, value, focusedOptionIndex, theme2.colors, onClickOption, renderOption]
5020
+ );
4991
5021
  useEffect5(() => {
4992
5022
  if (isOpen) {
4993
5023
  setIsOpenLate.setTrue();
@@ -5004,7 +5034,7 @@ var DropdownComponent = forwardRef7(function Dropdown({
5004
5034
  }, [filteredOptions]);
5005
5035
  useEffect5(() => {
5006
5036
  const handleClickOutside = (event) => {
5007
- if (inputFieldHolderRef.current && !inputFieldHolderRef.current.contains(event.target)) {
5037
+ if (inputFieldHolderRef.current && buttonsRef.current && !inputFieldHolderRef.current.contains(event.target) && !buttonsRef.current.contains(event.target)) {
5008
5038
  setIsOpen.setFalse();
5009
5039
  setSearchQuery("");
5010
5040
  setFocusedOptionIndex(void 0);
@@ -5024,7 +5054,7 @@ var DropdownComponent = forwardRef7(function Dropdown({
5024
5054
  const displayValue = withSearch && isFocused ? searchQuery : selectedOption?.label ?? "";
5025
5055
  const withClearButton = isOpen && selectedOption;
5026
5056
  const readyPlaceholder = placeholder ? placeholder : `Select an ${label?.toLowerCase() ?? "option"}`;
5027
- return /* @__PURE__ */ jsx13(Div_default.column, { width: "100%", position: "relative", userSelect: "none", ...props, children: /* @__PURE__ */ jsxs8(Div_default.row, { position: "relative", width: "100%", ref: inputFieldHolderRef, children: [
5057
+ return /* @__PURE__ */ jsx13(Div_default.column, { width: "100%", position: "relative", userSelect: "none", ...props, children: /* @__PURE__ */ jsxs8(Div_default.row, { position: "relative", width: "100%", children: [
5028
5058
  /* @__PURE__ */ jsx13(
5029
5059
  InputField_default,
5030
5060
  {
@@ -5069,30 +5099,7 @@ var DropdownComponent = forwardRef7(function Dropdown({
5069
5099
  transition: theme2.styles.transition,
5070
5100
  role: "listbox",
5071
5101
  "aria-label": label,
5072
- children: isLoadingDebouncedSearchQuery || debounceIsLoading ? /* @__PURE__ */ jsx13(Div_default, { padding: `${theme2.styles.space / 2}px ${theme2.styles.space + theme2.styles.gap}px`, children: /* @__PURE__ */ jsx13(Loader_default.text, {}) }) : filteredOptions.length ? filteredOptions.map((option, index) => {
5073
- const isSelected = option.value === value;
5074
- const isDisabled = option.disabled;
5075
- const isFocused2 = index === focusedOptionIndex;
5076
- return /* @__PURE__ */ jsx13(
5077
- Div_default,
5078
- {
5079
- color: isDisabled ? theme2.colors.textSecondary + "80" : isSelected ? theme2.colors.base : theme2.colors.textPrimary,
5080
- backgroundColor: isSelected ? theme2.colors.primary : theme2.colors.backgroundContent,
5081
- filter: isFocused2 ? isDisabled ? "brightness(0.95)" : "brightness(0.9)" : void 0,
5082
- filterHover: focusedOptionIndex === void 0 && !isDisabled ? "brightness(0.9)" : void 0,
5083
- cursor: isDisabled ? "not-allowed" : "pointer",
5084
- padding: `${theme2.styles.space / 2}px ${theme2.styles.space + theme2.styles.gap}px`,
5085
- value: option,
5086
- onClickWithValue: onClickOption,
5087
- onMouseMove: () => setFocusedOptionIndex(void 0),
5088
- role: "option",
5089
- "aria-selected": isSelected,
5090
- "aria-disabled": isDisabled,
5091
- children: renderOption ? renderOption(option, index, isSelected) : /* @__PURE__ */ jsx13(Text_default, { children: option.label })
5092
- },
5093
- JSON.stringify(option)
5094
- );
5095
- }) : /* @__PURE__ */ jsx13(Div_default, { padding: `${theme2.styles.space / 2}px ${theme2.styles.space + theme2.styles.gap}px`, children: /* @__PURE__ */ jsx13(Text_default.unknown, { textAlign: "left", children: debounceMinimumSymbolsRequired !== void 0 && searchQuery.length < debounceMinimumSymbolsRequired ? `Enter at least ${debounceMinimumSymbolsRequired} characters` : "No options" }) })
5102
+ children: isLoadingDebouncedSearchQuery || debounceIsLoading ? /* @__PURE__ */ jsx13(Div_default, { padding: `${theme2.styles.space / 2}px ${theme2.styles.space + theme2.styles.gap}px`, children: /* @__PURE__ */ jsx13(Loader_default.text, {}) }) : filteredOptions.length ? /* @__PURE__ */ jsx13(Fragment3, { children: (withoutRenderingOptionsWhenClosed ? isOpen || isOpenLate : true) ? renderedOptions : void 0 }) : /* @__PURE__ */ jsx13(Div_default, { padding: `${theme2.styles.space / 2}px ${theme2.styles.space + theme2.styles.gap}px`, children: /* @__PURE__ */ jsx13(Text_default.unknown, { textAlign: "left", children: debounceMinimumSymbolsRequired !== void 0 && searchQuery.length < debounceMinimumSymbolsRequired ? `Enter at least ${debounceMinimumSymbolsRequired} characters` : "No options" }) })
5096
5103
  }
5097
5104
  ),
5098
5105
  role: "combobox",
@@ -5100,6 +5107,7 @@ var DropdownComponent = forwardRef7(function Dropdown({
5100
5107
  "aria-controls": "dropdown-list",
5101
5108
  "aria-haspopup": "listbox",
5102
5109
  "aria-label": label,
5110
+ holderRef: inputFieldHolderRef,
5103
5111
  ref: inputRef
5104
5112
  }
5105
5113
  ),
@@ -5116,6 +5124,7 @@ var DropdownComponent = forwardRef7(function Dropdown({
5116
5124
  filter: disabled ? "brightness(0.9)" : void 0,
5117
5125
  opacity: disabled ? 0.6 : void 0,
5118
5126
  zIndex: isOpen || isOpenLate ? 1001 : void 0,
5127
+ ref: buttonsRef,
5119
5128
  children: [
5120
5129
  !withoutClearButton && /* @__PURE__ */ jsx13(
5121
5130
  Button_default.icon,
@@ -5174,6 +5183,7 @@ DropdownComponent.countries = forwardRef7(function Countries({ ...props }, ref)
5174
5183
  placeholder: "Select a country",
5175
5184
  options,
5176
5185
  renderOption,
5186
+ withoutRenderingOptionsWhenClosed: true,
5177
5187
  ref,
5178
5188
  ...props
5179
5189
  }
@@ -5365,6 +5375,9 @@ var Calendar_default = memo15(Calendar);
5365
5375
  // src/components/InputField.tsx
5366
5376
  import { jsx as jsx15, jsxs as jsxs10 } from "react/jsx-runtime";
5367
5377
  var buttonWidth = 50;
5378
+ var colorPickerSpacing = 4;
5379
+ var colorPickerColorWidth = 12 + 27 + colorPickerSpacing;
5380
+ var colorPickerValueWidth = 12 + 74 + colorPickerSpacing;
5368
5381
  var InputElement = styled8.input.withConfig({
5369
5382
  shouldForwardProp: (prop) => !["theme", "withLeftIcon", "withRightIcon", "normalStyle", "hoverStyle"].includes(prop)
5370
5383
  })`
@@ -5413,6 +5426,17 @@ var InputElement = styled8.input.withConfig({
5413
5426
  }
5414
5427
  }
5415
5428
 
5429
+ &[type="color"] {
5430
+ --color-spacing: ${(props) => (props.theme.styles.space + props.theme.styles.gap) / 2}px;
5431
+
5432
+ width: calc(var(--color-spacing) + 27px + ${colorPickerValueWidth}px);
5433
+ height: 48px;
5434
+ padding: 0px;
5435
+ padding-block: calc(var(--color-spacing) - 3px);
5436
+ padding-left: var(--color-spacing);
5437
+ padding-right: ${colorPickerValueWidth}px;
5438
+ }
5439
+
5416
5440
  &.react-better-html-phone-number-holder {
5417
5441
  border-right: none;
5418
5442
  border-top-right-radius: 0px;
@@ -6125,6 +6149,41 @@ InputFieldComponent.time = forwardRef8(function Time({ ...props }, ref) {
6125
6149
  }
6126
6150
  );
6127
6151
  });
6152
+ InputFieldComponent.color = forwardRef8(function Color2({ value, onChangeValue, ...props }, ref) {
6153
+ const [inputFieldValue, setInputFieldValue] = useState6(value ?? "#000000");
6154
+ const onChangeValueElement = useCallback8(
6155
+ (value2) => {
6156
+ setInputFieldValue(value2);
6157
+ onChangeValue?.(value2);
6158
+ },
6159
+ [onChangeValue]
6160
+ );
6161
+ return /* @__PURE__ */ jsx15(
6162
+ InputFieldComponent,
6163
+ {
6164
+ type: "color",
6165
+ insideInputFieldComponent: /* @__PURE__ */ jsx15(
6166
+ Div_default.row,
6167
+ {
6168
+ position: "absolute",
6169
+ width: "100%",
6170
+ height: "100%",
6171
+ top: 0,
6172
+ left: colorPickerSpacing,
6173
+ alignItems: "center",
6174
+ pointerEvents: "none",
6175
+ userSelect: "none",
6176
+ paddingLeft: colorPickerColorWidth,
6177
+ children: /* @__PURE__ */ jsx15(Text_default, { children: inputFieldValue })
6178
+ }
6179
+ ),
6180
+ value: inputFieldValue,
6181
+ onChangeValue: onChangeValueElement,
6182
+ ref,
6183
+ ...props
6184
+ }
6185
+ );
6186
+ });
6128
6187
  var InputField2 = memo16(InputFieldComponent);
6129
6188
  InputField2.multiline = InputFieldComponent.multiline;
6130
6189
  InputField2.email = InputFieldComponent.email;
@@ -6134,6 +6193,7 @@ InputField2.phoneNumber = InputFieldComponent.phoneNumber;
6134
6193
  InputField2.date = InputFieldComponent.date;
6135
6194
  InputField2.dateTime = InputFieldComponent.dateTime;
6136
6195
  InputField2.time = InputFieldComponent.time;
6196
+ InputField2.color = InputFieldComponent.color;
6137
6197
  var InputField_default = InputField2;
6138
6198
 
6139
6199
  // src/components/ToggleInput.tsx
@@ -6596,7 +6656,7 @@ var ColorThemeSwitch_default = ColorThemeSwitch2;
6596
6656
  // src/components/Table.tsx
6597
6657
  import { forwardRef as forwardRef11, memo as memo20, useCallback as useCallback10, useMemo as useMemo7, useState as useState8 } from "react";
6598
6658
  import styled10, { css as css2 } from "styled-components";
6599
- import { Fragment as Fragment3, jsx as jsx20, jsxs as jsxs15 } from "react/jsx-runtime";
6659
+ import { Fragment as Fragment4, jsx as jsx20, jsxs as jsxs15 } from "react/jsx-runtime";
6600
6660
  var defaultImageWidth = 120;
6601
6661
  var TableStyledComponent = styled10.table.withConfig({
6602
6662
  shouldForwardProp: (prop) => !["isStriped", "withHover", "withStickyHeader", "colorTheme", "theme"].includes(prop)
@@ -6683,7 +6743,7 @@ var TableComponent = forwardRef11(function Table({
6683
6743
  return column.format ? column.format(item, index) : String(value ?? "");
6684
6744
  }
6685
6745
  case "element": {
6686
- return column.render?.(item, index) ?? /* @__PURE__ */ jsx20(Fragment3, {});
6746
+ return column.render?.(item, index) ?? /* @__PURE__ */ jsx20(Fragment4, {});
6687
6747
  }
6688
6748
  case "image": {
6689
6749
  const { type, keyName, ...props2 } = column;
@@ -6708,7 +6768,7 @@ var TableComponent = forwardRef11(function Table({
6708
6768
  );
6709
6769
  }
6710
6770
  default: {
6711
- return /* @__PURE__ */ jsx20(Fragment3, {});
6771
+ return /* @__PURE__ */ jsx20(Fragment4, {});
6712
6772
  }
6713
6773
  }
6714
6774
  },