react-better-html 1.1.123 → 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.d.mts CHANGED
@@ -699,6 +699,7 @@ type DateFilter<DataItem> = {
699
699
  type ListFilter<DataItem> = {
700
700
  filter?: "list";
701
701
  withTotalNumber?: boolean;
702
+ withSearch?: boolean;
702
703
  getValueForList?: (item: DataItem) => OmitProps<ListFilterValue, "count">;
703
704
  };
704
705
  type TableColumn<DataItem> = {
package/dist/index.d.ts CHANGED
@@ -699,6 +699,7 @@ type DateFilter<DataItem> = {
699
699
  type ListFilter<DataItem> = {
700
700
  filter?: "list";
701
701
  withTotalNumber?: boolean;
702
+ withSearch?: boolean;
702
703
  getValueForList?: (item: DataItem) => OmitProps<ListFilterValue, "count">;
703
704
  };
704
705
  type TableColumn<DataItem> = {
package/dist/index.js CHANGED
@@ -5974,8 +5974,48 @@ InputFieldComponent.password = (0, import_react18.forwardRef)(function Password(
5974
5974
  }
5975
5975
  );
5976
5976
  });
5977
- InputFieldComponent.search = (0, import_react18.forwardRef)(function Search({ ...props }, ref) {
5978
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(InputFieldComponent, { leftIcon: "magnifyingGlass", placeholder: "Search...", ref, ...props });
5977
+ InputFieldComponent.search = (0, import_react18.forwardRef)(function Search({ value, onChangeValue, onFocus, onBlur, ...props }, ref) {
5978
+ const [inputFieldValue, setInputFieldValue] = (0, import_react18.useState)(value?.toString() ?? "");
5979
+ const [inputFieldFocused, setInputFieldFocused] = useBooleanState();
5980
+ const onChangeValueElement = (0, import_react18.useCallback)(
5981
+ (value2) => {
5982
+ setInputFieldValue(value2);
5983
+ onChangeValue?.(value2);
5984
+ },
5985
+ [onChangeValue]
5986
+ );
5987
+ const onFocusElement = (0, import_react18.useCallback)(
5988
+ (event) => {
5989
+ setInputFieldFocused.setTrue();
5990
+ onFocus?.(event);
5991
+ },
5992
+ [onFocus]
5993
+ );
5994
+ const onBlurElement = (0, import_react18.useCallback)(
5995
+ (event) => {
5996
+ setTimeout(() => setInputFieldFocused.setFalse(), 0.1 * 1e3);
5997
+ onBlur?.(event);
5998
+ },
5999
+ [onBlur]
6000
+ );
6001
+ const onClickRightIcon = (0, import_react18.useCallback)(() => {
6002
+ onChangeValueElement("");
6003
+ }, [onChangeValueElement]);
6004
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
6005
+ InputFieldComponent,
6006
+ {
6007
+ leftIcon: "magnifyingGlass",
6008
+ placeholder: "Search...",
6009
+ rightIcon: inputFieldValue.length > 0 && inputFieldFocused ? "XMark" : void 0,
6010
+ onClickRightIcon,
6011
+ value: inputFieldValue,
6012
+ onChangeValue: onChangeValueElement,
6013
+ onFocus: onFocusElement,
6014
+ onBlur: onBlurElement,
6015
+ ref,
6016
+ ...props
6017
+ }
6018
+ );
5979
6019
  });
5980
6020
  InputFieldComponent.phoneNumber = (0, import_react18.forwardRef)(function PhoneNumber({ label, value, onChangeValue, labelColor, id, ...props }, ref) {
5981
6021
  const theme2 = useTheme();
@@ -7043,7 +7083,8 @@ var TableComponent = (0, import_react23.forwardRef)(function Table({
7043
7083
  const filterForm = useForm({
7044
7084
  defaultValues: {
7045
7085
  min: void 0,
7046
- max: void 0
7086
+ max: void 0,
7087
+ search: ""
7047
7088
  },
7048
7089
  onSubmit: (values) => {
7049
7090
  if (!openedFilterColumn?.filter) return;
@@ -7058,10 +7099,10 @@ var TableComponent = (0, import_react23.forwardRef)(function Table({
7058
7099
  type: openedFilterColumn.filter,
7059
7100
  min: values.min,
7060
7101
  max: values.max
7061
- } : openedFilterColumn.filter === "list" ? {
7102
+ } : openedFilterColumn.filter === "list" ? filterListSelectedItems && filterListSelectedItems.length > 0 ? {
7062
7103
  type: openedFilterColumn.filter,
7063
7104
  list: filterListSelectedItems
7064
- } : void 0
7105
+ } : void 0 : void 0
7065
7106
  }));
7066
7107
  filterModalRef.current?.close();
7067
7108
  }
@@ -7314,7 +7355,12 @@ var TableComponent = (0, import_react23.forwardRef)(function Table({
7314
7355
  return data.reduce((previousValue, currentValue) => {
7315
7356
  const valueFromList = openedFilterColumn.filter === "list" && openedFilterColumn.getValueForList ? openedFilterColumn.getValueForList(currentValue) : void 0;
7316
7357
  const value = valueFromList ? valueFromList.value : openedFilterColumn.type === "text" && openedFilterColumn.keyName ? String(currentValue[openedFilterColumn.keyName]) : void 0;
7317
- if (value !== void 0) {
7358
+ const label = valueFromList ? valueFromList.label : value;
7359
+ let searchPassed = openedFilterColumn.filter === "list" && openedFilterColumn.withSearch ? false : true;
7360
+ if (openedFilterColumn.filter === "list" && openedFilterColumn.withSearch) {
7361
+ searchPassed = label?.toLowerCase().includes(filterForm.values.search.toLowerCase()) ?? false;
7362
+ }
7363
+ if (value !== void 0 && value !== null && value !== "" && searchPassed) {
7318
7364
  if (previousValue.some((item) => item.value === value)) {
7319
7365
  previousValue = previousValue.map(
7320
7366
  (item) => item.value === value ? {
@@ -7324,14 +7370,14 @@ var TableComponent = (0, import_react23.forwardRef)(function Table({
7324
7370
  );
7325
7371
  } else
7326
7372
  previousValue.push({
7327
- label: valueFromList ? valueFromList.label : value,
7373
+ label,
7328
7374
  value,
7329
7375
  count: 1
7330
7376
  });
7331
7377
  }
7332
7378
  return previousValue;
7333
7379
  }, []);
7334
- }, [data, openedFilterColumn]);
7380
+ }, [data, openedFilterColumn, filterForm.values.search]);
7335
7381
  const pageCountInternal = pageCount ?? (pageSize !== void 0 ? Math.ceil(dataAfterFilter.length / pageSize) : 1);
7336
7382
  const paginationItems = (0, import_react23.useMemo)(() => {
7337
7383
  const halfRange = Math.floor(maximumVisiblePages / 2);
@@ -7601,9 +7647,10 @@ var TableComponent = (0, import_react23.forwardRef)(function Table({
7601
7647
  ] })
7602
7648
  ]
7603
7649
  }
7604
- ) : openedFilterColumn.filter === "list" ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
7650
+ ) : openedFilterColumn.filter === "list" ? /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
7605
7651
  Form_default,
7606
7652
  {
7653
+ gap: theme2.styles.space,
7607
7654
  submitButtonText: "Filter",
7608
7655
  cancelButtonText: "Clear",
7609
7656
  renderActionButtons: /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(Div_default.row, { marginRight: "auto", alignItems: "center", gap: theme2.styles.gap, children: [
@@ -7611,6 +7658,7 @@ var TableComponent = (0, import_react23.forwardRef)(function Table({
7611
7658
  Button_default.secondary,
7612
7659
  {
7613
7660
  text: "Select All",
7661
+ isSmall: true,
7614
7662
  disabled: possibleFilterListValues.length === filterListSelectedItems?.length,
7615
7663
  onClick: onClickSelectAllFilterListItems
7616
7664
  }
@@ -7619,6 +7667,7 @@ var TableComponent = (0, import_react23.forwardRef)(function Table({
7619
7667
  Button_default.secondary,
7620
7668
  {
7621
7669
  text: "Deselect All",
7670
+ isSmall: true,
7622
7671
  disabled: !filterListSelectedItems?.length,
7623
7672
  onClick: onClickDeselectAllFilterListItems
7624
7673
  }
@@ -7626,36 +7675,47 @@ var TableComponent = (0, import_react23.forwardRef)(function Table({
7626
7675
  ] }),
7627
7676
  onClickCancel: openedFilterData ? onClickCancelFormFilter : void 0,
7628
7677
  onSubmit: filterForm.onSubmit,
7629
- children: /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(Div_default.column, { gap: theme2.styles.gap / 2, marginBottom: theme2.styles.space, children: [
7630
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Label_default, { text: "Possible values" }),
7631
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Div_default.row, { flexWrap: "wrap", gap: theme2.styles.gap, children: possibleFilterListValues.map((value) => {
7632
- const isActive = filterListSelectedItems?.includes(value.value);
7633
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
7634
- Div_default.box,
7635
- {
7636
- isActive,
7637
- value: value.value,
7638
- onClickWithValue: onClickFilterListItem,
7639
- children: /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(Div_default.row, { alignItems: "center", gap: theme2.styles.gap / 2, children: [
7640
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Text_default, { children: value.label ?? value.value }),
7641
- openedFilterColumn.withTotalNumber && /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
7642
- Text_default,
7643
- {
7644
- fontSize: 14,
7645
- color: isActive ? theme2.colors.base + "c0" : theme2.colors.textSecondary,
7646
- children: [
7647
- "(",
7648
- value.count,
7649
- ")"
7650
- ]
7651
- }
7652
- )
7653
- ] })
7654
- },
7655
- value.value
7656
- );
7657
- }) })
7658
- ] })
7678
+ children: [
7679
+ openedFilterColumn?.withSearch && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(FormRow_default, { oneItemOnly: true, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
7680
+ InputField_default.search,
7681
+ {
7682
+ label: "Search",
7683
+ autoComplete: "off",
7684
+ ...filterForm.getInputFieldProps("search")
7685
+ }
7686
+ ) }),
7687
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(Div_default.column, { gap: theme2.styles.gap / 2, children: [
7688
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Label_default, { text: "Possible values" }),
7689
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Div_default.row, { flexWrap: "wrap", gap: theme2.styles.gap, children: possibleFilterListValues.length > 0 ? possibleFilterListValues.map((value) => {
7690
+ const isActive = filterListSelectedItems?.includes(value.value);
7691
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
7692
+ Div_default.box,
7693
+ {
7694
+ isActive,
7695
+ value: value.value,
7696
+ onClickWithValue: onClickFilterListItem,
7697
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(Div_default.row, { alignItems: "center", gap: theme2.styles.gap / 2, children: [
7698
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Text_default, { children: value.label ?? value.value }),
7699
+ openedFilterColumn.withTotalNumber && /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
7700
+ Text_default,
7701
+ {
7702
+ fontSize: 14,
7703
+ color: isActive ? theme2.colors.base + "c0" : theme2.colors.textSecondary,
7704
+ children: [
7705
+ "(",
7706
+ value.count,
7707
+ ")"
7708
+ ]
7709
+ }
7710
+ )
7711
+ ] })
7712
+ },
7713
+ value.value
7714
+ );
7715
+ }) : /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Text_default.unknown, { children: "No values" }) })
7716
+ ] }),
7717
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Div_default, {})
7718
+ ]
7659
7719
  }
7660
7720
  ) : /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Text_default.unknown, { children: "Unknown filter" }) : /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Loader_default.box, {})
7661
7721
  }