baaz-custom-components 5.0.20 → 5.0.22

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.css CHANGED
@@ -675,9 +675,6 @@
675
675
  .touch-none {
676
676
  touch-action: none;
677
677
  }
678
- .resize {
679
- resize: both;
680
- }
681
678
  .scroll-my-1 {
682
679
  scroll-margin-block: calc(var(--spacing) * 1);
683
680
  }
package/dist/index.d.mts CHANGED
@@ -92,13 +92,10 @@ type GridProps = {
92
92
  fonts?: boolean;
93
93
  autoConfig?: boolean | {};
94
94
  downloadable?: boolean;
95
- fileNmae?: string;
95
+ fileName?: string;
96
96
  search: boolean;
97
97
  searchkey: string;
98
98
  searchValue: string;
99
- autoResize?: boolean;
100
- autoResizeMode?: boolean | "data" | "header" | undefined;
101
- defaultMinWidth?: number;
102
99
  onExportPdf?: () => void;
103
100
  onExportExcel?: () => void;
104
101
  onSearch: (e: React.ChangeEvent<HTMLInputElement>) => void;
@@ -114,7 +111,18 @@ type ActiveFilter = {
114
111
  endDate?: string | null;
115
112
  };
116
113
 
117
- declare function Grid({ data, columns, sortKey, sortOrder, onSortChange, onExportPdf, onExportExcel, downloadable, autoResize, autoResizeMode, defaultMinWidth, fileNmae, fonts, onFilterChange, ...rest }: GridProps): react.JSX.Element;
114
+ declare const Grid: react.ForwardRefExoticComponent<GridProps & react.RefAttributes<IApi | null>>;
115
+
116
+ type Props = {
117
+ cell: {
118
+ id?: string;
119
+ text?: string;
120
+ };
121
+ sortKey?: string | null;
122
+ sortOrder?: SortOrder | null;
123
+ onSortChange?: (key: string, order: SortOrder) => void;
124
+ };
125
+ declare function SortableHeaderCell({ cell, sortKey, sortOrder, onSortChange }: Props): react.JSX.Element;
118
126
 
119
127
  type Pagination$1 = {
120
128
  totalCount: number;
@@ -130,4 +138,4 @@ type Pagination$1 = {
130
138
 
131
139
  declare function Pagination({ totalCount, count, currentPage, totalPages, pageSize, onPageChange, onPageSizeChange, showSizeChanger, sizeChangerOptions, }: Pagination$1): react.JSX.Element | null;
132
140
 
133
- export { type BreadcrumbProps, CustomBreadcrumb, Grid, type GridProps, Navbar, type NavbarData, type NavbarEntry, type NavbarProps, type NotificationDataTypes, Pagination, type Pagination$1 as PaginationProps, type RouteTree, type RouterAdapter, type UserData };
141
+ export { type BreadcrumbProps, CustomBreadcrumb, Grid, type GridProps, Navbar, type NavbarData, type NavbarEntry, type NavbarProps, type NotificationDataTypes, Pagination, type Pagination$1 as PaginationProps, type RouteTree, type RouterAdapter, SortableHeaderCell, type UserData };
package/dist/index.d.ts CHANGED
@@ -92,13 +92,10 @@ type GridProps = {
92
92
  fonts?: boolean;
93
93
  autoConfig?: boolean | {};
94
94
  downloadable?: boolean;
95
- fileNmae?: string;
95
+ fileName?: string;
96
96
  search: boolean;
97
97
  searchkey: string;
98
98
  searchValue: string;
99
- autoResize?: boolean;
100
- autoResizeMode?: boolean | "data" | "header" | undefined;
101
- defaultMinWidth?: number;
102
99
  onExportPdf?: () => void;
103
100
  onExportExcel?: () => void;
104
101
  onSearch: (e: React.ChangeEvent<HTMLInputElement>) => void;
@@ -114,7 +111,18 @@ type ActiveFilter = {
114
111
  endDate?: string | null;
115
112
  };
116
113
 
117
- declare function Grid({ data, columns, sortKey, sortOrder, onSortChange, onExportPdf, onExportExcel, downloadable, autoResize, autoResizeMode, defaultMinWidth, fileNmae, fonts, onFilterChange, ...rest }: GridProps): react.JSX.Element;
114
+ declare const Grid: react.ForwardRefExoticComponent<GridProps & react.RefAttributes<IApi | null>>;
115
+
116
+ type Props = {
117
+ cell: {
118
+ id?: string;
119
+ text?: string;
120
+ };
121
+ sortKey?: string | null;
122
+ sortOrder?: SortOrder | null;
123
+ onSortChange?: (key: string, order: SortOrder) => void;
124
+ };
125
+ declare function SortableHeaderCell({ cell, sortKey, sortOrder, onSortChange }: Props): react.JSX.Element;
118
126
 
119
127
  type Pagination$1 = {
120
128
  totalCount: number;
@@ -130,4 +138,4 @@ type Pagination$1 = {
130
138
 
131
139
  declare function Pagination({ totalCount, count, currentPage, totalPages, pageSize, onPageChange, onPageSizeChange, showSizeChanger, sizeChangerOptions, }: Pagination$1): react.JSX.Element | null;
132
140
 
133
- export { type BreadcrumbProps, CustomBreadcrumb, Grid, type GridProps, Navbar, type NavbarData, type NavbarEntry, type NavbarProps, type NotificationDataTypes, Pagination, type Pagination$1 as PaginationProps, type RouteTree, type RouterAdapter, type UserData };
141
+ export { type BreadcrumbProps, CustomBreadcrumb, Grid, type GridProps, Navbar, type NavbarData, type NavbarEntry, type NavbarProps, type NotificationDataTypes, Pagination, type Pagination$1 as PaginationProps, type RouteTree, type RouterAdapter, SortableHeaderCell, type UserData };
package/dist/index.js CHANGED
@@ -62,7 +62,8 @@ __export(index_exports, {
62
62
  CustomBreadcrumb: () => breadcrumb_default,
63
63
  Grid: () => grid_default,
64
64
  Navbar: () => Navbar,
65
- Pagination: () => pagination_default
65
+ Pagination: () => pagination_default,
66
+ SortableHeaderCell: () => sortableHeaderCell_default
66
67
  });
67
68
  module.exports = __toCommonJS(index_exports);
68
69
 
@@ -1948,39 +1949,6 @@ var breadcrumb_default = CustomBreadcrumb;
1948
1949
  var import_react6 = require("react");
1949
1950
  var import_react_grid = require("@svar-ui/react-grid");
1950
1951
 
1951
- // src/components/custom/grid/sortableHeaderCell.tsx
1952
- var import_lucide_react12 = require("lucide-react");
1953
- var import_jsx_runtime23 = require("react/jsx-runtime");
1954
- function SortableHeaderCell({ cell, sortKey, sortOrder, onSortChange }) {
1955
- if (!(cell == null ? void 0 : cell.id)) return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { children: cell == null ? void 0 : cell.text });
1956
- const active = sortKey === cell.id;
1957
- const handleClick = () => {
1958
- if (!onSortChange || !cell.id) return;
1959
- if (!active) {
1960
- onSortChange(cell.id, "asc");
1961
- return;
1962
- }
1963
- if (sortOrder === "asc") {
1964
- onSortChange(cell.id, "desc");
1965
- return;
1966
- }
1967
- onSortChange("", null);
1968
- };
1969
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
1970
- "div",
1971
- {
1972
- onClick: handleClick,
1973
- className: "cursor-pointer flex items-center gap-2 justify-between select-none",
1974
- children: [
1975
- /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { children: cell.text }),
1976
- !active && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_lucide_react12.ArrowUpDown, { className: "w-4 h-4 opacity-50" }),
1977
- active && (sortOrder === "asc" ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_lucide_react12.MoveDown, { className: "w-4 h-4" }) : /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_lucide_react12.MoveUp, { className: "w-4 h-4" }))
1978
- ]
1979
- }
1980
- );
1981
- }
1982
- var sortableHeaderCell_default = SortableHeaderCell;
1983
-
1984
1952
  // src/utils/exportPdf.ts
