react-better-html 1.1.122 → 1.1.124

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
@@ -5892,8 +5892,48 @@ InputFieldComponent.password = forwardRef11(function Password({ ...props }, ref)
5892
5892
  }
5893
5893
  );
5894
5894
  });
5895
- InputFieldComponent.search = forwardRef11(function Search({ ...props }, ref) {
5896
- return /* @__PURE__ */ jsx15(InputFieldComponent, { leftIcon: "magnifyingGlass", placeholder: "Search...", ref, ...props });
5895
+ InputFieldComponent.search = forwardRef11(function Search({ value, onChangeValue, onFocus, onBlur, ...props }, ref) {
5896
+ const [inputFieldValue, setInputFieldValue] = useState6(value?.toString() ?? "");
5897
+ const [inputFieldFocused, setInputFieldFocused] = useBooleanState();
5898
+ const onChangeValueElement = useCallback8(
5899
+ (value2) => {
5900
+ setInputFieldValue(value2);
5901
+ onChangeValue?.(value2);
5902
+ },
5903
+ [onChangeValue]
5904
+ );
5905
+ const onFocusElement = useCallback8(
5906
+ (event) => {
5907
+ setInputFieldFocused.setTrue();
5908
+ onFocus?.(event);
5909
+ },
5910
+ [onFocus]
5911
+ );
5912
+ const onBlurElement = useCallback8(
5913
+ (event) => {
5914
+ setTimeout(() => setInputFieldFocused.setFalse(), 0.1 * 1e3);
5915
+ onBlur?.(event);
5916
+ },
5917
+ [onBlur]
5918
+ );
5919
+ const onClickRightIcon = useCallback8(() => {
5920
+ onChangeValueElement("");
5921
+ }, [onChangeValueElement]);
5922
+ return /* @__PURE__ */ jsx15(
5923
+ InputFieldComponent,
5924
+ {
5925
+ leftIcon: "magnifyingGlass",
5926
+ placeholder: "Search...",
5927
+ rightIcon: inputFieldValue.length > 0 && inputFieldFocused ? "XMark" : void 0,
5928
+ onClickRightIcon,
5929
+ value: inputFieldValue,
5930
+ onChangeValue: onChangeValueElement,
5931
+ onFocus: onFocusElement,
5932
+ onBlur: onBlurElement,
5933
+ ref,
5934
+ ...props
5935
+ }
5936
+ );
5897
5937
  });
5898
5938
  InputFieldComponent.phoneNumber = forwardRef11(function PhoneNumber({ label, value, onChangeValue, labelColor, id, ...props }, ref) {
5899
5939
  const theme2 = useTheme();
@@ -6971,7 +7011,8 @@ var TableComponent = forwardRef15(function Table({
6971
7011
  const filterForm = useForm({
6972
7012
  defaultValues: {
6973
7013
  min: void 0,
6974
- max: void 0
7014
+ max: void 0,
7015
+ search: ""
6975
7016
  },
6976
7017
  onSubmit: (values) => {
6977
7018
  if (!openedFilterColumn?.filter) return;
@@ -6986,10 +7027,10 @@ var TableComponent = forwardRef15(function Table({
6986
7027
  type: openedFilterColumn.filter,
6987
7028
  min: values.min,
6988
7029
  max: values.max
6989
- } : openedFilterColumn.filter === "list" ? {
7030
+ } : openedFilterColumn.filter === "list" ? filterListSelectedItems && filterListSelectedItems.length > 0 ? {
6990
7031
  type: openedFilterColumn.filter,
6991
7032
  list: filterListSelectedItems
6992
- } : void 0
7033
+ } : void 0 : void 0
6993
7034
  }));
6994
7035
  filterModalRef.current?.close();
6995
7036
  }
@@ -7219,7 +7260,7 @@ var TableComponent = forwardRef15(function Table({
7219
7260
  if (filter.min !== void 0 && minDate && itemValue < minDate) return false;
7220
7261
  if (filter.max !== void 0 && maxDate && itemValue > maxDate) return false;
7221
7262
  } else if (column.filter === "list" && filter.type === "list") {
7222
- const itemValue = column.getValueForList?.(item) ?? (column.type === "text" && column.keyName ? String(item[column.keyName]) : "");
7263
+ const itemValue = column.getValueForList?.(item).value ?? (column.type === "text" && column.keyName ? String(item[column.keyName]) : "");
7223
7264
  if (!filter.list?.includes(itemValue)) return false;
7224
7265
  }
7225
7266
  return true;
@@ -7239,28 +7280,32 @@ var TableComponent = forwardRef15(function Table({
7239
7280
  }, [data, checkedItems]);
7240
7281
  const possibleFilterListValues = useMemo7(() => {
7241
7282
  if (!openedFilterColumn) return [];
7242
- return data.reduce(
7243
- (previousValue, currentValue) => {
7244
- const value = openedFilterColumn.type === "text" && openedFilterColumn.keyName ? String(currentValue[openedFilterColumn.keyName]) : void 0;
7245
- if (value !== void 0) {
7246
- if (previousValue.some((item) => item.value === value)) {
7247
- previousValue = previousValue.map(
7248
- (item) => item.value === value ? {
7249
- ...item,
7250
- count: item.count + 1
7251
- } : item
7252
- );
7253
- } else
7254
- previousValue.push({
7255
- value,
7256
- count: 1
7257
- });
7258
- }
7259
- return previousValue;
7260
- },
7261
- []
7262
- );
7263
- }, [data, openedFilterColumn]);
7283
+ return data.reduce((previousValue, currentValue) => {
7284
+ const valueFromList = openedFilterColumn.filter === "list" && openedFilterColumn.getValueForList ? openedFilterColumn.getValueForList(currentValue) : void 0;
7285
+ const value = valueFromList ? valueFromList.value : openedFilterColumn.type === "text" && openedFilterColumn.keyName ? String(currentValue[openedFilterColumn.keyName]) : void 0;
7286
+ const label = valueFromList ? valueFromList.label : value;
7287
+ let searchPassed = openedFilterColumn.filter === "list" && openedFilterColumn.withSearch ? false : true;
7288
+ if (openedFilterColumn.filter === "list" && openedFilterColumn.withSearch) {
7289
+ searchPassed = label?.toLowerCase().includes(filterForm.values.search.toLowerCase()) ?? false;
7290
+ }
7291
+ if (value !== void 0 && value !== null && value !== "" && searchPassed) {
7292
+ if (previousValue.some((item) => item.value === value)) {
7293
+ previousValue = previousValue.map(
7294
+ (item) => item.value === value ? {
7295
+ ...item,
7296
+ count: item.count + 1
7297
+ } : item
7298
+ );
7299
+ } else
7300
+ previousValue.push({
7301
+ label,
7302
+ value,
7303
+ count: 1
7304
+ });
7305
+ }
7306
+ return previousValue;
7307
+ }, []);
7308
+ }, [data, openedFilterColumn, filterForm.values.search]);
7264
7309
  const pageCountInternal = pageCount ?? (pageSize !== void 0 ? Math.ceil(dataAfterFilter.length / pageSize) : 1);
7265
7310
  const paginationItems = useMemo7(() => {
7266
7311
  const halfRange = Math.floor(maximumVisiblePages / 2);
@@ -7530,9 +7575,10 @@ var TableComponent = forwardRef15(function Table({
7530
7575
  ] })
7531
7576
  ]
7532
7577
  }
7533
- ) : openedFilterColumn.filter === "list" ? /* @__PURE__ */ jsx20(
7578
+ ) : openedFilterColumn.filter === "list" ? /* @__PURE__ */ jsxs16(
7534
7579
  Form_default,
7535
7580
  {
7581
+ gap: theme2.styles.space,
7536
7582
  submitButtonText: "Filter",
7537
7583
  cancelButtonText: "Clear",
7538
7584
  renderActionButtons: /* @__PURE__ */ jsxs16(Div_default.row, { marginRight: "auto", alignItems: "center", gap: theme2.styles.gap, children: [
@@ -7540,6 +7586,7 @@ var TableComponent = forwardRef15(function Table({
7540
7586
  Button_default.secondary,
7541
7587
  {
7542
7588
  text: "Select All",
7589
+ isSmall: true,
7543
7590
  disabled: possibleFilterListValues.length === filterListSelectedItems?.length,
7544
7591
  onClick: onClickSelectAllFilterListItems
7545
7592
  }
@@ -7548,6 +7595,7 @@ var TableComponent = forwardRef15(function Table({
7548
7595
  Button_default.secondary,
7549
7596
  {
7550
7597
  text: "Deselect All",
7598
+ isSmall: true,
7551
7599
  disabled: !filterListSelectedItems?.length,
7552
7600
  onClick: onClickDeselectAllFilterListItems
7553
7601
  }
@@ -7555,36 +7603,47 @@ var TableComponent = forwardRef15(function Table({
7555
7603
  ] }),
7556
7604
  onClickCancel: openedFilterData ? onClickCancelFormFilter : void 0,
7557
7605
  onSubmit: filterForm.onSubmit,
7558
- children: /* @__PURE__ */ jsxs16(Div_default.column, { gap: theme2.styles.gap / 2, marginBottom: theme2.styles.space, children: [
7559
- /* @__PURE__ */ jsx20(Label_default, { text: "Possible values" }),
7560
- /* @__PURE__ */ jsx20(Div_default.row, { flexWrap: "wrap", gap: theme2.styles.gap, children: possibleFilterListValues.map((value) => {
7561
- const isActive = filterListSelectedItems?.includes(value.value);
7562
- return /* @__PURE__ */ jsx20(
7563
- Div_default.box,
7564
- {
7565
- isActive,
7566
- value: value.value,
7567
- onClickWithValue: onClickFilterListItem,
7568
- children: /* @__PURE__ */ jsxs16(Div_default.row, { alignItems: "center", gap: theme2.styles.gap / 2, children: [
7569
- /* @__PURE__ */ jsx20(Text_default, { children: value.value }),
7570
- openedFilterColumn.withTotalNumber && /* @__PURE__ */ jsxs16(
7571
- Text_default,
7572
- {
7573
- fontSize: 14,
7574
- color: isActive ? theme2.colors.base + "c0" : theme2.colors.textSecondary,
7575
- children: [
7576
- "(",
7577
- value.count,
7578
- ")"
7579
- ]
7580
- }
7581
- )
7582
- ] })
7583
- },
7584
- value.value
7585
- );
7586
- }) })
7587
- ] })
7606
+ children: [
7607
+ openedFilterColumn?.withSearch && /* @__PURE__ */ jsx20(FormRow_default, { oneItemOnly: true, children: /* @__PURE__ */ jsx20(
7608
+ InputField_default.search,
7609
+ {
7610
+ label: "Search",
7611
+ autoComplete: "off",
7612
+ ...filterForm.getInputFieldProps("search")
7613
+ }
7614
+ ) }),
7615
+ /* @__PURE__ */ jsxs16(Div_default.column, { gap: theme2.styles.gap / 2, children: [
7616
+ /* @__PURE__ */ jsx20(Label_default, { text: "Possible values" }),
7617
+ /* @__PURE__ */ jsx20(Div_default.row, { flexWrap: "wrap", gap: theme2.styles.gap, children: possibleFilterListValues.length > 0 ? possibleFilterListValues.map((value) => {
7618
+ const isActive = filterListSelectedItems?.includes(value.value);
7619
+ return /* @__PURE__ */ jsx20(
7620
+ Div_default.box,
7621
+ {
7622
+ isActive,
7623
+ value: value.value,
7624
+ onClickWithValue: onClickFilterListItem,
7625
+ children: /* @__PURE__ */ jsxs16(Div_default.row, { alignItems: "center", gap: theme2.styles.gap / 2, children: [
7626
+ /* @__PURE__ */ jsx20(Text_default, { children: value.label ?? value.value }),
7627
+ openedFilterColumn.withTotalNumber && /* @__PURE__ */ jsxs16(
7628
+ Text_default,
7629
+ {
7630
+ fontSize: 14,
7631
+ color: isActive ? theme2.colors.base + "c0" : theme2.colors.textSecondary,
7632
+ children: [
7633
+ "(",
7634
+ value.count,
7635
+ ")"
7636
+ ]
7637
+ }
7638
+ )
7639
+ ] })
7640
+ },
7641
+ value.value
7642
+ );
7643
+ }) : /* @__PURE__ */ jsx20(Text_default.unknown, { children: "No values" }) })
7644
+ ] }),
7645
+ /* @__PURE__ */ jsx20(Div_default, {})
7646
+ ]
7588
7647
  }
7589
7648
  ) : /* @__PURE__ */ jsx20(Text_default.unknown, { children: "Unknown filter" }) : /* @__PURE__ */ jsx20(Loader_default.box, {})
7590
7649
  }