@spaced-out/ui-design-system 0.1.37-beta.1 → 0.1.37
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 +13 -0
- package/lib/components/ButtonDropdown/SimpleButtonDropdown.js +75 -0
- package/lib/components/ButtonDropdown/SimpleButtonDropdown.js.flow +142 -0
- package/lib/components/ButtonDropdown/index.js +21 -12
- package/lib/components/ButtonDropdown/index.js.flow +2 -2
- package/lib/components/Dropdown/Dropdown.js +1 -1
- package/lib/components/Dropdown/Dropdown.js.flow +1 -1
- package/lib/components/Dropdown/SimpleDropdown.js +74 -0
- package/lib/components/Dropdown/SimpleDropdown.js.flow +134 -0
- package/lib/components/Dropdown/index.js +11 -0
- package/lib/components/Dropdown/index.js.flow +1 -0
- package/lib/components/FocusManager/FocusManager.js +7 -1
- package/lib/components/FocusManager/FocusManager.js.flow +7 -0
- package/lib/components/FocusManagerWithArrowKeyNavigation/FocusManagerWithArrowKeyNavigation.js +102 -0
- package/lib/components/FocusManagerWithArrowKeyNavigation/FocusManagerWithArrowKeyNavigation.js.flow +118 -0
- package/lib/components/FocusManagerWithArrowKeyNavigation/FocusManagerWithArrowKeyNavigation.module.css +7 -0
- package/lib/components/FocusManagerWithArrowKeyNavigation/index.js +16 -0
- package/lib/components/FocusManagerWithArrowKeyNavigation/index.js.flow +3 -0
- package/lib/components/InlineDropdown/SimpleInlineDropdown.js +75 -0
- package/lib/components/InlineDropdown/SimpleInlineDropdown.js.flow +139 -0
- package/lib/components/InlineDropdown/index.js +11 -0
- package/lib/components/InlineDropdown/index.js.flow +1 -0
- package/lib/components/Menu/Menu.js +2 -1
- package/lib/components/Menu/Menu.js.flow +12 -0
- package/lib/components/Menu/MenuOptionButton.js +9 -4
- package/lib/components/Menu/MenuOptionButton.js.flow +10 -2
- package/lib/components/OptionButton/SimpleOptionButton.js +74 -0
- package/lib/components/OptionButton/SimpleOptionButton.js.flow +139 -0
- package/lib/components/OptionButton/index.js +21 -6
- package/lib/components/OptionButton/index.js.flow +3 -2
- package/lib/components/RadioButton/RadioButton.js +2 -1
- package/lib/components/RadioButton/RadioButton.js.flow +1 -0
- package/lib/components/RadioButton/RadioButton.module.css +4 -0
- package/lib/components/Typeahead/SimpleTypeahead.js +76 -0
- package/lib/components/Typeahead/SimpleTypeahead.js.flow +134 -0
- package/lib/components/Typeahead/Typeahead.js +3 -4
- package/lib/components/Typeahead/Typeahead.js.flow +123 -117
- package/lib/components/Typeahead/index.js +21 -6
- package/lib/components/Typeahead/index.js.flow +2 -2
- package/lib/components/index.js +11 -0
- package/lib/components/index.js.flow +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SimpleOptionButton = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _menu = require("../../utils/menu");
|
|
9
|
+
var _OptionButton = require("./OptionButton");
|
|
10
|
+
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); }
|
|
11
|
+
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; }
|
|
12
|
+
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); }
|
|
13
|
+
const SimpleOptionButtonBase = (props, ref) => {
|
|
14
|
+
const {
|
|
15
|
+
size = 'small',
|
|
16
|
+
classNames,
|
|
17
|
+
tooltip,
|
|
18
|
+
anchorPosition,
|
|
19
|
+
options,
|
|
20
|
+
optionsVariant,
|
|
21
|
+
allowSearch,
|
|
22
|
+
selectedKeys,
|
|
23
|
+
onOptionSelect,
|
|
24
|
+
onButtonClick,
|
|
25
|
+
onMenuOpen,
|
|
26
|
+
onMenuClose,
|
|
27
|
+
resolveLabel,
|
|
28
|
+
resolveSecondaryLabel,
|
|
29
|
+
children,
|
|
30
|
+
menuSize = 'small',
|
|
31
|
+
...buttonProps
|
|
32
|
+
} = props;
|
|
33
|
+
const [optionButtonSelectedKeys, setOptionButtonSelectedKeys] = React.useState(selectedKeys);
|
|
34
|
+
React.useEffect(() => {
|
|
35
|
+
setOptionButtonSelectedKeys(selectedKeys);
|
|
36
|
+
}, [selectedKeys]);
|
|
37
|
+
const handleOptionChange = selectedOption => {
|
|
38
|
+
let newSelectedKeys = [selectedOption.key];
|
|
39
|
+
if (optionsVariant === 'checkbox') {
|
|
40
|
+
newSelectedKeys = (0, _menu.getSelectedKeysFromSelectedOption)(selectedOption, optionButtonSelectedKeys);
|
|
41
|
+
} else {
|
|
42
|
+
newSelectedKeys = [selectedOption.key];
|
|
43
|
+
}
|
|
44
|
+
setOptionButtonSelectedKeys(newSelectedKeys);
|
|
45
|
+
setTimeout(() => {
|
|
46
|
+
onOptionSelect?.(selectedOption);
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
React.useImperativeHandle(ref, () => ({
|
|
50
|
+
selectedKeys: optionButtonSelectedKeys
|
|
51
|
+
}));
|
|
52
|
+
return /*#__PURE__*/React.createElement(_OptionButton.OptionButton, _extends({}, buttonProps, {
|
|
53
|
+
tooltip: tooltip,
|
|
54
|
+
onButtonClick: onButtonClick,
|
|
55
|
+
anchorPosition: anchorPosition,
|
|
56
|
+
classNames: classNames,
|
|
57
|
+
size: size,
|
|
58
|
+
onOptionSelect: handleOptionChange,
|
|
59
|
+
onMenuOpen: onMenuOpen,
|
|
60
|
+
onMenuClose: onMenuClose,
|
|
61
|
+
menu: {
|
|
62
|
+
isFluid: false,
|
|
63
|
+
options,
|
|
64
|
+
selectedKeys: optionButtonSelectedKeys,
|
|
65
|
+
optionsVariant,
|
|
66
|
+
allowSearch,
|
|
67
|
+
resolveLabel,
|
|
68
|
+
resolveSecondaryLabel,
|
|
69
|
+
size: menuSize
|
|
70
|
+
}
|
|
71
|
+
}), children);
|
|
72
|
+
};
|
|
73
|
+
const SimpleOptionButton = /*#__PURE__*/React.forwardRef(SimpleOptionButtonBase);
|
|
74
|
+
exports.SimpleOptionButton = SimpleOptionButton;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// @flow strict
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
import {getSelectedKeysFromSelectedOption} from '../../utils/menu';
|
|
6
|
+
import type {ButtonProps} from '../Button';
|
|
7
|
+
import type {AnchorType} from '../ButtonDropdown';
|
|
8
|
+
import type {MenuOption, MenuOptionsVariant} from '../Menu';
|
|
9
|
+
|
|
10
|
+
import type {OptionButtonTooltipProps} from './OptionButton';
|
|
11
|
+
import {OptionButton} from './OptionButton';
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
type ClassNames = $ReadOnly<{
|
|
15
|
+
wrapper?: string,
|
|
16
|
+
baseButtonWrapper?: string,
|
|
17
|
+
baseButtonIcon?: string,
|
|
18
|
+
optionsButtonWrapper?: string,
|
|
19
|
+
optionsButtonIcon?: string,
|
|
20
|
+
dropdownContainer?: string,
|
|
21
|
+
}>;
|
|
22
|
+
|
|
23
|
+
export type SimpleOptionButtonRef = {
|
|
24
|
+
selectedKeys?: Array<string>,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type SimpleOptionButtonProps = {
|
|
28
|
+
// Input props
|
|
29
|
+
...ButtonProps,
|
|
30
|
+
|
|
31
|
+
classNames?: ClassNames,
|
|
32
|
+
tooltip?: OptionButtonTooltipProps,
|
|
33
|
+
anchorPosition?: AnchorType,
|
|
34
|
+
tooltip?: OptionButtonTooltipProps,
|
|
35
|
+
menuSize?: 'small' | 'medium',
|
|
36
|
+
|
|
37
|
+
// Menu props
|
|
38
|
+
options?: Array<MenuOption>,
|
|
39
|
+
|
|
40
|
+
optionsVariant?: MenuOptionsVariant,
|
|
41
|
+
allowSearch?: boolean,
|
|
42
|
+
selectedKeys?: Array<string>,
|
|
43
|
+
|
|
44
|
+
// events
|
|
45
|
+
onOptionSelect?: (option: MenuOption) => mixed,
|
|
46
|
+
onButtonClick?: ?(SyntheticEvent<HTMLElement>) => mixed,
|
|
47
|
+
onMenuOpen?: () => mixed,
|
|
48
|
+
onMenuClose?: () => mixed,
|
|
49
|
+
|
|
50
|
+
// Resolvers
|
|
51
|
+
resolveLabel?: (option: MenuOption) => string | React.Node,
|
|
52
|
+
resolveSecondaryLabel?: (option: MenuOption) => string | React.Node,
|
|
53
|
+
...
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const SimpleOptionButtonBase = (props: SimpleOptionButtonProps, ref) => {
|
|
57
|
+
const {
|
|
58
|
+
size = 'small',
|
|
59
|
+
classNames,
|
|
60
|
+
tooltip,
|
|
61
|
+
anchorPosition,
|
|
62
|
+
options,
|
|
63
|
+
optionsVariant,
|
|
64
|
+
allowSearch,
|
|
65
|
+
selectedKeys,
|
|
66
|
+
onOptionSelect,
|
|
67
|
+
onButtonClick,
|
|
68
|
+
onMenuOpen,
|
|
69
|
+
onMenuClose,
|
|
70
|
+
resolveLabel,
|
|
71
|
+
resolveSecondaryLabel,
|
|
72
|
+
children,
|
|
73
|
+
menuSize = 'small',
|
|
74
|
+
...buttonProps
|
|
75
|
+
} = props;
|
|
76
|
+
|
|
77
|
+
const [optionButtonSelectedKeys, setOptionButtonSelectedKeys] =
|
|
78
|
+
React.useState(selectedKeys);
|
|
79
|
+
|
|
80
|
+
React.useEffect(() => {
|
|
81
|
+
setOptionButtonSelectedKeys(selectedKeys);
|
|
82
|
+
}, [selectedKeys]);
|
|
83
|
+
|
|
84
|
+
const handleOptionChange = (selectedOption: MenuOption) => {
|
|
85
|
+
let newSelectedKeys = [selectedOption.key];
|
|
86
|
+
|
|
87
|
+
if (optionsVariant === 'checkbox') {
|
|
88
|
+
newSelectedKeys = getSelectedKeysFromSelectedOption(
|
|
89
|
+
selectedOption,
|
|
90
|
+
optionButtonSelectedKeys,
|
|
91
|
+
);
|
|
92
|
+
} else {
|
|
93
|
+
newSelectedKeys = [selectedOption.key];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
setOptionButtonSelectedKeys(newSelectedKeys);
|
|
97
|
+
|
|
98
|
+
setTimeout(() => {
|
|
99
|
+
onOptionSelect?.(selectedOption);
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
React.useImperativeHandle(ref, () => ({
|
|
104
|
+
selectedKeys: optionButtonSelectedKeys,
|
|
105
|
+
}));
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<OptionButton
|
|
109
|
+
{...buttonProps}
|
|
110
|
+
tooltip={tooltip}
|
|
111
|
+
onButtonClick={onButtonClick}
|
|
112
|
+
anchorPosition={anchorPosition}
|
|
113
|
+
classNames={classNames}
|
|
114
|
+
size={size}
|
|
115
|
+
onOptionSelect={handleOptionChange}
|
|
116
|
+
onMenuOpen={onMenuOpen}
|
|
117
|
+
onMenuClose={onMenuClose}
|
|
118
|
+
menu={{
|
|
119
|
+
isFluid: false,
|
|
120
|
+
options,
|
|
121
|
+
selectedKeys: optionButtonSelectedKeys,
|
|
122
|
+
optionsVariant,
|
|
123
|
+
allowSearch,
|
|
124
|
+
resolveLabel,
|
|
125
|
+
resolveSecondaryLabel,
|
|
126
|
+
size: menuSize,
|
|
127
|
+
}}
|
|
128
|
+
>
|
|
129
|
+
{children}
|
|
130
|
+
</OptionButton>
|
|
131
|
+
);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export const SimpleOptionButton: React.AbstractComponent<
|
|
135
|
+
SimpleOptionButtonProps,
|
|
136
|
+
SimpleOptionButtonRef,
|
|
137
|
+
> = React.forwardRef<SimpleOptionButtonProps, SimpleOptionButtonRef>(
|
|
138
|
+
SimpleOptionButtonBase,
|
|
139
|
+
);
|
|
@@ -3,10 +3,25 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
var _OptionButton = require("./OptionButton");
|
|
7
|
+
Object.keys(_OptionButton).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _OptionButton[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _OptionButton[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
11
16
|
});
|
|
12
|
-
var
|
|
17
|
+
var _SimpleOptionButton = require("./SimpleOptionButton");
|
|
18
|
+
Object.keys(_SimpleOptionButton).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _SimpleOptionButton[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _SimpleOptionButton[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -51,7 +51,8 @@ const RadioButton = /*#__PURE__*/React.forwardRef((_ref, forwardRef) => {
|
|
|
51
51
|
return /*#__PURE__*/React.createElement("div", {
|
|
52
52
|
className: (0, _classify.default)(_RadioButtonModule.default.container, {
|
|
53
53
|
[_RadioButtonModule.default.horizontalRadioButton]: align === 'horizontal-fixed',
|
|
54
|
-
[_RadioButtonModule.default.fluidRadioButton]: align === 'horizontal-fluid'
|
|
54
|
+
[_RadioButtonModule.default.fluidRadioButton]: align === 'horizontal-fluid',
|
|
55
|
+
[_RadioButtonModule.default.containerDisabled]: disabled
|
|
55
56
|
}, classNames?.wrapper),
|
|
56
57
|
onClick: onWrapClickHandler
|
|
57
58
|
}, /*#__PURE__*/React.createElement("input", _extends({
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SimpleTypeahead = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _menu = require("../../utils/menu");
|
|
9
|
+
var _Typeahead = require("./Typeahead");
|
|
10
|
+
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); }
|
|
11
|
+
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; }
|
|
12
|
+
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); }
|
|
13
|
+
const SimpleTypeaheadBase = (props, ref) => {
|
|
14
|
+
const {
|
|
15
|
+
size = 'medium',
|
|
16
|
+
classNames,
|
|
17
|
+
placeholder = 'Select...',
|
|
18
|
+
options,
|
|
19
|
+
selectedKeys,
|
|
20
|
+
onSelect,
|
|
21
|
+
onMenuOpen,
|
|
22
|
+
onMenuClose,
|
|
23
|
+
resolveLabel,
|
|
24
|
+
resolveSecondaryLabel,
|
|
25
|
+
onClear,
|
|
26
|
+
onSearch,
|
|
27
|
+
...inputProps
|
|
28
|
+
} = props;
|
|
29
|
+
const [typeaheadInputText, setTypeaheadInputText] = React.useState('');
|
|
30
|
+
const [typeaheadSelectedKeys, setTypeaheadSelectedKeys] = React.useState(selectedKeys);
|
|
31
|
+
React.useEffect(() => {
|
|
32
|
+
const newTypeaheadText = (0, _menu.getTextLabelFromSelectedKeys)(selectedKeys, options);
|
|
33
|
+
setTypeaheadSelectedKeys(selectedKeys);
|
|
34
|
+
setTypeaheadInputText(newTypeaheadText);
|
|
35
|
+
}, [selectedKeys]);
|
|
36
|
+
const handleOptionChange = selectedOption => {
|
|
37
|
+
const newSelectedKeys = [selectedOption.key];
|
|
38
|
+
const newTypeaheadText = (0, _menu.getTextLabelFromSelectedKeys)(newSelectedKeys, options);
|
|
39
|
+
setTypeaheadSelectedKeys(newSelectedKeys);
|
|
40
|
+
setTypeaheadInputText(newTypeaheadText);
|
|
41
|
+
setTimeout(() => {
|
|
42
|
+
onSelect?.(selectedOption);
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
React.useImperativeHandle(ref, () => ({
|
|
46
|
+
selectedKeys: typeaheadSelectedKeys
|
|
47
|
+
}));
|
|
48
|
+
return /*#__PURE__*/React.createElement(_Typeahead.Typeahead, _extends({}, inputProps, {
|
|
49
|
+
classNames: classNames,
|
|
50
|
+
label: "Form Label",
|
|
51
|
+
size: size,
|
|
52
|
+
placeholder: placeholder,
|
|
53
|
+
onSelect: handleOptionChange,
|
|
54
|
+
onMenuOpen: onMenuOpen,
|
|
55
|
+
onMenuClose: onMenuClose,
|
|
56
|
+
typeaheadInputText: typeaheadInputText,
|
|
57
|
+
onSearch: e => {
|
|
58
|
+
setTypeaheadInputText(e.target.value);
|
|
59
|
+
onSearch?.(e);
|
|
60
|
+
},
|
|
61
|
+
onClear: () => {
|
|
62
|
+
setTypeaheadInputText('');
|
|
63
|
+
setTypeaheadSelectedKeys([]);
|
|
64
|
+
onClear?.();
|
|
65
|
+
},
|
|
66
|
+
menu: {
|
|
67
|
+
options,
|
|
68
|
+
selectedKeys: typeaheadSelectedKeys,
|
|
69
|
+
resolveLabel,
|
|
70
|
+
resolveSecondaryLabel,
|
|
71
|
+
size
|
|
72
|
+
}
|
|
73
|
+
}));
|
|
74
|
+
};
|
|
75
|
+
const SimpleTypeahead = /*#__PURE__*/React.forwardRef(SimpleTypeaheadBase);
|
|
76
|
+
exports.SimpleTypeahead = SimpleTypeahead;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// @flow strict
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
import {getTextLabelFromSelectedKeys} from '../../utils/menu';
|
|
6
|
+
import type {InputProps} from '../Input';
|
|
7
|
+
import type {MenuOption} from '../Menu';
|
|
8
|
+
|
|
9
|
+
import {Typeahead} from './Typeahead';
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
type ClassNames = $ReadOnly<{
|
|
13
|
+
wrapper?: string,
|
|
14
|
+
box?: string,
|
|
15
|
+
}>;
|
|
16
|
+
|
|
17
|
+
export type SimpleTypeaheadRef = {
|
|
18
|
+
selectedKeys?: Array<string>,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type SimpleTypeaheadProps = {
|
|
22
|
+
// Input props
|
|
23
|
+
...InputProps,
|
|
24
|
+
|
|
25
|
+
isLoading?: boolean,
|
|
26
|
+
menuOpenOffset?: number,
|
|
27
|
+
|
|
28
|
+
classNames?: ClassNames,
|
|
29
|
+
|
|
30
|
+
// Menu props
|
|
31
|
+
options?: Array<MenuOption>,
|
|
32
|
+
selectedKeys?: Array<string>,
|
|
33
|
+
|
|
34
|
+
// events
|
|
35
|
+
onSelect?: (option: MenuOption) => mixed,
|
|
36
|
+
onSearch?: (evt: SyntheticInputEvent<HTMLInputElement>) => mixed,
|
|
37
|
+
onMenuOpen?: () => mixed,
|
|
38
|
+
onMenuClose?: () => mixed,
|
|
39
|
+
onClear?: () => void,
|
|
40
|
+
|
|
41
|
+
// Resolvers
|
|
42
|
+
resolveLabel?: (option: MenuOption) => string | React.Node,
|
|
43
|
+
resolveSecondaryLabel?: (option: MenuOption) => string | React.Node,
|
|
44
|
+
...
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const SimpleTypeaheadBase = (props: SimpleTypeaheadProps, ref) => {
|
|
48
|
+
const {
|
|
49
|
+
size = 'medium',
|
|
50
|
+
classNames,
|
|
51
|
+
placeholder = 'Select...',
|
|
52
|
+
options,
|
|
53
|
+
selectedKeys,
|
|
54
|
+
onSelect,
|
|
55
|
+
onMenuOpen,
|
|
56
|
+
onMenuClose,
|
|
57
|
+
resolveLabel,
|
|
58
|
+
resolveSecondaryLabel,
|
|
59
|
+
onClear,
|
|
60
|
+
onSearch,
|
|
61
|
+
...inputProps
|
|
62
|
+
} = props;
|
|
63
|
+
|
|
64
|
+
const [typeaheadInputText, setTypeaheadInputText] = React.useState('');
|
|
65
|
+
const [typeaheadSelectedKeys, setTypeaheadSelectedKeys] =
|
|
66
|
+
React.useState(selectedKeys);
|
|
67
|
+
|
|
68
|
+
React.useEffect(() => {
|
|
69
|
+
const newTypeaheadText = getTextLabelFromSelectedKeys(
|
|
70
|
+
selectedKeys,
|
|
71
|
+
options,
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
setTypeaheadSelectedKeys(selectedKeys);
|
|
75
|
+
setTypeaheadInputText(newTypeaheadText);
|
|
76
|
+
}, [selectedKeys]);
|
|
77
|
+
|
|
78
|
+
const handleOptionChange = (selectedOption: MenuOption) => {
|
|
79
|
+
const newSelectedKeys = [selectedOption.key];
|
|
80
|
+
|
|
81
|
+
const newTypeaheadText = getTextLabelFromSelectedKeys(
|
|
82
|
+
newSelectedKeys,
|
|
83
|
+
options,
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
setTypeaheadSelectedKeys(newSelectedKeys);
|
|
87
|
+
setTypeaheadInputText(newTypeaheadText);
|
|
88
|
+
|
|
89
|
+
setTimeout(() => {
|
|
90
|
+
onSelect?.(selectedOption);
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
React.useImperativeHandle(ref, () => ({
|
|
95
|
+
selectedKeys: typeaheadSelectedKeys,
|
|
96
|
+
}));
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<Typeahead
|
|
100
|
+
{...inputProps}
|
|
101
|
+
classNames={classNames}
|
|
102
|
+
label="Form Label"
|
|
103
|
+
size={size}
|
|
104
|
+
placeholder={placeholder}
|
|
105
|
+
onSelect={handleOptionChange}
|
|
106
|
+
onMenuOpen={onMenuOpen}
|
|
107
|
+
onMenuClose={onMenuClose}
|
|
108
|
+
typeaheadInputText={typeaheadInputText}
|
|
109
|
+
onSearch={(e) => {
|
|
110
|
+
setTypeaheadInputText(e.target.value);
|
|
111
|
+
onSearch?.(e);
|
|
112
|
+
}}
|
|
113
|
+
onClear={() => {
|
|
114
|
+
setTypeaheadInputText('');
|
|
115
|
+
setTypeaheadSelectedKeys([]);
|
|
116
|
+
onClear?.();
|
|
117
|
+
}}
|
|
118
|
+
menu={{
|
|
119
|
+
options,
|
|
120
|
+
selectedKeys: typeaheadSelectedKeys,
|
|
121
|
+
resolveLabel,
|
|
122
|
+
resolveSecondaryLabel,
|
|
123
|
+
size,
|
|
124
|
+
}}
|
|
125
|
+
/>
|
|
126
|
+
);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export const SimpleTypeahead: React.AbstractComponent<
|
|
130
|
+
SimpleTypeaheadProps,
|
|
131
|
+
SimpleTypeaheadRef,
|
|
132
|
+
> = React.forwardRef<SimpleTypeaheadProps, SimpleTypeaheadRef>(
|
|
133
|
+
SimpleTypeaheadBase,
|
|
134
|
+
);
|
|
@@ -18,7 +18,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
18
18
|
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); }
|
|
19
19
|
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; }
|
|
20
20
|
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); }
|
|
21
|
-
const Typeahead = _ref => {
|
|
21
|
+
const Typeahead = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
22
22
|
let {
|
|
23
23
|
size = 'medium',
|
|
24
24
|
classNames,
|
|
@@ -34,7 +34,6 @@ const Typeahead = _ref => {
|
|
|
34
34
|
menuOpenOffset = 1,
|
|
35
35
|
...inputProps
|
|
36
36
|
} = _ref;
|
|
37
|
-
const typeaheadRef = React.useRef();
|
|
38
37
|
const [filteredOptions, setFilteredOptions] = React.useState(menu?.options);
|
|
39
38
|
const {
|
|
40
39
|
x,
|
|
@@ -73,9 +72,9 @@ const Typeahead = _ref => {
|
|
|
73
72
|
return /*#__PURE__*/React.createElement("div", {
|
|
74
73
|
"data-testid": "Typeahead",
|
|
75
74
|
className: (0, _classify.classify)(_TypeaheadModule.default.typeaheadContainer, classNames?.wrapper),
|
|
76
|
-
ref: typeaheadRef,
|
|
77
75
|
onClickCapture: cancelNext
|
|
78
76
|
}, /*#__PURE__*/React.createElement(_SearchInput.SearchInput, _extends({}, inputProps, {
|
|
77
|
+
ref: ref,
|
|
79
78
|
boxRef: refs.setReference,
|
|
80
79
|
size: size,
|
|
81
80
|
placeholder: placeholder,
|
|
@@ -125,5 +124,5 @@ const Typeahead = _ref => {
|
|
|
125
124
|
onTabOut: clickAway
|
|
126
125
|
}))));
|
|
127
126
|
});
|
|
128
|
-
};
|
|
127
|
+
});
|
|
129
128
|
exports.Typeahead = Typeahead;
|