ar-design 0.2.21 → 0.2.23

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.
@@ -4,7 +4,7 @@ import { ARIcon } from "../../icons";
4
4
  import Button from "../../form/button";
5
5
  import Checkbox from "../../form/checkbox";
6
6
  import Pagination from "../../navigation/pagination";
7
- import React, { forwardRef, memo, useCallback, useEffect, useRef, useState } from "react";
7
+ import React, { forwardRef, memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
8
8
  import Input from "../../form/input";
9
9
  import Popover from "../../feedback/popover";
10
10
  const Table = forwardRef(({ children, title, description, data, columns, actions, selections, previousSelections, searchedParams, pagination, config = { isSearchable: false }, }, ref) => {
@@ -26,6 +26,7 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
26
26
  const [_searchedParams, setSearchedParams] = useState(undefined);
27
27
  const [checkboxSelectedParams, setCheckboxSelectedParams] = useState(undefined);
28
28
  // states -> Pagination
29
+ const [totalRecords, setTotalRecords] = useState(0);
29
30
  const [currentPage, setCurrentPage] = useState(1);
30
31
  if (config && Object.keys(config.scroll || {}).length > 0) {
31
32
  if (_tableContent.current && config.scroll) {
@@ -104,12 +105,10 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
104
105
  clearTimeout(_searchTimeOut.current);
105
106
  _searchTimeOut.current = setTimeout(() => {
106
107
  setSearchedParams((prev) => ({ ...prev, [event.target.name]: event.target.value }));
107
- setCurrentPage(1);
108
108
  pagination && pagination.onChange(1);
109
109
  }, 750);
110
110
  }
111
111
  else {
112
- setCurrentPage(1);
113
112
  setSearchedText((prev) => ({ ...prev, [event.target.name]: event.target.value }));
114
113
  }
115
114
  };
@@ -158,10 +157,16 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
158
157
  return false;
159
158
  });
160
159
  };
161
- const getData = useCallback(() => {
160
+ const getData = useMemo(() => {
162
161
  let _data = [...data];
163
- if (searchedText)
162
+ if (searchedText) {
164
163
  _data = _data.filter((item) => deepSearch(item, searchedText));
164
+ setTotalRecords(_data.length);
165
+ setCurrentPage(1);
166
+ }
167
+ else {
168
+ setTotalRecords(data.length);
169
+ }
165
170
  if (pagination && !config.isServerSide) {
166
171
  const indexOfLastRow = currentPage * pagination.perPage;
167
172
  const indexOfFirstRow = indexOfLastRow - pagination.perPage;
@@ -274,7 +279,7 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
274
279
  })), windowBlur: true },
275
280
  React.createElement(Button, { variant: "borderless", icon: { element: React.createElement(ARIcon, { icon: "Filter", stroke: "var(--primary)", size: 16 }) } })))))));
276
281
  })))),
277
- React.createElement("tbody", null, getData().map((item, index) => (React.createElement("tr", { key: `row-${index}-${Math.random()}` },
282
+ React.createElement("tbody", null, getData.map((item, index) => (React.createElement("tr", { key: `row-${index}-${Math.random()}` },
278
283
  selections && (React.createElement("td", { key: `selection-${index}`, className: "sticky-left", "data-sticky-position": "left" },
279
284
  React.createElement(Checkbox, { ref: (element) => (_checkboxItems.current[index] = element), status: "primary", checked: selectionItems.some((selectionItem) => JSON.stringify(selectionItem) === JSON.stringify(item)), onChange: (event) => {
280
285
  if (event.target.checked)
@@ -325,13 +330,13 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
325
330
  React.createElement("span", null,
326
331
  React.createElement("strong", null,
327
332
  "Showing ",
328
- getData().length),
333
+ getData.length),
329
334
  " ",
330
335
  React.createElement("span", null,
331
336
  "of ",
332
- pagination?.perPage ?? getData().length,
337
+ pagination?.perPage ?? getData.length,
333
338
  " agreement")),
334
- React.createElement(Pagination, { totalRecords: pagination.totalRecords, currentPage: currentPage, perPage: pagination.perPage, onChange: (currentPage) => {
339
+ React.createElement(Pagination, { totalRecords: config.isServerSide ? pagination.totalRecords : totalRecords ?? 0, currentPage: currentPage, perPage: pagination.perPage, onChange: (currentPage) => {
335
340
  config.isServerSide && pagination.onChange(currentPage);
336
341
  setCurrentPage(currentPage);
337
342
  } })))));
@@ -270,8 +270,6 @@ const Select = ({ variant = "outlined", status, border = { radius: "sm" }, optio
270
270
  if (event.key === "Enter")
271
271
  return;
272
272
  setSearchText(event.currentTarget.value);
273
- }, onBlur: () => {
274
- setTimeout(() => setOptionsOpen(false), 100);
275
273
  }, placeholder: placeholder, validation: validation, disabled: disabled })),
276
274
  React.createElement("span", { className: `button-clear ${!disabled && (multiple ? value.length > 0 : value) ? "opened" : "closed"}`, onClick: (event) => {
277
275
  if (disabled)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ar-design",
3
- "version": "0.2.21",
3
+ "version": "0.2.23",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",