tabler-react-2 0.1.152 → 0.1.153-alpha.1
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/input/checkbox.js +11 -4
- package/dist/table/index.js +74 -18
- package/docs/package.json +1 -1
- package/docs/src/docs/changelog.mdx +8 -0
- package/docs/src/docs/components/tables.mdx +98 -0
- package/package.json +1 -1
package/dist/input/checkbox.js
CHANGED
|
@@ -6,22 +6,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.Checkbox = void 0;
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
|
+
var _excluded = ["value", "onChange", "label", "required", "className"];
|
|
9
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
12
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
13
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
14
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
10
15
|
var Checkbox = exports.Checkbox = function Checkbox(_ref) {
|
|
11
16
|
var _ref$value = _ref.value,
|
|
12
17
|
value = _ref$value === void 0 ? false : _ref$value,
|
|
13
18
|
_onChange = _ref.onChange,
|
|
14
19
|
label = _ref.label,
|
|
15
20
|
_ref$required = _ref.required,
|
|
16
|
-
required = _ref$required === void 0 ? false : _ref$required
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
required = _ref$required === void 0 ? false : _ref$required,
|
|
22
|
+
className = _ref.className,
|
|
23
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
24
|
+
return /*#__PURE__*/_react["default"].createElement("label", _extends({
|
|
25
|
+
className: (0, _classnames["default"])("form-check", className),
|
|
19
26
|
style: {
|
|
20
27
|
display: "flex",
|
|
21
28
|
alignItems: "center",
|
|
22
29
|
gap: 8
|
|
23
30
|
}
|
|
24
|
-
}, /*#__PURE__*/_react["default"].createElement("input", {
|
|
31
|
+
}, props), /*#__PURE__*/_react["default"].createElement("input", {
|
|
25
32
|
className: "form-check-input",
|
|
26
33
|
type: "checkbox",
|
|
27
34
|
checked: value,
|
package/dist/table/index.js
CHANGED
|
@@ -120,6 +120,16 @@ var Table = exports.Table = function Table(_ref4) {
|
|
|
120
120
|
showPagination = _ref4$showPagination === void 0 ? false : _ref4$showPagination,
|
|
121
121
|
_ref4$defaultRowsPerP = _ref4.defaultRowsPerPage,
|
|
122
122
|
defaultRowsPerPage = _ref4$defaultRowsPerP === void 0 ? 10 : _ref4$defaultRowsPerP,
|
|
123
|
+
page = _ref4.page,
|
|
124
|
+
rowsPerPage = _ref4.rowsPerPage,
|
|
125
|
+
size = _ref4.size,
|
|
126
|
+
totalRows = _ref4.totalRows,
|
|
127
|
+
onPageChange = _ref4.onPageChange,
|
|
128
|
+
onRowsPerPageChange = _ref4.onRowsPerPageChange,
|
|
129
|
+
onSetPage = _ref4.onSetPage,
|
|
130
|
+
onSetSize = _ref4.onSetSize,
|
|
131
|
+
_ref4$pageSizeOptions = _ref4.pageSizeOptions,
|
|
132
|
+
pageSizeOptions = _ref4$pageSizeOptions === void 0 ? [10, 25, 50, 100] : _ref4$pageSizeOptions,
|
|
123
133
|
_ref4$tableClassName = _ref4.tableClassName,
|
|
124
134
|
tableClassName = _ref4$tableClassName === void 0 ? "" : _ref4$tableClassName,
|
|
125
135
|
_ref4$paginationClass = _ref4.paginationClassName,
|
|
@@ -141,6 +151,13 @@ var Table = exports.Table = function Table(_ref4) {
|
|
|
141
151
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
142
152
|
pageSize = _useState6[0],
|
|
143
153
|
setPageSize = _useState6[1];
|
|
154
|
+
|
|
155
|
+
// Determine controlled vs uncontrolled values
|
|
156
|
+
var isPageControlled = typeof page === "number" && page > 0;
|
|
157
|
+
var isPageSizeControlled = typeof size === "number" && size > 0 || typeof rowsPerPage === "number" && rowsPerPage > 0;
|
|
158
|
+
var useExternalPagination = isPageControlled || isPageSizeControlled || typeof totalRows === "number" || typeof onSetPage === "function" || typeof onSetSize === "function" || typeof onPageChange === "function" || typeof onRowsPerPageChange === "function";
|
|
159
|
+
var effectivePage = isPageControlled ? page : currentPage;
|
|
160
|
+
var effectivePageSize = isPageSizeControlled ? typeof size === "number" && size > 0 ? size : rowsPerPage : pageSize;
|
|
144
161
|
var defaultSortFn = function defaultSortFn(a, b) {
|
|
145
162
|
if (a === b) return 0;
|
|
146
163
|
return a > b ? 1 : -1;
|
|
@@ -154,7 +171,17 @@ var Table = exports.Table = function Table(_ref4) {
|
|
|
154
171
|
key: accessor,
|
|
155
172
|
direction: direction
|
|
156
173
|
});
|
|
157
|
-
|
|
174
|
+
if (useExternalPagination) {
|
|
175
|
+
if (typeof onSetPage === "function") {
|
|
176
|
+
onSetPage(1);
|
|
177
|
+
} else if (typeof onPageChange === "function") {
|
|
178
|
+
onPageChange(1);
|
|
179
|
+
} else {
|
|
180
|
+
setCurrentPage(1);
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
setCurrentPage(1);
|
|
184
|
+
}
|
|
158
185
|
};
|
|
159
186
|
var sortedData = (0, _react.useMemo)(function () {
|
|
160
187
|
if (!sortConfig.key) return data;
|
|
@@ -171,15 +198,18 @@ var Table = exports.Table = function Table(_ref4) {
|
|
|
171
198
|
return sortFunction(aValue, bValue) * order;
|
|
172
199
|
});
|
|
173
200
|
}, [data, sortConfig, columns]);
|
|
174
|
-
var
|
|
201
|
+
var totalRowCount = (0, _react.useMemo)(function () {
|
|
202
|
+
return useExternalPagination ? totalRows !== null && totalRows !== void 0 ? totalRows : data.length : sortedData.length;
|
|
203
|
+
}, [useExternalPagination, totalRows, data.length, sortedData]);
|
|
175
204
|
var totalPages = (0, _react.useMemo)(function () {
|
|
176
|
-
return Math.max(1, Math.ceil(
|
|
177
|
-
}, [
|
|
205
|
+
return Math.max(1, Math.ceil((totalRowCount || 0) / (effectivePageSize || 1)));
|
|
206
|
+
}, [totalRowCount, effectivePageSize]);
|
|
178
207
|
var paginatedData = (0, _react.useMemo)(function () {
|
|
179
208
|
if (!showPagination) return sortedData;
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
209
|
+
if (useExternalPagination) return sortedData; // data is already paginated externally
|
|
210
|
+
var start = (effectivePage - 1) * effectivePageSize;
|
|
211
|
+
return sortedData.slice(start, start + effectivePageSize);
|
|
212
|
+
}, [sortedData, effectivePage, effectivePageSize, showPagination, useExternalPagination]);
|
|
183
213
|
var getSortIcon = function getSortIcon(column) {
|
|
184
214
|
if (sortConfig.key === column.accessor) {
|
|
185
215
|
return sortConfig.direction === "asc" ? /*#__PURE__*/_react["default"].createElement(IconSortAscending, {
|
|
@@ -230,18 +260,24 @@ var Table = exports.Table = function Table(_ref4) {
|
|
|
230
260
|
className: "d-flex justify-content-between align-items-center mt-2 ".concat(paginationClassName)
|
|
231
261
|
}, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_index.Button, {
|
|
232
262
|
onClick: function onClick() {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
263
|
+
var prev = Math.max(effectivePage - 1, 1);
|
|
264
|
+
if (useExternalPagination) {
|
|
265
|
+
if (typeof onSetPage === "function") return onSetPage(prev);
|
|
266
|
+
if (typeof onPageChange === "function") return onPageChange(prev);
|
|
267
|
+
}
|
|
268
|
+
setCurrentPage(prev);
|
|
236
269
|
},
|
|
237
|
-
disabled:
|
|
270
|
+
disabled: effectivePage === 1
|
|
238
271
|
}, "Previous"), /*#__PURE__*/_react["default"].createElement(_index.Button, {
|
|
239
272
|
onClick: function onClick() {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
273
|
+
var next = Math.min(effectivePage + 1, totalPages);
|
|
274
|
+
if (useExternalPagination) {
|
|
275
|
+
if (typeof onSetPage === "function") return onSetPage(next);
|
|
276
|
+
if (typeof onPageChange === "function") return onPageChange(next);
|
|
277
|
+
}
|
|
278
|
+
setCurrentPage(next);
|
|
243
279
|
},
|
|
244
|
-
disabled:
|
|
280
|
+
disabled: effectivePage === totalPages,
|
|
245
281
|
style: {
|
|
246
282
|
marginLeft: 8
|
|
247
283
|
}
|
|
@@ -249,11 +285,16 @@ var Table = exports.Table = function Table(_ref4) {
|
|
|
249
285
|
style: {
|
|
250
286
|
marginLeft: 16
|
|
251
287
|
}
|
|
252
|
-
}, "Page ",
|
|
288
|
+
}, "Page ", effectivePage, " of ", totalPages), /*#__PURE__*/_react["default"].createElement("span", {
|
|
253
289
|
style: {
|
|
254
290
|
marginLeft: 16
|
|
255
291
|
}
|
|
256
|
-
},
|
|
292
|
+
}, function () {
|
|
293
|
+
var hasData = paginatedData.length > 0;
|
|
294
|
+
var startIndex = hasData ? (effectivePage - 1) * effectivePageSize + 1 : 0;
|
|
295
|
+
var endIndex = hasData ? startIndex + paginatedData.length - 1 : 0;
|
|
296
|
+
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, "Showing ", startIndex, " to ", endIndex, " of ", totalRowCount || 0, " rows");
|
|
297
|
+
}())), /*#__PURE__*/_react["default"].createElement(_index.DropdownInput, {
|
|
257
298
|
prompt: "Rows per page",
|
|
258
299
|
items: pageSizeOptions.map(function (size) {
|
|
259
300
|
return {
|
|
@@ -261,7 +302,12 @@ var Table = exports.Table = function Table(_ref4) {
|
|
|
261
302
|
label: size
|
|
262
303
|
};
|
|
263
304
|
}),
|
|
305
|
+
value: effectivePageSize,
|
|
264
306
|
onChange: function onChange(selected) {
|
|
307
|
+
if (useExternalPagination) {
|
|
308
|
+
if (typeof onSetSize === "function") return onSetSize(selected.id);
|
|
309
|
+
if (typeof onRowsPerPageChange === "function") return onRowsPerPageChange(selected.id);
|
|
310
|
+
}
|
|
265
311
|
setPageSize(selected.id);
|
|
266
312
|
setCurrentPage(1);
|
|
267
313
|
}
|
|
@@ -282,5 +328,15 @@ Table.propTypes = {
|
|
|
282
328
|
stickyHeader: _propTypes["default"].bool,
|
|
283
329
|
className: _propTypes["default"].string,
|
|
284
330
|
showPagination: _propTypes["default"].bool,
|
|
285
|
-
defaultRowsPerPage: _propTypes["default"].number
|
|
331
|
+
defaultRowsPerPage: _propTypes["default"].number,
|
|
332
|
+
// external pagination
|
|
333
|
+
page: _propTypes["default"].number,
|
|
334
|
+
rowsPerPage: _propTypes["default"].number,
|
|
335
|
+
size: _propTypes["default"].number,
|
|
336
|
+
totalRows: _propTypes["default"].number,
|
|
337
|
+
onPageChange: _propTypes["default"].func,
|
|
338
|
+
onRowsPerPageChange: _propTypes["default"].func,
|
|
339
|
+
onSetPage: _propTypes["default"].func,
|
|
340
|
+
onSetSize: _propTypes["default"].func,
|
|
341
|
+
pageSizeOptions: _propTypes["default"].arrayOf(_propTypes["default"].number)
|
|
286
342
|
};
|
package/docs/package.json
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
title: Changelog
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
# 0.1.153
|
|
6
|
+
|
|
7
|
+
- Support className and arbitrary props on the `Checkbox` component.
|
|
8
|
+
|
|
9
|
+
# 0.1.152
|
|
10
|
+
|
|
11
|
+
- Fix rendering of `invalid` prop on `Input` components with `prependedText` or `appendedText`.
|
|
12
|
+
|
|
5
13
|
# 0.1.151
|
|
6
14
|
|
|
7
15
|
- Add `invalidText` prop to the `Input` component.
|
|
@@ -454,3 +454,101 @@ const customSortFn = (a, b) => {
|
|
|
454
454
|
```
|
|
455
455
|
|
|
456
456
|
> **Note**: Sorting only works for the data in the table. If, for example, you have thousands of rows and are only rendering a few, you will need to handle the sorting yourself, outside of the table. Incorporating internal pagination that supports sorting is a planned feature but not yet implemented.
|
|
457
|
+
|
|
458
|
+
## Pagination
|
|
459
|
+
|
|
460
|
+
The `Table` supports built-in pagination UI. Enable it with `showPagination`.
|
|
461
|
+
|
|
462
|
+
- showPagination: toggles the pagination controls
|
|
463
|
+
- defaultRowsPerPage: initial rows per page for internal mode
|
|
464
|
+
- pageSizeOptions: selectable page sizes (default `[10, 25, 50, 100]`)
|
|
465
|
+
|
|
466
|
+
<Excerpt>
|
|
467
|
+
<Table
|
|
468
|
+
columns={[
|
|
469
|
+
{ label: "Name", accessor: "name" },
|
|
470
|
+
{ label: "Party", accessor: "party" },
|
|
471
|
+
{ label: "State", accessor: "region.state" },
|
|
472
|
+
]}
|
|
473
|
+
data={congressPeople}
|
|
474
|
+
showPagination
|
|
475
|
+
defaultRowsPerPage={10}
|
|
476
|
+
/>
|
|
477
|
+
</Excerpt>
|
|
478
|
+
|
|
479
|
+
```jsx
|
|
480
|
+
<Table
|
|
481
|
+
columns={columns}
|
|
482
|
+
data={rows}
|
|
483
|
+
showPagination
|
|
484
|
+
defaultRowsPerPage={10}
|
|
485
|
+
pageSizeOptions={[10, 25, 50, 100]}
|
|
486
|
+
/>
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
### External pagination
|
|
490
|
+
|
|
491
|
+
You can also fully control pagination from the parent (e.g., server-side paging) while keeping the same UI. Provide the controlled props and callbacks below. When any controlled pagination prop is provided, the table does not slice your `data` and instead assumes `data` already contains the current page.
|
|
492
|
+
|
|
493
|
+
- page: current page (1-based)
|
|
494
|
+
- size: current page size
|
|
495
|
+
- totalRows: total available row count used for page count and the “Showing … of …” text
|
|
496
|
+
- onSetPage: called with next page (1-based)
|
|
497
|
+
- onSetSize: called with next page size
|
|
498
|
+
|
|
499
|
+
Aliases are supported for compatibility: `rowsPerPage`, `onPageChange`, `onRowsPerPageChange`.
|
|
500
|
+
|
|
501
|
+
<Excerpt>
|
|
502
|
+
{(() => {
|
|
503
|
+
// Simulated external pagination
|
|
504
|
+
const React = require("react");
|
|
505
|
+
const [page, setPage] = React.useState(1);
|
|
506
|
+
const [rpp, setRpp] = React.useState(4);
|
|
507
|
+
const total = congressPeople.length;
|
|
508
|
+
const start = (page - 1) * rpp;
|
|
509
|
+
const pageData = congressPeople.slice(start, start + rpp);
|
|
510
|
+
return (
|
|
511
|
+
<Table
|
|
512
|
+
columns={[
|
|
513
|
+
{ label: "Name", accessor: "name" },
|
|
514
|
+
{ label: "Party", accessor: "party" },
|
|
515
|
+
{ label: "State", accessor: "region.state" },
|
|
516
|
+
]}
|
|
517
|
+
data={pageData}
|
|
518
|
+
showPagination
|
|
519
|
+
page={page}
|
|
520
|
+
size={rpp}
|
|
521
|
+
totalRows={total}
|
|
522
|
+
onSetPage={setPage}
|
|
523
|
+
onSetSize={(n) => {
|
|
524
|
+
setPage(1);
|
|
525
|
+
setRpp(n);
|
|
526
|
+
}}
|
|
527
|
+
/>
|
|
528
|
+
);
|
|
529
|
+
})()}
|
|
530
|
+
</Excerpt>
|
|
531
|
+
|
|
532
|
+
```jsx
|
|
533
|
+
// Parent controls the table
|
|
534
|
+
const [page, setPage] = useState(1);
|
|
535
|
+
const [rowsPerPage, setRowsPerPage] = useState(10);
|
|
536
|
+
const totalRows = allRows.length; // from your API
|
|
537
|
+
|
|
538
|
+
// Only pass the current slice to the table
|
|
539
|
+
const start = (page - 1) * rowsPerPage;
|
|
540
|
+
const currentData = allRows.slice(start, start + rowsPerPage);
|
|
541
|
+
|
|
542
|
+
<Table
|
|
543
|
+
columns={columns}
|
|
544
|
+
data={currentData}
|
|
545
|
+
showPagination
|
|
546
|
+
page={page}
|
|
547
|
+
size={rowsPerPage}
|
|
548
|
+
totalRows={totalRows}
|
|
549
|
+
onSetPage={setPage}
|
|
550
|
+
onSetSize={(n) => { setPage(1); setRowsPerPage(n); }}
|
|
551
|
+
/>;
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
If you don’t supply these controlled props, the table falls back to its internal pagination state, preserving backwards compatibility.
|