react-better-html 1.1.93 → 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.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +35 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -439,6 +439,8 @@ type DropdownProps<Value, Data = unknown> = {
|
|
|
439
439
|
debounceMinimumSymbolsRequired?: number;
|
|
440
440
|
/** @default false */
|
|
441
441
|
withoutClearButton?: boolean;
|
|
442
|
+
/** @default false */
|
|
443
|
+
withoutRenderingOptionsWhenClosed?: boolean;
|
|
442
444
|
onChange?: (value: Value | undefined) => void;
|
|
443
445
|
onChangeSearch?: (query: string) => void;
|
|
444
446
|
renderOption?: (option: DropdownOption<Value, Data>, index: number, isSelected: boolean) => React.ReactNode;
|
package/dist/index.d.ts
CHANGED
|
@@ -439,6 +439,8 @@ type DropdownProps<Value, Data = unknown> = {
|
|
|
439
439
|
debounceMinimumSymbolsRequired?: number;
|
|
440
440
|
/** @default false */
|
|
441
441
|
withoutClearButton?: boolean;
|
|
442
|
+
/** @default false */
|
|
443
|
+
withoutRenderingOptionsWhenClosed?: boolean;
|
|
442
444
|
onChange?: (value: Value | undefined) => void;
|
|
443
445
|
onChangeSearch?: (query: string) => void;
|
|
444
446
|
renderOption?: (option: DropdownOption<Value, Data>, index: number, isSelected: boolean) => React.ReactNode;
|
package/dist/index.js
CHANGED
|
@@ -4966,6 +4966,7 @@ var DropdownComponent = (0, import_react16.forwardRef)(function Dropdown({
|
|
|
4966
4966
|
debounceIsLoading,
|
|
4967
4967
|
debounceMinimumSymbolsRequired,
|
|
4968
4968
|
withoutClearButton,
|
|
4969
|
+
withoutRenderingOptionsWhenClosed,
|
|
4969
4970
|
onChange,
|
|
4970
4971
|
onChangeSearch,
|
|
4971
4972
|
renderOption,
|
|
@@ -4974,6 +4975,7 @@ var DropdownComponent = (0, import_react16.forwardRef)(function Dropdown({
|
|
|
4974
4975
|
}, ref) {
|
|
4975
4976
|
const theme2 = useTheme();
|
|
4976
4977
|
const inputFieldHolderRef = (0, import_react16.useRef)(null);
|
|
4978
|
+
const buttonsRef = (0, import_react16.useRef)(null);
|
|
4977
4979
|
const inputRef = (0, import_react16.useRef)(null);
|
|
4978
4980
|
const [isOpen, setIsOpen] = useBooleanState();
|
|
4979
4981
|
const [isOpenLate, setIsOpenLate] = useBooleanState();
|
|
@@ -5068,6 +5070,33 @@ var DropdownComponent = (0, import_react16.forwardRef)(function Dropdown({
|
|
|
5068
5070
|
[withDebounce, onChangeSearch]
|
|
5069
5071
|
);
|
|
5070
5072
|
const selectedOption = (0, import_react16.useMemo)(() => options.find((option) => option.value === value), [options, value]);
|
|
5073
|
+
const renderedOptions = (0, import_react16.useMemo)(
|
|
5074
|
+
() => filteredOptions.map((option, index) => {
|
|
5075
|
+
const isSelected = option.value === value;
|
|
5076
|
+
const isDisabled = option.disabled;
|
|
5077
|
+
const isFocused2 = index === focusedOptionIndex;
|
|
5078
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
5079
|
+
Div_default,
|
|
5080
|
+
{
|
|
5081
|
+
color: isDisabled ? theme2.colors.textSecondary + "80" : isSelected ? theme2.colors.base : theme2.colors.textPrimary,
|
|
5082
|
+
backgroundColor: isSelected ? theme2.colors.primary : theme2.colors.backgroundContent,
|
|
5083
|
+
filter: isFocused2 ? isDisabled ? "brightness(0.95)" : "brightness(0.9)" : void 0,
|
|
5084
|
+
filterHover: focusedOptionIndex === void 0 && !isDisabled ? "brightness(0.9)" : void 0,
|
|
5085
|
+
cursor: isDisabled ? "not-allowed" : "pointer",
|
|
5086
|
+
padding: `${theme2.styles.space / 2}px ${theme2.styles.space + theme2.styles.gap}px`,
|
|
5087
|
+
value: option,
|
|
5088
|
+
onClickWithValue: onClickOption,
|
|
5089
|
+
onMouseMove: () => setFocusedOptionIndex(void 0),
|
|
5090
|
+
role: "option",
|
|
5091
|
+
"aria-selected": isSelected,
|
|
5092
|
+
"aria-disabled": isDisabled,
|
|
5093
|
+
children: renderOption ? renderOption(option, index, isSelected) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Text_default, { children: option.label })
|
|
5094
|
+
},
|
|
5095
|
+
JSON.stringify(option)
|
|
5096
|
+
);
|
|
5097
|
+
}),
|
|
5098
|
+
[filteredOptions, value, focusedOptionIndex, theme2.colors, onClickOption, renderOption]
|
|
5099
|
+
);
|
|
5071
5100
|
(0, import_react16.useEffect)(() => {
|
|
5072
5101
|
if (isOpen) {
|
|
5073
5102
|
setIsOpenLate.setTrue();
|
|
@@ -5084,7 +5113,7 @@ var DropdownComponent = (0, import_react16.forwardRef)(function Dropdown({
|
|
|
5084
5113
|
}, [filteredOptions]);
|
|
5085
5114
|
(0, import_react16.useEffect)(() => {
|
|
5086
5115
|
const handleClickOutside = (event) => {
|
|
5087
|
-
if (inputFieldHolderRef.current && !inputFieldHolderRef.current.contains(event.target)) {
|
|
5116
|
+
if (inputFieldHolderRef.current && buttonsRef.current && !inputFieldHolderRef.current.contains(event.target) && !buttonsRef.current.contains(event.target)) {
|
|
5088
5117
|
setIsOpen.setFalse();
|
|
5089
5118
|
setSearchQuery("");
|
|
5090
5119
|
setFocusedOptionIndex(void 0);
|
|
@@ -5104,7 +5133,7 @@ var DropdownComponent = (0, import_react16.forwardRef)(function Dropdown({
|
|
|
5104
5133
|
const displayValue = withSearch && isFocused ? searchQuery : selectedOption?.label ?? "";
|
|
5105
5134
|
const withClearButton = isOpen && selectedOption;
|
|
5106
5135
|
const readyPlaceholder = placeholder ? placeholder : `Select an ${label?.toLowerCase() ?? "option"}`;
|
|
5107
|
-
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Div_default.column, { width: "100%", position: "relative", userSelect: "none", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(Div_default.row, { position: "relative", width: "100%",
|
|
5136
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Div_default.column, { width: "100%", position: "relative", userSelect: "none", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(Div_default.row, { position: "relative", width: "100%", children: [
|
|
5108
5137
|
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
5109
5138
|
InputField_default,
|
|
5110
5139
|
{
|
|
@@ -5149,30 +5178,7 @@ var DropdownComponent = (0, import_react16.forwardRef)(function Dropdown({
|
|
|
5149
5178
|
transition: theme2.styles.transition,
|
|
5150
5179
|
role: "listbox",
|
|
5151
5180
|
"aria-label": label,
|
|
5152
|
-
children: isLoadingDebouncedSearchQuery || debounceIsLoading ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Div_default, { padding: `${theme2.styles.space / 2}px ${theme2.styles.space + theme2.styles.gap}px`, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Loader_default.text, {}) }) : filteredOptions.length ?
|
|
5153
|
-
const isSelected = option.value === value;
|
|
5154
|
-
const isDisabled = option.disabled;
|
|
5155
|
-
const isFocused2 = index === focusedOptionIndex;
|
|
5156
|
-
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
5157
|
-
Div_default,
|
|
5158
|
-
{
|
|
5159
|
-
color: isDisabled ? theme2.colors.textSecondary + "80" : isSelected ? theme2.colors.base : theme2.colors.textPrimary,
|
|
5160
|
-
backgroundColor: isSelected ? theme2.colors.primary : theme2.colors.backgroundContent,
|
|
5161
|
-
filter: isFocused2 ? isDisabled ? "brightness(0.95)" : "brightness(0.9)" : void 0,
|
|
5162
|
-
filterHover: focusedOptionIndex === void 0 && !isDisabled ? "brightness(0.9)" : void 0,
|
|
5163
|
-
cursor: isDisabled ? "not-allowed" : "pointer",
|
|
5164
|
-
padding: `${theme2.styles.space / 2}px ${theme2.styles.space + theme2.styles.gap}px`,
|
|
5165
|
-
value: option,
|
|
5166
|
-
onClickWithValue: onClickOption,
|
|
5167
|
-
onMouseMove: () => setFocusedOptionIndex(void 0),
|
|
5168
|
-
role: "option",
|
|
5169
|
-
"aria-selected": isSelected,
|
|
5170
|
-
"aria-disabled": isDisabled,
|
|
5171
|
-
children: renderOption ? renderOption(option, index, isSelected) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Text_default, { children: option.label })
|
|
5172
|
-
},
|
|
5173
|
-
JSON.stringify(option)
|
|
5174
|
-
);
|
|
5175
|
-
}) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Div_default, { padding: `${theme2.styles.space / 2}px ${theme2.styles.space + theme2.styles.gap}px`, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Text_default.unknown, { textAlign: "left", children: debounceMinimumSymbolsRequired !== void 0 && searchQuery.length < debounceMinimumSymbolsRequired ? `Enter at least ${debounceMinimumSymbolsRequired} characters` : "No options" }) })
|
|
5181
|
+
children: isLoadingDebouncedSearchQuery || debounceIsLoading ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Div_default, { padding: `${theme2.styles.space / 2}px ${theme2.styles.space + theme2.styles.gap}px`, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Loader_default.text, {}) }) : filteredOptions.length ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_jsx_runtime14.Fragment, { children: (withoutRenderingOptionsWhenClosed ? isOpen || isOpenLate : true) ? renderedOptions : void 0 }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Div_default, { padding: `${theme2.styles.space / 2}px ${theme2.styles.space + theme2.styles.gap}px`, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Text_default.unknown, { textAlign: "left", children: debounceMinimumSymbolsRequired !== void 0 && searchQuery.length < debounceMinimumSymbolsRequired ? `Enter at least ${debounceMinimumSymbolsRequired} characters` : "No options" }) })
|
|
5176
5182
|
}
|
|
5177
5183
|
),
|
|
5178
5184
|
role: "combobox",
|
|
@@ -5180,6 +5186,7 @@ var DropdownComponent = (0, import_react16.forwardRef)(function Dropdown({
|
|
|
5180
5186
|
"aria-controls": "dropdown-list",
|
|
5181
5187
|
"aria-haspopup": "listbox",
|
|
5182
5188
|
"aria-label": label,
|
|
5189
|
+
holderRef: inputFieldHolderRef,
|
|
5183
5190
|
ref: inputRef
|
|
5184
5191
|
}
|
|
5185
5192
|
),
|
|
@@ -5196,6 +5203,7 @@ var DropdownComponent = (0, import_react16.forwardRef)(function Dropdown({
|
|
|
5196
5203
|
filter: disabled ? "brightness(0.9)" : void 0,
|
|
5197
5204
|
opacity: disabled ? 0.6 : void 0,
|
|
5198
5205
|
zIndex: isOpen || isOpenLate ? 1001 : void 0,
|
|
5206
|
+
ref: buttonsRef,
|
|
5199
5207
|
children: [
|
|
5200
5208
|
!withoutClearButton && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
5201
5209
|
Button_default.icon,
|
|
@@ -5254,6 +5262,7 @@ DropdownComponent.countries = (0, import_react16.forwardRef)(function Countries(
|
|
|
5254
5262
|
placeholder: "Select a country",
|
|
5255
5263
|
options,
|
|
5256
5264
|
renderOption,
|
|
5265
|
+
withoutRenderingOptionsWhenClosed: true,
|
|
5257
5266
|
ref,
|
|
5258
5267
|
...props
|
|
5259
5268
|
}
|