@synerise/ds-mapping 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +55 -0
- package/dist/Mapping.d.ts +4 -0
- package/dist/Mapping.js +106 -0
- package/dist/Mapping.styles.d.ts +15 -0
- package/dist/Mapping.styles.js +54 -0
- package/dist/Mapping.types.d.ts +54 -0
- package/dist/Mapping.types.js +1 -0
- package/dist/components/BatchSelectionHeader/BatchSelectionHeader.d.ts +3 -0
- package/dist/components/BatchSelectionHeader/BatchSelectionHeader.js +23 -0
- package/dist/components/RowSelection/RowSelection.d.ts +3 -0
- package/dist/components/RowSelection/RowSelection.js +15 -0
- package/dist/components/TitleRow/TitleRow.d.ts +3 -0
- package/dist/components/TitleRow/TitleRow.js +24 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.js +3 -0
- package/dist/hooks/useBatchSelection.d.ts +8 -0
- package/dist/hooks/useBatchSelection.js +36 -0
- package/dist/hooks/useTexts.d.ts +2 -0
- package/dist/hooks/useTexts.js +20 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/modules.d.js +1 -0
- package/dist/utils/counter.d.ts +2 -0
- package/dist/utils/counter.js +7 -0
- package/package.json +53 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Synerise
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: mapping
|
|
3
|
+
title: Mapping
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Mapping UI Component
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
npm i @synerise/ds-mapping
|
|
12
|
+
or
|
|
13
|
+
yarn add @synerise/ds-mapping
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
import Mapping from '@synerise/ds-mapping'
|
|
20
|
+
|
|
21
|
+
<Mapping />
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Demo
|
|
26
|
+
|
|
27
|
+
<iframe src="/storybook-static/iframe.html?id=components-mapping--default"></iframe>
|
|
28
|
+
|
|
29
|
+
## API
|
|
30
|
+
|
|
31
|
+
| Property | Description | Type | Default |
|
|
32
|
+
| ----------------- | -------------------------------------------------------- | ------------------------------------------------------------ | ------- |
|
|
33
|
+
| batchSelection | batch selection configuration | BatchSelectionType | - |
|
|
34
|
+
| dataSource | Data to be rendered in the mapping | Array<T extends BaseItemType> | - |
|
|
35
|
+
| leftTitle | Left column title | ReactNode | - |
|
|
36
|
+
| leftTitleTooltip | Tooltip for left column title | TooltipProps see ds-tooltip | - |
|
|
37
|
+
| rightTitle | Right column title | ReactNode | - |
|
|
38
|
+
| rightTitleTooltip | Tooltip for right column title | TooltipProps see ds-tooltip | - |
|
|
39
|
+
| leftComponent | Component to be rendered in the left column | ({item: T extends BaseItemType, index: number}) => ReactNode | - |
|
|
40
|
+
| rightComponent | Component to be rendered in the right column | ({item: T extends BaseItemType, index: number}) => ReactNode | - |
|
|
41
|
+
| centerComponent | Component to be rendered in the center column (optional) | ({item: T extends BaseItemType, index: number}) => ReactNode | - |
|
|
42
|
+
|
|
43
|
+
### BaseItemType
|
|
44
|
+
|
|
45
|
+
| Property | Description | Type | Default |
|
|
46
|
+
| -------- | ---------------------- | --------------- | ------- |
|
|
47
|
+
| id | Unique item identifier | number / string | - |
|
|
48
|
+
|
|
49
|
+
### BatchSelectionType
|
|
50
|
+
|
|
51
|
+
| Property | Description | Type | Default |
|
|
52
|
+
| ----------------- | -------------------------------------------------- | --------------------------------------------------- | ------- |
|
|
53
|
+
| actionButtons | Buttons to display when any items are selected | ReactNode | - |
|
|
54
|
+
| onSelectionChange | handler fired when items are selected / deselected | (selected: ItemType['id'][]) => void | - |
|
|
55
|
+
| renderCounter | custom counter renderer | (selectedCount: number, total: number) => ReactNode | - |
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { BaseItemType, MappingProps } from './Mapping.types';
|
|
3
|
+
declare const Mapping: <ItemType extends BaseItemType>({ batchSelection, dataSource, leftTitle, leftTitleTooltip, rightTitle, rightTitleTooltip, leftComponent, rightComponent, centerComponent, texts, ...htmlAttributes }: MappingProps<ItemType>) => React.JSX.Element;
|
|
4
|
+
export default Mapping;
|
package/dist/Mapping.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
var _excluded = ["batchSelection", "dataSource", "leftTitle", "leftTitleTooltip", "rightTitle", "rightTitleTooltip", "leftComponent", "rightComponent", "centerComponent", "texts"];
|
|
2
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
3
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
4
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
5
|
+
import Icon, { HideM, TaskCheckM } from '@synerise/ds-icon';
|
|
6
|
+
import Button from '@synerise/ds-button';
|
|
7
|
+
import * as S from './Mapping.styles';
|
|
8
|
+
import { BatchSelectionHeader, RowSelection, TitleRow } from './components';
|
|
9
|
+
import { renderCounter as defaultRenderCounter } from './utils/counter';
|
|
10
|
+
import { useBatchSelection } from './hooks/useBatchSelection';
|
|
11
|
+
import { useTexts } from './hooks/useTexts';
|
|
12
|
+
var Mapping = function Mapping(_ref) {
|
|
13
|
+
var batchSelection = _ref.batchSelection,
|
|
14
|
+
dataSource = _ref.dataSource,
|
|
15
|
+
leftTitle = _ref.leftTitle,
|
|
16
|
+
leftTitleTooltip = _ref.leftTitleTooltip,
|
|
17
|
+
rightTitle = _ref.rightTitle,
|
|
18
|
+
rightTitleTooltip = _ref.rightTitleTooltip,
|
|
19
|
+
leftComponent = _ref.leftComponent,
|
|
20
|
+
rightComponent = _ref.rightComponent,
|
|
21
|
+
centerComponent = _ref.centerComponent,
|
|
22
|
+
texts = _ref.texts,
|
|
23
|
+
htmlAttributes = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
24
|
+
var hasCenterComponent = !!centerComponent;
|
|
25
|
+
var hasSelection = !!batchSelection;
|
|
26
|
+
var isCompact = dataSource.length === 1;
|
|
27
|
+
var _useState = useState(false),
|
|
28
|
+
selectionEnabled = _useState[0],
|
|
29
|
+
setSelectionEnabled = _useState[1];
|
|
30
|
+
var allTexts = useTexts(texts);
|
|
31
|
+
var _useBatchSelection = useBatchSelection(dataSource, hasSelection),
|
|
32
|
+
selectedItemIds = _useBatchSelection.selectedItemIds,
|
|
33
|
+
setSelectedItemIds = _useBatchSelection.setSelectedItemIds,
|
|
34
|
+
handleBatchCheckboxChange = _useBatchSelection.handleBatchCheckboxChange,
|
|
35
|
+
batchSelectionCheckboxState = _useBatchSelection.batchSelectionCheckboxState;
|
|
36
|
+
var _ref2 = batchSelection || {},
|
|
37
|
+
actionButtons = _ref2.actionButtons,
|
|
38
|
+
onSelectionChange = _ref2.onSelectionChange,
|
|
39
|
+
_ref2$renderCounter = _ref2.renderCounter,
|
|
40
|
+
renderCounter = _ref2$renderCounter === void 0 ? defaultRenderCounter : _ref2$renderCounter;
|
|
41
|
+
var handleItemSelection = function handleItemSelection(checked, id) {
|
|
42
|
+
if (checked) {
|
|
43
|
+
setSelectedItemIds([].concat(selectedItemIds, [id]));
|
|
44
|
+
} else {
|
|
45
|
+
setSelectedItemIds(selectedItemIds.filter(function (itemId) {
|
|
46
|
+
return itemId !== id;
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var toggleBatchButton = useCallback(function (newState) {
|
|
51
|
+
setSelectionEnabled(newState);
|
|
52
|
+
setSelectedItemIds([]);
|
|
53
|
+
}, [setSelectedItemIds]);
|
|
54
|
+
var batchButton = useMemo(function () {
|
|
55
|
+
return /*#__PURE__*/React.createElement(Button, {
|
|
56
|
+
"data-testid": "toggle-bulk-actions",
|
|
57
|
+
type: "ghost",
|
|
58
|
+
mode: "icon-label",
|
|
59
|
+
onClick: function onClick() {
|
|
60
|
+
return toggleBatchButton(!selectionEnabled);
|
|
61
|
+
}
|
|
62
|
+
}, selectionEnabled ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Icon, {
|
|
63
|
+
component: /*#__PURE__*/React.createElement(HideM, null)
|
|
64
|
+
}), " ", allTexts.disableBatchSelection) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Icon, {
|
|
65
|
+
component: /*#__PURE__*/React.createElement(TaskCheckM, null)
|
|
66
|
+
}), " ", allTexts.enableBatchSelection));
|
|
67
|
+
}, [allTexts.disableBatchSelection, allTexts.enableBatchSelection, selectionEnabled, toggleBatchButton]);
|
|
68
|
+
useEffect(function () {
|
|
69
|
+
onSelectionChange && onSelectionChange(selectedItemIds);
|
|
70
|
+
}, [onSelectionChange, selectedItemIds]);
|
|
71
|
+
return /*#__PURE__*/React.createElement(S.MappingWrapper, _extends({
|
|
72
|
+
isCompact: isCompact
|
|
73
|
+
}, htmlAttributes), batchSelection && /*#__PURE__*/React.createElement(BatchSelectionHeader, {
|
|
74
|
+
checkboxState: batchSelectionCheckboxState,
|
|
75
|
+
onChange: handleBatchCheckboxChange,
|
|
76
|
+
actionButtons: actionButtons,
|
|
77
|
+
batchButton: batchButton,
|
|
78
|
+
enabled: selectionEnabled,
|
|
79
|
+
counter: renderCounter(selectedItemIds.length, dataSource.length)
|
|
80
|
+
}), (leftTitle || rightTitle) && /*#__PURE__*/React.createElement(TitleRow, {
|
|
81
|
+
leftTitle: leftTitle,
|
|
82
|
+
rightTitle: rightTitle,
|
|
83
|
+
leftTitleTooltip: leftTitleTooltip,
|
|
84
|
+
rightTitleTooltip: rightTitleTooltip,
|
|
85
|
+
hasCenterComponent: hasCenterComponent,
|
|
86
|
+
hasSelection: hasSelection && selectionEnabled
|
|
87
|
+
}), dataSource.map(function (item, index) {
|
|
88
|
+
return /*#__PURE__*/React.createElement(S.MappingRow, {
|
|
89
|
+
key: item.id
|
|
90
|
+
}, hasSelection && selectionEnabled && /*#__PURE__*/React.createElement(RowSelection, {
|
|
91
|
+
checkboxState: selectedItemIds.includes(item.id),
|
|
92
|
+
itemId: item.id,
|
|
93
|
+
onChange: handleItemSelection
|
|
94
|
+
}), /*#__PURE__*/React.createElement(S.MappingRowLeft, null, leftComponent({
|
|
95
|
+
item: item,
|
|
96
|
+
index: index
|
|
97
|
+
})), hasCenterComponent && /*#__PURE__*/React.createElement(S.MappingRowCenter, null, centerComponent({
|
|
98
|
+
item: item,
|
|
99
|
+
index: index
|
|
100
|
+
})), /*#__PURE__*/React.createElement(S.MappingRowRight, null, rightComponent({
|
|
101
|
+
item: item,
|
|
102
|
+
index: index
|
|
103
|
+
})));
|
|
104
|
+
}));
|
|
105
|
+
};
|
|
106
|
+
export default Mapping;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const MappingWrapper: import("styled-components").StyledComponent<"div", any, {
|
|
3
|
+
isCompact: boolean;
|
|
4
|
+
}, never>;
|
|
5
|
+
export declare const MappingRow: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
6
|
+
export declare const MappingRowLeft: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
7
|
+
export declare const MappingRowRight: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
8
|
+
export declare const MappingRowCenter: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
9
|
+
export declare const RowSelectionWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
10
|
+
export declare const ColumnTitle: import("styled-components").StyledComponent<({ level, withoutMargin, children, className, ellipsis, ...antdProps }: import("@synerise/ds-typography/dist/Title.types").Props) => import("react").JSX.Element, any, {}, never>;
|
|
11
|
+
export declare const BatchSelectionWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
12
|
+
export declare const BatchActionButtons: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
13
|
+
export declare const BatchCounter: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
14
|
+
export declare const BatchSelectionInner: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
15
|
+
export declare const BatchToggleButton: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
import { Title } from '@synerise/ds-typography';
|
|
3
|
+
export var MappingWrapper = styled.div.withConfig({
|
|
4
|
+
displayName: "Mappingstyles__MappingWrapper",
|
|
5
|
+
componentId: "sc-1f47eqt-0"
|
|
6
|
+
})(["display:flex;flex-direction:column;", ";"], function (props) {
|
|
7
|
+
return !props.isCompact && "gap: 16px";
|
|
8
|
+
});
|
|
9
|
+
export var MappingRow = styled.div.withConfig({
|
|
10
|
+
displayName: "Mappingstyles__MappingRow",
|
|
11
|
+
componentId: "sc-1f47eqt-1"
|
|
12
|
+
})(["display:flex;gap:14px;align-items:center;"]);
|
|
13
|
+
export var MappingRowLeft = styled.div.withConfig({
|
|
14
|
+
displayName: "Mappingstyles__MappingRowLeft",
|
|
15
|
+
componentId: "sc-1f47eqt-2"
|
|
16
|
+
})(["flex:1 1 50%;"]);
|
|
17
|
+
export var MappingRowRight = styled.div.withConfig({
|
|
18
|
+
displayName: "Mappingstyles__MappingRowRight",
|
|
19
|
+
componentId: "sc-1f47eqt-3"
|
|
20
|
+
})(["flex:1 1 50%;"]);
|
|
21
|
+
export var MappingRowCenter = styled.div.withConfig({
|
|
22
|
+
displayName: "Mappingstyles__MappingRowCenter",
|
|
23
|
+
componentId: "sc-1f47eqt-4"
|
|
24
|
+
})(["flex:0 0 32px;display:flex;justify-content:center;"]);
|
|
25
|
+
export var RowSelectionWrapper = styled.div.withConfig({
|
|
26
|
+
displayName: "Mappingstyles__RowSelectionWrapper",
|
|
27
|
+
componentId: "sc-1f47eqt-5"
|
|
28
|
+
})(["flex:0 0 32px;"]);
|
|
29
|
+
export var ColumnTitle = styled(Title).withConfig({
|
|
30
|
+
displayName: "Mappingstyles__ColumnTitle",
|
|
31
|
+
componentId: "sc-1f47eqt-6"
|
|
32
|
+
})([""]);
|
|
33
|
+
export var BatchSelectionWrapper = styled.div.withConfig({
|
|
34
|
+
displayName: "Mappingstyles__BatchSelectionWrapper",
|
|
35
|
+
componentId: "sc-1f47eqt-7"
|
|
36
|
+
})(["display:flex;align-items:center;justify-content:space-between;gap:14px;border-bottom:solid 1px ", ";height:64px;"], function (props) {
|
|
37
|
+
return props.theme.palette['grey-300'];
|
|
38
|
+
});
|
|
39
|
+
export var BatchActionButtons = styled.div.withConfig({
|
|
40
|
+
displayName: "Mappingstyles__BatchActionButtons",
|
|
41
|
+
componentId: "sc-1f47eqt-8"
|
|
42
|
+
})(["display:flex;gap:8px;"]);
|
|
43
|
+
export var BatchCounter = styled.div.withConfig({
|
|
44
|
+
displayName: "Mappingstyles__BatchCounter",
|
|
45
|
+
componentId: "sc-1f47eqt-9"
|
|
46
|
+
})(["white-space:nowrap;"]);
|
|
47
|
+
export var BatchSelectionInner = styled.div.withConfig({
|
|
48
|
+
displayName: "Mappingstyles__BatchSelectionInner",
|
|
49
|
+
componentId: "sc-1f47eqt-10"
|
|
50
|
+
})(["display:flex;flex-grow:1;align-items:center;gap:24px;"]);
|
|
51
|
+
export var BatchToggleButton = styled.div.withConfig({
|
|
52
|
+
displayName: "Mappingstyles__BatchToggleButton",
|
|
53
|
+
componentId: "sc-1f47eqt-11"
|
|
54
|
+
})([""]);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { TooltipProps } from '@synerise/ds-tooltip';
|
|
3
|
+
import { CheckboxTristateProps } from '@synerise/ds-checkbox-tristate';
|
|
4
|
+
import { CheckboxProps } from '@synerise/ds-checkbox';
|
|
5
|
+
import { WithHTMLAttributes } from '@synerise/ds-utils';
|
|
6
|
+
export type BaseItemType = {
|
|
7
|
+
id: string | number;
|
|
8
|
+
};
|
|
9
|
+
type BaseColumnComponentProps = {
|
|
10
|
+
index: number;
|
|
11
|
+
};
|
|
12
|
+
export type ColumnComponentProps<T extends BaseItemType> = {
|
|
13
|
+
item: T;
|
|
14
|
+
} & BaseColumnComponentProps;
|
|
15
|
+
export type MappingTexts = {
|
|
16
|
+
enableBatchSelection: ReactNode;
|
|
17
|
+
disableBatchSelection: ReactNode;
|
|
18
|
+
};
|
|
19
|
+
type BaseMappingProps = {
|
|
20
|
+
leftTitle?: ReactNode;
|
|
21
|
+
leftTitleTooltip?: TooltipProps;
|
|
22
|
+
rightTitle?: ReactNode;
|
|
23
|
+
rightTitleTooltip?: TooltipProps;
|
|
24
|
+
};
|
|
25
|
+
export type MappingProps<T extends BaseItemType> = WithHTMLAttributes<HTMLDivElement, {
|
|
26
|
+
dataSource: Array<T>;
|
|
27
|
+
leftComponent: (props: ColumnComponentProps<T>) => ReactNode;
|
|
28
|
+
rightComponent: (props: ColumnComponentProps<T>) => ReactNode;
|
|
29
|
+
centerComponent?: (props: ColumnComponentProps<T>) => ReactNode;
|
|
30
|
+
batchSelection?: BatchSelectionType<T>;
|
|
31
|
+
texts?: Partial<MappingTexts>;
|
|
32
|
+
} & BaseMappingProps>;
|
|
33
|
+
export type TitleRowProps = BaseMappingProps & {
|
|
34
|
+
hasSelection?: boolean;
|
|
35
|
+
hasCenterComponent?: boolean;
|
|
36
|
+
};
|
|
37
|
+
export type BatchSelectionType<T extends BaseItemType> = {
|
|
38
|
+
onSelectionChange: (selectedIndexes: T['id'][]) => void;
|
|
39
|
+
renderCounter?: (selectedCount: number, total: number) => ReactNode;
|
|
40
|
+
} & Pick<BatchSelectionProps, 'actionButtons'>;
|
|
41
|
+
export type BatchSelectionProps = {
|
|
42
|
+
actionButtons: ReactNode;
|
|
43
|
+
checkboxState: CheckboxTristateProps['checked'];
|
|
44
|
+
onChange: (checked?: boolean) => void;
|
|
45
|
+
counter: ReactNode;
|
|
46
|
+
batchButton: ReactNode;
|
|
47
|
+
enabled?: boolean;
|
|
48
|
+
};
|
|
49
|
+
export type RowSelectionProps<T extends BaseItemType> = {
|
|
50
|
+
checkboxState: CheckboxProps['checked'];
|
|
51
|
+
itemId: T['id'];
|
|
52
|
+
onChange: (checked: boolean, id: T['id']) => void;
|
|
53
|
+
};
|
|
54
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import CheckboxTristate from '@synerise/ds-checkbox-tristate';
|
|
3
|
+
import * as S from '../../Mapping.styles';
|
|
4
|
+
export var BatchSelectionHeader = function BatchSelectionHeader(_ref) {
|
|
5
|
+
var counter = _ref.counter,
|
|
6
|
+
checkboxState = _ref.checkboxState,
|
|
7
|
+
onChange = _ref.onChange,
|
|
8
|
+
actionButtons = _ref.actionButtons,
|
|
9
|
+
batchButton = _ref.batchButton,
|
|
10
|
+
enabled = _ref.enabled;
|
|
11
|
+
var handleChange = function handleChange() {
|
|
12
|
+
if (checkboxState !== true) {
|
|
13
|
+
onChange(true);
|
|
14
|
+
} else {
|
|
15
|
+
onChange(false);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
return /*#__PURE__*/React.createElement(S.BatchSelectionWrapper, null, enabled && /*#__PURE__*/React.createElement(S.RowSelectionWrapper, null, /*#__PURE__*/React.createElement(CheckboxTristate, {
|
|
19
|
+
withoutPadding: true,
|
|
20
|
+
checked: checkboxState,
|
|
21
|
+
onChange: handleChange
|
|
22
|
+
})), /*#__PURE__*/React.createElement(S.BatchSelectionInner, null, /*#__PURE__*/React.createElement(S.BatchCounter, null, counter), enabled && checkboxState !== false && /*#__PURE__*/React.createElement(S.BatchActionButtons, null, actionButtons)), /*#__PURE__*/React.createElement(S.BatchToggleButton, null, batchButton));
|
|
23
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Checkbox from '@synerise/ds-checkbox';
|
|
3
|
+
import * as S from '../../Mapping.styles';
|
|
4
|
+
export var RowSelection = function RowSelection(_ref) {
|
|
5
|
+
var itemId = _ref.itemId,
|
|
6
|
+
checkboxState = _ref.checkboxState,
|
|
7
|
+
_onChange = _ref.onChange;
|
|
8
|
+
return /*#__PURE__*/React.createElement(S.RowSelectionWrapper, null, /*#__PURE__*/React.createElement(Checkbox, {
|
|
9
|
+
withoutPadding: true,
|
|
10
|
+
checked: checkboxState,
|
|
11
|
+
onChange: function onChange(event) {
|
|
12
|
+
return _onChange(event.target.checked, itemId);
|
|
13
|
+
}
|
|
14
|
+
}));
|
|
15
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Tooltip from '@synerise/ds-tooltip';
|
|
3
|
+
import Icon, { InfoFillS } from '@synerise/ds-icon';
|
|
4
|
+
import { theme } from '@synerise/ds-core';
|
|
5
|
+
import * as S from '../../Mapping.styles';
|
|
6
|
+
export var TitleRow = function TitleRow(_ref) {
|
|
7
|
+
var leftTitle = _ref.leftTitle,
|
|
8
|
+
leftTitleTooltip = _ref.leftTitleTooltip,
|
|
9
|
+
rightTitle = _ref.rightTitle,
|
|
10
|
+
rightTitleTooltip = _ref.rightTitleTooltip,
|
|
11
|
+
hasCenterComponent = _ref.hasCenterComponent,
|
|
12
|
+
hasSelection = _ref.hasSelection;
|
|
13
|
+
return /*#__PURE__*/React.createElement(S.MappingRow, null, hasSelection && /*#__PURE__*/React.createElement(S.RowSelectionWrapper, null), /*#__PURE__*/React.createElement(S.MappingRowLeft, null, /*#__PURE__*/React.createElement(S.ColumnTitle, {
|
|
14
|
+
level: 6
|
|
15
|
+
}, leftTitle, ' ', leftTitleTooltip && /*#__PURE__*/React.createElement(Tooltip, leftTitleTooltip, /*#__PURE__*/React.createElement(Icon, {
|
|
16
|
+
component: /*#__PURE__*/React.createElement(InfoFillS, null),
|
|
17
|
+
color: theme.palette['grey-400']
|
|
18
|
+
})))), hasCenterComponent && /*#__PURE__*/React.createElement(S.MappingRowCenter, null), /*#__PURE__*/React.createElement(S.MappingRowLeft, null, /*#__PURE__*/React.createElement(S.ColumnTitle, {
|
|
19
|
+
level: 6
|
|
20
|
+
}, rightTitle, ' ', rightTitleTooltip && /*#__PURE__*/React.createElement(Tooltip, rightTitleTooltip, /*#__PURE__*/React.createElement(Icon, {
|
|
21
|
+
component: /*#__PURE__*/React.createElement(InfoFillS, null),
|
|
22
|
+
color: theme.palette['grey-400']
|
|
23
|
+
})))));
|
|
24
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { BaseItemType } from '../Mapping.types';
|
|
3
|
+
export declare const useBatchSelection: <ItemType extends BaseItemType>(dataSource: ItemType[], hasBatchSelection?: boolean) => {
|
|
4
|
+
selectedItemIds: ItemType["id"][];
|
|
5
|
+
batchSelectionCheckboxState: boolean | undefined;
|
|
6
|
+
setSelectedItemIds: import("react").Dispatch<import("react").SetStateAction<ItemType["id"][]>>;
|
|
7
|
+
handleBatchCheckboxChange: (newVal: boolean | undefined) => void;
|
|
8
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useMemo, useState } from 'react';
|
|
2
|
+
export var useBatchSelection = function useBatchSelection(dataSource, hasBatchSelection) {
|
|
3
|
+
var _useState = useState([]),
|
|
4
|
+
selectedItemIds = _useState[0],
|
|
5
|
+
setSelectedItemIds = _useState[1];
|
|
6
|
+
var handleBatchCheckboxChange = function handleBatchCheckboxChange(newVal) {
|
|
7
|
+
if (newVal === true) {
|
|
8
|
+
setSelectedItemIds(dataSource.map(function (item) {
|
|
9
|
+
return item.id;
|
|
10
|
+
}));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (newVal === false) {
|
|
14
|
+
setSelectedItemIds([]);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var batchSelectionCheckboxState = useMemo(function () {
|
|
18
|
+
if (hasBatchSelection) {
|
|
19
|
+
switch (dataSource.length - selectedItemIds.length) {
|
|
20
|
+
case 0:
|
|
21
|
+
return !!dataSource.length;
|
|
22
|
+
case dataSource.length:
|
|
23
|
+
return false;
|
|
24
|
+
default:
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}, [dataSource, selectedItemIds, hasBatchSelection]);
|
|
30
|
+
return {
|
|
31
|
+
selectedItemIds: selectedItemIds,
|
|
32
|
+
batchSelectionCheckboxState: batchSelectionCheckboxState,
|
|
33
|
+
setSelectedItemIds: setSelectedItemIds,
|
|
34
|
+
handleBatchCheckboxChange: handleBatchCheckboxChange
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { useIntl } from 'react-intl';
|
|
4
|
+
export var useTexts = function useTexts(defaultTexts) {
|
|
5
|
+
var _useIntl = useIntl(),
|
|
6
|
+
formatMessage = _useIntl.formatMessage;
|
|
7
|
+
var texts = useMemo(function () {
|
|
8
|
+
return _extends({
|
|
9
|
+
enableBatchSelection: formatMessage({
|
|
10
|
+
id: 'DS.MAPPING.BULK_ACTIONS_ENABLE',
|
|
11
|
+
defaultMessage: 'Bulk actions'
|
|
12
|
+
}),
|
|
13
|
+
disableBatchSelection: formatMessage({
|
|
14
|
+
id: 'DS.MAPPING.BULK_ACTIONS_DISABLE',
|
|
15
|
+
defaultMessage: 'Hide actions'
|
|
16
|
+
})
|
|
17
|
+
}, defaultTexts);
|
|
18
|
+
}, [defaultTexts, formatMessage]);
|
|
19
|
+
return texts;
|
|
20
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './Mapping';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export var renderCounter = function renderCounter(selected, total) {
|
|
3
|
+
if (selected === 0) {
|
|
4
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, total, " Items");
|
|
5
|
+
}
|
|
6
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, selected, " Selected");
|
|
7
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@synerise/ds-mapping",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Mapping UI Component for the Synerise Design System",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"repository": "Synerise/synerise-design",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"files": [
|
|
9
|
+
"/dist",
|
|
10
|
+
"CHANGELOG.md",
|
|
11
|
+
"README.md",
|
|
12
|
+
"package.json",
|
|
13
|
+
"LICENSE.md"
|
|
14
|
+
],
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "npm run build:js && npm run build:css && npm run defs",
|
|
20
|
+
"build:css": "node ../../../scripts/style/less.js",
|
|
21
|
+
"build:js": "babel --delete-dir-on-start --root-mode upward src --out-dir dist --extensions '.js,.ts,.tsx'",
|
|
22
|
+
"build:watch": "npm run build:js -- --watch",
|
|
23
|
+
"defs": "tsc --declaration --outDir dist/ --emitDeclarationOnly",
|
|
24
|
+
"pack:ci": "npm pack --pack-destination ../../storybook/storybook-static/static",
|
|
25
|
+
"prepublish": "npm run build",
|
|
26
|
+
"test": "jest",
|
|
27
|
+
"test:watch": "npm run test -- --watchAll",
|
|
28
|
+
"types": "tsc --noEmit",
|
|
29
|
+
"upgrade:ds": "ncu -f \"@synerise/ds-*\" -u"
|
|
30
|
+
},
|
|
31
|
+
"sideEffects": [
|
|
32
|
+
"dist/style/*",
|
|
33
|
+
"*.less"
|
|
34
|
+
],
|
|
35
|
+
"types": "dist/index.d.ts",
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@synerise/ds-button": "^0.23.4",
|
|
38
|
+
"@synerise/ds-checkbox": "^0.13.7",
|
|
39
|
+
"@synerise/ds-checkbox-tristate": "^0.3.7",
|
|
40
|
+
"@synerise/ds-icon": "^0.72.1",
|
|
41
|
+
"@synerise/ds-tooltip": "^0.16.3",
|
|
42
|
+
"@synerise/ds-typography": "^0.17.7",
|
|
43
|
+
"@synerise/ds-utils": "^0.32.3"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"@synerise/ds-core": "*",
|
|
47
|
+
"antd": "4.24.16",
|
|
48
|
+
"react": ">=16.9.0 <= 18.3.1",
|
|
49
|
+
"react-intl": ">=3.12.0 <= 6.8",
|
|
50
|
+
"styled-components": "^5.3.3"
|
|
51
|
+
},
|
|
52
|
+
"gitHead": "8b368564f3d87695bc8df911803f8b3f8546d465"
|
|
53
|
+
}
|