tabler-react-2 0.1.152 → 0.1.153-alpha.0
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
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,13 @@ 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
|
+
totalRows = _ref4.totalRows,
|
|
126
|
+
onPageChange = _ref4.onPageChange,
|
|
127
|
+
onRowsPerPageChange = _ref4.onRowsPerPageChange,
|
|
128
|
+
_ref4$pageSizeOptions = _ref4.pageSizeOptions,
|
|
129
|
+
pageSizeOptions = _ref4$pageSizeOptions === void 0 ? [10, 25, 50, 100] : _ref4$pageSizeOptions,
|
|
123
130
|
_ref4$tableClassName = _ref4.tableClassName,
|
|
124
131
|
tableClassName = _ref4$tableClassName === void 0 ? "" : _ref4$tableClassName,
|
|
125
132
|
_ref4$paginationClass = _ref4.paginationClassName,
|
|
@@ -141,6 +148,13 @@ var Table = exports.Table = function Table(_ref4) {
|
|
|
141
148
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
142
149
|
pageSize = _useState6[0],
|
|
143
150
|
setPageSize = _useState6[1];
|
|
151
|
+
|
|
152
|
+
// Determine controlled vs uncontrolled values
|
|
153
|
+
var isPageControlled = typeof page === "number" && page > 0;
|
|
154
|
+
var isPageSizeControlled = typeof rowsPerPage === "number" && rowsPerPage > 0;
|
|
155
|
+
var useExternalPagination = isPageControlled || isPageSizeControlled || typeof totalRows === "number" || typeof onPageChange === "function" || typeof onRowsPerPageChange === "function";
|
|
156
|
+
var effectivePage = isPageControlled ? page : currentPage;
|
|
157
|
+
var effectivePageSize = isPageSizeControlled ? rowsPerPage : pageSize;
|
|
144
158
|
var defaultSortFn = function defaultSortFn(a, b) {
|
|
145
159
|
if (a === b) return 0;
|
|
146
160
|
return a > b ? 1 : -1;
|
|
@@ -154,7 +168,11 @@ var Table = exports.Table = function Table(_ref4) {
|
|
|
154
168
|
key: accessor,
|
|
155
169
|
direction: direction
|
|
156
170
|
});
|
|
157
|
-
|
|
171
|
+
if (useExternalPagination && typeof onPageChange === "function") {
|
|
172
|
+
onPageChange(1);
|
|
173
|
+
} else {
|
|
174
|
+
setCurrentPage(1);
|
|
175
|
+
}
|
|
158
176
|
};
|
|
159
177
|
var sortedData = (0, _react.useMemo)(function () {
|
|
160
178
|
if (!sortConfig.key) return data;
|
|
@@ -171,15 +189,18 @@ var Table = exports.Table = function Table(_ref4) {
|
|
|
171
189
|
return sortFunction(aValue, bValue) * order;
|
|
172
190
|
});
|
|
173
191
|
}, [data, sortConfig, columns]);
|
|
174
|
-
var
|
|
192
|
+
var totalRowCount = (0, _react.useMemo)(function () {
|
|
193
|
+
return useExternalPagination ? totalRows !== null && totalRows !== void 0 ? totalRows : data.length : sortedData.length;
|
|
194
|
+
}, [useExternalPagination, totalRows, data.length, sortedData]);
|
|
175
195
|
var totalPages = (0, _react.useMemo)(function () {
|
|
176
|
-
return Math.max(1, Math.ceil(
|
|
177
|
-
}, [
|
|
196
|
+
return Math.max(1, Math.ceil((totalRowCount || 0) / (effectivePageSize || 1)));
|
|
197
|
+
}, [totalRowCount, effectivePageSize]);
|
|
178
198
|
var paginatedData = (0, _react.useMemo)(function () {
|
|
179
199
|
if (!showPagination) return sortedData;
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
200
|
+
if (useExternalPagination) return sortedData; // data is already paginated externally
|
|
201
|
+
var start = (effectivePage - 1) * effectivePageSize;
|
|
202
|
+
return sortedData.slice(start, start + effectivePageSize);
|
|
203
|
+
}, [sortedData, effectivePage, effectivePageSize, showPagination, useExternalPagination]);
|
|
183
204
|
var getSortIcon = function getSortIcon(column) {
|
|
184
205
|
if (sortConfig.key === column.accessor) {
|
|
185
206
|
return sortConfig.direction === "asc" ? /*#__PURE__*/_react["default"].createElement(IconSortAscending, {
|
|
@@ -230,18 +251,24 @@ var Table = exports.Table = function Table(_ref4) {
|
|
|
230
251
|
className: "d-flex justify-content-between align-items-center mt-2 ".concat(paginationClassName)
|
|
231
252
|
}, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_index.Button, {
|
|
232
253
|
onClick: function onClick() {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
254
|
+
var prev = Math.max(effectivePage - 1, 1);
|
|
255
|
+
if (useExternalPagination && typeof onPageChange === "function") {
|
|
256
|
+
onPageChange(prev);
|
|
257
|
+
} else {
|
|
258
|
+
setCurrentPage(prev);
|
|
259
|
+
}
|
|
236
260
|
},
|
|
237
|
-
disabled:
|
|
261
|
+
disabled: effectivePage === 1
|
|
238
262
|
}, "Previous"), /*#__PURE__*/_react["default"].createElement(_index.Button, {
|
|
239
263
|
onClick: function onClick() {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
264
|
+
var next = Math.min(effectivePage + 1, totalPages);
|
|
265
|
+
if (useExternalPagination && typeof onPageChange === "function") {
|
|
266
|
+
onPageChange(next);
|
|
267
|
+
} else {
|
|
268
|
+
setCurrentPage(next);
|
|
269
|
+
}
|
|
243
270
|
},
|
|
244
|
-
disabled:
|
|
271
|
+
disabled: effectivePage === totalPages,
|
|
245
272
|
style: {
|
|
246
273
|
marginLeft: 8
|
|
247
274
|
}
|
|
@@ -249,11 +276,16 @@ var Table = exports.Table = function Table(_ref4) {
|
|
|
249
276
|
style: {
|
|
250
277
|
marginLeft: 16
|
|
251
278
|
}
|
|
252
|
-
}, "Page ",
|
|
279
|
+
}, "Page ", effectivePage, " of ", totalPages), /*#__PURE__*/_react["default"].createElement("span", {
|
|
253
280
|
style: {
|
|
254
281
|
marginLeft: 16
|
|
255
282
|
}
|
|
256
|
-
},
|
|
283
|
+
}, function () {
|
|
284
|
+
var hasData = paginatedData.length > 0;
|
|
285
|
+
var startIndex = hasData ? (effectivePage - 1) * effectivePageSize + 1 : 0;
|
|
286
|
+
var endIndex = hasData ? startIndex + paginatedData.length - 1 : 0;
|
|
287
|
+
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, "Showing ", startIndex, " to ", endIndex, " of ", totalRowCount || 0, " rows");
|
|
288
|
+
}())), /*#__PURE__*/_react["default"].createElement(_index.DropdownInput, {
|
|
257
289
|
prompt: "Rows per page",
|
|
258
290
|
items: pageSizeOptions.map(function (size) {
|
|
259
291
|
return {
|
|
@@ -261,9 +293,14 @@ var Table = exports.Table = function Table(_ref4) {
|
|
|
261
293
|
label: size
|
|
262
294
|
};
|
|
263
295
|
}),
|
|
296
|
+
value: effectivePageSize,
|
|
264
297
|
onChange: function onChange(selected) {
|
|
265
|
-
|
|
266
|
-
|
|
298
|
+
if (useExternalPagination && typeof onRowsPerPageChange === "function") {
|
|
299
|
+
onRowsPerPageChange(selected.id);
|
|
300
|
+
} else {
|
|
301
|
+
setPageSize(selected.id);
|
|
302
|
+
setCurrentPage(1);
|
|
303
|
+
}
|
|
267
304
|
}
|
|
268
305
|
})));
|
|
269
306
|
};
|
|
@@ -282,5 +319,12 @@ Table.propTypes = {
|
|
|
282
319
|
stickyHeader: _propTypes["default"].bool,
|
|
283
320
|
className: _propTypes["default"].string,
|
|
284
321
|
showPagination: _propTypes["default"].bool,
|
|
285
|
-
defaultRowsPerPage: _propTypes["default"].number
|
|
322
|
+
defaultRowsPerPage: _propTypes["default"].number,
|
|
323
|
+
// external pagination
|
|
324
|
+
page: _propTypes["default"].number,
|
|
325
|
+
rowsPerPage: _propTypes["default"].number,
|
|
326
|
+
totalRows: _propTypes["default"].number,
|
|
327
|
+
onPageChange: _propTypes["default"].func,
|
|
328
|
+
onRowsPerPageChange: _propTypes["default"].func,
|
|
329
|
+
pageSizeOptions: _propTypes["default"].arrayOf(_propTypes["default"].number)
|
|
286
330
|
};
|
|
@@ -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,99 @@ 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
|
+
- rowsPerPage: current page size
|
|
495
|
+
- totalRows: total available row count used for page count and the “Showing … of …” text
|
|
496
|
+
- onPageChange: called with next page (1-based)
|
|
497
|
+
- onRowsPerPageChange: called with next page size
|
|
498
|
+
|
|
499
|
+
<Excerpt>
|
|
500
|
+
{(() => {
|
|
501
|
+
// Simulated external pagination
|
|
502
|
+
const React = require("react");
|
|
503
|
+
const [page, setPage] = React.useState(1);
|
|
504
|
+
const [rpp, setRpp] = React.useState(10);
|
|
505
|
+
const total = congressPeople.length;
|
|
506
|
+
const start = (page - 1) * rpp;
|
|
507
|
+
const pageData = congressPeople.slice(start, start + rpp);
|
|
508
|
+
return (
|
|
509
|
+
<Table
|
|
510
|
+
columns={[
|
|
511
|
+
{ label: "Name", accessor: "name" },
|
|
512
|
+
{ label: "Party", accessor: "party" },
|
|
513
|
+
{ label: "State", accessor: "region.state" },
|
|
514
|
+
]}
|
|
515
|
+
data={pageData}
|
|
516
|
+
showPagination
|
|
517
|
+
page={page}
|
|
518
|
+
rowsPerPage={rpp}
|
|
519
|
+
totalRows={total}
|
|
520
|
+
onPageChange={setPage}
|
|
521
|
+
onRowsPerPageChange={(n) => {
|
|
522
|
+
setPage(1);
|
|
523
|
+
setRpp(n);
|
|
524
|
+
}}
|
|
525
|
+
/>
|
|
526
|
+
);
|
|
527
|
+
})()}
|
|
528
|
+
</Excerpt>
|
|
529
|
+
|
|
530
|
+
```jsx
|
|
531
|
+
// Parent controls the table
|
|
532
|
+
const [page, setPage] = useState(1);
|
|
533
|
+
const [rowsPerPage, setRowsPerPage] = useState(10);
|
|
534
|
+
const totalRows = allRows.length; // from your API
|
|
535
|
+
|
|
536
|
+
// Only pass the current slice to the table
|
|
537
|
+
const start = (page - 1) * rowsPerPage;
|
|
538
|
+
const currentData = allRows.slice(start, start + rowsPerPage);
|
|
539
|
+
|
|
540
|
+
<Table
|
|
541
|
+
columns={columns}
|
|
542
|
+
data={currentData}
|
|
543
|
+
showPagination
|
|
544
|
+
page={page}
|
|
545
|
+
rowsPerPage={rowsPerPage}
|
|
546
|
+
totalRows={totalRows}
|
|
547
|
+
onPageChange={setPage}
|
|
548
|
+
onRowsPerPageChange={(n) => { setPage(1); setRowsPerPage(n); }}
|
|
549
|
+
/>;
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
If you don’t supply these controlled props, the table falls back to its internal pagination state, preserving backwards compatibility.
|