1985
1953
  var import_jspdf = __toESM(require("jspdf"));
1986
1954
  var import_jspdf_autotable = __toESM(require("jspdf-autotable"));
@@ -2013,12 +1981,13 @@ function exportExcel(rows, name) {
2013
1981
 
2014
1982
  // src/components/custom/grid/gridHeader.tsx
2015
1983
  var import_react5 = require("react");
2016
- var import_lucide_react13 = require("lucide-react");
2017
- var import_jsx_runtime24 = require("react/jsx-runtime");
1984
+ var import_lucide_react12 = require("lucide-react");
1985
+ var import_jsx_runtime23 = require("react/jsx-runtime");
2018
1986
  var GridHeader = ({
2019
1987
  onPdf,
2020
1988
  onExcel,
2021
- onSearch,
1989
+ onSearch = () => {
1990
+ },
2022
1991
  download,
2023
1992
  search,
2024
1993
  searchValue,
@@ -2032,9 +2001,7 @@ var GridHeader = ({
2032
2001
  const [filter, setFilter] = (0, import_react5.useState)({});
2033
2002
  const downloadRef = (0, import_react5.useRef)(null);
2034
2003
  const filterRef = (0, import_react5.useRef)(null);
2035
- const selectedColumn = filterList.find(
2036
- (f) => f.columnName === filter.column
2037
- );
2004
+ const selectedColumn = filterList.find((f) => f.columnName === filter.column);
2038
2005
  const selectedOperator = selectedColumn == null ? void 0 : selectedColumn.operators.find(
2039
2006
  (op) => op.label === filter.operator
2040
2007
  );
@@ -2059,26 +2026,26 @@ var GridHeader = ({
2059
2026
  document.addEventListener("mousedown", handleClickOutside);
2060
2027
  return () => document.removeEventListener("mousedown", handleClickOutside);
2061
2028
  }, []);
2062
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "flex justify-end gap-4 items-center", children: [
2063
- filterList.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "relative", ref: filterRef, children: [
2064
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2029
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "flex justify-end gap-4 items-center", children: [
2030
+ filterList.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "relative", ref: filterRef, children: [
2031
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2065
2032
  "button",
2066
2033
  {
2067
2034
  onClick: () => setFilterMenu((p) => !p),
2068
2035
  className: "py-2 px-4 rounded-md bg-input hover:bg-muted transition cursor-pointer",
2069
- children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react13.ListFilter, { size: 18 })
2036
+ children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_lucide_react12.ListFilter, { size: 18 })
2070
2037
  }
2071
2038
  ),
2072
- filterMenu && /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "absolute top-full right-0 mt-2 p-3 rounded-md border bg-background shadow-lg z-50 flex items-center gap-2", children: [
2073
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2039
+ filterMenu && /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "absolute top-full right-0 mt-2 p-3 rounded-md border bg-background shadow-lg z-50 flex items-center gap-2", children: [
2040
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2074
2041
  "button",
2075
2042
  {
2076
2043
  onClick: clearFilters,
2077
2044
  className: "mr-auto p-2 rounded-md hover:bg-destructive bg-destructive/40 transition cursor-pointer",
2078
- children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react13.X, { size: 16 })
2045
+ children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_lucide_react12.X, { size: 16 })
2079
2046
  }
2080
2047
  ),
2081
- /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
2048
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
2082
2049
  "select",
2083
2050
  {
2084
2051
  value: (_a = filter.column) != null ? _a : "",
@@ -2089,12 +2056,12 @@ var GridHeader = ({
2089
2056
  }),
2090
2057
  className: "px-4 py-2 rounded-md bg-input text-sm",
2091
2058
  children: [
2092
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("option", { value: "", disabled: true, children: "Columns" }),
2093
- filterList.map((f) => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("option", { value: f.columnName, children: f.columnName }, f.columnName))
2059
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("option", { value: "", disabled: true, children: "Columns" }),
2060
+ filterList.map((f) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("option", { value: f.columnName, children: f.columnName }, f.columnName))
2094
2061
  ]
2095
2062
  }
2096
2063
  ),
2097
- /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
2064
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
2098
2065
  "select",
2099
2066
  {
2100
2067
  value: (_b = filter.operator) != null ? _b : "",
@@ -2105,12 +2072,12 @@ var GridHeader = ({
2105
2072
  }),
2106
2073
  className: "px-4 py-2 rounded-md bg-input text-sm",
2107
2074
  children: [
2108
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("option", { value: "", disabled: true, children: "Operator" }),
2109
- selectedColumn == null ? void 0 : selectedColumn.operators.map((op) => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("option", { value: op.label, children: op.label }, op.label))
2075
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("option", { value: "", disabled: true, children: "Operator" }),
2076
+ selectedColumn == null ? void 0 : selectedColumn.operators.map((op) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("option", { value: op.label, children: op.label }, op.label))
2110
2077
  ]
2111
2078
  }
2112
2079
  ),
2113
- (selectedOperator == null ? void 0 : selectedOperator.value) === "input" && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2080
+ (selectedOperator == null ? void 0 : selectedOperator.value) === "input" && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2114
2081
  "input",
2115
2082
  {
2116
2083
  placeholder: "Filter value",
@@ -2119,31 +2086,31 @@ var GridHeader = ({
2119
2086
  className: "px-4 py-2 rounded-md bg-input text-sm"
2120
2087
  }
2121
2088
  ),
2122
- (selectedOperator == null ? void 0 : selectedOperator.value) === "select" && /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
2089
+ (selectedOperator == null ? void 0 : selectedOperator.value) === "select" && /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
2123
2090
  "select",
2124
2091
  {
2125
2092
  value: (_d = filter.value) != null ? _d : "",
2126
2093
  onChange: (e) => updateFilter({ value: e.target.value }),
2127
2094
  className: "px-4 py-2 rounded-md bg-input text-sm",
2128
2095
  children: [
2129
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("option", { value: "", disabled: true, children: "Value" }),
2130
- (_e = selectedOperator.options) == null ? void 0 : _e.map((opt) => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("option", { value: opt.value, children: opt.label }, opt.value))
2096
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("option", { value: "", disabled: true, children: "Value" }),
2097
+ (_e = selectedOperator.options) == null ? void 0 : _e.map((opt) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("option", { value: opt.value, children: opt.label }, opt.value))
2131
2098
  ]
2132
2099
  }
2133
2100
  )
2134
2101
  ] })
