react-better-html 1.1.173 → 1.1.175

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
@@ -765,6 +765,7 @@ type TableColumn<DataItem> = {
765
765
  clickStopPropagation?: boolean;
766
766
  } & (TextColumn<DataItem> | ElementColumn<DataItem> | ImageColumn<DataItem> | CheckboxColumn<DataItem> | ExpandColumn<DataItem>) & (NumberFilter<DataItem> | DateFilter<DataItem> | ListFilter<DataItem>);
767
767
  type TableProps<DataItem> = {
768
+ name?: string;
768
769
  columns: TableColumn<DataItem>[];
769
770
  data: DataItem[];
770
771
  /** @default false */
@@ -780,6 +781,16 @@ type TableProps<DataItem> = {
780
781
  isInsideTableExpandRow?: boolean;
781
782
  containsOverflowComponents?: boolean;
782
783
  wrapperComponentRef?: React.Ref<HTMLDivElement>;
784
+ /**
785
+ * @default false
786
+ * @requires name
787
+ */
788
+ memoizeFilters?: boolean;
789
+ /**
790
+ * The lifespan of the memoized filters in milliseconds. The time will reset if the user changes the filters or reloads the page.
791
+ * @default 7200000 (2 hours)
792
+ */
793
+ memoizeFiltersLifespan?: number;
783
794
  getRowStyle?: (item: DataItem, index: number) => ComponentStyle;
784
795
  onClickRow?: (item: DataItem, index: number) => void;
785
796
  onClickAllCheckboxes?: (checked: boolean) => void;
@@ -966,9 +977,9 @@ declare const useAlertControls: () => {
966
977
  createAlert: (alert: OmitProps<Alert, "id">) => Alert;
967
978
  removeAlert: (alertId: string) => void;
968
979
  };
969
- type BetterHtmlProviderValue = DeepPartialRecord<BetterHtmlConfig>;
980
+ type BetterHtmlProviderConfig = DeepPartialRecord<BetterHtmlConfig>;
970
981
  type BetterHtmlProviderProps = {
971
- config?: BetterHtmlProviderValue;
982
+ config?: BetterHtmlProviderConfig;
972
983
  plugins?: BetterHtmlPlugin[];
973
984
  children?: React.ReactNode;
974
985
  };
@@ -1058,4 +1069,4 @@ type LocalStoragePluginOptions = {
1058
1069
  declare const defaultLocalStoragePluginOptions: Required<LocalStoragePluginOptions>;
1059
1070
  declare const localStoragePlugin: BetterHtmlPluginConstructor<LocalStoragePluginOptions>;
1060
1071
 
1061
- export { type Alert, type AlertType, type AlertsPluginOptions, type AppConfig, type AssetName, type AssetsConfig, type BetterHtmlConfig, type BetterHtmlPlugin, _default as BetterHtmlProvider, type BetterHtmlProviderValue, type BrowserName, Button, type ButtonProps, Chip, type ChipProps, type Color, type ColorName, type ColorTheme, ColorThemeSwitch, type ColorThemeSwitchProps, type Colors, type ComponentHoverStyle, type ComponentMarginProps, type ComponentPaddingProps, type DeepPartialRecord, Div, type DivProps, _default$3 as Divider, Dropdown, type DropdownOption, type DropdownProps, type ExcludeOptions, Foldable, type FoldableProps, type FoldableRef, Form, type FormProps, FormRow, type FormRowProps, type HorizontalDividerProps, _default$5 as Icon, type IconName, type IconProps, type IconsConfig, _default$4 as Image, type ImageProps, InputField, type InputFieldProps, _default$1 as Label, type LabelProps, Loader, type LoaderConfig, type LoaderName, type LoaderProps, type LocalStoragePluginOptions, Modal, type ModalProps, type ModalRef, type OmitProps, PageHeader, type PageHeaderProps, PageHolder, type PageHolderProps, type PartialRecord, type PickAllRequired, type PickValue, type PluginName, type ReactRouterDomPluginOptions, type Styles, type TabGroup, Table, type TableColumn, type TableProps, type TableRef, Tabs, type TabsProps, type TabsRef, Text, type TextAs, type TextProps, type TextareaFieldProps, type Theme, type ThemeConfig, _default$2 as ToggleInput, type ToggleInputProps, type ToggleInputRef, Tooltip, type TooltipProps, type TooltipRef, type VerticalDividerProps, alertControls, alertsPlugin, colorThemeControls, countries, darkenColor, defaultAlertsPluginOptions, defaultLocalStoragePluginOptions, defaultReactRouterDomPluginOptions, desaturateColor, eventPreventDefault, eventPreventStop, eventStopPropagation, filterHover, formatPhoneNumber, generateLocalStorage, generateRandomString, getBrowser, getFormErrorObject, isMobileDevice, lightenColor, loaderControls, localStoragePlugin, reactRouterDomPlugin, saturateColor, useAlertControls, useBetterHtmlContext, useBooleanState, useDebounceState, useForm, useLoader, useLoaderControls, useMediaQuery, usePageResize, usePageScroll, useTheme, useUrlQuery };
1072
+ export { type Alert, type AlertType, type AlertsPluginOptions, type AppConfig, type AssetName, type AssetsConfig, type BetterHtmlConfig, type BetterHtmlPlugin, _default as BetterHtmlProvider, type BetterHtmlProviderConfig, type BrowserName, Button, type ButtonProps, Chip, type ChipProps, type Color, type ColorName, type ColorTheme, ColorThemeSwitch, type ColorThemeSwitchProps, type Colors, type ComponentHoverStyle, type ComponentMarginProps, type ComponentPaddingProps, type DeepPartialRecord, Div, type DivProps, _default$3 as Divider, Dropdown, type DropdownOption, type DropdownProps, type ExcludeOptions, Foldable, type FoldableProps, type FoldableRef, Form, type FormProps, FormRow, type FormRowProps, type HorizontalDividerProps, _default$5 as Icon, type IconName, type IconProps, type IconsConfig, _default$4 as Image, type ImageProps, InputField, type InputFieldProps, _default$1 as Label, type LabelProps, Loader, type LoaderConfig, type LoaderName, type LoaderProps, type LocalStoragePluginOptions, Modal, type ModalProps, type ModalRef, type OmitProps, PageHeader, type PageHeaderProps, PageHolder, type PageHolderProps, type PartialRecord, type PickAllRequired, type PickValue, type PluginName, type ReactRouterDomPluginOptions, type Styles, type TabGroup, Table, type TableColumn, type TableProps, type TableRef, Tabs, type TabsProps, type TabsRef, Text, type TextAs, type TextProps, type TextareaFieldProps, type Theme, type ThemeConfig, _default$2 as ToggleInput, type ToggleInputProps, type ToggleInputRef, Tooltip, type TooltipProps, type TooltipRef, type VerticalDividerProps, alertControls, alertsPlugin, colorThemeControls, countries, darkenColor, defaultAlertsPluginOptions, defaultLocalStoragePluginOptions, defaultReactRouterDomPluginOptions, desaturateColor, eventPreventDefault, eventPreventStop, eventStopPropagation, filterHover, formatPhoneNumber, generateLocalStorage, generateRandomString, getBrowser, getFormErrorObject, isMobileDevice, lightenColor, loaderControls, localStoragePlugin, reactRouterDomPlugin, saturateColor, useAlertControls, useBetterHtmlContext, useBooleanState, useDebounceState, useForm, useLoader, useLoaderControls, useMediaQuery, usePageResize, usePageScroll, useTheme, useUrlQuery };
package/dist/index.d.ts CHANGED
@@ -765,6 +765,7 @@ type TableColumn<DataItem> = {
765
765
  clickStopPropagation?: boolean;
766
766
  } & (TextColumn<DataItem> | ElementColumn<DataItem> | ImageColumn<DataItem> | CheckboxColumn<DataItem> | ExpandColumn<DataItem>) & (NumberFilter<DataItem> | DateFilter<DataItem> | ListFilter<DataItem>);
767
767
  type TableProps<DataItem> = {
768
+ name?: string;
768
769
  columns: TableColumn<DataItem>[];
769
770
  data: DataItem[];
770
771
  /** @default false */
@@ -780,6 +781,16 @@ type TableProps<DataItem> = {
780
781
  isInsideTableExpandRow?: boolean;
781
782
  containsOverflowComponents?: boolean;
782
783
  wrapperComponentRef?: React.Ref<HTMLDivElement>;
784
+ /**
785
+ * @default false
786
+ * @requires name
787
+ */
788
+ memoizeFilters?: boolean;
789
+ /**
790
+ * The lifespan of the memoized filters in milliseconds. The time will reset if the user changes the filters or reloads the page.
791
+ * @default 7200000 (2 hours)
792
+ */
793
+ memoizeFiltersLifespan?: number;
783
794
  getRowStyle?: (item: DataItem, index: number) => ComponentStyle;
784
795
  onClickRow?: (item: DataItem, index: number) => void;
785
796
  onClickAllCheckboxes?: (checked: boolean) => void;
@@ -966,9 +977,9 @@ declare const useAlertControls: () => {
966
977
  createAlert: (alert: OmitProps<Alert, "id">) => Alert;
967
978
  removeAlert: (alertId: string) => void;
968
979
  };
969
- type BetterHtmlProviderValue = DeepPartialRecord<BetterHtmlConfig>;
980
+ type BetterHtmlProviderConfig = DeepPartialRecord<BetterHtmlConfig>;
970
981
  type BetterHtmlProviderProps = {
971
- config?: BetterHtmlProviderValue;
982
+ config?: BetterHtmlProviderConfig;
972
983
  plugins?: BetterHtmlPlugin[];
973
984
  children?: React.ReactNode;
974
985
  };
@@ -1058,4 +1069,4 @@ type LocalStoragePluginOptions = {
1058
1069
  declare const defaultLocalStoragePluginOptions: Required<LocalStoragePluginOptions>;
1059
1070
  declare const localStoragePlugin: BetterHtmlPluginConstructor<LocalStoragePluginOptions>;
1060
1071
 
1061
- export { type Alert, type AlertType, type AlertsPluginOptions, type AppConfig, type AssetName, type AssetsConfig, type BetterHtmlConfig, type BetterHtmlPlugin, _default as BetterHtmlProvider, type BetterHtmlProviderValue, type BrowserName, Button, type ButtonProps, Chip, type ChipProps, type Color, type ColorName, type ColorTheme, ColorThemeSwitch, type ColorThemeSwitchProps, type Colors, type ComponentHoverStyle, type ComponentMarginProps, type ComponentPaddingProps, type DeepPartialRecord, Div, type DivProps, _default$3 as Divider, Dropdown, type DropdownOption, type DropdownProps, type ExcludeOptions, Foldable, type FoldableProps, type FoldableRef, Form, type FormProps, FormRow, type FormRowProps, type HorizontalDividerProps, _default$5 as Icon, type IconName, type IconProps, type IconsConfig, _default$4 as Image, type ImageProps, InputField, type InputFieldProps, _default$1 as Label, type LabelProps, Loader, type LoaderConfig, type LoaderName, type LoaderProps, type LocalStoragePluginOptions, Modal, type ModalProps, type ModalRef, type OmitProps, PageHeader, type PageHeaderProps, PageHolder, type PageHolderProps, type PartialRecord, type PickAllRequired, type PickValue, type PluginName, type ReactRouterDomPluginOptions, type Styles, type TabGroup, Table, type TableColumn, type TableProps, type TableRef, Tabs, type TabsProps, type TabsRef, Text, type TextAs, type TextProps, type TextareaFieldProps, type Theme, type ThemeConfig, _default$2 as ToggleInput, type ToggleInputProps, type ToggleInputRef, Tooltip, type TooltipProps, type TooltipRef, type VerticalDividerProps, alertControls, alertsPlugin, colorThemeControls, countries, darkenColor, defaultAlertsPluginOptions, defaultLocalStoragePluginOptions, defaultReactRouterDomPluginOptions, desaturateColor, eventPreventDefault, eventPreventStop, eventStopPropagation, filterHover, formatPhoneNumber, generateLocalStorage, generateRandomString, getBrowser, getFormErrorObject, isMobileDevice, lightenColor, loaderControls, localStoragePlugin, reactRouterDomPlugin, saturateColor, useAlertControls, useBetterHtmlContext, useBooleanState, useDebounceState, useForm, useLoader, useLoaderControls, useMediaQuery, usePageResize, usePageScroll, useTheme, useUrlQuery };
1072
+ export { type Alert, type AlertType, type AlertsPluginOptions, type AppConfig, type AssetName, type AssetsConfig, type BetterHtmlConfig, type BetterHtmlPlugin, _default as BetterHtmlProvider, type BetterHtmlProviderConfig, type BrowserName, Button, type ButtonProps, Chip, type ChipProps, type Color, type ColorName, type ColorTheme, ColorThemeSwitch, type ColorThemeSwitchProps, type Colors, type ComponentHoverStyle, type ComponentMarginProps, type ComponentPaddingProps, type DeepPartialRecord, Div, type DivProps, _default$3 as Divider, Dropdown, type DropdownOption, type DropdownProps, type ExcludeOptions, Foldable, type FoldableProps, type FoldableRef, Form, type FormProps, FormRow, type FormRowProps, type HorizontalDividerProps, _default$5 as Icon, type IconName, type IconProps, type IconsConfig, _default$4 as Image, type ImageProps, InputField, type InputFieldProps, _default$1 as Label, type LabelProps, Loader, type LoaderConfig, type LoaderName, type LoaderProps, type LocalStoragePluginOptions, Modal, type ModalProps, type ModalRef, type OmitProps, PageHeader, type PageHeaderProps, PageHolder, type PageHolderProps, type PartialRecord, type PickAllRequired, type PickValue, type PluginName, type ReactRouterDomPluginOptions, type Styles, type TabGroup, Table, type TableColumn, type TableProps, type TableRef, Tabs, type TabsProps, type TabsRef, Text, type TextAs, type TextProps, type TextareaFieldProps, type Theme, type ThemeConfig, _default$2 as ToggleInput, type ToggleInputProps, type ToggleInputRef, Tooltip, type TooltipProps, type TooltipRef, type VerticalDividerProps, alertControls, alertsPlugin, colorThemeControls, countries, darkenColor, defaultAlertsPluginOptions, defaultLocalStoragePluginOptions, defaultReactRouterDomPluginOptions, desaturateColor, eventPreventDefault, eventPreventStop, eventStopPropagation, filterHover, formatPhoneNumber, generateLocalStorage, generateRandomString, getBrowser, getFormErrorObject, isMobileDevice, lightenColor, loaderControls, localStoragePlugin, reactRouterDomPlugin, saturateColor, useAlertControls, useBetterHtmlContext, useBooleanState, useDebounceState, useForm, useLoader, useLoaderControls, useMediaQuery, usePageResize, usePageScroll, useTheme, useUrlQuery };
package/dist/index.js CHANGED
@@ -3697,14 +3697,15 @@ var ModalComponent = (0, import_react14.forwardRef)(function Modal({
3697
3697
  marginTop: 1,
3698
3698
  iconColor: titleColor,
3699
3699
  onClick: onClickClose,
3700
- transition: theme2.styles.transition
3700
+ transition: theme2.styles.transition,
3701
+ zIndex: 10
3701
3702
  }
3702
3703
  )
3703
3704
  ]
3704
3705
  }
3705
3706
  ),
3706
3707
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Divider_default.horizontal, {})
3707
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_jsx_runtime12.Fragment, { children: !withoutCloseButton && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Div_default, { position: "absolute", top: theme2.styles.space, right: theme2.styles.space, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Button_default.icon, { icon: "XMark", onClick: onClickClose }) }) }),
3708
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_jsx_runtime12.Fragment, { children: !withoutCloseButton && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Div_default, { position: "absolute", top: theme2.styles.space, right: theme2.styles.space, zIndex: 10, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Button_default.icon, { icon: "XMark", onClick: onClickClose }) }) }),
3708
3709
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Div_default, { padding: title ? theme2.styles.space : void 0, children })
3709
3710
  ]
