@snack-uikit/toolbar 0.10.2-preview-08c7f775.0 → 0.10.3
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/CHANGELOG.md +19 -0
- package/README.md +0 -1
- package/dist/cjs/components/Toolbar/Toolbar.d.ts +3 -6
- package/dist/cjs/components/Toolbar/Toolbar.js +33 -46
- package/dist/cjs/components/Toolbar/helpers.d.ts +1 -2
- package/dist/cjs/components/Toolbar/styles.module.css +0 -10
- package/dist/cjs/components/Toolbar/types.d.ts +0 -5
- package/dist/cjs/constants.d.ts +0 -2
- package/dist/cjs/constants.js +0 -2
- package/dist/cjs/helperComponents/index.d.ts +0 -1
- package/dist/cjs/helperComponents/index.js +0 -1
- package/dist/esm/components/Toolbar/Toolbar.d.ts +3 -6
- package/dist/esm/components/Toolbar/Toolbar.js +3 -6
- package/dist/esm/components/Toolbar/helpers.d.ts +1 -2
- package/dist/esm/components/Toolbar/styles.module.css +0 -10
- package/dist/esm/components/Toolbar/types.d.ts +0 -5
- package/dist/esm/constants.d.ts +0 -2
- package/dist/esm/constants.js +0 -2
- package/dist/esm/helperComponents/index.d.ts +0 -1
- package/dist/esm/helperComponents/index.js +0 -1
- package/package.json +6 -11
- package/src/components/Toolbar/Toolbar.tsx +50 -62
- package/src/components/Toolbar/helpers.ts +1 -5
- package/src/components/Toolbar/styles.module.scss +0 -11
- package/src/components/Toolbar/types.ts +0 -7
- package/src/constants.ts +0 -2
- package/src/helperComponents/index.ts +0 -1
- package/dist/cjs/components/Toolbar/hooks.d.ts +0 -12
- package/dist/cjs/components/Toolbar/hooks.js +0 -65
- package/dist/cjs/helperComponents/FilterButton/FilterButton.d.ts +0 -6
- package/dist/cjs/helperComponents/FilterButton/FilterButton.js +0 -35
- package/dist/cjs/helperComponents/FilterButton/index.d.ts +0 -1
- package/dist/cjs/helperComponents/FilterButton/index.js +0 -25
- package/dist/esm/components/Toolbar/hooks.d.ts +0 -12
- package/dist/esm/components/Toolbar/hooks.js +0 -38
- package/dist/esm/helperComponents/FilterButton/FilterButton.d.ts +0 -6
- package/dist/esm/helperComponents/FilterButton/FilterButton.js +0 -10
- package/dist/esm/helperComponents/FilterButton/index.d.ts +0 -1
- package/dist/esm/helperComponents/FilterButton/index.js +0 -1
- package/src/components/Toolbar/hooks.ts +0 -82
- package/src/helperComponents/FilterButton/FilterButton.tsx +0 -28
- package/src/helperComponents/FilterButton/index.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 0.10.3 (2025-02-04)
|
|
7
|
+
|
|
8
|
+
### Only dependencies have been changed
|
|
9
|
+
* [@snack-uikit/list@0.24.1](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/list/CHANGELOG.md)
|
|
10
|
+
* [@snack-uikit/tooltip@0.16.0](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/tooltip/CHANGELOG.md)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## 0.10.2 (2025-02-04)
|
|
17
|
+
|
|
18
|
+
### Only dependencies have been changed
|
|
19
|
+
* [@snack-uikit/list@0.24.0](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/list/CHANGELOG.md)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
## 0.10.1 (2025-01-31)
|
|
7
26
|
|
|
8
27
|
|
package/README.md
CHANGED
|
@@ -24,7 +24,6 @@ Toolbar
|
|
|
24
24
|
| onRefresh | `() => void` | - | Колбек обновления |
|
|
25
25
|
| after | `ReactNode` | - | Дополнительный слот в конце тулбара |
|
|
26
26
|
| moreActions | `Action[]` | - | Элементы выпадающего списка кнопки с действиями |
|
|
27
|
-
| filterRow | `FilterRow<TState>` | - | |
|
|
28
27
|
|
|
29
28
|
|
|
30
29
|
[//]: DOCUMENTATION_SECTION_END
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { FiltersState } from '@snack-uikit/chips';
|
|
2
1
|
import { WithSupportProps } from '@snack-uikit/utils';
|
|
3
|
-
import { CheckedToolbarProps, DefaultToolbarProps
|
|
4
|
-
export type ToolbarProps
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
export declare function Toolbar<TState extends FiltersState>({ className, after, outline, moreActions, onRefresh, search, filterRow: filterRowProps, ...rest }: ToolbarProps<TState>): import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
import { CheckedToolbarProps, DefaultToolbarProps } from './types';
|
|
3
|
+
export type ToolbarProps = WithSupportProps<DefaultToolbarProps | CheckedToolbarProps>;
|
|
4
|
+
export declare function Toolbar({ className, after, outline, moreActions, onRefresh, search, ...rest }: ToolbarProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -21,14 +21,12 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
21
21
|
const classnames_1 = __importDefault(require("classnames"));
|
|
22
22
|
const react_1 = require("react");
|
|
23
23
|
const button_1 = require("@snack-uikit/button");
|
|
24
|
-
const chips_1 = require("@snack-uikit/chips");
|
|
25
24
|
const icons_1 = require("@snack-uikit/icons");
|
|
26
25
|
const search_private_1 = require("@snack-uikit/search-private");
|
|
27
26
|
const utils_1 = require("@snack-uikit/utils");
|
|
28
27
|
const constants_1 = require("../../constants");
|
|
29
28
|
const helperComponents_1 = require("../../helperComponents");
|
|
30
29
|
const helpers_1 = require("./helpers");
|
|
31
|
-
const hooks_1 = require("./hooks");
|
|
32
30
|
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
33
31
|
function Toolbar(_a) {
|
|
34
32
|
var {
|
|
@@ -37,59 +35,48 @@ function Toolbar(_a) {
|
|
|
37
35
|
outline,
|
|
38
36
|
moreActions,
|
|
39
37
|
onRefresh,
|
|
40
|
-
search
|
|
41
|
-
filterRow: filterRowProps
|
|
38
|
+
search
|
|
42
39
|
} = _a,
|
|
43
|
-
rest = __rest(_a, ["className", "after", "outline", "moreActions", "onRefresh", "search"
|
|
40
|
+
rest = __rest(_a, ["className", "after", "outline", "moreActions", "onRefresh", "search"]);
|
|
44
41
|
const needsBulkActions = (0, helpers_1.isBulkActionsProps)(rest);
|
|
45
42
|
const hasLeftSideElements = Boolean(needsBulkActions || onRefresh);
|
|
46
43
|
const resizingContainerRef = (0, react_1.useRef)(null);
|
|
47
|
-
const {
|
|
48
|
-
filterButton,
|
|
49
|
-
filterRow
|
|
50
|
-
} = (0, hooks_1.useFilters)({
|
|
51
|
-
filterRow: filterRowProps
|
|
52
|
-
});
|
|
53
44
|
return (0, jsx_runtime_1.jsxs)("div", Object.assign({
|
|
54
|
-
className: styles_module_scss_1.default.
|
|
45
|
+
className: (0, classnames_1.default)(styles_module_scss_1.default.container, className)
|
|
55
46
|
}, (0, utils_1.extractSupportProps)(rest), {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
children: [
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
47
|
+
"data-outline": outline || undefined,
|
|
48
|
+
ref: resizingContainerRef,
|
|
49
|
+
children: [hasLeftSideElements && (0, jsx_runtime_1.jsxs)("div", {
|
|
50
|
+
className: styles_module_scss_1.default.beforeSearch,
|
|
51
|
+
children: [needsBulkActions && (0, jsx_runtime_1.jsx)(helperComponents_1.BulkActions, Object.assign({}, (0, helpers_1.extractBulkActionsProps)(rest), {
|
|
52
|
+
resizingContainerRef: resizingContainerRef
|
|
53
|
+
})), needsBulkActions && (0, jsx_runtime_1.jsx)(helperComponents_1.Separator, {}), onRefresh && (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, {
|
|
54
|
+
children: [(0, jsx_runtime_1.jsx)(button_1.ButtonFunction, {
|
|
55
|
+
icon: (0, jsx_runtime_1.jsx)(icons_1.UpdateSVG, {}),
|
|
56
|
+
size: 'm',
|
|
57
|
+
className: styles_module_scss_1.default.updateButton,
|
|
58
|
+
onClick: onRefresh,
|
|
59
|
+
"data-test-id": constants_1.TEST_IDS.refreshButton
|
|
60
|
+
}), (0, jsx_runtime_1.jsx)(helperComponents_1.Separator, {})]
|
|
61
|
+
})]
|
|
62
|
+
}), search && (0, jsx_runtime_1.jsx)(search_private_1.SearchPrivate, Object.assign({}, search, {
|
|
63
|
+
className: styles_module_scss_1.default.search,
|
|
64
|
+
size: 'm',
|
|
65
|
+
"data-test-id": constants_1.TEST_IDS.search
|
|
66
|
+
})), (moreActions || after) && (0, jsx_runtime_1.jsxs)("div", {
|
|
67
|
+
className: styles_module_scss_1.default.flexRow,
|
|
68
|
+
"data-align-right": !search && !hasLeftSideElements || undefined,
|
|
69
|
+
children: [after && (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, {
|
|
70
|
+
children: [(search || hasLeftSideElements) && (0, jsx_runtime_1.jsx)(helperComponents_1.Separator, {}), (0, jsx_runtime_1.jsx)("div", {
|
|
71
|
+
"data-test-id": constants_1.TEST_IDS.after,
|
|
72
|
+
className: styles_module_scss_1.default.actions,
|
|
73
|
+
children: after
|
|
72
74
|
})]
|
|
73
|
-
}),
|
|
74
|
-
|
|
75
|
-
size: 'm',
|
|
76
|
-
"data-test-id": constants_1.TEST_IDS.search
|
|
77
|
-
})), (moreActions || after || filterButton) && (0, jsx_runtime_1.jsxs)("div", {
|
|
78
|
-
className: styles_module_scss_1.default.flexRow,
|
|
79
|
-
"data-align-right": !search && !hasLeftSideElements || undefined,
|
|
80
|
-
children: [after && (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, {
|
|
81
|
-
children: [(search || hasLeftSideElements) && (0, jsx_runtime_1.jsx)(helperComponents_1.Separator, {}), (0, jsx_runtime_1.jsx)("div", {
|
|
82
|
-
"data-test-id": constants_1.TEST_IDS.after,
|
|
83
|
-
className: styles_module_scss_1.default.actions,
|
|
84
|
-
children: after
|
|
85
|
-
})]
|
|
86
|
-
}), (moreActions || filterButton) && (0, jsx_runtime_1.jsx)(helperComponents_1.Separator, {}), filterButton && (0, jsx_runtime_1.jsx)(helperComponents_1.FilterButton, Object.assign({}, filterButton)), moreActions && (0, jsx_runtime_1.jsx)(helperComponents_1.MoreActions, {
|
|
75
|
+
}), moreActions && (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, {
|
|
76
|
+
children: [(0, jsx_runtime_1.jsx)(helperComponents_1.Separator, {}), (0, jsx_runtime_1.jsx)(helperComponents_1.MoreActions, {
|
|
87
77
|
moreActions: moreActions
|
|
88
78
|
})]
|
|
89
79
|
})]
|
|
90
|
-
})
|
|
91
|
-
size: 'xs',
|
|
92
|
-
"data-test-id": constants_1.TEST_IDS.filterRow
|
|
93
|
-
}))]
|
|
80
|
+
})]
|
|
94
81
|
}));
|
|
95
82
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { FiltersState } from '@snack-uikit/chips';
|
|
2
1
|
import { ToolbarProps } from './Toolbar';
|
|
3
2
|
import { ToolbarBulkActionProps } from './types';
|
|
4
3
|
export declare function extractBulkActionsProps({ onCheck, checked, indeterminate, bulkActions, selectionMode, }: ToolbarBulkActionProps): {
|
|
@@ -8,4 +7,4 @@ export declare function extractBulkActionsProps({ onCheck, checked, indeterminat
|
|
|
8
7
|
actions: import("../../helperComponents").BulkAction[];
|
|
9
8
|
selectionMode: import("../../helperComponents").SelectionMode | undefined;
|
|
10
9
|
};
|
|
11
|
-
export declare function isBulkActionsProps
|
|
10
|
+
export declare function isBulkActionsProps(props: Partial<ToolbarProps>): props is ToolbarBulkActionProps;
|
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
box-sizing:border-box;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
.containerWrapper{
|
|
6
|
-
gap:var(--space-toolbar-container-wrapper-gap, 8px);
|
|
7
|
-
display:flex;
|
|
8
|
-
flex-direction:column;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
5
|
.container{
|
|
12
6
|
border-radius:var(--radius-toolbar-container, 14px);
|
|
13
7
|
position:relative;
|
|
@@ -77,8 +71,4 @@
|
|
|
77
71
|
.actions{
|
|
78
72
|
flex-shrink:0;
|
|
79
73
|
box-sizing:border-box;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
.list{
|
|
83
|
-
width:200px;
|
|
84
74
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { ChipChoiceRowProps, FiltersState } from '@snack-uikit/chips';
|
|
3
2
|
import { BulkActionsProps, MoreActionsProps } from '../../helperComponents';
|
|
4
3
|
import { NeverOrUndefined, RequireAtLeastOne } from './typesUtils';
|
|
5
4
|
type OptionalProps = {
|
|
@@ -36,8 +35,4 @@ export type ToolbarBulkActionProps = Omit<BulkActionsProps, 'actions'> & {
|
|
|
36
35
|
};
|
|
37
36
|
export type CheckedToolbarProps = CommonToolbarProps & ToolbarBulkActionProps & OptionalProps;
|
|
38
37
|
export type DefaultToolbarProps = CommonToolbarProps & NeverOrUndefined<ToolbarBulkActionProps> & RequireAtLeastOne<OptionalProps>;
|
|
39
|
-
export type FilterRow<TState extends FiltersState> = Omit<ChipChoiceRowProps<TState>, 'size' | 'data-test-id'> & {
|
|
40
|
-
open?: boolean;
|
|
41
|
-
onOpenChange?: (isOpen: boolean) => void;
|
|
42
|
-
};
|
|
43
38
|
export {};
|
package/dist/cjs/constants.d.ts
CHANGED
package/dist/cjs/constants.js
CHANGED
|
@@ -16,8 +16,6 @@ exports.TEST_IDS = {
|
|
|
16
16
|
moreBulkActionsButton: 'toolbar__more-bulk-actions-button',
|
|
17
17
|
refreshButton: 'toolbar__refresh-button',
|
|
18
18
|
search: 'toolbar__search',
|
|
19
|
-
filterButton: 'toolbar__filter-button',
|
|
20
|
-
filterRow: 'toolbar__filter-row',
|
|
21
19
|
moreActionsButton: 'toolbar__more-actions-button',
|
|
22
20
|
droplist: 'toolbar__droplist',
|
|
23
21
|
option: 'toolbar__droplist-option',
|
|
@@ -23,6 +23,5 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
23
23
|
value: true
|
|
24
24
|
});
|
|
25
25
|
__exportStar(require("./BulkActions"), exports);
|
|
26
|
-
__exportStar(require("./FilterButton"), exports);
|
|
27
26
|
__exportStar(require("./Separator"), exports);
|
|
28
27
|
__exportStar(require("./MoreActions"), exports);
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { FiltersState } from '@snack-uikit/chips';
|
|
2
1
|
import { WithSupportProps } from '@snack-uikit/utils';
|
|
3
|
-
import { CheckedToolbarProps, DefaultToolbarProps
|
|
4
|
-
export type ToolbarProps
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
export declare function Toolbar<TState extends FiltersState>({ className, after, outline, moreActions, onRefresh, search, filterRow: filterRowProps, ...rest }: ToolbarProps<TState>): import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
import { CheckedToolbarProps, DefaultToolbarProps } from './types';
|
|
3
|
+
export type ToolbarProps = WithSupportProps<DefaultToolbarProps | CheckedToolbarProps>;
|
|
4
|
+
export declare function Toolbar({ className, after, outline, moreActions, onRefresh, search, ...rest }: ToolbarProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -13,20 +13,17 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
13
13
|
import cn from 'classnames';
|
|
14
14
|
import { useRef } from 'react';
|
|
15
15
|
import { ButtonFunction } from '@snack-uikit/button';
|
|
16
|
-
import { ChipChoiceRow } from '@snack-uikit/chips';
|
|
17
16
|
import { UpdateSVG } from '@snack-uikit/icons';
|
|
18
17
|
import { SearchPrivate } from '@snack-uikit/search-private';
|
|
19
18
|
import { extractSupportProps } from '@snack-uikit/utils';
|
|
20
19
|
import { TEST_IDS } from '../../constants';
|
|
21
|
-
import { BulkActions,
|
|
20
|
+
import { BulkActions, MoreActions, Separator } from '../../helperComponents';
|
|
22
21
|
import { extractBulkActionsProps, isBulkActionsProps } from './helpers';
|
|
23
|
-
import { useFilters } from './hooks';
|
|
24
22
|
import styles from './styles.module.css';
|
|
25
23
|
export function Toolbar(_a) {
|
|
26
|
-
var { className, after, outline, moreActions, onRefresh, search
|
|
24
|
+
var { className, after, outline, moreActions, onRefresh, search } = _a, rest = __rest(_a, ["className", "after", "outline", "moreActions", "onRefresh", "search"]);
|
|
27
25
|
const needsBulkActions = isBulkActionsProps(rest);
|
|
28
26
|
const hasLeftSideElements = Boolean(needsBulkActions || onRefresh);
|
|
29
27
|
const resizingContainerRef = useRef(null);
|
|
30
|
-
|
|
31
|
-
return (_jsxs("div", Object.assign({ className: styles.containerWrapper }, extractSupportProps(rest), { children: [_jsxs("div", { className: cn(styles.container, className), "data-outline": outline || undefined, ref: resizingContainerRef, children: [hasLeftSideElements && (_jsxs("div", { className: styles.beforeSearch, children: [needsBulkActions && (_jsx(BulkActions, Object.assign({}, extractBulkActionsProps(rest), { resizingContainerRef: resizingContainerRef }))), needsBulkActions && _jsx(Separator, {}), onRefresh && (_jsxs(_Fragment, { children: [_jsx(ButtonFunction, { icon: _jsx(UpdateSVG, {}), size: 'm', className: styles.updateButton, onClick: onRefresh, "data-test-id": TEST_IDS.refreshButton }), _jsx(Separator, {})] }))] })), search && _jsx(SearchPrivate, Object.assign({}, search, { className: styles.search, size: 'm', "data-test-id": TEST_IDS.search })), (moreActions || after || filterButton) && (_jsxs("div", { className: styles.flexRow, "data-align-right": (!search && !hasLeftSideElements) || undefined, children: [after && (_jsxs(_Fragment, { children: [(search || hasLeftSideElements) && _jsx(Separator, {}), _jsx("div", { "data-test-id": TEST_IDS.after, className: styles.actions, children: after })] })), (moreActions || filterButton) && _jsx(Separator, {}), filterButton && _jsx(FilterButton, Object.assign({}, filterButton)), moreActions && _jsx(MoreActions, { moreActions: moreActions })] }))] }), filterRow && _jsx(ChipChoiceRow, Object.assign({}, filterRow, { size: 'xs', "data-test-id": TEST_IDS.filterRow }))] })));
|
|
28
|
+
return (_jsxs("div", Object.assign({ className: cn(styles.container, className) }, extractSupportProps(rest), { "data-outline": outline || undefined, ref: resizingContainerRef, children: [hasLeftSideElements && (_jsxs("div", { className: styles.beforeSearch, children: [needsBulkActions && (_jsx(BulkActions, Object.assign({}, extractBulkActionsProps(rest), { resizingContainerRef: resizingContainerRef }))), needsBulkActions && _jsx(Separator, {}), onRefresh && (_jsxs(_Fragment, { children: [_jsx(ButtonFunction, { icon: _jsx(UpdateSVG, {}), size: 'm', className: styles.updateButton, onClick: onRefresh, "data-test-id": TEST_IDS.refreshButton }), _jsx(Separator, {})] }))] })), search && _jsx(SearchPrivate, Object.assign({}, search, { className: styles.search, size: 'm', "data-test-id": TEST_IDS.search })), (moreActions || after) && (_jsxs("div", { className: styles.flexRow, "data-align-right": (!search && !hasLeftSideElements) || undefined, children: [after && (_jsxs(_Fragment, { children: [(search || hasLeftSideElements) && _jsx(Separator, {}), _jsx("div", { "data-test-id": TEST_IDS.after, className: styles.actions, children: after })] })), moreActions && (_jsxs(_Fragment, { children: [_jsx(Separator, {}), _jsx(MoreActions, { moreActions: moreActions })] }))] }))] })));
|
|
32
29
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { FiltersState } from '@snack-uikit/chips';
|
|
2
1
|
import { ToolbarProps } from './Toolbar';
|
|
3
2
|
import { ToolbarBulkActionProps } from './types';
|
|
4
3
|
export declare function extractBulkActionsProps({ onCheck, checked, indeterminate, bulkActions, selectionMode, }: ToolbarBulkActionProps): {
|
|
@@ -8,4 +7,4 @@ export declare function extractBulkActionsProps({ onCheck, checked, indeterminat
|
|
|
8
7
|
actions: import("../../helperComponents").BulkAction[];
|
|
9
8
|
selectionMode: import("../../helperComponents").SelectionMode | undefined;
|
|
10
9
|
};
|
|
11
|
-
export declare function isBulkActionsProps
|
|
10
|
+
export declare function isBulkActionsProps(props: Partial<ToolbarProps>): props is ToolbarBulkActionProps;
|
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
box-sizing:border-box;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
.containerWrapper{
|
|
6
|
-
gap:var(--space-toolbar-container-wrapper-gap, 8px);
|
|
7
|
-
display:flex;
|
|
8
|
-
flex-direction:column;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
5
|
.container{
|
|
12
6
|
border-radius:var(--radius-toolbar-container, 14px);
|
|
13
7
|
position:relative;
|
|
@@ -77,8 +71,4 @@
|
|
|
77
71
|
.actions{
|
|
78
72
|
flex-shrink:0;
|
|
79
73
|
box-sizing:border-box;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
.list{
|
|
83
|
-
width:200px;
|
|
84
74
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { ChipChoiceRowProps, FiltersState } from '@snack-uikit/chips';
|
|
3
2
|
import { BulkActionsProps, MoreActionsProps } from '../../helperComponents';
|
|
4
3
|
import { NeverOrUndefined, RequireAtLeastOne } from './typesUtils';
|
|
5
4
|
type OptionalProps = {
|
|
@@ -36,8 +35,4 @@ export type ToolbarBulkActionProps = Omit<BulkActionsProps, 'actions'> & {
|
|
|
36
35
|
};
|
|
37
36
|
export type CheckedToolbarProps = CommonToolbarProps & ToolbarBulkActionProps & OptionalProps;
|
|
38
37
|
export type DefaultToolbarProps = CommonToolbarProps & NeverOrUndefined<ToolbarBulkActionProps> & RequireAtLeastOne<OptionalProps>;
|
|
39
|
-
export type FilterRow<TState extends FiltersState> = Omit<ChipChoiceRowProps<TState>, 'size' | 'data-test-id'> & {
|
|
40
|
-
open?: boolean;
|
|
41
|
-
onOpenChange?: (isOpen: boolean) => void;
|
|
42
|
-
};
|
|
43
38
|
export {};
|
package/dist/esm/constants.d.ts
CHANGED
package/dist/esm/constants.js
CHANGED
|
@@ -10,8 +10,6 @@ export const TEST_IDS = {
|
|
|
10
10
|
moreBulkActionsButton: 'toolbar__more-bulk-actions-button',
|
|
11
11
|
refreshButton: 'toolbar__refresh-button',
|
|
12
12
|
search: 'toolbar__search',
|
|
13
|
-
filterButton: 'toolbar__filter-button',
|
|
14
|
-
filterRow: 'toolbar__filter-row',
|
|
15
13
|
moreActionsButton: 'toolbar__more-actions-button',
|
|
16
14
|
droplist: 'toolbar__droplist',
|
|
17
15
|
option: 'toolbar__droplist-option',
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Toolbar",
|
|
7
|
-
"version": "0.10.
|
|
7
|
+
"version": "0.10.3",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -36,20 +36,15 @@
|
|
|
36
36
|
"license": "Apache-2.0",
|
|
37
37
|
"scripts": {},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@snack-uikit/button": "0.19.
|
|
40
|
-
"@snack-uikit/chips": "0.24.2-preview-08c7f775.0",
|
|
39
|
+
"@snack-uikit/button": "0.19.6",
|
|
41
40
|
"@snack-uikit/icons": "0.24.2",
|
|
42
|
-
"@snack-uikit/list": "0.
|
|
41
|
+
"@snack-uikit/list": "0.24.1",
|
|
43
42
|
"@snack-uikit/search-private": "0.4.9",
|
|
44
43
|
"@snack-uikit/tag": "0.12.2",
|
|
45
44
|
"@snack-uikit/toggles": "0.13.5",
|
|
46
|
-
"@snack-uikit/tooltip": "0.
|
|
45
|
+
"@snack-uikit/tooltip": "0.16.0",
|
|
47
46
|
"@snack-uikit/utils": "3.7.0",
|
|
48
|
-
"classnames": "2.5.1"
|
|
49
|
-
"uncontrollable": "8.0.4"
|
|
47
|
+
"classnames": "2.5.1"
|
|
50
48
|
},
|
|
51
|
-
"
|
|
52
|
-
"@snack-uikit/locale": "*"
|
|
53
|
-
},
|
|
54
|
-
"gitHead": "2f4d6256c36e231fb66b7b54e48cab8e916d6c79"
|
|
49
|
+
"gitHead": "4beda461fbd94378a1534458d7942270226a39ef"
|
|
55
50
|
}
|
|
@@ -2,87 +2,75 @@ import cn from 'classnames';
|
|
|
2
2
|
import { useRef } from 'react';
|
|
3
3
|
|
|
4
4
|
import { ButtonFunction } from '@snack-uikit/button';
|
|
5
|
-
import { ChipChoiceRow, FiltersState } from '@snack-uikit/chips';
|
|
6
5
|
import { UpdateSVG } from '@snack-uikit/icons';
|
|
7
6
|
import { SearchPrivate } from '@snack-uikit/search-private';
|
|
8
7
|
import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
|
|
9
8
|
|
|
10
9
|
import { TEST_IDS } from '../../constants';
|
|
11
|
-
import { BulkActions,
|
|
10
|
+
import { BulkActions, MoreActions, Separator } from '../../helperComponents';
|
|
12
11
|
import { extractBulkActionsProps, isBulkActionsProps } from './helpers';
|
|
13
|
-
import { useFilters } from './hooks';
|
|
14
12
|
import styles from './styles.module.scss';
|
|
15
|
-
import { CheckedToolbarProps, DefaultToolbarProps
|
|
13
|
+
import { CheckedToolbarProps, DefaultToolbarProps } from './types';
|
|
16
14
|
|
|
17
|
-
export type ToolbarProps
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
export function Toolbar<TState extends FiltersState>({
|
|
21
|
-
className,
|
|
22
|
-
after,
|
|
23
|
-
outline,
|
|
24
|
-
moreActions,
|
|
25
|
-
onRefresh,
|
|
26
|
-
search,
|
|
27
|
-
filterRow: filterRowProps,
|
|
28
|
-
...rest
|
|
29
|
-
}: ToolbarProps<TState>) {
|
|
15
|
+
export type ToolbarProps = WithSupportProps<DefaultToolbarProps | CheckedToolbarProps>;
|
|
16
|
+
|
|
17
|
+
export function Toolbar({ className, after, outline, moreActions, onRefresh, search, ...rest }: ToolbarProps) {
|
|
30
18
|
const needsBulkActions = isBulkActionsProps(rest);
|
|
31
19
|
const hasLeftSideElements = Boolean(needsBulkActions || onRefresh);
|
|
32
20
|
const resizingContainerRef = useRef<HTMLDivElement>(null);
|
|
33
21
|
|
|
34
|
-
const { filterButton, filterRow } = useFilters<TState>({ filterRow: filterRowProps });
|
|
35
|
-
|
|
36
22
|
return (
|
|
37
|
-
<div
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
<>
|
|
49
|
-
<ButtonFunction
|
|
50
|
-
icon={<UpdateSVG />}
|
|
51
|
-
size='m'
|
|
52
|
-
className={styles.updateButton}
|
|
53
|
-
onClick={onRefresh}
|
|
54
|
-
data-test-id={TEST_IDS.refreshButton}
|
|
55
|
-
/>
|
|
56
|
-
<Separator />
|
|
57
|
-
</>
|
|
58
|
-
)}
|
|
59
|
-
</div>
|
|
60
|
-
)}
|
|
61
|
-
|
|
62
|
-
{search && <SearchPrivate {...search} className={styles.search} size='m' data-test-id={TEST_IDS.search} />}
|
|
23
|
+
<div
|
|
24
|
+
className={cn(styles.container, className)}
|
|
25
|
+
{...extractSupportProps(rest)}
|
|
26
|
+
data-outline={outline || undefined}
|
|
27
|
+
ref={resizingContainerRef}
|
|
28
|
+
>
|
|
29
|
+
{hasLeftSideElements && (
|
|
30
|
+
<div className={styles.beforeSearch}>
|
|
31
|
+
{needsBulkActions && (
|
|
32
|
+
<BulkActions {...extractBulkActionsProps(rest)} resizingContainerRef={resizingContainerRef} />
|
|
33
|
+
)}
|
|
63
34
|
|
|
64
|
-
|
|
65
|
-
<div className={styles.flexRow} data-align-right={(!search && !hasLeftSideElements) || undefined}>
|
|
66
|
-
{after && (
|
|
67
|
-
<>
|
|
68
|
-
{(search || hasLeftSideElements) && <Separator />}
|
|
35
|
+
{needsBulkActions && <Separator />}
|
|
69
36
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
37
|
+
{onRefresh && (
|
|
38
|
+
<>
|
|
39
|
+
<ButtonFunction
|
|
40
|
+
icon={<UpdateSVG />}
|
|
41
|
+
size='m'
|
|
42
|
+
className={styles.updateButton}
|
|
43
|
+
onClick={onRefresh}
|
|
44
|
+
data-test-id={TEST_IDS.refreshButton}
|
|
45
|
+
/>
|
|
46
|
+
<Separator />
|
|
47
|
+
</>
|
|
48
|
+
)}
|
|
49
|
+
</div>
|
|
50
|
+
)}
|
|
75
51
|
|
|
76
|
-
|
|
52
|
+
{search && <SearchPrivate {...search} className={styles.search} size='m' data-test-id={TEST_IDS.search} />}
|
|
77
53
|
|
|
78
|
-
|
|
54
|
+
{(moreActions || after) && (
|
|
55
|
+
<div className={styles.flexRow} data-align-right={(!search && !hasLeftSideElements) || undefined}>
|
|
56
|
+
{after && (
|
|
57
|
+
<>
|
|
58
|
+
{(search || hasLeftSideElements) && <Separator />}
|
|
79
59
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
60
|
+
<div data-test-id={TEST_IDS.after} className={styles.actions}>
|
|
61
|
+
{after}
|
|
62
|
+
</div>
|
|
63
|
+
</>
|
|
64
|
+
)}
|
|
84
65
|
|
|
85
|
-
|
|
66
|
+
{moreActions && (
|
|
67
|
+
<>
|
|
68
|
+
<Separator />
|
|
69
|
+
<MoreActions moreActions={moreActions} />
|
|
70
|
+
</>
|
|
71
|
+
)}
|
|
72
|
+
</div>
|
|
73
|
+
)}
|
|
86
74
|
</div>
|
|
87
75
|
);
|
|
88
76
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { FiltersState } from '@snack-uikit/chips';
|
|
2
|
-
|
|
3
1
|
import { ToolbarProps } from './Toolbar';
|
|
4
2
|
import { ToolbarBulkActionProps } from './types';
|
|
5
3
|
|
|
@@ -13,9 +11,7 @@ export function extractBulkActionsProps({
|
|
|
13
11
|
return { onCheck, checked, indeterminate, actions: bulkActions, selectionMode };
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
export function isBulkActionsProps<
|
|
17
|
-
props: Partial<ToolbarProps<TState>>,
|
|
18
|
-
): props is ToolbarBulkActionProps {
|
|
14
|
+
export function isBulkActionsProps(props: Partial<ToolbarProps>): props is ToolbarBulkActionProps {
|
|
19
15
|
return (
|
|
20
16
|
'bulkActions' in props &&
|
|
21
17
|
Array.isArray(props.bulkActions) &&
|
|
@@ -5,13 +5,6 @@
|
|
|
5
5
|
box-sizing: border-box;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
.containerWrapper {
|
|
9
|
-
@include element.composite-var(toolbar.$toolbar-container-wrapper);
|
|
10
|
-
|
|
11
|
-
display: flex;
|
|
12
|
-
flex-direction: column;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
8
|
.container {
|
|
16
9
|
@include element.composite-var(toolbar.$toolbar-container);
|
|
17
10
|
|
|
@@ -94,7 +87,3 @@
|
|
|
94
87
|
flex-shrink: 0;
|
|
95
88
|
box-sizing: border-box;
|
|
96
89
|
}
|
|
97
|
-
|
|
98
|
-
.list {
|
|
99
|
-
width: 200px;
|
|
100
|
-
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
|
|
3
|
-
import { ChipChoiceRowProps, FiltersState } from '@snack-uikit/chips';
|
|
4
|
-
|
|
5
3
|
import { BulkActionsProps, MoreActionsProps } from '../../helperComponents';
|
|
6
4
|
import { NeverOrUndefined, RequireAtLeastOne } from './typesUtils';
|
|
7
5
|
|
|
@@ -45,8 +43,3 @@ export type CheckedToolbarProps = CommonToolbarProps & ToolbarBulkActionProps &
|
|
|
45
43
|
export type DefaultToolbarProps = CommonToolbarProps &
|
|
46
44
|
NeverOrUndefined<ToolbarBulkActionProps> &
|
|
47
45
|
RequireAtLeastOne<OptionalProps>;
|
|
48
|
-
|
|
49
|
-
export type FilterRow<TState extends FiltersState> = Omit<ChipChoiceRowProps<TState>, 'size' | 'data-test-id'> & {
|
|
50
|
-
open?: boolean;
|
|
51
|
-
onOpenChange?: (isOpen: boolean) => void;
|
|
52
|
-
};
|
package/src/constants.ts
CHANGED
|
@@ -10,8 +10,6 @@ export const TEST_IDS = {
|
|
|
10
10
|
moreBulkActionsButton: 'toolbar__more-bulk-actions-button',
|
|
11
11
|
refreshButton: 'toolbar__refresh-button',
|
|
12
12
|
search: 'toolbar__search',
|
|
13
|
-
filterButton: 'toolbar__filter-button',
|
|
14
|
-
filterRow: 'toolbar__filter-row',
|
|
15
13
|
moreActionsButton: 'toolbar__more-actions-button',
|
|
16
14
|
droplist: 'toolbar__droplist',
|
|
17
15
|
option: 'toolbar__droplist-option',
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { FiltersState } from '@snack-uikit/chips';
|
|
2
|
-
import { FilterButtonProps } from '../../helperComponents';
|
|
3
|
-
import { FilterRow } from './types';
|
|
4
|
-
type UseFiltersProps<TState extends FiltersState> = {
|
|
5
|
-
filterRow?: FilterRow<TState>;
|
|
6
|
-
};
|
|
7
|
-
type UseFiltersReturnType<TState extends FiltersState> = {
|
|
8
|
-
filterButton?: FilterButtonProps;
|
|
9
|
-
filterRow?: FilterRow<TState>;
|
|
10
|
-
};
|
|
11
|
-
export declare function useFilters<TState extends FiltersState>({ filterRow, }: UseFiltersProps<TState>): UseFiltersReturnType<TState>;
|
|
12
|
-
export {};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
4
|
-
return mod && mod.__esModule ? mod : {
|
|
5
|
-
"default": mod
|
|
6
|
-
};
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", {
|
|
9
|
-
value: true
|
|
10
|
-
});
|
|
11
|
-
exports.useFilters = useFilters;
|
|
12
|
-
const classnames_1 = __importDefault(require("classnames"));
|
|
13
|
-
const react_1 = require("react");
|
|
14
|
-
const uncontrollable_1 = require("uncontrollable");
|
|
15
|
-
const chips_1 = require("@snack-uikit/chips");
|
|
16
|
-
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
17
|
-
function useFilters(_ref) {
|
|
18
|
-
let {
|
|
19
|
-
filterRow
|
|
20
|
-
} = _ref;
|
|
21
|
-
var _a;
|
|
22
|
-
const [filtersOpen, setFiltersOpen] = (0, uncontrollable_1.useUncontrolledProp)(filterRow === null || filterRow === void 0 ? void 0 : filterRow.open, false, newValue => {
|
|
23
|
-
var _a;
|
|
24
|
-
const result = typeof newValue === 'function' ? newValue(filtersOpen) : newValue;
|
|
25
|
-
(_a = filterRow === null || filterRow === void 0 ? void 0 : filterRow.onOpenChange) === null || _a === void 0 ? void 0 : _a.call(filterRow, result);
|
|
26
|
-
});
|
|
27
|
-
const [value, setValue] = (0, uncontrollable_1.useUncontrolledProp)(filterRow === null || filterRow === void 0 ? void 0 : filterRow.value, (_a = filterRow === null || filterRow === void 0 ? void 0 : filterRow.defaultValue) !== null && _a !== void 0 ? _a : {}, newValue => {
|
|
28
|
-
var _a;
|
|
29
|
-
const result = typeof newValue === 'function' ? newValue(value) : newValue;
|
|
30
|
-
(_a = filterRow === null || filterRow === void 0 ? void 0 : filterRow.onChange) === null || _a === void 0 ? void 0 : _a.call(filterRow, result);
|
|
31
|
-
});
|
|
32
|
-
const [visibleFilters, setVisibleFilters] = (0, uncontrollable_1.useUncontrolledProp)(filterRow === null || filterRow === void 0 ? void 0 : filterRow.visibleFilters, Object.keys(value), newState => {
|
|
33
|
-
var _a;
|
|
34
|
-
const result = typeof newState === 'function' ? newState(visibleFilters) : newState;
|
|
35
|
-
(_a = filterRow === null || filterRow === void 0 ? void 0 : filterRow.onVisibleFiltersChange) === null || _a === void 0 ? void 0 : _a.call(filterRow, result);
|
|
36
|
-
});
|
|
37
|
-
const patchedFilters = (0, react_1.useMemo)(() => {
|
|
38
|
-
var _a;
|
|
39
|
-
return ((_a = filterRow === null || filterRow === void 0 ? void 0 : filterRow.filters) !== null && _a !== void 0 ? _a : []).map(filter => {
|
|
40
|
-
if (['single', 'multiple'].includes(filter.type)) {
|
|
41
|
-
return Object.assign(Object.assign({}, filter), {
|
|
42
|
-
dropDownClassName: (0, classnames_1.default)(filter.dropDownClassName, styles_module_scss_1.default.list)
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return filter;
|
|
46
|
-
});
|
|
47
|
-
}, [filterRow === null || filterRow === void 0 ? void 0 : filterRow.filters]);
|
|
48
|
-
const numberOfFilters = (0, react_1.useMemo)(() => Object.keys(value).reduce((result, filterKey) => result + Number((0, chips_1.hasFilterBeenApplied)(value[filterKey])), 0), [value]);
|
|
49
|
-
return {
|
|
50
|
-
filterButton: filterRow ? {
|
|
51
|
-
open: filtersOpen,
|
|
52
|
-
onOpenChange: setFiltersOpen,
|
|
53
|
-
numberOfFilters
|
|
54
|
-
} : undefined,
|
|
55
|
-
filterRow: filtersOpen && filterRow ? Object.assign(Object.assign({}, filterRow), {
|
|
56
|
-
open: undefined,
|
|
57
|
-
onOpenChange: undefined,
|
|
58
|
-
filters: patchedFilters,
|
|
59
|
-
value,
|
|
60
|
-
onChange: setValue,
|
|
61
|
-
visibleFilters,
|
|
62
|
-
onVisibleFiltersChange: setVisibleFilters
|
|
63
|
-
}) : undefined
|
|
64
|
-
};
|
|
65
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.FilterButton = FilterButton;
|
|
7
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
-
const button_1 = require("@snack-uikit/button");
|
|
9
|
-
const icons_1 = require("@snack-uikit/icons");
|
|
10
|
-
const locale_1 = require("@snack-uikit/locale");
|
|
11
|
-
const tooltip_1 = require("@snack-uikit/tooltip");
|
|
12
|
-
const constants_1 = require("../../constants");
|
|
13
|
-
function FilterButton(_ref) {
|
|
14
|
-
let {
|
|
15
|
-
open,
|
|
16
|
-
onOpenChange,
|
|
17
|
-
numberOfFilters
|
|
18
|
-
} = _ref;
|
|
19
|
-
const {
|
|
20
|
-
t
|
|
21
|
-
} = (0, locale_1.useLocale)('Toolbar');
|
|
22
|
-
return (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, {
|
|
23
|
-
tip: open ? t('hideFilters') : t('showFilters'),
|
|
24
|
-
children: (0, jsx_runtime_1.jsx)(button_1.ButtonFunction, {
|
|
25
|
-
size: 'm',
|
|
26
|
-
icon: (0, jsx_runtime_1.jsx)(icons_1.FilterSVG, {}),
|
|
27
|
-
onClick: () => onOpenChange(!open),
|
|
28
|
-
counter: numberOfFilters ? {
|
|
29
|
-
value: numberOfFilters,
|
|
30
|
-
appearance: 'neutral'
|
|
31
|
-
} : undefined,
|
|
32
|
-
"data-test-id": constants_1.TEST_IDS.filterButton
|
|
33
|
-
})
|
|
34
|
-
});
|
|
35
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './FilterButton';
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () {
|
|
10
|
-
return m[k];
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
Object.defineProperty(o, k2, desc);
|
|
15
|
-
} : function (o, m, k, k2) {
|
|
16
|
-
if (k2 === undefined) k2 = k;
|
|
17
|
-
o[k2] = m[k];
|
|
18
|
-
});
|
|
19
|
-
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
20
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(exports, "__esModule", {
|
|
23
|
-
value: true
|
|
24
|
-
});
|
|
25
|
-
__exportStar(require("./FilterButton"), exports);
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { FiltersState } from '@snack-uikit/chips';
|
|
2
|
-
import { FilterButtonProps } from '../../helperComponents';
|
|
3
|
-
import { FilterRow } from './types';
|
|
4
|
-
type UseFiltersProps<TState extends FiltersState> = {
|
|
5
|
-
filterRow?: FilterRow<TState>;
|
|
6
|
-
};
|
|
7
|
-
type UseFiltersReturnType<TState extends FiltersState> = {
|
|
8
|
-
filterButton?: FilterButtonProps;
|
|
9
|
-
filterRow?: FilterRow<TState>;
|
|
10
|
-
};
|
|
11
|
-
export declare function useFilters<TState extends FiltersState>({ filterRow, }: UseFiltersProps<TState>): UseFiltersReturnType<TState>;
|
|
12
|
-
export {};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import cn from 'classnames';
|
|
2
|
-
import { useMemo } from 'react';
|
|
3
|
-
import { useUncontrolledProp } from 'uncontrollable';
|
|
4
|
-
import { hasFilterBeenApplied } from '@snack-uikit/chips';
|
|
5
|
-
import styles from './styles.module.css';
|
|
6
|
-
export function useFilters({ filterRow, }) {
|
|
7
|
-
var _a;
|
|
8
|
-
const [filtersOpen, setFiltersOpen] = useUncontrolledProp(filterRow === null || filterRow === void 0 ? void 0 : filterRow.open, false, newValue => {
|
|
9
|
-
var _a;
|
|
10
|
-
const result = typeof newValue === 'function' ? newValue(filtersOpen) : newValue;
|
|
11
|
-
(_a = filterRow === null || filterRow === void 0 ? void 0 : filterRow.onOpenChange) === null || _a === void 0 ? void 0 : _a.call(filterRow, result);
|
|
12
|
-
});
|
|
13
|
-
const [value, setValue] = useUncontrolledProp(filterRow === null || filterRow === void 0 ? void 0 : filterRow.value, ((_a = filterRow === null || filterRow === void 0 ? void 0 : filterRow.defaultValue) !== null && _a !== void 0 ? _a : {}), newValue => {
|
|
14
|
-
var _a;
|
|
15
|
-
const result = typeof newValue === 'function' ? newValue(value) : newValue;
|
|
16
|
-
(_a = filterRow === null || filterRow === void 0 ? void 0 : filterRow.onChange) === null || _a === void 0 ? void 0 : _a.call(filterRow, result);
|
|
17
|
-
});
|
|
18
|
-
const [visibleFilters, setVisibleFilters] = useUncontrolledProp(filterRow === null || filterRow === void 0 ? void 0 : filterRow.visibleFilters, Object.keys(value), newState => {
|
|
19
|
-
var _a;
|
|
20
|
-
const result = typeof newState === 'function' ? newState(visibleFilters) : newState;
|
|
21
|
-
(_a = filterRow === null || filterRow === void 0 ? void 0 : filterRow.onVisibleFiltersChange) === null || _a === void 0 ? void 0 : _a.call(filterRow, result);
|
|
22
|
-
});
|
|
23
|
-
const patchedFilters = useMemo(() => {
|
|
24
|
-
var _a;
|
|
25
|
-
return ((_a = filterRow === null || filterRow === void 0 ? void 0 : filterRow.filters) !== null && _a !== void 0 ? _a : []).map(filter => {
|
|
26
|
-
if (['single', 'multiple'].includes(filter.type)) {
|
|
27
|
-
return Object.assign(Object.assign({}, filter), { dropDownClassName: cn(filter.dropDownClassName, styles.list) });
|
|
28
|
-
}
|
|
29
|
-
return filter;
|
|
30
|
-
});
|
|
31
|
-
}, [filterRow === null || filterRow === void 0 ? void 0 : filterRow.filters]);
|
|
32
|
-
const numberOfFilters = useMemo(() => Object.keys(value).reduce((result, filterKey) => result + Number(hasFilterBeenApplied(value[filterKey])), 0), [value]);
|
|
33
|
-
return {
|
|
34
|
-
filterButton: filterRow ? { open: filtersOpen, onOpenChange: setFiltersOpen, numberOfFilters } : undefined,
|
|
35
|
-
filterRow: filtersOpen && filterRow
|
|
36
|
-
? Object.assign(Object.assign({}, filterRow), { open: undefined, onOpenChange: undefined, filters: patchedFilters, value, onChange: setValue, visibleFilters, onVisibleFiltersChange: setVisibleFilters }) : undefined,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { ButtonFunction } from '@snack-uikit/button';
|
|
3
|
-
import { FilterSVG } from '@snack-uikit/icons';
|
|
4
|
-
import { useLocale } from '@snack-uikit/locale';
|
|
5
|
-
import { Tooltip } from '@snack-uikit/tooltip';
|
|
6
|
-
import { TEST_IDS } from '../../constants';
|
|
7
|
-
export function FilterButton({ open, onOpenChange, numberOfFilters }) {
|
|
8
|
-
const { t } = useLocale('Toolbar');
|
|
9
|
-
return (_jsx(Tooltip, { tip: open ? t('hideFilters') : t('showFilters'), children: _jsx(ButtonFunction, { size: 'm', icon: _jsx(FilterSVG, {}), onClick: () => onOpenChange(!open), counter: numberOfFilters ? { value: numberOfFilters, appearance: 'neutral' } : undefined, "data-test-id": TEST_IDS.filterButton }) }));
|
|
10
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './FilterButton';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './FilterButton';
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import cn from 'classnames';
|
|
2
|
-
import { useMemo } from 'react';
|
|
3
|
-
import { useUncontrolledProp } from 'uncontrollable';
|
|
4
|
-
|
|
5
|
-
import { FiltersState, hasFilterBeenApplied } from '@snack-uikit/chips';
|
|
6
|
-
|
|
7
|
-
import { FilterButtonProps } from '../../helperComponents';
|
|
8
|
-
import styles from './styles.module.scss';
|
|
9
|
-
import { FilterRow } from './types';
|
|
10
|
-
|
|
11
|
-
type UseFiltersProps<TState extends FiltersState> = {
|
|
12
|
-
filterRow?: FilterRow<TState>;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
type UseFiltersReturnType<TState extends FiltersState> = {
|
|
16
|
-
filterButton?: FilterButtonProps;
|
|
17
|
-
filterRow?: FilterRow<TState>;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export function useFilters<TState extends FiltersState>({
|
|
21
|
-
filterRow,
|
|
22
|
-
}: UseFiltersProps<TState>): UseFiltersReturnType<TState> {
|
|
23
|
-
const [filtersOpen, setFiltersOpen] = useUncontrolledProp<boolean>(filterRow?.open, false, newValue => {
|
|
24
|
-
const result = typeof newValue === 'function' ? newValue(filtersOpen) : newValue;
|
|
25
|
-
filterRow?.onOpenChange?.(result);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const [value, setValue] = useUncontrolledProp<TState>(
|
|
29
|
-
filterRow?.value,
|
|
30
|
-
(filterRow?.defaultValue ?? {}) as TState,
|
|
31
|
-
newValue => {
|
|
32
|
-
const result = typeof newValue === 'function' ? newValue(value) : newValue;
|
|
33
|
-
filterRow?.onChange?.(result);
|
|
34
|
-
},
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
const [visibleFilters, setVisibleFilters] = useUncontrolledProp<string[]>(
|
|
38
|
-
filterRow?.visibleFilters,
|
|
39
|
-
Object.keys(value),
|
|
40
|
-
newState => {
|
|
41
|
-
const result = typeof newState === 'function' ? newState(visibleFilters) : newState;
|
|
42
|
-
filterRow?.onVisibleFiltersChange?.(result);
|
|
43
|
-
},
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
const patchedFilters = useMemo(
|
|
47
|
-
() =>
|
|
48
|
-
(filterRow?.filters ?? []).map(filter => {
|
|
49
|
-
if (['single', 'multiple'].includes(filter.type)) {
|
|
50
|
-
return {
|
|
51
|
-
...filter,
|
|
52
|
-
dropDownClassName: cn(filter.dropDownClassName, styles.list),
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return filter;
|
|
57
|
-
}),
|
|
58
|
-
[filterRow?.filters],
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
const numberOfFilters = useMemo(
|
|
62
|
-
() => Object.keys(value).reduce((result, filterKey) => result + Number(hasFilterBeenApplied(value[filterKey])), 0),
|
|
63
|
-
[value],
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
filterButton: filterRow ? { open: filtersOpen, onOpenChange: setFiltersOpen, numberOfFilters } : undefined,
|
|
68
|
-
filterRow:
|
|
69
|
-
filtersOpen && filterRow
|
|
70
|
-
? {
|
|
71
|
-
...filterRow,
|
|
72
|
-
open: undefined,
|
|
73
|
-
onOpenChange: undefined,
|
|
74
|
-
filters: patchedFilters,
|
|
75
|
-
value,
|
|
76
|
-
onChange: setValue,
|
|
77
|
-
visibleFilters,
|
|
78
|
-
onVisibleFiltersChange: setVisibleFilters,
|
|
79
|
-
}
|
|
80
|
-
: undefined,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { ButtonFunction } from '@snack-uikit/button';
|
|
2
|
-
import { FilterSVG } from '@snack-uikit/icons';
|
|
3
|
-
import { useLocale } from '@snack-uikit/locale';
|
|
4
|
-
import { Tooltip } from '@snack-uikit/tooltip';
|
|
5
|
-
|
|
6
|
-
import { TEST_IDS } from '../../constants';
|
|
7
|
-
|
|
8
|
-
export type FilterButtonProps = {
|
|
9
|
-
open: boolean;
|
|
10
|
-
onOpenChange: (open: boolean) => void;
|
|
11
|
-
numberOfFilters?: number;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export function FilterButton({ open, onOpenChange, numberOfFilters }: FilterButtonProps) {
|
|
15
|
-
const { t } = useLocale('Toolbar');
|
|
16
|
-
|
|
17
|
-
return (
|
|
18
|
-
<Tooltip tip={open ? t('hideFilters') : t('showFilters')}>
|
|
19
|
-
<ButtonFunction
|
|
20
|
-
size='m'
|
|
21
|
-
icon={<FilterSVG />}
|
|
22
|
-
onClick={() => onOpenChange(!open)}
|
|
23
|
-
counter={numberOfFilters ? { value: numberOfFilters, appearance: 'neutral' } : undefined}
|
|
24
|
-
data-test-id={TEST_IDS.filterButton}
|
|
25
|
-
/>
|
|
26
|
-
</Tooltip>
|
|
27
|
-
);
|
|
28
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './FilterButton';
|