@spaced-out/ui-design-system 0.0.67 → 0.1.0
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 +20 -0
- package/lib/components/ButtonDropdown/ButtonDropdown.js +4 -2
- package/lib/components/ButtonDropdown/ButtonDropdown.js.flow +8 -3
- package/lib/components/Checkbox/Checkbox.js +3 -2
- package/lib/components/Checkbox/Checkbox.js.flow +3 -1
- package/lib/components/Chip/Chip.module.css +1 -0
- package/lib/components/Dropdown/Dropdown.js +22 -28
- package/lib/components/Dropdown/Dropdown.js.flow +30 -47
- package/lib/components/Icon/ClickableIcon.js +1 -1
- package/lib/components/Icon/ClickableIcon.js.flow +1 -1
- package/lib/components/InlineDropdown/InlineDropdown.js +5 -2
- package/lib/components/InlineDropdown/InlineDropdown.js.flow +8 -2
- package/lib/components/Input/Input.js +2 -1
- package/lib/components/Input/Input.js.flow +1 -0
- package/lib/components/Input/Input.module.css +15 -2
- package/lib/components/Menu/Menu.js +8 -4
- package/lib/components/Menu/Menu.js.flow +43 -13
- package/lib/components/Menu/Menu.module.css +19 -2
- package/lib/components/Menu/MenuOptionButton.js +22 -3
- package/lib/components/Menu/MenuOptionButton.js.flow +37 -13
- package/lib/components/RadioButton/RadioButton.js +2 -1
- package/lib/components/RadioButton/RadioButton.js.flow +3 -1
- package/lib/components/SearchInput/SearchInput.js.flow +2 -22
- package/lib/components/Tabs/Tab/Tab.js +1 -1
- package/lib/components/Tabs/Tab/Tab.js.flow +1 -1
- package/lib/components/Tabs/TabList/TabList.js +2 -5
- package/lib/components/Tabs/TabList/TabList.js.flow +4 -7
- package/lib/components/Typeahead/Typeahead.js +23 -18
- package/lib/components/Typeahead/Typeahead.js.flow +32 -33
- package/lib/utils/menu.js +52 -0
- package/lib/utils/menu.js.flow +81 -0
- package/package.json +1 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// @flow strict
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
import type {MenuOption} from '../components/Menu';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export const getSelectedKeysFromSelectedOption = (
|
|
8
|
+
currentOption?: MenuOption,
|
|
9
|
+
currentSelectedKeys?: Array<string>,
|
|
10
|
+
): Array<string> => {
|
|
11
|
+
if (!Array.isArray(currentSelectedKeys) || !currentOption?.key) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let newSelectedKeys = [];
|
|
16
|
+
|
|
17
|
+
if (currentSelectedKeys.includes(currentOption.key)) {
|
|
18
|
+
newSelectedKeys = currentSelectedKeys.filter(
|
|
19
|
+
(item) => item !== currentOption.key,
|
|
20
|
+
);
|
|
21
|
+
} else {
|
|
22
|
+
newSelectedKeys = [...currentSelectedKeys, currentOption.key];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return newSelectedKeys;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const getTextLabelFromSelectedKeys = (
|
|
29
|
+
currentSelectedKeys?: Array<string>,
|
|
30
|
+
options?: MenuOption[],
|
|
31
|
+
): string => {
|
|
32
|
+
if (!Array.isArray(currentSelectedKeys) || !Array.isArray(options)) {
|
|
33
|
+
return '';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const selectedOptions = getOptionsFromKeys(options, currentSelectedKeys);
|
|
37
|
+
|
|
38
|
+
return selectedOptions.map((option) => option.label).join(', ');
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const getButtonLabelFromSelectedKeys = (
|
|
42
|
+
currentSelectedKeys?: Array<string>,
|
|
43
|
+
label?: React.Node,
|
|
44
|
+
): React.Node => {
|
|
45
|
+
if (
|
|
46
|
+
!Array.isArray(currentSelectedKeys) ||
|
|
47
|
+
typeof label !== 'string' ||
|
|
48
|
+
!currentSelectedKeys.length
|
|
49
|
+
) {
|
|
50
|
+
return label;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return `(${currentSelectedKeys.length}) ${label}`;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const getOptionFromKey = (
|
|
57
|
+
options?: MenuOption[],
|
|
58
|
+
key?: string,
|
|
59
|
+
): ?MenuOption => {
|
|
60
|
+
if (!Array.isArray(options) || !key || !options.length) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return options.find((option) => option.key === key);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const getOptionsFromKeys = (
|
|
68
|
+
options?: MenuOption[],
|
|
69
|
+
keys?: Array<string>,
|
|
70
|
+
): Array<MenuOption> => {
|
|
71
|
+
if (
|
|
72
|
+
!Array.isArray(options) ||
|
|
73
|
+
!Array.isArray(keys) ||
|
|
74
|
+
!options.length ||
|
|
75
|
+
!keys.length
|
|
76
|
+
) {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return options.filter((option) => keys.includes(option.key));
|
|
81
|
+
};
|