3710
3711
  }
@@ -5897,6 +5898,9 @@ var DropdownComponent = (0, import_react18.forwardRef)(function Dropdown({
5897
5898
  ] }),
5898
5899
  [filteredOptions, value, focusedOptionIndex, theme2.colors, onClickOption, renderOption, renderOptionDivider]
5899
5900
  );
5901
+ (0, import_react18.useEffect)(() => {
5902
+ setInternalValue(controlledValue);
5903
+ }, [controlledValue]);
5900
5904
  (0, import_react18.useEffect)(() => {
5901
5905
  if (isOpen) {
5902
5906
  setIsOpenLate.setTrue();
@@ -5932,7 +5936,7 @@ var DropdownComponent = (0, import_react18.forwardRef)(function Dropdown({
5932
5936
  }, [withDebounce, onChangeSearch, debouncedSearchQuery]);
5933
5937
  const displayValue = withSearch && isFocused ? searchQuery : selectedOption?.label ?? "";
5934
5938
  const withClearButton = isOpen && selectedOption;
5935
- const readyPlaceholder = placeholder ? placeholder : `Select an ${label?.toLowerCase() ?? "option"}`;
5939
+ const readyPlaceholder = placeholder ?? `Select an ${label?.toLowerCase() ?? "option"}`;
5936
5940
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Div_default.column, { width: "100%", position: "relative", userSelect: "none", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(Div_default.row, { position: "relative", width: "100%", children: [
5937
5941
  /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
5938
5942
  InputField_default,
@@ -7889,6 +7893,7 @@ var filterPresetsText = {
7889
7893
  nextYear: "Next year"
7890
7894
  };
7891
7895
  var TableComponent = (0, import_react25.forwardRef)(function Table({
7896
+ name,
7892
7897
  columns,
7893
7898
  data,
7894
7899
  isStriped,
@@ -7900,6 +7905,8 @@ var TableComponent = (0, import_react25.forwardRef)(function Table({
7900
7905
  isInsideTableExpandRow,
7901
7906
  containsOverflowComponents,
7902
7907
  wrapperComponentRef,
7908
+ memoizeFilters,
7909
+ memoizeFiltersLifespan = 72e5,
7903
7910
  getRowStyle,
7904
7911
  onClickRow,
7905
7912
  onClickAllCheckboxes,
@@ -7917,7 +7924,15 @@ var TableComponent = (0, import_react25.forwardRef)(function Table({
7917
7924
  const [checkedItems, setCheckedItems] = (0, import_react25.useState)([]);
7918
7925
  const [expandedRows, setExpandedRows] = (0, import_react25.useState)([]);
7919
7926
  const [currentPage, setCurrentPage] = (0, import_react25.useState)(1);
7920
- const [filterData, setFilterData] = (0, import_react25.useState)({});
7927
+ const [filterData, setFilterData] = (0, import_react25.useState)(() => {
7928
+ if (!memoizeFilters || !name) return {};
7929
+ const localStorageData = JSON.parse(localStorage.getItem(`react-better-html-table-filters-${name}`) || "{}");
7930
+ const timestamp = localStorageData.timestamp;
7931
+ const data2 = localStorageData.data ?? {};
7932
+ const timeDiff = Date.now() - timestamp;
7933
+ if (timeDiff > memoizeFiltersLifespan) return {};
7934
+ return data2;
7935
+ });
7921
7936
  const [openedFilterColumnIndex, setOpenedFilterColumnIndex] = (0, import_react25.useState)();
7922
7937
  const [filterListSelectedItems, setFilterListSelectedItems] = (0, import_react25.useState)();
7923
7938
  const openedFilterData = openedFilterColumnIndex ? filterData[openedFilterColumnIndex] : void 0;
@@ -8172,6 +8187,10 @@ var TableComponent = (0, import_react25.forwardRef)(function Table({
8172
8187
  } else if (column.filter === "date" && filter.type === "date" || column.filter === "date-time" && filter.type === "date-time") {
8173
8188
  const minDate = filter.min ? new Date(filter.min) : void 0;
8174
8189
  const maxDate = filter.max ? new Date(filter.max) : void 0;
8190
+ if (column.filter === "date") {
8191
+ minDate?.setHours(0, 0, 0, 0);
8192
+ maxDate?.setHours(23, 59, 59, 999);
8193
+ }
8175
8194
  const itemValue = column.getValue?.(item) ?? new Date(column.type === "text" && column.keyName ? String(item[column.keyName]) : "");
8176
8195
  if (filter.min !== void 0 && minDate && itemValue < minDate) return false;
8177
8196
  if (filter.max !== void 0 && maxDate && itemValue > maxDate) return false;
@@ -8255,6 +8274,17 @@ var TableComponent = (0, import_react25.forwardRef)(function Table({
8255
8274
  (0, import_react25.useEffect)(() => {
8256
8275
  onChangeFilter?.(filterData);
8257
8276
  }, [onChangeFilter, filterData]);
8277
+ (0, import_react25.useEffect)(() => {
8278
+ if (!memoizeFilters) return;
8279
+ if (!name) return;
8280
+ localStorage.setItem(
8281
+ `react-better-html-table-filters-${name}`,
8282
+ JSON.stringify({
8283
+ timestamp: Date.now(),
8284
+ data: filterData
8285
+ })
8286
+ );
8287
+ }, [memoizeFilters, name, filterData]);
8258
8288
  (0, import_react25.useEffect)(() => {
8259
8289
  onChangeFilterDataValue?.(dataAfterFilter);
8260
8290
  }, [onChangeFilterDataValue, dataAfterFilter]);