@spaced-out/ui-design-system 0.0.68 → 0.1.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/lib/components/ButtonDropdown/ButtonDropdown.js +4 -2
  3. package/lib/components/ButtonDropdown/ButtonDropdown.js.flow +8 -3
  4. package/lib/components/Checkbox/Checkbox.js +3 -2
  5. package/lib/components/Checkbox/Checkbox.js.flow +3 -1
  6. package/lib/components/Chip/Chip.module.css +1 -0
  7. package/lib/components/Dropdown/Dropdown.js +22 -28
  8. package/lib/components/Dropdown/Dropdown.js.flow +30 -47
  9. package/lib/components/Icon/ClickableIcon.js +9 -6
  10. package/lib/components/Icon/ClickableIcon.js.flow +57 -45
  11. package/lib/components/InlineDropdown/InlineDropdown.js +5 -2
  12. package/lib/components/InlineDropdown/InlineDropdown.js.flow +8 -2
  13. package/lib/components/Input/Input.js +2 -1
  14. package/lib/components/Input/Input.js.flow +1 -0
  15. package/lib/components/Input/Input.module.css +15 -2
  16. package/lib/components/Menu/Menu.js +8 -4
  17. package/lib/components/Menu/Menu.js.flow +44 -13
  18. package/lib/components/Menu/Menu.module.css +19 -2
  19. package/lib/components/Menu/MenuOptionButton.js +24 -4
  20. package/lib/components/Menu/MenuOptionButton.js.flow +38 -13
  21. package/lib/components/RadioButton/RadioButton.js +2 -1
  22. package/lib/components/RadioButton/RadioButton.js.flow +3 -1
  23. package/lib/components/SearchInput/SearchInput.js.flow +2 -22
  24. package/lib/components/Tabs/Tab/Tab.js +1 -1
  25. package/lib/components/Tabs/Tab/Tab.js.flow +1 -1
  26. package/lib/components/Tabs/TabList/TabList.js +2 -5
  27. package/lib/components/Tabs/TabList/TabList.js.flow +4 -7
  28. package/lib/components/Tooltip/Tooltip.js +1 -0
  29. package/lib/components/Tooltip/Tooltip.js.flow +1 -0
  30. package/lib/components/Typeahead/Typeahead.js +23 -18
  31. package/lib/components/Typeahead/Typeahead.js.flow +32 -33
  32. package/lib/utils/menu.js +52 -0
  33. package/lib/utils/menu.js.flow +81 -0
  34. package/package.json +1 -1
@@ -17,7 +17,8 @@ import {sizeFluid} from '../../styles/variables/_size';
17
17
  import {spaceNone, spaceXXSmall} from '../../styles/variables/_space';
18
18
  import {classify} from '../../utils/classify';
19
19
  import {ClickAway} from '../../utils/click-away';
20
- import type {MenuOption} from '../Menu';
20
+ import type {InputProps} from '../Input';
21
+ import type {MenuOption, MenuProps} from '../Menu';
21
22
  import {Menu} from '../Menu';
22
23
  import {SearchInput} from '../SearchInput';
23
24
 
@@ -27,43 +28,34 @@ import css from './Typeahead.module.css';
27
28
  type ClassNames = $ReadOnly<{wrapper?: string, box?: string}>;
28
29
 
29
30
  export type TypeaheadProps = {
31
+ ...InputProps,
30
32
  classNames?: ClassNames,
31
33
  onSelect?: (option: MenuOption) => mixed,
32
34
  onSearch?: (evt: SyntheticInputEvent<HTMLInputElement>) => mixed,
33
- onFocus?: (e: SyntheticInputEvent<HTMLInputElement>) => mixed,
34
- onBlur?: (e: SyntheticInputEvent<HTMLInputElement>) => mixed,
35
- name?: string,
36
- disabled?: boolean,
37
- placeholder?: string,
38
- locked?: boolean,
39
- error?: boolean,
40
- errorText?: string,
41
- label?: string | React.Node,
42
- helperText?: string | React.Node,
43
- size?: 'medium' | 'small',
44
- required?: boolean,
45
- options?: Array<MenuOption>,
46
- selectedOption?: MenuOption,
47
- menuSize?: 'medium' | 'small',
35
+ onMenuOpen?: () => mixed,
36
+ onMenuClose?: () => mixed,
37
+ typeaheadInputText?: string,
38
+ menu?: MenuProps,
48
39
  onClear?: () => void,
49
40
  };
50
41
 