2135
2102
  ] }),
2136
- download && /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "relative", ref: downloadRef, children: [
2137
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2103
+ download && /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "relative", ref: downloadRef, children: [
2104
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2138
2105
  "button",
2139
2106
  {
2140
2107
  onClick: () => setDownloadMenu((p) => !p),
2141
2108
  className: "py-2 px-4 rounded-md bg-input hover:bg-muted transition",
2142
- children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react13.Download, { size: 18 })
2109
+ children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_lucide_react12.Download, { size: 18 })
2143
2110
  }
2144
2111
  ),
2145
- downloadMenu && /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "absolute top-full right-0 mt-2 w-32 rounded-md border bg-background shadow-lg z-50", children: [
2146
- /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
2112
+ downloadMenu && /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "absolute top-full right-0 mt-2 w-32 rounded-md border bg-background shadow-lg z-50", children: [
2113
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
2147
2114
  "button",
2148
2115
  {
2149
2116
  onClick: () => {
@@ -2152,12 +2119,12 @@ var GridHeader = ({
2152
2119
  },
2153
2120
  className: "flex items-center gap-2 w-full px-3 py-2 text-sm hover:bg-muted",
2154
2121
  children: [
2155
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react13.FileText, { size: 14 }),
2122
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_lucide_react12.FileText, { size: 14 }),
2156
2123
  "PDF"
2157
2124
  ]
2158
2125
  }
2159
2126
  ),
2160
- /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
2127
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
2161
2128
  "button",
2162
2129
  {
2163
2130
  onClick: () => {
@@ -2166,16 +2133,16 @@ var GridHeader = ({
2166
2133
  },
2167
2134
  className: "flex items-center gap-2 w-full px-3 py-2 text-sm hover:bg-muted",
2168
2135
  children: [
2169
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react13.FileSpreadsheet, { size: 14 }),
2136
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_lucide_react12.FileSpreadsheet, { size: 14 }),
2170
2137
  "Excel"
2171
2138
  ]
2172
2139
  }
2173
2140
  )
