@tint-ui/data-table 0.3.12 → 0.3.13
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/cjs/filter-adapters/option.js +9 -3
- package/cjs/filter-adapters/use-option-filter.js +6 -2
- package/filter-adapters/option.js +9 -3
- package/filter-adapters/use-option-filter.d.ts +2 -0
- package/filter-adapters/use-option-filter.js +4 -0
- package/package.json +1 -1
- package/styles-filter.css +1 -1
- package/styles-filter.module.css +6 -0
- package/styles-filter.module.scss +6 -0
- package/types.d.ts +1 -0
|
@@ -65,7 +65,9 @@ const FilterOptionType = ({
|
|
|
65
65
|
lexicon,
|
|
66
66
|
icon,
|
|
67
67
|
groupBy = null,
|
|
68
|
-
disableSearch = false
|
|
68
|
+
disableSearch = false,
|
|
69
|
+
multiple,
|
|
70
|
+
toggleMode
|
|
69
71
|
} = ctx;
|
|
70
72
|
const selectedOptions = getSelectedOptions();
|
|
71
73
|
const optionGroups = React.useMemo(() => groupBy ? createOptionGroups(options, groupBy) : [{
|
|
@@ -111,12 +113,16 @@ const FilterOptionType = ({
|
|
|
111
113
|
} = option.config || {};
|
|
112
114
|
return /*#__PURE__*/React.createElement(_command.CommandItem, {
|
|
113
115
|
key: option.value,
|
|
116
|
+
"data-multiple": multiple,
|
|
114
117
|
onSelect: () => {
|
|
115
118
|
const selectedValues = new Set(value);
|
|
116
119
|
if (isSelected) {
|
|
120
|
+
if (!toggleMode) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
117
123
|
selectedValues.delete(optionValue);
|
|
118
124
|
} else {
|
|
119
|
-
if (!
|
|
125
|
+
if (!multiple) {
|
|
120
126
|
selectedValues.clear();
|
|
121
127
|
}
|
|
122
128
|
selectedValues.add(optionValue);
|
|
@@ -126,7 +132,7 @@ const FilterOptionType = ({
|
|
|
126
132
|
}, /*#__PURE__*/React.createElement("div", {
|
|
127
133
|
className: (0, _clsx.default)(classes.checkbox, isSelected && classes.selected)
|
|
128
134
|
}, /*#__PURE__*/React.createElement(_svgIcon.SvgThemeIcon, {
|
|
129
|
-
icon: "
|
|
135
|
+
icon: multiple ? "filter-option-checkbox" : "filter-option-radio",
|
|
130
136
|
"aria-hidden": "true"
|
|
131
137
|
})), !(0, _isEmpty.isEmptyString)(icon) && /*#__PURE__*/React.createElement(_svgIcon.SvgThemeIcon, {
|
|
132
138
|
icon: icon,
|
|
@@ -10,7 +10,7 @@ var React = _interopRequireWildcard(require("react"));
|
|
|
10
10
|
var _context = require("../context");
|
|
11
11
|
var _errorMessage = require("@tint-ui/tools/error-message");
|
|
12
12
|
var _makeOption = require("@tint-ui/tools/make-option");
|
|
13
|
-
const _excluded = ["options", "initialOptions"];
|
|
13
|
+
const _excluded = ["options", "initialOptions", "toggleMode"];
|
|
14
14
|
const getOptions = (result, dump) => {
|
|
15
15
|
const options = [];
|
|
16
16
|
if (result.length) {
|
|
@@ -26,9 +26,11 @@ const getOptions = (result, dump) => {
|
|
|
26
26
|
const useOptionFilter = function (filter) {
|
|
27
27
|
const {
|
|
28
28
|
name,
|
|
29
|
+
multiple = false,
|
|
29
30
|
config: {
|
|
30
31
|
options: filterOptions,
|
|
31
|
-
initialOptions
|
|
32
|
+
initialOptions,
|
|
33
|
+
toggleMode = multiple
|
|
32
34
|
} = {}
|
|
33
35
|
} = filter,
|
|
34
36
|
rest = (0, _objectWithoutPropertiesLoose2.default)(filter.config, _excluded);
|
|
@@ -181,6 +183,8 @@ const useOptionFilter = function (filter) {
|
|
|
181
183
|
name,
|
|
182
184
|
column,
|
|
183
185
|
inputProps,
|
|
186
|
+
multiple,
|
|
187
|
+
toggleMode,
|
|
184
188
|
getSelectedOptions,
|
|
185
189
|
lexicon: ctx.lexicon,
|
|
186
190
|
size: ctx.toolbar.size,
|
|
@@ -60,7 +60,9 @@ const FilterOptionType = ({
|
|
|
60
60
|
lexicon,
|
|
61
61
|
icon,
|
|
62
62
|
groupBy = null,
|
|
63
|
-
disableSearch = false
|
|
63
|
+
disableSearch = false,
|
|
64
|
+
multiple,
|
|
65
|
+
toggleMode
|
|
64
66
|
} = ctx;
|
|
65
67
|
const selectedOptions = getSelectedOptions();
|
|
66
68
|
const optionGroups = React.useMemo(() => groupBy ? createOptionGroups(options, groupBy) : [{
|
|
@@ -106,12 +108,16 @@ const FilterOptionType = ({
|
|
|
106
108
|
} = option.config || {};
|
|
107
109
|
return /*#__PURE__*/React.createElement(CommandItem, {
|
|
108
110
|
key: option.value,
|
|
111
|
+
"data-multiple": multiple,
|
|
109
112
|
onSelect: () => {
|
|
110
113
|
const selectedValues = new Set(value);
|
|
111
114
|
if (isSelected) {
|
|
115
|
+
if (!toggleMode) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
112
118
|
selectedValues.delete(optionValue);
|
|
113
119
|
} else {
|
|
114
|
-
if (!
|
|
120
|
+
if (!multiple) {
|
|
115
121
|
selectedValues.clear();
|
|
116
122
|
}
|
|
117
123
|
selectedValues.add(optionValue);
|
|
@@ -121,7 +127,7 @@ const FilterOptionType = ({
|
|
|
121
127
|
}, /*#__PURE__*/React.createElement("div", {
|
|
122
128
|
className: clsx(classes.checkbox, isSelected && classes.selected)
|
|
123
129
|
}, /*#__PURE__*/React.createElement(SvgThemeIcon, {
|
|
124
|
-
icon: "
|
|
130
|
+
icon: multiple ? "filter-option-checkbox" : "filter-option-radio",
|
|
125
131
|
"aria-hidden": "true"
|
|
126
132
|
})), !isEmptyString(icon) && /*#__PURE__*/React.createElement(SvgThemeIcon, {
|
|
127
133
|
icon: icon,
|
|
@@ -9,6 +9,8 @@ declare const useOptionFilter: <TData>(filter: DataTableDisplayFilter<keyof TDat
|
|
|
9
9
|
onValueChange(inputText: string): void;
|
|
10
10
|
onFocus(): void;
|
|
11
11
|
};
|
|
12
|
+
multiple: boolean;
|
|
13
|
+
toggleMode: boolean;
|
|
12
14
|
getSelectedOptions: () => InputSelectOption<object>[];
|
|
13
15
|
lexicon: import("../types").LexiconType;
|
|
14
16
|
size: import("../types").DataTableToolbarSize;
|
|
@@ -19,9 +19,11 @@ const getOptions = (result, dump) => {
|
|
|
19
19
|
const useOptionFilter = function (filter) {
|
|
20
20
|
const {
|
|
21
21
|
name,
|
|
22
|
+
multiple = false,
|
|
22
23
|
config: {
|
|
23
24
|
options: filterOptions,
|
|
24
25
|
initialOptions,
|
|
26
|
+
toggleMode = multiple,
|
|
25
27
|
...rest
|
|
26
28
|
} = {}
|
|
27
29
|
} = filter;
|
|
@@ -178,6 +180,8 @@ const useOptionFilter = function (filter) {
|
|
|
178
180
|
name,
|
|
179
181
|
column,
|
|
180
182
|
inputProps,
|
|
183
|
+
multiple,
|
|
184
|
+
toggleMode,
|
|
181
185
|
getSelectedOptions,
|
|
182
186
|
lexicon: ctx.lexicon,
|
|
183
187
|
size: ctx.toolbar.size,
|
package/package.json
CHANGED
package/styles-filter.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.tui-data-table-filter_badges{align-items:center;gap:.5rem}.tui-data-table-filter_badges [data-size=sm]{gap:.25rem}.tui-data-table-filter_badge{border-radius:calc(var(--radius) - 4px);display:inline-block;font-weight:400;max-width:120px;overflow:hidden;padding-left:.25rem;padding-right:.25rem;text-overflow:ellipsis;white-space:nowrap}.tui-data-table-filter_popover{max-width:200px;padding:0}.tui-data-table-filter{border-style:dashed}.tui-data-table-filter>.tui-data-table-filter_badge,.tui-data-table-filter>.tui-data-table-filter_badges{margin-left:.25rem;margin-right:-.5rem}.tui-data-table-filter:hover .tui-data-table-filter_badge{background-color:hsl(var(--background))}.tui-data-table-filter_mobile{display:inline-flex}@media (min-width:1024px){.tui-data-table-filter_mobile{display:none}}.tui-data-table-filter_mobile.tui-data-table-filter_badge{display:flow-root}@media (min-width:1024px){.tui-data-table-filter_mobile.tui-data-table-filter_badge{display:none}}.tui-data-table-filter_desktop{display:none}@media (min-width:1024px){.tui-data-table-filter_desktop{display:inline-flex}}.tui-data-table-filter_checkbox{align-items:center;border:1px dashed #64748b80;border-radius:calc(var(--radius) - 4px);display:inline-flex;height:1rem;justify-content:center;opacity:.5;width:1rem}.tui-data-table-filter_checkbox svg{height:1rem;visibility:hidden;width:1rem}.tui-data-table-filter_checkbox.tui-data-table-filter_selected{border-color:#0000;opacity:1}.tui-data-table-filter_checkbox.tui-data-table-filter_selected svg{visibility:visible}.tui-data-table-filter_text{width:180px}@media (min-width:1024px){.tui-data-table-filter_text{width:220px}}.tui-data-table-filter_text.tui-data-table-filter_text--mobile{width:100%}.tui-data-table-filter_icon{color:hsl(var(--muted-foreground));height:1rem;margin-right:.5rem;width:1rem}.tui-data-table-filter_label{margin-right:auto}
|
|
1
|
+
.tui-data-table-filter_badges{align-items:center;gap:.5rem}.tui-data-table-filter_badges [data-size=sm]{gap:.25rem}.tui-data-table-filter_badge{border-radius:calc(var(--radius) - 4px);display:inline-block;font-weight:400;max-width:120px;overflow:hidden;padding-left:.25rem;padding-right:.25rem;text-overflow:ellipsis;white-space:nowrap}.tui-data-table-filter_popover{max-width:200px;padding:0}.tui-data-table-filter{border-style:dashed}.tui-data-table-filter>.tui-data-table-filter_badge,.tui-data-table-filter>.tui-data-table-filter_badges{margin-left:.25rem;margin-right:-.5rem}.tui-data-table-filter:hover .tui-data-table-filter_badge{background-color:hsl(var(--background))}.tui-data-table-filter_mobile{display:inline-flex}@media (min-width:1024px){.tui-data-table-filter_mobile{display:none}}.tui-data-table-filter_mobile.tui-data-table-filter_badge{display:flow-root}@media (min-width:1024px){.tui-data-table-filter_mobile.tui-data-table-filter_badge{display:none}}.tui-data-table-filter_desktop{display:none}@media (min-width:1024px){.tui-data-table-filter_desktop{display:inline-flex}}.tui-data-table-filter_checkbox{align-items:center;border:1px dashed #64748b80;border-radius:calc(var(--radius) - 4px);display:inline-flex;height:1rem;justify-content:center;opacity:.5;width:1rem}.tui-data-table-filter_checkbox svg{height:1rem;visibility:hidden;width:1rem}.tui-data-table-filter_checkbox.tui-data-table-filter_selected{border-color:#0000;opacity:1}.tui-data-table-filter_checkbox.tui-data-table-filter_selected svg{visibility:visible}[data-multiple=false]>.tui-data-table-filter_checkbox{border-radius:9999px}[data-multiple=false]>.tui-data-table-filter_checkbox.tui-data-table-filter_selected{background-color:hsl(var(--foreground));color:hsl(var(--background))}.tui-data-table-filter_text{width:180px}@media (min-width:1024px){.tui-data-table-filter_text{width:220px}}.tui-data-table-filter_text.tui-data-table-filter_text--mobile{width:100%}.tui-data-table-filter_icon{color:hsl(var(--muted-foreground));height:1rem;margin-right:.5rem;width:1rem}.tui-data-table-filter_label{margin-right:auto}
|
package/styles-filter.module.css
CHANGED
|
@@ -47,6 +47,12 @@
|
|
|
47
47
|
.checkbox.selected svg {
|
|
48
48
|
@apply visible;
|
|
49
49
|
}
|
|
50
|
+
[data-multiple=false] > .checkbox {
|
|
51
|
+
@apply rounded-full;
|
|
52
|
+
}
|
|
53
|
+
[data-multiple=false] > .checkbox.selected {
|
|
54
|
+
@apply bg-foreground text-background;
|
|
55
|
+
}
|
|
50
56
|
|
|
51
57
|
.text {
|
|
52
58
|
@apply w-[180px] lg:w-[220px];
|
package/types.d.ts
CHANGED
|
@@ -146,6 +146,7 @@ export interface DataTableFilterOptionConfig {
|
|
|
146
146
|
disableSearch?: boolean;
|
|
147
147
|
autoSelect?: boolean;
|
|
148
148
|
groupBy?: string;
|
|
149
|
+
toggleMode?: boolean;
|
|
149
150
|
}
|
|
150
151
|
export type DataTableDisplayCell<TValue = string, TConfig extends object = any> = Required<Omit<DataTableCellType<TValue, TConfig>, "filter">> & {
|
|
151
152
|
filter: boolean;
|