51
42
  export const Typeahead = ({
52
- options,
53
- size,
43
+ size = 'medium',
54
44
  classNames,
55
45
  placeholder = 'Select...',
56
46
  onSelect,
57
47
  onSearch,
58
- selectedOption,
59
- menuSize,
60
48
  onClear,
49
+ menu,
50
+ onMenuOpen,
51
+ onMenuClose,
52
+ typeaheadInputText,
61
53
  ...inputProps
62
54
  }: TypeaheadProps): React.Node => {
63
55
  const typeaheadRef = React.useRef();
64
56
 
65
- const [inputValue, setInputValue] = React.useState(selectedOption?.label);
66
- const [filteredOptions, setFilteredOptions] = React.useState(options);
57
+ const [inputValue, setInputValue] = React.useState(typeaheadInputText || '');
58
+ const [filteredOptions, setFilteredOptions] = React.useState(menu?.options);
67
59
 
68
60
  const {x, y, reference, floating, strategy} = useFloating({
69
61
  strategy: 'absolute',
@@ -80,15 +72,17 @@ export const Typeahead = ({
80
72
  };
81
73
 
82
74
  React.useEffect(() => {
83
- if (selectedOption?.key) {
84
- setInputValue(selectedOption.label);
85
- }
86
- }, [selectedOption]);
75
+ setInputValue(typeaheadInputText || '');
76
+ }, [typeaheadInputText]);
77
+
78
+ const onMenuToggle = (isOpen: boolean) => {
79
+ isOpen ? onMenuOpen && onMenuOpen() : onMenuClose && onMenuClose();
80
+ };
87
81
 
88
82
  React.useEffect(() => {
89
83
  const optionsFiltered =
90
- options &&
91
- options.filter((option) => {
84
+ menu?.options &&
85
+ menu.options.filter((option) => {
92
86
  if (!option.label || !inputValue) {
93
87
  return true;
94
88
  } else {
@@ -101,7 +95,7 @@ export const Typeahead = ({
101
95
  }, [inputValue]);
102
96
 
103
97
  return (
104
- <ClickAway>
98
+ <ClickAway onChange={onMenuToggle}>
105
99
  {({isOpen, onOpen, cancelNext, clickAway}) => (
106
100
  <div
107
101
  data-testid="Typeahead"
@@ -131,7 +125,7 @@ export const Typeahead = ({
131
125
  }}
132
126
  />
133
127
 
134
- {isOpen && filteredOptions && !!filteredOptions.length && (
128
+ {isOpen && menu && filteredOptions && !!filteredOptions.length && (
135
129
  <div
136
130
  onClickCapture={cancelNext}
137
131
  ref={floating}
@@ -144,13 +138,18 @@ export const Typeahead = ({
144
138
  }}
145
139
  >
146
140
  <Menu
147
- isFluid
141
+ {...menu}
148
142
  options={filteredOptions}
149
143
  onSelect={(option) => {
150
144
  handleSelect(option);
151
- clickAway();
145
+ if (
146
+ !menu.optionsVariant ||
147
+ menu.optionsVariant === 'normal'
148
+ ) {
149
+ clickAway();
150
+ }
152
151
  }}
153
- size={menuSize || size}
152
+ size={menu.size || size}
154
153
  />
155
154
  </div>
156
155
  )}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getTextLabelFromSelectedKeys = exports.getSelectedKeysFromSelectedOption = exports.getOptionsFromKeys = exports.getOptionFromKey = exports.getButtonLabelFromSelectedKeys = void 0;
7
+ var React = _interopRequireWildcard(require("react"));
8
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
9
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
10
+
11
+ const getSelectedKeysFromSelectedOption = (currentOption, currentSelectedKeys) => {
12
+ if (!Array.isArray(currentSelectedKeys) || !currentOption?.key) {
13
+ return [];
14
+ }
15
+ let newSelectedKeys = [];
16
+ if (currentSelectedKeys.includes(currentOption.key)) {
17
+ newSelectedKeys = currentSelectedKeys.filter(item => item !== currentOption.key);
18
+ } else {
19
+ newSelectedKeys = [...currentSelectedKeys, currentOption.key];
20
+ }
21
+ return newSelectedKeys;
22
+ };
23
+ exports.getSelectedKeysFromSelectedOption = getSelectedKeysFromSelectedOption;
24
+ const getTextLabelFromSelectedKeys = (currentSelectedKeys, options) => {
25
+ if (!Array.isArray(currentSelectedKeys) || !Array.isArray(options)) {
26
+ return '';
27
+ }
28
+ const selectedOptions = getOptionsFromKeys(options, currentSelectedKeys);
29
+ return selectedOptions.map(option => option.label).join(', ');
30
+ };
31
+ exports.getTextLabelFromSelectedKeys = getTextLabelFromSelectedKeys;
32
+ const getButtonLabelFromSelectedKeys = (currentSelectedKeys, label) => {
33
+ if (!Array.isArray(currentSelectedKeys) || typeof label !== 'string' || !currentSelectedKeys.length) {
34
+ return label;
35
+ }
36
+ return `(${currentSelectedKeys.length}) ${label}`;
37
+ };
38
+ exports.getButtonLabelFromSelectedKeys = getButtonLabelFromSelectedKeys;
39
+ const getOptionFromKey = (options, key) => {
40
+ if (!Array.isArray(options) || !key || !options.length) {
41
+ return null;
42
+ }
43
+ return options.find(option => option.key === key);
44
+ };
45
+ exports.getOptionFromKey = getOptionFromKey;
46
+ const getOptionsFromKeys = (options, keys) => {
47
+ if (!Array.isArray(options) || !Array.isArray(keys) || !options.length || !keys.length) {
48
+ return [];
49
+ }
50
+ return options.filter(option => keys.includes(option.key));
51
+ };
52
+ exports.getOptionsFromKeys = getOptionsFromKeys;
@@ -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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spaced-out/ui-design-system",
3
- "version": "0.0.68",
3
+ "version": "0.1.1",
4
4
  "main": "index.js",
5
5
  "description": "Sense UI components library",
6
6
  "author": {