@tint-ui/data-table 0.3.5
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/LICENSE +21 -0
- package/README.md +9 -0
- package/adapters/boolean.d.ts +10 -0
- package/adapters/boolean.js +38 -0
- package/adapters/index.d.ts +6 -0
- package/adapters/index.js +18 -0
- package/adapters/number-format.d.ts +1 -0
- package/adapters/number-format.js +42 -0
- package/adapters/number.d.ts +12 -0
- package/adapters/number.js +51 -0
- package/adapters/text.d.ts +4 -0
- package/adapters/text.js +9 -0
- package/cell-adapter-type.d.ts +43 -0
- package/cell-adapter-type.js +306 -0
- package/cjs/adapters/boolean.js +43 -0
- package/cjs/adapters/index.js +21 -0
- package/cjs/adapters/number-format.js +46 -0
- package/cjs/adapters/number.js +56 -0
- package/cjs/adapters/text.js +13 -0
- package/cjs/cell-adapter-type.js +312 -0
- package/cjs/classes.js +27 -0
- package/cjs/context.js +14 -0
- package/cjs/data-table-content.js +105 -0
- package/cjs/data-table-pagination.js +38 -0
- package/cjs/data-table-text-filter.js +83 -0
- package/cjs/data-table-toolbar.js +103 -0
- package/cjs/data-table-views-options.js +137 -0
- package/cjs/data-table.js +63 -0
- package/cjs/filter-adapter-type.js +162 -0
- package/cjs/filter-adapters/index.js +10 -0
- package/cjs/filter-adapters/option.js +152 -0
- package/cjs/filter-adapters/use-option-filter.js +195 -0
- package/cjs/filter-classes.js +26 -0
- package/cjs/filter-fn.js +84 -0
- package/cjs/index.js +99 -0
- package/cjs/package.json +3 -0
- package/cjs/pagination-arrow.js +93 -0
- package/cjs/pagination-classes.js +20 -0
- package/cjs/pagination-number.js +66 -0
- package/cjs/pagination-size-options.js +48 -0
- package/cjs/row-button-menu.js +49 -0
- package/cjs/row-popover-menu.js +52 -0
- package/cjs/toolbar-classes.js +24 -0
- package/cjs/types.js +3 -0
- package/cjs/use-data-table.js +768 -0
- package/cjs/use-lexicon.js +155 -0
- package/cjs/use-row-menu.js +60 -0
- package/cjs/use-visibility-column.js +105 -0
- package/cjs/use-visibility-filter.js +149 -0
- package/cjs/utils.js +136 -0
- package/classes.d.ts +34 -0
- package/classes.js +23 -0
- package/context.d.ts +5 -0
- package/context.js +9 -0
- package/data-table-content.d.ts +9 -0
- package/data-table-content.js +98 -0
- package/data-table-pagination.d.ts +5 -0
- package/data-table-pagination.js +31 -0
- package/data-table-text-filter.d.ts +7 -0
- package/data-table-text-filter.js +76 -0
- package/data-table-toolbar.d.ts +5 -0
- package/data-table-toolbar.js +95 -0
- package/data-table-views-options.d.ts +2 -0
- package/data-table-views-options.js +133 -0
- package/data-table.d.ts +18 -0
- package/data-table.js +56 -0
- package/filter-adapter-type.d.ts +9 -0
- package/filter-adapter-type.js +155 -0
- package/filter-adapters/index.d.ts +5 -0
- package/filter-adapters/index.js +7 -0
- package/filter-adapters/option.d.ts +3 -0
- package/filter-adapters/option.js +147 -0
- package/filter-adapters/use-option-filter.d.ts +27 -0
- package/filter-adapters/use-option-filter.js +192 -0
- package/filter-classes.d.ts +32 -0
- package/filter-classes.js +22 -0
- package/filter-fn.d.ts +7 -0
- package/filter-fn.js +76 -0
- package/index.d.ts +16 -0
- package/index.js +16 -0
- package/package.json +97 -0
- package/pagination-arrow.d.ts +5 -0
- package/pagination-arrow.js +86 -0
- package/pagination-classes.d.ts +20 -0
- package/pagination-classes.js +16 -0
- package/pagination-number.d.ts +5 -0
- package/pagination-number.js +59 -0
- package/pagination-size-options.d.ts +3 -0
- package/pagination-size-options.js +44 -0
- package/row-button-menu.d.ts +5 -0
- package/row-button-menu.js +45 -0
- package/row-popover-menu.d.ts +5 -0
- package/row-popover-menu.js +48 -0
- package/styles-filter.css +1 -0
- package/styles-filter.module.css +64 -0
- package/styles-filter.module.scss +65 -0
- package/styles-pagination.css +1 -0
- package/styles-pagination.module.css +28 -0
- package/styles-pagination.module.scss +31 -0
- package/styles-toolbar.css +1 -0
- package/styles-toolbar.module.css +70 -0
- package/styles-toolbar.module.scss +67 -0
- package/styles.css +1 -0
- package/styles.json +8 -0
- package/styles.module.css +39 -0
- package/styles.module.scss +38 -0
- package/toolbar-classes.d.ts +26 -0
- package/toolbar-classes.js +20 -0
- package/types.d.ts +226 -0
- package/types.js +2 -0
- package/use-data-table.d.ts +3 -0
- package/use-data-table.js +768 -0
- package/use-lexicon.d.ts +12 -0
- package/use-lexicon.js +151 -0
- package/use-row-menu.d.ts +7 -0
- package/use-row-menu.js +58 -0
- package/use-visibility-column.d.ts +7 -0
- package/use-visibility-column.js +101 -0
- package/use-visibility-filter.d.ts +7 -0
- package/use-visibility-filter.js +145 -0
- package/utils.d.ts +14 -0
- package/utils.js +128 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
6
|
+
exports.__esModule = true;
|
|
7
|
+
exports.useOptionFilter = void 0;
|
|
8
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _context = require("../context");
|
|
11
|
+
var _errorMessage = require("@tint-ui/tools/error-message");
|
|
12
|
+
var _makeOption = require("@tint-ui/tools/make-option");
|
|
13
|
+
const _excluded = ["options", "initialOptions"];
|
|
14
|
+
const getOptions = (result, dump) => {
|
|
15
|
+
const options = [];
|
|
16
|
+
if (result.length) {
|
|
17
|
+
result.forEach(option => {
|
|
18
|
+
const item = (0, _makeOption.makeOption)(option, dump);
|
|
19
|
+
if (item) {
|
|
20
|
+
options.push(item);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return options;
|
|
25
|
+
};
|
|
26
|
+
const useOptionFilter = function (filter) {
|
|
27
|
+
const {
|
|
28
|
+
name,
|
|
29
|
+
config: {
|
|
30
|
+
options: filterOptions,
|
|
31
|
+
initialOptions
|
|
32
|
+
} = {}
|
|
33
|
+
} = filter,
|
|
34
|
+
rest = (0, _objectWithoutPropertiesLoose2.default)(filter.config, _excluded);
|
|
35
|
+
const ctx = (0, _context.useDataTableContext)();
|
|
36
|
+
const column = ctx.table.getColumn(name);
|
|
37
|
+
const refFn = React.useRef(null);
|
|
38
|
+
refFn.current = typeof filterOptions === "function" ? filterOptions : null;
|
|
39
|
+
const refDump = React.useRef({});
|
|
40
|
+
const filterValue = column ? column.getFilterValue() : null;
|
|
41
|
+
const value = filterValue == null ? [] : Array.isArray(filterValue) ? filterValue : [filterValue];
|
|
42
|
+
const refValue = React.useRef(value);
|
|
43
|
+
refValue.current = value;
|
|
44
|
+
const [state, setState] = React.useState(() => ({
|
|
45
|
+
options: Array.isArray(filterOptions) ? getOptions(filterOptions, refDump.current) : Array.isArray(initialOptions) ? getOptions(initialOptions, refDump.current) : [],
|
|
46
|
+
inputText: "",
|
|
47
|
+
text: "",
|
|
48
|
+
loading: false,
|
|
49
|
+
error: null
|
|
50
|
+
}));
|
|
51
|
+
const refState = React.useRef(state);
|
|
52
|
+
refState.current = state;
|
|
53
|
+
const {
|
|
54
|
+
onMount,
|
|
55
|
+
inputProps,
|
|
56
|
+
getSelectedOptions
|
|
57
|
+
} = React.useMemo(() => {
|
|
58
|
+
let localState = state;
|
|
59
|
+
let lazyId = null;
|
|
60
|
+
let mount = false;
|
|
61
|
+
let abortController = null;
|
|
62
|
+
const update = newState => {
|
|
63
|
+
if (!mount) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
localState = Object.assign({}, localState, newState);
|
|
67
|
+
setState(localState);
|
|
68
|
+
};
|
|
69
|
+
const lazyClear = () => {
|
|
70
|
+
if (lazyId != null) {
|
|
71
|
+
window.clearTimeout(lazyId);
|
|
72
|
+
lazyId = null;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const abort = () => {
|
|
76
|
+
if (abortController != null) {
|
|
77
|
+
abortController.abort();
|
|
78
|
+
abortController = null;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const query = (force = false, mode = "search") => {
|
|
82
|
+
if (!mount) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const callback = refFn.current;
|
|
86
|
+
const text = localState.inputText.trim();
|
|
87
|
+
if (callback == null) {
|
|
88
|
+
return update({
|
|
89
|
+
loading: false,
|
|
90
|
+
error: null,
|
|
91
|
+
text
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (!force && localState.text === text) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
abort();
|
|
98
|
+
update({
|
|
99
|
+
loading: true,
|
|
100
|
+
error: null,
|
|
101
|
+
text
|
|
102
|
+
});
|
|
103
|
+
abortController = new AbortController();
|
|
104
|
+
const signal = abortController.signal;
|
|
105
|
+
(async (...args) => callback(...args))(localState.text, refValue.current, mode, abortController).then(result => {
|
|
106
|
+
const options = [];
|
|
107
|
+
const resultDump = {};
|
|
108
|
+
result.forEach(option => {
|
|
109
|
+
const item = (0, _makeOption.makeOption)(option, resultDump);
|
|
110
|
+
if (item) {
|
|
111
|
+
options.push(item);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
Object.assign(refDump.current, resultDump);
|
|
115
|
+
update({
|
|
116
|
+
options,
|
|
117
|
+
loading: false
|
|
118
|
+
});
|
|
119
|
+
}).catch(error => {
|
|
120
|
+
if (signal.aborted) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
update({
|
|
124
|
+
loading: false,
|
|
125
|
+
error: (0, _errorMessage.errorMessage)(error).message
|
|
126
|
+
});
|
|
127
|
+
}).finally(() => {
|
|
128
|
+
abortController = null;
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
const lazyLoad = () => {
|
|
132
|
+
if (refFn.current) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
lazyClear();
|
|
136
|
+
lazyId = window.setTimeout(() => {
|
|
137
|
+
lazyId = null;
|
|
138
|
+
query();
|
|
139
|
+
}, 250);
|
|
140
|
+
};
|
|
141
|
+
return {
|
|
142
|
+
onMount() {
|
|
143
|
+
mount = true;
|
|
144
|
+
if (refValue.current.length) {
|
|
145
|
+
query(true, "initial");
|
|
146
|
+
}
|
|
147
|
+
return () => {
|
|
148
|
+
mount = false;
|
|
149
|
+
lazyClear();
|
|
150
|
+
abort();
|
|
151
|
+
};
|
|
152
|
+
},
|
|
153
|
+
getSelectedOptions() {
|
|
154
|
+
const options = [];
|
|
155
|
+
refValue.current.forEach(name => {
|
|
156
|
+
const option = refDump.current[name];
|
|
157
|
+
if (option) {
|
|
158
|
+
options.push(option);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
return options;
|
|
162
|
+
},
|
|
163
|
+
inputProps: {
|
|
164
|
+
get value() {
|
|
165
|
+
return localState.inputText;
|
|
166
|
+
},
|
|
167
|
+
onValueChange(inputText) {
|
|
168
|
+
update({
|
|
169
|
+
inputText
|
|
170
|
+
});
|
|
171
|
+
lazyLoad();
|
|
172
|
+
},
|
|
173
|
+
onFocus() {
|
|
174
|
+
query(true);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}, []);
|
|
179
|
+
React.useEffect(onMount, [onMount]);
|
|
180
|
+
return Object.assign({}, rest, {
|
|
181
|
+
name,
|
|
182
|
+
column,
|
|
183
|
+
inputProps,
|
|
184
|
+
getSelectedOptions,
|
|
185
|
+
lexicon: ctx.lexicon,
|
|
186
|
+
size: ctx.toolbar.size,
|
|
187
|
+
manual: refFn.current != null,
|
|
188
|
+
value: refValue.current,
|
|
189
|
+
options: state.options,
|
|
190
|
+
inputText: state.inputText,
|
|
191
|
+
error: state.error,
|
|
192
|
+
loading: state.loading
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
exports.useOptionFilter = useOptionFilter;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.useDataTableFilterClasses = exports.filterClasses = void 0;
|
|
5
|
+
var _classGroup = require("@tint-ui/tools/class-group");
|
|
6
|
+
var _theme = require("@tint-ui/theme");
|
|
7
|
+
const {
|
|
8
|
+
base,
|
|
9
|
+
b
|
|
10
|
+
} = (0, _classGroup.classGroup)("data-table-filter");
|
|
11
|
+
const filterClasses = exports.filterClasses = {
|
|
12
|
+
button: base,
|
|
13
|
+
popover: b("popover"),
|
|
14
|
+
badges: b("badges"),
|
|
15
|
+
badge: b("badge"),
|
|
16
|
+
mobile: b("mobile"),
|
|
17
|
+
desktop: b("desktop"),
|
|
18
|
+
checkbox: b("checkbox"),
|
|
19
|
+
icon: b("icon"),
|
|
20
|
+
label: b("label"),
|
|
21
|
+
selected: b("selected"),
|
|
22
|
+
text: b("text"),
|
|
23
|
+
textMobile: b("text", "mobile")
|
|
24
|
+
};
|
|
25
|
+
const useDataTableFilterClasses = () => (0, _theme.useClasses)("data-table-filter", filterClasses);
|
|
26
|
+
exports.useDataTableFilterClasses = useDataTableFilterClasses;
|
package/cjs/filter-fn.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.filterStringMultiple = exports.filterString = exports.filterNumberMultiple = exports.filterNumber = exports.filterBoolean = void 0;
|
|
5
|
+
const isEmpty = (value, filterValue) => value == null || Array.isArray(filterValue) && filterValue.length === 0;
|
|
6
|
+
const filterBoolean = (row, columnId, filterValue) => {
|
|
7
|
+
const value = row.getValue(columnId);
|
|
8
|
+
if (Array.isArray(filterValue)) {
|
|
9
|
+
filterValue = filterValue[0];
|
|
10
|
+
}
|
|
11
|
+
if (value == null) {
|
|
12
|
+
return filterValue === "";
|
|
13
|
+
}
|
|
14
|
+
if (typeof filterValue === "boolean") {
|
|
15
|
+
return value === filterValue;
|
|
16
|
+
}
|
|
17
|
+
if (filterValue === "1") {
|
|
18
|
+
return value === true;
|
|
19
|
+
}
|
|
20
|
+
if (filterValue === "0") {
|
|
21
|
+
return value === false;
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
};
|
|
25
|
+
exports.filterBoolean = filterBoolean;
|
|
26
|
+
const isNumberValue = (value, filterValue) => {
|
|
27
|
+
return value === (typeof filterValue === "number" ? filterValue : parseInt(String(filterValue)));
|
|
28
|
+
};
|
|
29
|
+
const filterNumber = (row, columnId, filterValue) => {
|
|
30
|
+
const value = row.getValue(columnId);
|
|
31
|
+
if (isEmpty(value, filterValue)) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
if (typeof value !== "number") {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return isNumberValue(value, Array.isArray(filterValue) ? filterValue[0] : filterValue);
|
|
38
|
+
};
|
|
39
|
+
exports.filterNumber = filterNumber;
|
|
40
|
+
const filterNumberMultiple = (row, columnId, filterValue) => {
|
|
41
|
+
const value = row.getValue(columnId);
|
|
42
|
+
if (isEmpty(value, filterValue)) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (typeof value !== "number") {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (Array.isArray(filterValue)) {
|
|
49
|
+
for (const val of filterValue) {
|
|
50
|
+
if (isNumberValue(value, val)) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
} else if (isNumberValue(value, filterValue)) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
};
|
|
59
|
+
exports.filterNumberMultiple = filterNumberMultiple;
|
|
60
|
+
const filterString = (row, columnId, filterValue) => {
|
|
61
|
+
const value = row.getValue(columnId);
|
|
62
|
+
if (isEmpty(value, filterValue)) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
return value === String(Array.isArray(filterValue) ? filterValue[0] : filterValue);
|
|
66
|
+
};
|
|
67
|
+
exports.filterString = filterString;
|
|
68
|
+
const filterStringMultiple = (row, columnId, filterValue) => {
|
|
69
|
+
const value = row.getValue(columnId);
|
|
70
|
+
if (isEmpty(value, filterValue)) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
if (Array.isArray(filterValue)) {
|
|
74
|
+
for (const val of filterValue) {
|
|
75
|
+
if (value === String(val)) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
} else if (value === String(filterValue)) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
};
|
|
84
|
+
exports.filterStringMultiple = filterStringMultiple;
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
var _classes = require("./classes");
|
|
5
|
+
Object.keys(_classes).forEach(function (key) {
|
|
6
|
+
if (key === "default" || key === "__esModule") return;
|
|
7
|
+
if (key in exports && exports[key] === _classes[key]) return;
|
|
8
|
+
exports[key] = _classes[key];
|
|
9
|
+
});
|
|
10
|
+
var _filterClasses = require("./filter-classes");
|
|
11
|
+
Object.keys(_filterClasses).forEach(function (key) {
|
|
12
|
+
if (key === "default" || key === "__esModule") return;
|
|
13
|
+
if (key in exports && exports[key] === _filterClasses[key]) return;
|
|
14
|
+
exports[key] = _filterClasses[key];
|
|
15
|
+
});
|
|
16
|
+
var _toolbarClasses = require("./toolbar-classes");
|
|
17
|
+
Object.keys(_toolbarClasses).forEach(function (key) {
|
|
18
|
+
if (key === "default" || key === "__esModule") return;
|
|
19
|
+
if (key in exports && exports[key] === _toolbarClasses[key]) return;
|
|
20
|
+
exports[key] = _toolbarClasses[key];
|
|
21
|
+
});
|
|
22
|
+
var _paginationClasses = require("./pagination-classes");
|
|
23
|
+
Object.keys(_paginationClasses).forEach(function (key) {
|
|
24
|
+
if (key === "default" || key === "__esModule") return;
|
|
25
|
+
if (key in exports && exports[key] === _paginationClasses[key]) return;
|
|
26
|
+
exports[key] = _paginationClasses[key];
|
|
27
|
+
});
|
|
28
|
+
var _context = require("./context");
|
|
29
|
+
Object.keys(_context).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _context[key]) return;
|
|
32
|
+
exports[key] = _context[key];
|
|
33
|
+
});
|
|
34
|
+
var _cellAdapterType = require("./cell-adapter-type");
|
|
35
|
+
Object.keys(_cellAdapterType).forEach(function (key) {
|
|
36
|
+
if (key === "default" || key === "__esModule") return;
|
|
37
|
+
if (key in exports && exports[key] === _cellAdapterType[key]) return;
|
|
38
|
+
exports[key] = _cellAdapterType[key];
|
|
39
|
+
});
|
|
40
|
+
var _filterAdapterType = require("./filter-adapter-type");
|
|
41
|
+
Object.keys(_filterAdapterType).forEach(function (key) {
|
|
42
|
+
if (key === "default" || key === "__esModule") return;
|
|
43
|
+
if (key in exports && exports[key] === _filterAdapterType[key]) return;
|
|
44
|
+
exports[key] = _filterAdapterType[key];
|
|
45
|
+
});
|
|
46
|
+
var _dataTableContent = require("./data-table-content");
|
|
47
|
+
Object.keys(_dataTableContent).forEach(function (key) {
|
|
48
|
+
if (key === "default" || key === "__esModule") return;
|
|
49
|
+
if (key in exports && exports[key] === _dataTableContent[key]) return;
|
|
50
|
+
exports[key] = _dataTableContent[key];
|
|
51
|
+
});
|
|
52
|
+
var _dataTablePagination = require("./data-table-pagination");
|
|
53
|
+
Object.keys(_dataTablePagination).forEach(function (key) {
|
|
54
|
+
if (key === "default" || key === "__esModule") return;
|
|
55
|
+
if (key in exports && exports[key] === _dataTablePagination[key]) return;
|
|
56
|
+
exports[key] = _dataTablePagination[key];
|
|
57
|
+
});
|
|
58
|
+
var _dataTableToolbar = require("./data-table-toolbar");
|
|
59
|
+
Object.keys(_dataTableToolbar).forEach(function (key) {
|
|
60
|
+
if (key === "default" || key === "__esModule") return;
|
|
61
|
+
if (key in exports && exports[key] === _dataTableToolbar[key]) return;
|
|
62
|
+
exports[key] = _dataTableToolbar[key];
|
|
63
|
+
});
|
|
64
|
+
var _dataTableViewsOptions = require("./data-table-views-options");
|
|
65
|
+
Object.keys(_dataTableViewsOptions).forEach(function (key) {
|
|
66
|
+
if (key === "default" || key === "__esModule") return;
|
|
67
|
+
if (key in exports && exports[key] === _dataTableViewsOptions[key]) return;
|
|
68
|
+
exports[key] = _dataTableViewsOptions[key];
|
|
69
|
+
});
|
|
70
|
+
var _dataTable = require("./data-table");
|
|
71
|
+
Object.keys(_dataTable).forEach(function (key) {
|
|
72
|
+
if (key === "default" || key === "__esModule") return;
|
|
73
|
+
if (key in exports && exports[key] === _dataTable[key]) return;
|
|
74
|
+
exports[key] = _dataTable[key];
|
|
75
|
+
});
|
|
76
|
+
var _paginationArrow = require("./pagination-arrow");
|
|
77
|
+
Object.keys(_paginationArrow).forEach(function (key) {
|
|
78
|
+
if (key === "default" || key === "__esModule") return;
|
|
79
|
+
if (key in exports && exports[key] === _paginationArrow[key]) return;
|
|
80
|
+
exports[key] = _paginationArrow[key];
|
|
81
|
+
});
|
|
82
|
+
var _paginationNumber = require("./pagination-number");
|
|
83
|
+
Object.keys(_paginationNumber).forEach(function (key) {
|
|
84
|
+
if (key === "default" || key === "__esModule") return;
|
|
85
|
+
if (key in exports && exports[key] === _paginationNumber[key]) return;
|
|
86
|
+
exports[key] = _paginationNumber[key];
|
|
87
|
+
});
|
|
88
|
+
var _paginationSizeOptions = require("./pagination-size-options");
|
|
89
|
+
Object.keys(_paginationSizeOptions).forEach(function (key) {
|
|
90
|
+
if (key === "default" || key === "__esModule") return;
|
|
91
|
+
if (key in exports && exports[key] === _paginationSizeOptions[key]) return;
|
|
92
|
+
exports[key] = _paginationSizeOptions[key];
|
|
93
|
+
});
|
|
94
|
+
var _types = require("./types");
|
|
95
|
+
Object.keys(_types).forEach(function (key) {
|
|
96
|
+
if (key === "default" || key === "__esModule") return;
|
|
97
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
98
|
+
exports[key] = _types[key];
|
|
99
|
+
});
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
6
|
+
exports.__esModule = true;
|
|
7
|
+
exports.PaginationArrow = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
10
|
+
var React = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _clsx = _interopRequireDefault(require("clsx"));
|
|
12
|
+
var _button = require("@tint-ui/button");
|
|
13
|
+
var _svgIcon = require("@tint-ui/svg-icon");
|
|
14
|
+
var _context = require("./context");
|
|
15
|
+
var _paginationClasses = require("./pagination-classes");
|
|
16
|
+
const _excluded = ["className"];
|
|
17
|
+
const PaginationArrow = exports.PaginationArrow = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
18
|
+
let {
|
|
19
|
+
className
|
|
20
|
+
} = _ref,
|
|
21
|
+
props = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
|
|
22
|
+
const classes = (0, _paginationClasses.useDataTablePaginationClasses)();
|
|
23
|
+
const {
|
|
24
|
+
loading,
|
|
25
|
+
table,
|
|
26
|
+
lexicon,
|
|
27
|
+
navbar: {
|
|
28
|
+
size
|
|
29
|
+
}
|
|
30
|
+
} = (0, _context.useDataTableContext)();
|
|
31
|
+
const pageCount = table.getPageCount();
|
|
32
|
+
return /*#__PURE__*/React.createElement("div", (0, _extends2.default)({}, props, {
|
|
33
|
+
className: (0, _clsx.default)(classes.group, className),
|
|
34
|
+
ref: ref
|
|
35
|
+
}), pageCount > 1 && /*#__PURE__*/React.createElement("span", null, lexicon.pageOf), /*#__PURE__*/React.createElement(_button.Button, {
|
|
36
|
+
"aria-label": lexicon.pageFirst,
|
|
37
|
+
variant: "outline",
|
|
38
|
+
size: size,
|
|
39
|
+
className: classes.firstLast,
|
|
40
|
+
onClick: () => {
|
|
41
|
+
table.setPageIndex(0);
|
|
42
|
+
},
|
|
43
|
+
disabled: loading || !table.getCanPreviousPage(),
|
|
44
|
+
iconOnly: true,
|
|
45
|
+
iconLeft: /*#__PURE__*/React.createElement(_svgIcon.SvgThemeIcon, {
|
|
46
|
+
icon: "pagination-first",
|
|
47
|
+
"aria-hidden": "true"
|
|
48
|
+
})
|
|
49
|
+
}), /*#__PURE__*/React.createElement(_button.Button, {
|
|
50
|
+
"aria-label": lexicon.pagePrevious,
|
|
51
|
+
variant: "outline",
|
|
52
|
+
size: size,
|
|
53
|
+
className: classes.previousNext,
|
|
54
|
+
onClick: () => {
|
|
55
|
+
table.previousPage();
|
|
56
|
+
},
|
|
57
|
+
disabled: loading || !table.getCanPreviousPage(),
|
|
58
|
+
iconOnly: true,
|
|
59
|
+
iconLeft: /*#__PURE__*/React.createElement(_svgIcon.SvgThemeIcon, {
|
|
60
|
+
icon: "pagination-previous",
|
|
61
|
+
"aria-hidden": "true"
|
|
62
|
+
})
|
|
63
|
+
}), /*#__PURE__*/React.createElement(_button.Button, {
|
|
64
|
+
"aria-label": lexicon.pageNext,
|
|
65
|
+
variant: "outline",
|
|
66
|
+
size: size,
|
|
67
|
+
className: classes.previousNext,
|
|
68
|
+
onClick: () => {
|
|
69
|
+
table.nextPage();
|
|
70
|
+
},
|
|
71
|
+
disabled: loading || !table.getCanNextPage(),
|
|
72
|
+
iconOnly: true,
|
|
73
|
+
iconRight: /*#__PURE__*/React.createElement(_svgIcon.SvgThemeIcon, {
|
|
74
|
+
icon: "pagination-next",
|
|
75
|
+
"aria-hidden": "true"
|
|
76
|
+
})
|
|
77
|
+
}), /*#__PURE__*/React.createElement(_button.Button, {
|
|
78
|
+
"aria-label": lexicon.pageLast,
|
|
79
|
+
variant: "outline",
|
|
80
|
+
size: size,
|
|
81
|
+
className: classes.firstLast,
|
|
82
|
+
onClick: () => {
|
|
83
|
+
table.setPageIndex(table.getPageCount() - 1);
|
|
84
|
+
},
|
|
85
|
+
disabled: loading || !table.getCanNextPage(),
|
|
86
|
+
iconOnly: true,
|
|
87
|
+
iconRight: /*#__PURE__*/React.createElement(_svgIcon.SvgThemeIcon, {
|
|
88
|
+
icon: "pagination-last",
|
|
89
|
+
"aria-hidden": "true"
|
|
90
|
+
})
|
|
91
|
+
}));
|
|
92
|
+
});
|
|
93
|
+
PaginationArrow.displayName = "PaginationArrow";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.useDataTablePaginationClasses = exports.paginationClasses = void 0;
|
|
5
|
+
var _classGroup = require("@tint-ui/tools/class-group");
|
|
6
|
+
var _theme = require("@tint-ui/theme");
|
|
7
|
+
const {
|
|
8
|
+
base,
|
|
9
|
+
b
|
|
10
|
+
} = (0, _classGroup.classGroup)("data-table-pagination");
|
|
11
|
+
const paginationClasses = exports.paginationClasses = {
|
|
12
|
+
pagination: base,
|
|
13
|
+
divider: b("divider"),
|
|
14
|
+
group: b("group"),
|
|
15
|
+
separator: b("separator"),
|
|
16
|
+
firstLast: b("first-last"),
|
|
17
|
+
previousNext: b("previous-next")
|
|
18
|
+
};
|
|
19
|
+
const useDataTablePaginationClasses = () => (0, _theme.useClasses)("data-table-pagination", paginationClasses);
|
|
20
|
+
exports.useDataTablePaginationClasses = useDataTablePaginationClasses;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
6
|
+
exports.__esModule = true;
|
|
7
|
+
exports.PaginationNumber = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
10
|
+
var React = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _clsx = _interopRequireDefault(require("clsx"));
|
|
12
|
+
var _button = require("@tint-ui/button");
|
|
13
|
+
var _svgIcon = require("@tint-ui/svg-icon");
|
|
14
|
+
var _context = require("./context");
|
|
15
|
+
var _paginationClasses = require("./pagination-classes");
|
|
16
|
+
var _utils = require("./utils");
|
|
17
|
+
const _excluded = ["className"];
|
|
18
|
+
const PaginationNumber = exports.PaginationNumber = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
19
|
+
let {
|
|
20
|
+
className
|
|
21
|
+
} = _ref,
|
|
22
|
+
props = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
|
|
23
|
+
const classes = (0, _paginationClasses.useDataTablePaginationClasses)();
|
|
24
|
+
const {
|
|
25
|
+
loading,
|
|
26
|
+
loadingTarget,
|
|
27
|
+
table,
|
|
28
|
+
lexicon,
|
|
29
|
+
navbar: {
|
|
30
|
+
size,
|
|
31
|
+
numberSize
|
|
32
|
+
}
|
|
33
|
+
} = (0, _context.useDataTableContext)();
|
|
34
|
+
const pageNumber = table.getState().pagination.pageIndex + 1;
|
|
35
|
+
const pageCount = table.getPageCount();
|
|
36
|
+
const pages = React.useMemo(() => (0, _utils.getPaginationNumber)(pageNumber, pageCount, numberSize), [pageNumber, pageCount, numberSize]);
|
|
37
|
+
return /*#__PURE__*/React.createElement("div", (0, _extends2.default)({}, props, {
|
|
38
|
+
className: (0, _clsx.default)(classes.group, className),
|
|
39
|
+
ref: ref
|
|
40
|
+
}), pages.map((item, index) => {
|
|
41
|
+
if (item.divider) {
|
|
42
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
43
|
+
className: classes.separator,
|
|
44
|
+
key: index
|
|
45
|
+
}, /*#__PURE__*/React.createElement(_svgIcon.SvgThemeIcon, {
|
|
46
|
+
icon: "dots"
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
const {
|
|
50
|
+
page
|
|
51
|
+
} = item;
|
|
52
|
+
return /*#__PURE__*/React.createElement(_button.Button, {
|
|
53
|
+
key: index,
|
|
54
|
+
"aria-label": item.page === 1 ? lexicon.pageFirst : page === pageCount ? lexicon.pageLast : String(page),
|
|
55
|
+
variant: item.selected ? "primary" : "outline",
|
|
56
|
+
size: size,
|
|
57
|
+
onClick: () => {
|
|
58
|
+
table.setPageIndex(page - 1);
|
|
59
|
+
},
|
|
60
|
+
disabled: loading || item.selected,
|
|
61
|
+
loading: loading && loadingTarget === `pagination:${page}`,
|
|
62
|
+
iconOnly: true
|
|
63
|
+
}, page);
|
|
64
|
+
}));
|
|
65
|
+
});
|
|
66
|
+
PaginationNumber.displayName = "PaginationNumber";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.PaginationSizeOptions = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _button = require("@tint-ui/button");
|
|
9
|
+
var _dropdownMenu = require("@tint-ui/dropdown-menu");
|
|
10
|
+
var _context = require("./context");
|
|
11
|
+
var _svgIcon = require("@tint-ui/svg-icon");
|
|
12
|
+
const PaginationSizeOptions = () => {
|
|
13
|
+
const {
|
|
14
|
+
loading,
|
|
15
|
+
loadingTarget,
|
|
16
|
+
navbar: {
|
|
17
|
+
pageSize,
|
|
18
|
+
pageSizeOptions,
|
|
19
|
+
size,
|
|
20
|
+
onPageSizeChange
|
|
21
|
+
}
|
|
22
|
+
} = (0, _context.useDataTableContext)();
|
|
23
|
+
if (pageSizeOptions.length < 2) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return /*#__PURE__*/React.createElement(_dropdownMenu.DropdownMenu, null, /*#__PURE__*/React.createElement(_dropdownMenu.DropdownMenuTrigger, {
|
|
27
|
+
asChild: true
|
|
28
|
+
}, /*#__PURE__*/React.createElement(_button.Button, {
|
|
29
|
+
variant: "outline",
|
|
30
|
+
disabled: loading,
|
|
31
|
+
loading: loading && loadingTarget === "page-size",
|
|
32
|
+
size: size,
|
|
33
|
+
iconRight: /*#__PURE__*/React.createElement(_svgIcon.SvgThemeIcon, {
|
|
34
|
+
icon: "selector"
|
|
35
|
+
})
|
|
36
|
+
}, pageSize)), /*#__PURE__*/React.createElement(_dropdownMenu.DropdownMenuPortal, null, /*#__PURE__*/React.createElement(_dropdownMenu.DropdownMenuContent, {
|
|
37
|
+
align: "end"
|
|
38
|
+
}, /*#__PURE__*/React.createElement(_dropdownMenu.DropdownMenuRadioGroup, {
|
|
39
|
+
value: String(pageSize),
|
|
40
|
+
onValueChange: value => {
|
|
41
|
+
onPageSizeChange(parseInt(value));
|
|
42
|
+
}
|
|
43
|
+
}, pageSizeOptions.map(option => /*#__PURE__*/React.createElement(_dropdownMenu.DropdownMenuRadioItem, {
|
|
44
|
+
key: option,
|
|
45
|
+
value: String(option)
|
|
46
|
+
}, option))))));
|
|
47
|
+
};
|
|
48
|
+
exports.PaginationSizeOptions = PaginationSizeOptions;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.rowButtonMenu = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _button = require("@tint-ui/button");
|
|
9
|
+
var _tooltip = require("@tint-ui/tooltip");
|
|
10
|
+
var _svgIcon = require("@tint-ui/svg-icon");
|
|
11
|
+
var _useRowMenu = require("./use-row-menu");
|
|
12
|
+
var _classes = require("./classes");
|
|
13
|
+
var _context = require("./context");
|
|
14
|
+
const rowButtonMenu = (info, menu) => {
|
|
15
|
+
const classes = (0, _classes.useDataTableClasses)();
|
|
16
|
+
const {
|
|
17
|
+
loading
|
|
18
|
+
} = (0, _context.useDataTableContext)();
|
|
19
|
+
const rowHandler = (0, _useRowMenu.useRowMenu)(info);
|
|
20
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
21
|
+
className: classes.menuGroup
|
|
22
|
+
}, menu.map(item => {
|
|
23
|
+
const {
|
|
24
|
+
icon,
|
|
25
|
+
label,
|
|
26
|
+
id,
|
|
27
|
+
destructive
|
|
28
|
+
} = item;
|
|
29
|
+
const {
|
|
30
|
+
disabled,
|
|
31
|
+
onClick
|
|
32
|
+
} = rowHandler(item);
|
|
33
|
+
return /*#__PURE__*/React.createElement(_tooltip.TooltipText, {
|
|
34
|
+
key: id,
|
|
35
|
+
tooltip: label,
|
|
36
|
+
asChild: true
|
|
37
|
+
}, /*#__PURE__*/React.createElement(_button.Button, {
|
|
38
|
+
disabled: disabled || loading,
|
|
39
|
+
onClick: onClick,
|
|
40
|
+
iconOnly: true,
|
|
41
|
+
size: "xs",
|
|
42
|
+
variant: destructive ? "destructive" : "outline",
|
|
43
|
+
iconLeft: /*#__PURE__*/React.createElement(_svgIcon.SvgThemeIcon, {
|
|
44
|
+
icon: icon || "data-table-row-menu"
|
|
45
|
+
})
|
|
46
|
+
}));
|
|
47
|
+
}));
|
|
48
|
+
};
|
|
49
|
+
exports.rowButtonMenu = rowButtonMenu;
|