2174
2141
  ] })
2175
2142
  ] }),
2176
- search && /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "py-2 px-4 w-[20rem] rounded-md border border-input bg-background flex items-center gap-2 text-sm", children: [
2177
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react13.Search, { className: "w-4 h-4" }),
2178
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2143
+ search && /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "py-2 px-4 w-[20rem] rounded-md border border-input bg-background flex items-center gap-2 text-sm", children: [
2144
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_lucide_react12.Search, { className: "w-4 h-4" }),
2145
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2179
2146
  "input",
2180
2147
  {
2181
2148
  placeholder: `Search by ${searchkey}`,
@@ -2190,139 +2157,135 @@ var GridHeader = ({
2190
2157
  var gridHeader_default = GridHeader;
2191
2158
 
2192
2159
  // src/components/custom/grid/index.tsx
2193
- var import_jsx_runtime25 = require("react/jsx-runtime");
2194
- function Grid(_a) {
2195
- var _b = _a, {
2196
- data,
2197
- columns,
2198
- sortKey,
2199
- sortOrder,
2200
- onSortChange,
2201
- onExportPdf,
2202
- onExportExcel,
2203
- downloadable = true,
2204
- autoResize = true,
2205
- autoResizeMode = true,
2206
- defaultMinWidth = 120,
2207
- fileNmae,
2208
- fonts,
2209
- onFilterChange
2210
- } = _b, rest = __objRest(_b, [
2211
- "data",
2212
- "columns",
2213
- "sortKey",
2214
- "sortOrder",
2215
- "onSortChange",
2216
- "onExportPdf",
2217
- "onExportExcel",
2218
- "downloadable",
2219
- "autoResize",
2220
- "autoResizeMode",
2221
- "defaultMinWidth",
2222
- "fileNmae",
2223
- "fonts",
2224
- "onFilterChange"
2225
- ]);
2226
- const apiRef = (0, import_react6.useRef)(null);
2227
- const svarColumns = columns.map((col) => {
2228
- const _a2 = col, { sortable, header } = _a2, columnProps = __objRest(_a2, ["sortable", "header"]);
2229
- if (!sortable) {
2230
- return __spreadProps(__spreadValues({}, columnProps), {
2231
- header
2232
- });
2233
- }
2234
- return __spreadProps(__spreadValues({}, columnProps), {
2235
- header: {
2236
- text: header,
2237
- cell: (props) => /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
2238
- sortableHeaderCell_default,
2239
- __spreadProps(__spreadValues({}, props), {
2240
- sortKey,
2241
- sortOrder,
2242
- onSortChange
2243
- })
2244
- )
2245
- }
2246
- });
2247
- });
2248
- const init = (api) => {
2249
- var _a2;
2250
- apiRef.current = api;
2251
- (_a2 = rest.onApiReady) == null ? void 0 : _a2.call(rest, api);
2252
- };
2253
- (0, import_react6.useEffect)(() => {
2254
- if (!apiRef.current || !columns.length || !autoResize) return;
2255
- const resize = () => {
2160
+ var import_jsx_runtime24 = require("react/jsx-runtime");
2161
+ var Grid = (0, import_react6.forwardRef)(
2162
+ (_a, ref) => {
2163
+ var _b = _a, {
2164
+ data,
2165
+ columns,
2166
+ sortKey,
2167
+ sortOrder,
2168
+ onSortChange,
2169
+ onExportPdf,
2170
+ onExportExcel,
2171
+ downloadable = true,
2172
+ fileName,
2173
+ fonts,
2174
+ onFilterChange
2175
+ } = _b, rest = __objRest(_b, [
2176
+ "data",
2177
+ "columns",
2178
+ "sortKey",
2179
+ "sortOrder",
2180
+ "onSortChange",
2181
+ "onExportPdf",
2182
+ "onExportExcel",
2183
+ "downloadable",
2184
+ "fileName",
2185
+ "fonts",
2186
+ "onFilterChange"
2187
+ ]);
2188
+ const apiRef = (0, import_react6.useRef)(null);
2189
+ (0, import_react6.useImperativeHandle)(ref, () => apiRef.current, []);
2190
+ const resizeColumns = (0, import_react6.useCallback)(() => {
2191
+ const api = apiRef.current;
2192
+ if (!api) return;
2256
2193
  columns.forEach((col) => {
2257
- var _a2, _b2;
2258
- if (!(col == null ? void 0 : col.width)) {
2259
- (_a2 = apiRef.current) == null ? void 0 : _a2.exec("resize-column", {
2260
- id: col.id,
2261
- auto: autoResizeMode
2262
- });
2263
- }
2264
- if (defaultMinWidth) {
2265
- (_b2 = apiRef.current) == null ? void 0 : _b2.exec("update-column", {
2266
- id: col.id,
2267
- minWidth: defaultMinWidth
2268
- });
2269
- }
2194
+ api.exec("resize-column", {
2195
+ id: col.id,
2196
+ auto: "data"
2197
+ });
2270
2198
  });
2271
- };
2272
- const run = async () => {
2273
- var _a2;
2274
- if ((_a2 = document == null ? void 0 : document.fonts) == null ? void 0 : _a2.ready) {
2275
- await document.fonts.ready;
2276
- }
2277
- requestAnimationFrame(() => {
2278
- requestAnimationFrame(resize);
2199
+ }, [columns, data]);
2200
+ const init = (0, import_react6.useCallback)((api) => {
2201
+ apiRef.current = api;
2202
+ resizeColumns();
2203
+ }, [resizeColumns]);
2204
+ const getSelectedData = () => {
2205
+ var _a2, _b2;
2206
+ const selected = (_b2 = (_a2 = apiRef.current) == null ? void 0 : _a2.getState().selectedRows) != null ? _b2 : [];
2207
+ let selectedData = data.filter((row) => {
2208
+ return selected.includes(row.id);
2279
2209
  });
2210
+ return selectedData;
2280
2211
  };
2281
- run();
2282
- }, [columns, data, autoResize, autoResizeMode, defaultMinWidth]);
2283
- const getSelectedData = () => {
2284
- var _a2, _b2;
2285
- const selected = (_b2 = (_a2 = apiRef.current) == null ? void 0 : _a2.getState().selectedRows) != null ? _b2 : [];
2286
- let selectedData = data.filter((row) => {
2287
- return selected.includes(row.id);
2288
- });
2289
- return selectedData;
2290
- };
2291
- const handleExportPdf = () => {
2292
- const selected = getSelectedData();
2293
- if (selected.length) {
2294
- exportPdf(selected, fileNmae);
2295
- } else {
2296
- onExportPdf == null ? void 0 : onExportPdf();
2212
+ const handleExportPdf = (0, import_react6.useCallback)(() => {
2213
+ const selected = getSelectedData();
2214
+ if (selected.length) {
2215
+ exportPdf(selected, fileName);
2216
+ } else {
2217
+ onExportPdf == null ? void 0 : onExportPdf();
2218
+ }
2219
+ }, [getSelectedData, exportPdf, onExportPdf, fileName]);
2220
+ const handleExportExcel = (0, import_react6.useCallback)(() => {
2221
+ const selected = getSelectedData();
2222
+ if (selected.length) {
2223
+ exportExcel(selected, fileName);
2224
+ } else {
2225
+ onExportExcel == null ? void 0 : onExportExcel();
2226
+ }
2227
+ }, [getSelectedData, exportExcel, onExportExcel, fileName]);
2228
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "w-full flex flex-col gap-4 overflow-hidden", children: [
2229
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2230
+ gridHeader_default,
2231
+ {
2232
+ onPdf: handleExportPdf,
2233
+ onExcel: handleExportExcel,
2234
+ download: downloadable,
2235
+ search: rest.search,
2236
+ searchkey: rest.searchkey,
2237
+ onSearch: rest.onSearch,
2238
+ searchValue: rest.searchValue,
2239
+ filterList: rest.filterList,
2240
+ onFilterChange
2241
+ }
2242
+ ),
2243
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "w-full overflow-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_react_grid.WillowDark, { fonts, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "w-grid h-full overflow-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2244
+ import_react_grid.Grid,
2245
+ __spreadProps(__spreadValues({}, rest), {
2246
+ data,
2247
+ columns,
2248
+ init,
2249
+ onUpdateCell: () => resizeColumns()
2250
+ })
2251
+ ) }) }) })
2252
+ ] });
2253
+ }
2254
+ );
2255
+ var grid_default = Grid;
2256
+
2257
+ // src/components/custom/grid/sortableHeaderCell.tsx
2258
+ var import_lucide_react13 = require("lucide-react");
2259
+ var import_jsx_runtime25 = require("react/jsx-runtime");
2260
+ function SortableHeaderCell({ cell, sortKey, sortOrder, onSortChange }) {
2261
+ if (!(cell == null ? void 0 : cell.id)) return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { children: cell == null ? void 0 : cell.text });
2262
+ const active = sortKey === cell.id;
2263
+ const handleClick = () => {
2264
+ if (!onSortChange || !cell.id) return;
2265
+ if (!active) {
2266
+ onSortChange(cell.id, "asc");
2267
+ return;
2297
2268
  }
2298
- };
2299
- const handleExportExcel = () => {
2300
- const selected = getSelectedData();
2301
- if (selected.length) {
2302
- exportExcel(selected, fileNmae);
2303
- } else {
2304
- onExportExcel == null ? void 0 : onExportExcel();
2269
+ if (sortOrder === "asc") {
2270
+ onSortChange(cell.id, "desc");
2271
+ return;
2305
2272
  }
2273
+ onSortChange("", null);
2306
2274
  };
2307
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "w-full flex flex-col gap-4 overflow-hidden", children: [
2308
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
2309
- gridHeader_default,
2310
- {
2311
- onPdf: handleExportPdf,
2312
- onExcel: handleExportExcel,
2313
- download: downloadable,
2314
- search: rest.search,
2315
- searchkey: rest.searchkey,
2316
- onSearch: rest.onSearch,
2317
- searchValue: rest.searchValue,
2318
- filterList: rest.filterList,
2319
- onFilterChange
2320
- }
2321
- ),
2322
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "w-full overflow-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_react_grid.WillowDark, { fonts, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "w-grid h-full overflow-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_react_grid.Grid, __spreadProps(__spreadValues({}, rest), { data, columns: svarColumns, init })) }) }) })
2323
- ] });
2275
+ return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
2276
+ "div",
2277
+ {
2278
+ onClick: handleClick,
2279
+ className: "cursor-pointer flex items-center gap-2 justify-between select-none",
2280
+ children: [
2281
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { children: cell.text }),
2282
+ !active && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_lucide_react13.ArrowUpDown, { className: "w-4 h-4 opacity-50" }),
2283
+ active && (sortOrder === "asc" ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_lucide_react13.MoveDown, { className: "w-4 h-4" }) : /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_lucide_react13.MoveUp, { className: "w-4 h-4" }))
2284
+ ]
2285
+ }
2286
+ );
2324
2287
  }
2325
- var grid_default = Grid;
2288
+ var sortableHeaderCell_default = SortableHeaderCell;
2326
2289
 
2327
2290
  // src/utils/pagination.ts
2328
2291
  function getPaginationRange(currentPage, totalPages, siblingCount = 2) {
@@ -2445,5 +2408,6 @@ var pagination_default = Pagination;
2445
2408
  CustomBreadcrumb,
2446
2409
  Grid,
2447
2410
  Navbar,
2448
- Pagination
2411
+ Pagination,
2412
+ SortableHeaderCell
2449
2413
  });