colibri-ui 0.8.8 → 0.8.10
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/Avatar/index.js +4 -4
- package/Avatar/index.props.d.ts +1 -1
- package/MultiSelect/components/MenuOverlay/index.js +4 -1
- package/MultiSelect/index.js +32 -30
- package/MultiSelect/index.props.d.ts +6 -1
- package/MultiSelect/utils/index.d.ts +3 -1
- package/MultiSelect/utils/index.js +16 -4
- package/esm/Avatar/index.js +4 -4
- package/esm/Avatar/index.props.d.ts +1 -1
- package/esm/MultiSelect/components/MenuOverlay/index.js +5 -2
- package/esm/MultiSelect/index.js +34 -32
- package/esm/MultiSelect/index.props.d.ts +6 -1
- package/esm/MultiSelect/utils/index.d.ts +3 -1
- package/esm/MultiSelect/utils/index.js +15 -4
- package/package.json +1 -1
package/Avatar/index.js
CHANGED
|
@@ -36,10 +36,10 @@ var Avatar = /*#__PURE__*/React.memo(function (props) {
|
|
|
36
36
|
accountType = _c === void 0 ? index_props.AccountType.Organization : _c,
|
|
37
37
|
onClick = props.onClick,
|
|
38
38
|
initials = props.initials,
|
|
39
|
-
|
|
39
|
+
loading = props.loading,
|
|
40
40
|
ariaLabel = props.ariaLabel,
|
|
41
41
|
ref = props.ref,
|
|
42
|
-
rest = tslib.__rest(props, ["src", "size", "className", "bordered", "alt", "accountType", "onClick", "initials", "
|
|
42
|
+
rest = tslib.__rest(props, ["src", "size", "className", "bordered", "alt", "accountType", "onClick", "initials", "loading", "ariaLabel", "ref"]);
|
|
43
43
|
if ((initials === null || initials === void 0 ? void 0 : initials.trim()) && initials.length <= 2) {
|
|
44
44
|
return (
|
|
45
45
|
/*#__PURE__*/
|
|
@@ -52,7 +52,7 @@ var Avatar = /*#__PURE__*/React.memo(function (props) {
|
|
|
52
52
|
onClick: onClick,
|
|
53
53
|
className: clx(styles__default.default.avatarInitials, {
|
|
54
54
|
avatarBordered: !!bordered,
|
|
55
|
-
|
|
55
|
+
loading: !!loading
|
|
56
56
|
}, SIZE_CLASSES[size], className)
|
|
57
57
|
}, rest), /*#__PURE__*/React__default.default.createElement("span", {
|
|
58
58
|
className: clx(styles__default.default.initialsText, TEXT_CLASSES[size])
|
|
@@ -65,7 +65,7 @@ var Avatar = /*#__PURE__*/React.memo(function (props) {
|
|
|
65
65
|
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,
|
|
66
66
|
React__default.default.createElement("div", {
|
|
67
67
|
className: clx(styles__default.default.avatarWrapper, {
|
|
68
|
-
avatarLoader: !!
|
|
68
|
+
avatarLoader: !!loading
|
|
69
69
|
}),
|
|
70
70
|
onClick: onClick,
|
|
71
71
|
role: "button",
|
package/Avatar/index.props.d.ts
CHANGED
|
@@ -92,7 +92,10 @@ var MenuOverlay = function MenuOverlay(_a) {
|
|
|
92
92
|
option: option,
|
|
93
93
|
key: "item-".concat(optionIndex),
|
|
94
94
|
onClick: function onClick() {
|
|
95
|
-
return onChange(index$4.
|
|
95
|
+
return onChange(index$4.toKey({
|
|
96
|
+
group: group.value,
|
|
97
|
+
option: option.value
|
|
98
|
+
}));
|
|
96
99
|
}
|
|
97
100
|
});
|
|
98
101
|
})));
|
package/MultiSelect/index.js
CHANGED
|
@@ -23,21 +23,6 @@ var classNames__default = /*#__PURE__*/_interopDefault(classNames);
|
|
|
23
23
|
var styles__default = /*#__PURE__*/_interopDefault(styles);
|
|
24
24
|
|
|
25
25
|
var clx = classNames__default.default.bind(styles__default.default);
|
|
26
|
-
var sortItems = function sortItems(items) {
|
|
27
|
-
return tslib.__spreadArray([], items, true).sort(function (a, b) {
|
|
28
|
-
var parseKey = function parseKey(key) {
|
|
29
|
-
var _a;
|
|
30
|
-
return ((_a = key.match(/group-(\d+)-option-(\d+)/)) === null || _a === void 0 ? void 0 : _a.slice(1).map(Number)) || [];
|
|
31
|
-
};
|
|
32
|
-
var _a = parseKey(a),
|
|
33
|
-
groupA = _a[0],
|
|
34
|
-
optionA = _a[1];
|
|
35
|
-
var _b = parseKey(b),
|
|
36
|
-
groupB = _b[0],
|
|
37
|
-
optionB = _b[1];
|
|
38
|
-
return groupA - groupB || optionA - optionB;
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
26
|
var getValue = function getValue(options) {
|
|
42
27
|
return options.map(function (_a) {
|
|
43
28
|
var label = _a.label;
|
|
@@ -60,30 +45,42 @@ var MultiSelect = function MultiSelect(_a) {
|
|
|
60
45
|
size = _c === void 0 ? "m" : _c,
|
|
61
46
|
placeholder = _a.placeholder,
|
|
62
47
|
name = _a.name,
|
|
48
|
+
_d = _a.value,
|
|
49
|
+
value = _d === void 0 ? [] : _d,
|
|
63
50
|
type = _a.type,
|
|
64
51
|
onChange = _a.onChange;
|
|
65
|
-
var
|
|
66
|
-
isOpen =
|
|
67
|
-
setIsOpen =
|
|
68
|
-
var
|
|
69
|
-
|
|
70
|
-
|
|
52
|
+
var _e = React.useState(false),
|
|
53
|
+
isOpen = _e[0],
|
|
54
|
+
setIsOpen = _e[1];
|
|
55
|
+
var _f = React.useState(value || []),
|
|
56
|
+
selected = _f[0],
|
|
57
|
+
setSelected = _f[1];
|
|
58
|
+
var internalSelectedKeys = React.useMemo(function () {
|
|
59
|
+
return selected.map(index.toKey);
|
|
60
|
+
}, [selected]);
|
|
71
61
|
var preparedGroups = React.useMemo(function () {
|
|
72
62
|
return groups.map(function (group) {
|
|
73
63
|
return tslib.__assign(tslib.__assign({}, group), {
|
|
74
64
|
options: group.options.map(function (option) {
|
|
75
65
|
return tslib.__assign(tslib.__assign({}, option), {
|
|
76
|
-
selected:
|
|
66
|
+
selected: internalSelectedKeys.includes(index.toKey({
|
|
67
|
+
group: group.value,
|
|
68
|
+
option: option.value
|
|
69
|
+
}))
|
|
77
70
|
});
|
|
78
71
|
})
|
|
79
72
|
});
|
|
80
73
|
});
|
|
81
|
-
}, [
|
|
74
|
+
}, [groups, internalSelectedKeys]);
|
|
82
75
|
var handleChange = React.useCallback(function (key) {
|
|
83
|
-
|
|
84
|
-
var
|
|
85
|
-
return v
|
|
86
|
-
})
|
|
76
|
+
setSelected(function (prev) {
|
|
77
|
+
var exists = prev.some(function (v) {
|
|
78
|
+
return index.toKey(v) === key;
|
|
79
|
+
});
|
|
80
|
+
var item = index.fromKey(key);
|
|
81
|
+
var newValue = exists ? prev.filter(function (v) {
|
|
82
|
+
return index.toKey(v) !== key;
|
|
83
|
+
}) : tslib.__spreadArray(tslib.__spreadArray([], prev, true), [item], false);
|
|
87
84
|
onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
|
|
88
85
|
return newValue;
|
|
89
86
|
});
|
|
@@ -92,7 +89,9 @@ var MultiSelect = function MultiSelect(_a) {
|
|
|
92
89
|
return preparedGroups.flatMap(function (_a) {
|
|
93
90
|
var groupVal = _a.value,
|
|
94
91
|
options = _a.options;
|
|
95
|
-
return options
|
|
92
|
+
return options
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
94
|
+
.filter(function (_a) {
|
|
96
95
|
var selected = _a.selected;
|
|
97
96
|
return selected;
|
|
98
97
|
}).map(
|
|
@@ -102,7 +101,10 @@ var MultiSelect = function MultiSelect(_a) {
|
|
|
102
101
|
optVal = _a.value;
|
|
103
102
|
return {
|
|
104
103
|
label: label,
|
|
105
|
-
key: index.
|
|
104
|
+
key: index.toKey({
|
|
105
|
+
group: groupVal,
|
|
106
|
+
option: optVal
|
|
107
|
+
})
|
|
106
108
|
};
|
|
107
109
|
});
|
|
108
110
|
});
|
|
@@ -162,7 +164,7 @@ var MultiSelect = function MultiSelect(_a) {
|
|
|
162
164
|
type: "hidden",
|
|
163
165
|
name: name,
|
|
164
166
|
tabIndex: -1,
|
|
165
|
-
value:
|
|
167
|
+
value: internalSelectedKeys.join(",") || ""
|
|
166
168
|
}))));
|
|
167
169
|
};
|
|
168
170
|
|
|
@@ -15,6 +15,10 @@ export type GroupProps = {
|
|
|
15
15
|
};
|
|
16
16
|
type Size = "s" | "m" | "l";
|
|
17
17
|
type Type = "chip";
|
|
18
|
+
export type SelectedItem = {
|
|
19
|
+
group: string;
|
|
20
|
+
option: string;
|
|
21
|
+
};
|
|
18
22
|
export interface MultiSelectProps extends Omit<FormFieldProps, "children"> {
|
|
19
23
|
groups: GroupProps[];
|
|
20
24
|
className?: string;
|
|
@@ -27,6 +31,7 @@ export interface MultiSelectProps extends Omit<FormFieldProps, "children"> {
|
|
|
27
31
|
placeholder?: string;
|
|
28
32
|
name?: string;
|
|
29
33
|
type?: Type;
|
|
30
|
-
|
|
34
|
+
value?: SelectedItem[];
|
|
35
|
+
onChange?: (value: SelectedItem[]) => void;
|
|
31
36
|
}
|
|
32
37
|
export {};
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { SelectedItem } from "../index.props";
|
|
2
|
+
export declare const toKey: ({ group, option }: SelectedItem) => string;
|
|
3
|
+
export declare const fromKey: (key: string) => SelectedItem;
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
var toKey = function toKey(_a) {
|
|
4
|
+
var group = _a.group,
|
|
5
|
+
option = _a.option;
|
|
6
|
+
return "group-".concat(group, "-option-").concat(option);
|
|
7
|
+
};
|
|
8
|
+
var fromKey = function fromKey(key) {
|
|
9
|
+
var _a = key.replace(/^group-/, "").split("-option-"),
|
|
10
|
+
group = _a[0],
|
|
11
|
+
option = _a[1];
|
|
12
|
+
return {
|
|
13
|
+
group: group,
|
|
14
|
+
option: option
|
|
15
|
+
};
|
|
16
|
+
};
|
|
6
17
|
|
|
7
|
-
exports.
|
|
18
|
+
exports.fromKey = fromKey;
|
|
19
|
+
exports.toKey = toKey;
|
package/esm/Avatar/index.js
CHANGED
|
@@ -26,10 +26,10 @@ var Avatar = /*#__PURE__*/memo(function (props) {
|
|
|
26
26
|
accountType = _c === void 0 ? AccountType.Organization : _c,
|
|
27
27
|
onClick = props.onClick,
|
|
28
28
|
initials = props.initials,
|
|
29
|
-
|
|
29
|
+
loading = props.loading,
|
|
30
30
|
ariaLabel = props.ariaLabel,
|
|
31
31
|
ref = props.ref,
|
|
32
|
-
rest = __rest(props, ["src", "size", "className", "bordered", "alt", "accountType", "onClick", "initials", "
|
|
32
|
+
rest = __rest(props, ["src", "size", "className", "bordered", "alt", "accountType", "onClick", "initials", "loading", "ariaLabel", "ref"]);
|
|
33
33
|
if ((initials === null || initials === void 0 ? void 0 : initials.trim()) && initials.length <= 2) {
|
|
34
34
|
return (
|
|
35
35
|
/*#__PURE__*/
|
|
@@ -42,7 +42,7 @@ var Avatar = /*#__PURE__*/memo(function (props) {
|
|
|
42
42
|
onClick: onClick,
|
|
43
43
|
className: clx(styles.avatarInitials, {
|
|
44
44
|
avatarBordered: !!bordered,
|
|
45
|
-
|
|
45
|
+
loading: !!loading
|
|
46
46
|
}, SIZE_CLASSES[size], className)
|
|
47
47
|
}, rest), /*#__PURE__*/React__default.createElement("span", {
|
|
48
48
|
className: clx(styles.initialsText, TEXT_CLASSES[size])
|
|
@@ -55,7 +55,7 @@ var Avatar = /*#__PURE__*/memo(function (props) {
|
|
|
55
55
|
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,
|
|
56
56
|
React__default.createElement("div", {
|
|
57
57
|
className: clx(styles.avatarWrapper, {
|
|
58
|
-
avatarLoader: !!
|
|
58
|
+
avatarLoader: !!loading
|
|
59
59
|
}),
|
|
60
60
|
onClick: onClick,
|
|
61
61
|
role: "button",
|
|
@@ -4,7 +4,7 @@ import Menu from '../../../Menu/index.js';
|
|
|
4
4
|
import SelectItem from '../MenuOverlayItem/index.js';
|
|
5
5
|
import Typography from '../../../Typography/index.js';
|
|
6
6
|
import Separator from '../../../Separator/index.js';
|
|
7
|
-
import {
|
|
7
|
+
import { toKey } from '../../utils/index.js';
|
|
8
8
|
import styles from './index.module.css';
|
|
9
9
|
|
|
10
10
|
var clx = classNames.bind(styles);
|
|
@@ -82,7 +82,10 @@ var MenuOverlay = function MenuOverlay(_a) {
|
|
|
82
82
|
option: option,
|
|
83
83
|
key: "item-".concat(optionIndex),
|
|
84
84
|
onClick: function onClick() {
|
|
85
|
-
return onChange(
|
|
85
|
+
return onChange(toKey({
|
|
86
|
+
group: group.value,
|
|
87
|
+
option: option.value
|
|
88
|
+
}));
|
|
86
89
|
}
|
|
87
90
|
});
|
|
88
91
|
})));
|
package/esm/MultiSelect/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __assign, __spreadArray } from 'tslib';
|
|
2
2
|
import React__default, { useState, useMemo, useCallback } from 'react';
|
|
3
3
|
import classNames from 'classnames/bind';
|
|
4
4
|
import Dropdown from '../Dropdown/index.js';
|
|
@@ -8,26 +8,11 @@ import '../Icons/index.js';
|
|
|
8
8
|
import Chip from '../Chip/index.js';
|
|
9
9
|
import styles from './index.module.css';
|
|
10
10
|
import MenuOverlay from './components/MenuOverlay/index.js';
|
|
11
|
-
import {
|
|
11
|
+
import { toKey, fromKey } from './utils/index.js';
|
|
12
12
|
import Chevron from '../Icons/Chevron.js';
|
|
13
13
|
import CrossFill from '../Icons/CrossFill.js';
|
|
14
14
|
|
|
15
15
|
var clx = classNames.bind(styles);
|
|
16
|
-
var sortItems = function sortItems(items) {
|
|
17
|
-
return __spreadArray([], items, true).sort(function (a, b) {
|
|
18
|
-
var parseKey = function parseKey(key) {
|
|
19
|
-
var _a;
|
|
20
|
-
return ((_a = key.match(/group-(\d+)-option-(\d+)/)) === null || _a === void 0 ? void 0 : _a.slice(1).map(Number)) || [];
|
|
21
|
-
};
|
|
22
|
-
var _a = parseKey(a),
|
|
23
|
-
groupA = _a[0],
|
|
24
|
-
optionA = _a[1];
|
|
25
|
-
var _b = parseKey(b),
|
|
26
|
-
groupB = _b[0],
|
|
27
|
-
optionB = _b[1];
|
|
28
|
-
return groupA - groupB || optionA - optionB;
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
16
|
var getValue = function getValue(options) {
|
|
32
17
|
return options.map(function (_a) {
|
|
33
18
|
var label = _a.label;
|
|
@@ -50,30 +35,42 @@ var MultiSelect = function MultiSelect(_a) {
|
|
|
50
35
|
size = _c === void 0 ? "m" : _c,
|
|
51
36
|
placeholder = _a.placeholder,
|
|
52
37
|
name = _a.name,
|
|
38
|
+
_d = _a.value,
|
|
39
|
+
value = _d === void 0 ? [] : _d,
|
|
53
40
|
type = _a.type,
|
|
54
41
|
onChange = _a.onChange;
|
|
55
|
-
var
|
|
56
|
-
isOpen =
|
|
57
|
-
setIsOpen =
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
|
|
42
|
+
var _e = useState(false),
|
|
43
|
+
isOpen = _e[0],
|
|
44
|
+
setIsOpen = _e[1];
|
|
45
|
+
var _f = useState(value || []),
|
|
46
|
+
selected = _f[0],
|
|
47
|
+
setSelected = _f[1];
|
|
48
|
+
var internalSelectedKeys = useMemo(function () {
|
|
49
|
+
return selected.map(toKey);
|
|
50
|
+
}, [selected]);
|
|
61
51
|
var preparedGroups = useMemo(function () {
|
|
62
52
|
return groups.map(function (group) {
|
|
63
53
|
return __assign(__assign({}, group), {
|
|
64
54
|
options: group.options.map(function (option) {
|
|
65
55
|
return __assign(__assign({}, option), {
|
|
66
|
-
selected:
|
|
56
|
+
selected: internalSelectedKeys.includes(toKey({
|
|
57
|
+
group: group.value,
|
|
58
|
+
option: option.value
|
|
59
|
+
}))
|
|
67
60
|
});
|
|
68
61
|
})
|
|
69
62
|
});
|
|
70
63
|
});
|
|
71
|
-
}, [
|
|
64
|
+
}, [groups, internalSelectedKeys]);
|
|
72
65
|
var handleChange = useCallback(function (key) {
|
|
73
|
-
|
|
74
|
-
var
|
|
75
|
-
return v
|
|
76
|
-
})
|
|
66
|
+
setSelected(function (prev) {
|
|
67
|
+
var exists = prev.some(function (v) {
|
|
68
|
+
return toKey(v) === key;
|
|
69
|
+
});
|
|
70
|
+
var item = fromKey(key);
|
|
71
|
+
var newValue = exists ? prev.filter(function (v) {
|
|
72
|
+
return toKey(v) !== key;
|
|
73
|
+
}) : __spreadArray(__spreadArray([], prev, true), [item], false);
|
|
77
74
|
onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
|
|
78
75
|
return newValue;
|
|
79
76
|
});
|
|
@@ -82,7 +79,9 @@ var MultiSelect = function MultiSelect(_a) {
|
|
|
82
79
|
return preparedGroups.flatMap(function (_a) {
|
|
83
80
|
var groupVal = _a.value,
|
|
84
81
|
options = _a.options;
|
|
85
|
-
return options
|
|
82
|
+
return options
|
|
83
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
84
|
+
.filter(function (_a) {
|
|
86
85
|
var selected = _a.selected;
|
|
87
86
|
return selected;
|
|
88
87
|
}).map(
|
|
@@ -92,7 +91,10 @@ var MultiSelect = function MultiSelect(_a) {
|
|
|
92
91
|
optVal = _a.value;
|
|
93
92
|
return {
|
|
94
93
|
label: label,
|
|
95
|
-
key:
|
|
94
|
+
key: toKey({
|
|
95
|
+
group: groupVal,
|
|
96
|
+
option: optVal
|
|
97
|
+
})
|
|
96
98
|
};
|
|
97
99
|
});
|
|
98
100
|
});
|
|
@@ -152,7 +154,7 @@ var MultiSelect = function MultiSelect(_a) {
|
|
|
152
154
|
type: "hidden",
|
|
153
155
|
name: name,
|
|
154
156
|
tabIndex: -1,
|
|
155
|
-
value:
|
|
157
|
+
value: internalSelectedKeys.join(",") || ""
|
|
156
158
|
}))));
|
|
157
159
|
};
|
|
158
160
|
|
|
@@ -15,6 +15,10 @@ export type GroupProps = {
|
|
|
15
15
|
};
|
|
16
16
|
type Size = "s" | "m" | "l";
|
|
17
17
|
type Type = "chip";
|
|
18
|
+
export type SelectedItem = {
|
|
19
|
+
group: string;
|
|
20
|
+
option: string;
|
|
21
|
+
};
|
|
18
22
|
export interface MultiSelectProps extends Omit<FormFieldProps, "children"> {
|
|
19
23
|
groups: GroupProps[];
|
|
20
24
|
className?: string;
|
|
@@ -27,6 +31,7 @@ export interface MultiSelectProps extends Omit<FormFieldProps, "children"> {
|
|
|
27
31
|
placeholder?: string;
|
|
28
32
|
name?: string;
|
|
29
33
|
type?: Type;
|
|
30
|
-
|
|
34
|
+
value?: SelectedItem[];
|
|
35
|
+
onChange?: (value: SelectedItem[]) => void;
|
|
31
36
|
}
|
|
32
37
|
export {};
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { SelectedItem } from "../index.props";
|
|
2
|
+
export declare const toKey: ({ group, option }: SelectedItem) => string;
|
|
3
|
+
export declare const fromKey: (key: string) => SelectedItem;
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
var toKey = function toKey(_a) {
|
|
2
|
+
var group = _a.group,
|
|
3
|
+
option = _a.option;
|
|
4
|
+
return "group-".concat(group, "-option-").concat(option);
|
|
5
|
+
};
|
|
6
|
+
var fromKey = function fromKey(key) {
|
|
7
|
+
var _a = key.replace(/^group-/, "").split("-option-"),
|
|
8
|
+
group = _a[0],
|
|
9
|
+
option = _a[1];
|
|
10
|
+
return {
|
|
11
|
+
group: group,
|
|
12
|
+
option: option
|
|
13
|
+
};
|
|
14
|
+
};
|
|
4
15
|
|
|
5
|
-
export {
|
|
16
|
+
export { fromKey, toKey };
|