@evoke-platform/ui-components 1.0.0-dev.195 → 1.0.0-dev.197
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.
@@ -7,7 +7,7 @@ import { DndContext, closestCenter, KeyboardSensor, PointerSensor, useSensor, us
|
|
7
7
|
import { SortableContext, sortableKeyboardCoordinates, verticalListSortingStrategy } from '@dnd-kit/sortable';
|
8
8
|
import { restrictToVerticalAxis, restrictToWindowEdges } from '@dnd-kit/modifiers';
|
9
9
|
import { SortableItem } from './SortableItem';
|
10
|
-
import { Tooltip } from '../../core';
|
10
|
+
import { Link, Tooltip } from '../../core';
|
11
11
|
const styles = {
|
12
12
|
textField: {
|
13
13
|
borderRadius: '8px',
|
@@ -51,6 +51,7 @@ export default function MultiSelect(props) {
|
|
51
51
|
const [optionsArray, setOptions] = useState(options);
|
52
52
|
const [selectAll, setSelectAll] = useState(false);
|
53
53
|
const [searchText, setSearchText] = useState('');
|
54
|
+
const [deletedOptions] = useState(options.filter((opt) => opt.deleted).map((opt) => { var _a; return (_a = opt.id) !== null && _a !== void 0 ? _a : ''; }));
|
54
55
|
const sensors = useSensors(useSensor(PointerSensor), useSensor(KeyboardSensor, {
|
55
56
|
coordinateGetter: sortableKeyboardCoordinates,
|
56
57
|
}), useSensor(PointerSensor, {
|
@@ -96,6 +97,16 @@ export default function MultiSelect(props) {
|
|
96
97
|
updateOptions(false);
|
97
98
|
setSelectAll(false);
|
98
99
|
};
|
100
|
+
const handleDeletedOptions = (event) => {
|
101
|
+
const newOptions = optionsArray.map((option) => {
|
102
|
+
if (option.id && deletedOptions.includes(option.id)) {
|
103
|
+
option.value = false;
|
104
|
+
}
|
105
|
+
return option;
|
106
|
+
});
|
107
|
+
onChange(newOptions);
|
108
|
+
setOptions(newOptions);
|
109
|
+
};
|
99
110
|
const filterItems = (event) => {
|
100
111
|
setSearchText(event.target.value);
|
101
112
|
const keyword = event.target.value.toLowerCase();
|
@@ -137,12 +148,19 @@ export default function MultiSelect(props) {
|
|
137
148
|
startAdornment: (React.createElement(InputAdornment, { position: "start" },
|
138
149
|
React.createElement(Search, null))),
|
139
150
|
}, fullWidth: true, sx: styles.textField, value: searchText, onChange: filterItems }))),
|
140
|
-
(optionsArray === null || optionsArray === void 0 ? void 0 : optionsArray.length)
|
141
|
-
React.createElement(Grid,
|
142
|
-
React.createElement(
|
143
|
-
|
144
|
-
|
145
|
-
|
151
|
+
(optionsArray === null || optionsArray === void 0 ? void 0 : optionsArray.length) ? (React.createElement(Grid, { container: true },
|
152
|
+
deletedOptions.length ? (React.createElement(Grid, { item: true, xs: 6, sx: { display: 'flex', justifyContent: 'start', textAlign: 'center' } },
|
153
|
+
React.createElement(Link, { sx: {
|
154
|
+
color: 'red',
|
155
|
+
'&:hover': { backgroundColor: 'transparent', cursor: 'pointer' },
|
156
|
+
textDecoration: 'none',
|
157
|
+
margin: '8px',
|
158
|
+
}, onClick: (e) => handleDeletedOptions(e) }, `Clear ${deletedOptions.length} deleted fields`))) : (React.createElement(React.Fragment, null)),
|
159
|
+
React.createElement(Grid, { item: true, xs: 3 },
|
160
|
+
React.createElement(Button, { sx: Object.assign(Object.assign({}, styles.button), { fontWeight: 'bold' }), variant: "text", onClick: (e) => handleSelectAllChange(e), disabled: optionsArray.every((option) => option.disabled === true || selectAll) }, "Select All")),
|
161
|
+
React.createElement(Grid, { item: true, xs: 3 },
|
162
|
+
React.createElement(Button, { sx: Object.assign(Object.assign({}, styles.button), { color: 'gray', fontWeight: 'bold' }), variant: "text", onClick: (e) => handleClearAll(e), disabled: optionsArray.every((option) => option.disabled === true) ||
|
163
|
+
optionsArray.every((option) => option.value === false) }, "Clear All")))) : (React.createElement(React.Fragment, null)),
|
146
164
|
React.createElement(Box, { sx: Object.assign(Object.assign({}, styles.list), { maxHeight: maxHeight !== null && maxHeight !== void 0 ? maxHeight : 'auto' }) }, isSortable ? (React.createElement(DndContext, { sensors: sensors, collisionDetection: closestCenter, onDragEnd: handleDragEnd, modifiers: [restrictToVerticalAxis, restrictToWindowEdges] },
|
147
165
|
React.createElement(SortableContext, { items: optionsArray, strategy: verticalListSortingStrategy }, optionsArray.map((option) => {
|
148
166
|
var _a, _b;
|