carbon-addons-iot-react 2.98.2 → 2.100.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 (44) hide show
  1. package/css/carbon-addons-iot-react.css +39 -33
  2. package/css/carbon-addons-iot-react.css.map +1 -1
  3. package/es/node_modules/carbon-components-react/es/components/ListBox/ListBox.js +98 -0
  4. package/es/node_modules/carbon-components-react/es/components/ListBox/ListBoxField.js +57 -0
  5. package/es/node_modules/carbon-components-react/es/components/ListBox/ListBoxMenu.js +43 -0
  6. package/es/node_modules/carbon-components-react/es/components/ListBox/ListBoxMenuIcon.js +55 -0
  7. package/es/node_modules/carbon-components-react/es/components/ListBox/ListBoxMenuItem.js +58 -0
  8. package/es/node_modules/carbon-components-react/es/components/ListBox/ListBoxPropTypes.js +12 -0
  9. package/es/node_modules/carbon-components-react/es/components/ListBox/ListBoxSelection.js +96 -0
  10. package/es/node_modules/carbon-components-react/es/components/ListBox/index.js +21 -0
  11. package/es/node_modules/carbon-components-react/es/prop-types/childrenOfType.js +36 -0
  12. package/es/node_modules/carbon-components-react/es/prop-types/tools/createChainableTypeChecker.js +38 -0
  13. package/es/node_modules/carbon-components-react/es/prop-types/tools/getDisplayName.js +37 -0
  14. package/es/src/components/ComboBox/CarbonComboBox.jsx +882 -0
  15. package/es/src/components/ComboBox/ComboBox.jsx +375 -0
  16. package/es/src/components/ComposedModal/ComposedModal.jsx +5 -1
  17. package/es/src/index.js +2 -1
  18. package/lib/css/carbon-addons-iot-react.css +39 -33
  19. package/lib/css/carbon-addons-iot-react.css.map +1 -1
  20. package/lib/node_modules/carbon-components-react/es/components/ListBox/ListBox.js +103 -0
  21. package/lib/node_modules/carbon-components-react/es/components/ListBox/ListBoxField.js +62 -0
  22. package/lib/node_modules/carbon-components-react/es/components/ListBox/ListBoxMenu.js +48 -0
  23. package/lib/node_modules/carbon-components-react/es/components/ListBox/ListBoxMenuIcon.js +60 -0
  24. package/lib/node_modules/carbon-components-react/es/components/ListBox/ListBoxMenuItem.js +63 -0
  25. package/lib/node_modules/carbon-components-react/es/components/ListBox/ListBoxPropTypes.js +17 -0
  26. package/lib/node_modules/carbon-components-react/es/components/ListBox/ListBoxSelection.js +101 -0
  27. package/lib/node_modules/carbon-components-react/es/components/ListBox/index.js +23 -0
  28. package/lib/node_modules/carbon-components-react/es/prop-types/childrenOfType.js +41 -0
  29. package/lib/node_modules/carbon-components-react/es/prop-types/tools/createChainableTypeChecker.js +40 -0
  30. package/lib/node_modules/carbon-components-react/es/prop-types/tools/getDisplayName.js +39 -0
  31. package/lib/scss/components/ComboBox/_combo-box.scss +43 -0
  32. package/lib/scss/components/ComposedModal/_composed-modal.scss +5 -0
  33. package/lib/scss/components/Tag/_tag.scss +11 -0
  34. package/lib/scss/styles.scss +1 -44
  35. package/lib/src/components/ComboBox/CarbonComboBox.jsx +889 -0
  36. package/lib/src/components/ComboBox/ComboBox.jsx +380 -0
  37. package/lib/src/components/ComposedModal/ComposedModal.jsx +5 -1
  38. package/lib/src/index.js +2 -1
  39. package/package.json +7 -5
  40. package/scss/components/ComboBox/_combo-box.scss +43 -0
  41. package/scss/components/ComposedModal/_composed-modal.scss +5 -0
  42. package/scss/components/Tag/_tag.scss +11 -0
  43. package/scss/styles.scss +1 -44
  44. package/umd/carbon-addons-iot-react.js +3327 -237
@@ -0,0 +1,98 @@
1
+ import PropTypes from 'prop-types';
2
+ import React from 'react';
3
+ import classnames from 'classnames';
4
+ import { settings } from 'carbon-components';
5
+ import { ListBoxType, ListBoxSize } from './ListBoxPropTypes.js';
6
+
7
+ function _extends() { _extends = Object.assign || 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); }
8
+
9
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
+
11
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
12
+
13
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
14
+ var prefix = settings.prefix;
15
+
16
+ var handleOnKeyDown = function handleOnKeyDown(event) {
17
+ if (event.keyCode === 27) {
18
+ event.stopPropagation();
19
+ }
20
+ };
21
+
22
+ var handleClick = function handleClick(event) {
23
+ event.preventDefault();
24
+ event.stopPropagation();
25
+ };
26
+ /**
27
+ * `ListBox` is a generic container component that handles creating the
28
+ * container class name in response to certain props.
29
+ */
30
+
31
+
32
+ var ListBox = function ListBox(_ref) {
33
+ var _cx;
34
+
35
+ var children = _ref.children,
36
+ containerClassName = _ref.className,
37
+ disabled = _ref.disabled,
38
+ innerRef = _ref.innerRef,
39
+ type = _ref.type,
40
+ size = _ref.size,
41
+ invalid = _ref.invalid,
42
+ invalidText = _ref.invalidText,
43
+ light = _ref.light,
44
+ isOpen = _ref.isOpen,
45
+ rest = _objectWithoutProperties(_ref, ["children", "className", "disabled", "innerRef", "type", "size", "invalid", "invalidText", "light", "isOpen"]);
46
+
47
+ var className = classnames((_cx = {}, _defineProperty(_cx, containerClassName, !!containerClassName), _defineProperty(_cx, "".concat(prefix, "--list-box"), true), _defineProperty(_cx, "".concat(prefix, "--list-box--").concat(size), size), _defineProperty(_cx, "".concat(prefix, "--list-box--inline"), type === 'inline'), _defineProperty(_cx, "".concat(prefix, "--list-box--disabled"), disabled), _defineProperty(_cx, "".concat(prefix, "--list-box--light"), light), _defineProperty(_cx, "".concat(prefix, "--list-box--expanded"), isOpen), _cx));
48
+ return React.createElement(React.Fragment, null, React.createElement("div", _extends({}, rest, {
49
+ className: className,
50
+ ref: innerRef,
51
+ onKeyDown: handleOnKeyDown,
52
+ onClick: handleClick,
53
+ "data-invalid": invalid || undefined
54
+ }), children), invalid ? React.createElement("div", {
55
+ className: "".concat(prefix, "--form-requirement")
56
+ }, invalidText) : null);
57
+ };
58
+
59
+ ListBox.propTypes = {
60
+ /**
61
+ * Provide the contents of your ListBox
62
+ */
63
+ children: PropTypes.node,
64
+
65
+ /**
66
+ * Specify a class name to be applied on the containing list box node
67
+ */
68
+ className: PropTypes.string,
69
+
70
+ /**
71
+ * `innerRef` hook used for libraries like Downshift that require a reference
72
+ * on a container node when it is not a native element
73
+ */
74
+ innerRef: PropTypes.func.isRequired,
75
+
76
+ /**
77
+ * Specify whether the ListBox is currently disabled
78
+ */
79
+ disabled: PropTypes.bool.isRequired,
80
+
81
+ /**
82
+ * Specify the "type" of the ListBox. Currently supports either `default` or
83
+ * `inline` as an option.
84
+ */
85
+ type: ListBoxType.isRequired,
86
+
87
+ /**
88
+ * Specify the size of the ListBox. Currently supports either `sm` or `xl` as an option.
89
+ */
90
+ size: ListBoxSize
91
+ };
92
+ ListBox.defaultProps = {
93
+ innerRef: function innerRef() {},
94
+ disabled: false,
95
+ type: 'default'
96
+ };
97
+
98
+ export default ListBox;
@@ -0,0 +1,57 @@
1
+ import PropTypes from 'prop-types';
2
+ import React from 'react';
3
+ import { settings } from 'carbon-components';
4
+
5
+ function _extends() { _extends = Object.assign || 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); }
6
+
7
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
8
+
9
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
10
+ var prefix = settings.prefix;
11
+
12
+ /**
13
+ * `ListBoxField` is responsible for creating the containing node for valid
14
+ * elements inside of a field. It also provides a11y-related attributes like
15
+ * `role` to make sure a user can focus the given field.
16
+ */
17
+
18
+ var ListBoxField = function ListBoxField(_ref) {
19
+ var children = _ref.children,
20
+ id = _ref.id,
21
+ disabled = _ref.disabled,
22
+ tabIndex = _ref.tabIndex,
23
+ rest = _objectWithoutProperties(_ref, ["children", "id", "disabled", "tabIndex"]);
24
+
25
+ return React.createElement("div", _extends({
26
+ role: rest['aria-expanded'] ? 'combobox' : rest.role || 'combobox',
27
+ "aria-owns": rest['aria-expanded'] && "".concat(id, "__menu") || null,
28
+ "aria-controls": rest['aria-expanded'] && "".concat(id, "__menu") || null,
29
+ "aria-haspopup": "listbox",
30
+ className: "".concat(prefix, "--list-box__field"),
31
+ tabIndex: !disabled && tabIndex || -1
32
+ }, rest), children);
33
+ };
34
+
35
+ ListBoxField.propTypes = {
36
+ /**
37
+ * Provide the contents of your ListBoxField
38
+ */
39
+ children: PropTypes.node,
40
+
41
+ /**
42
+ * Specify a custom `id`
43
+ */
44
+ id: PropTypes.string.isRequired,
45
+
46
+ /**
47
+ * Specify if the parent <ListBox> is disabled
48
+ */
49
+ disabled: PropTypes.bool,
50
+
51
+ /**
52
+ * Optional prop to specify the tabIndex of the <ListBox> trigger button
53
+ */
54
+ tabIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
55
+ };
56
+
57
+ export default ListBoxField;
@@ -0,0 +1,43 @@
1
+ import PropTypes from 'prop-types';
2
+ import React from 'react';
3
+ import { settings } from 'carbon-components';
4
+ import ListBoxMenuItem from './ListBoxMenuItem.js';
5
+ import childrenOfType from '../../prop-types/childrenOfType.js';
6
+
7
+ function _extends() { _extends = Object.assign || 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); }
8
+
9
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
10
+
11
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
12
+ var prefix = settings.prefix;
13
+ /**
14
+ * `ListBoxMenu` is a simple container node that isolates the `list-box__menu`
15
+ * class into a single component. It is also being used to validate given
16
+ * `children` components.
17
+ */
18
+
19
+ var ListBoxMenu = function ListBoxMenu(_ref) {
20
+ var children = _ref.children,
21
+ id = _ref.id,
22
+ rest = _objectWithoutProperties(_ref, ["children", "id"]);
23
+
24
+ return React.createElement("div", _extends({
25
+ id: "".concat(id, "__menu"),
26
+ className: "".concat(prefix, "--list-box__menu"),
27
+ role: "listbox"
28
+ }, rest), children);
29
+ };
30
+
31
+ ListBoxMenu.propTypes = {
32
+ /**
33
+ * Provide the contents of your ListBoxMenu
34
+ */
35
+ children: childrenOfType(ListBoxMenuItem),
36
+
37
+ /**
38
+ * Specify a custom `id`
39
+ */
40
+ id: PropTypes.string.isRequired
41
+ };
42
+
43
+ export default ListBoxMenu;
@@ -0,0 +1,55 @@
1
+ import PropTypes from 'prop-types';
2
+ import React from 'react';
3
+ import classnames from 'classnames';
4
+ import { ChevronDown16 } from '@carbon/icons-react';
5
+ import { settings } from 'carbon-components';
6
+
7
+ var _defaultTranslations;
8
+
9
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
+ var prefix = settings.prefix;
11
+ var translationIds = {
12
+ 'close.menu': 'close.menu',
13
+ 'open.menu': 'open.menu'
14
+ };
15
+ var defaultTranslations = (_defaultTranslations = {}, _defineProperty(_defaultTranslations, translationIds['close.menu'], 'Close menu'), _defineProperty(_defaultTranslations, translationIds['open.menu'], 'Open menu'), _defaultTranslations);
16
+ /**
17
+ * `ListBoxMenuIcon` is used to orient the icon up or down depending on the
18
+ * state of the menu for a given `ListBox`
19
+ */
20
+
21
+ var ListBoxMenuIcon = function ListBoxMenuIcon(_ref) {
22
+ var isOpen = _ref.isOpen,
23
+ t = _ref.translateWithId;
24
+ var className = classnames("".concat(prefix, "--list-box__menu-icon"), _defineProperty({}, "".concat(prefix, "--list-box__menu-icon--open"), isOpen));
25
+ var description = isOpen ? t('close.menu') : t('open.menu');
26
+ return React.createElement("div", {
27
+ className: className
28
+ }, React.createElement(ChevronDown16, {
29
+ name: "chevron--down",
30
+ "aria-label": description
31
+ }, React.createElement("title", null, description)));
32
+ };
33
+
34
+ ListBoxMenuIcon.propTypes = {
35
+ /**
36
+ * Specify whether the menu is currently open, which will influence the
37
+ * direction of the menu icon
38
+ */
39
+ isOpen: PropTypes.bool.isRequired,
40
+
41
+ /**
42
+ * i18n hook used to provide the appropriate description for the given menu
43
+ * icon. This function takes in an id defined in `translationIds` and should
44
+ * return a string message for that given message id.
45
+ */
46
+ translateWithId: PropTypes.func.isRequired
47
+ };
48
+ ListBoxMenuIcon.defaultProps = {
49
+ translateWithId: function translateWithId(id) {
50
+ return defaultTranslations[id];
51
+ }
52
+ };
53
+
54
+ export default ListBoxMenuIcon;
55
+ export { translationIds };
@@ -0,0 +1,58 @@
1
+ import PropTypes from 'prop-types';
2
+ import React from 'react';
3
+ import classnames from 'classnames';
4
+ import { settings } from 'carbon-components';
5
+
6
+ function _extends() { _extends = Object.assign || 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); }
7
+
8
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
+
10
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
11
+
12
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
13
+ var prefix = settings.prefix;
14
+ /**
15
+ * `ListBoxMenuItem` is a helper component for managing the container class
16
+ * name, alongside any classes for any corresponding states, for a generic list
17
+ * box menu item.
18
+ */
19
+
20
+ var ListBoxMenuItem = function ListBoxMenuItem(_ref) {
21
+ var _cx;
22
+
23
+ var children = _ref.children,
24
+ isActive = _ref.isActive,
25
+ isHighlighted = _ref.isHighlighted,
26
+ rest = _objectWithoutProperties(_ref, ["children", "isActive", "isHighlighted"]);
27
+
28
+ var className = classnames((_cx = {}, _defineProperty(_cx, "".concat(prefix, "--list-box__menu-item"), true), _defineProperty(_cx, "".concat(prefix, "--list-box__menu-item--active"), isActive), _defineProperty(_cx, "".concat(prefix, "--list-box__menu-item--highlighted"), isHighlighted), _cx));
29
+ return React.createElement("div", _extends({
30
+ className: className
31
+ }, rest), React.createElement("div", {
32
+ className: "".concat(prefix, "--list-box__menu-item__option")
33
+ }, children));
34
+ };
35
+
36
+ ListBoxMenuItem.propTypes = {
37
+ /**
38
+ * Specify any children nodes that hsould be rendered inside of the ListBox
39
+ * Menu Item
40
+ */
41
+ children: PropTypes.node,
42
+
43
+ /**
44
+ * Specify whether the current menu item is "active".
45
+ */
46
+ isActive: PropTypes.bool.isRequired,
47
+
48
+ /**
49
+ * Specify whether the current menu item is "highlighed".
50
+ */
51
+ isHighlighted: PropTypes.bool.isRequired
52
+ };
53
+ ListBoxMenuItem.defaultProps = {
54
+ isActive: false,
55
+ isHighlighted: false
56
+ };
57
+
58
+ export default ListBoxMenuItem;
@@ -0,0 +1,12 @@
1
+ import PropTypes from 'prop-types';
2
+
3
+ /**
4
+ * Copyright IBM Corp. 2016, 2018
5
+ *
6
+ * This source code is licensed under the Apache-2.0 license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ var ListBoxType = PropTypes.oneOf(['default', 'inline']);
10
+ var ListBoxSize = PropTypes.oneOf(['sm', 'xl']);
11
+
12
+ export { ListBoxType, ListBoxSize };
@@ -0,0 +1,96 @@
1
+ import PropTypes from 'prop-types';
2
+ import React from 'react';
3
+ import classnames from 'classnames';
4
+ import { Close16 } from '@carbon/icons-react';
5
+ import { settings } from 'carbon-components';
6
+ import { Enter } from '../../internal/keyboard/keys.js';
7
+ import { match } from '../../internal/keyboard/match.js';
8
+ import '../../internal/keyboard/navigation.js';
9
+
10
+ var _defaultTranslations;
11
+
12
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
+ var prefix = settings.prefix;
14
+ /**
15
+ * `ListBoxSelection` is used to provide controls for clearing a selection, in
16
+ * addition to conditionally rendering a badge if the control has more than one
17
+ * selection.
18
+ */
19
+
20
+ var ListBoxSelection = function ListBoxSelection(_ref) {
21
+ var _cx;
22
+
23
+ var clearSelection = _ref.clearSelection,
24
+ selectionCount = _ref.selectionCount,
25
+ t = _ref.translateWithId,
26
+ disabled = _ref.disabled;
27
+ var className = classnames("".concat(prefix, "--list-box__selection"), (_cx = {}, _defineProperty(_cx, "".concat(prefix, "--tag--filter"), selectionCount), _defineProperty(_cx, "".concat(prefix, "--list-box__selection--multi"), selectionCount), _cx));
28
+
29
+ var handleOnClick = function handleOnClick(event) {
30
+ event.stopPropagation();
31
+
32
+ if (disabled) {
33
+ return;
34
+ }
35
+
36
+ clearSelection(event);
37
+ };
38
+
39
+ var handleOnKeyDown = function handleOnKeyDown(event) {
40
+ event.stopPropagation();
41
+
42
+ if (disabled) {
43
+ return;
44
+ } // When a user hits ENTER, we'll clear the selection
45
+
46
+
47
+ if (match(event, Enter)) {
48
+ clearSelection(event);
49
+ }
50
+ };
51
+
52
+ var description = selectionCount ? t('clear.all') : t('clear.selection');
53
+ return React.createElement("div", {
54
+ role: "button",
55
+ className: className,
56
+ tabIndex: disabled ? -1 : 0,
57
+ onClick: handleOnClick,
58
+ onKeyDown: handleOnKeyDown,
59
+ "aria-label": "Clear Selection",
60
+ title: description
61
+ }, selectionCount, React.createElement(Close16, null));
62
+ };
63
+
64
+ var translationIds = {
65
+ 'clear.all': 'clear.all',
66
+ 'clear.selection': 'clear.selection'
67
+ };
68
+ var defaultTranslations = (_defaultTranslations = {}, _defineProperty(_defaultTranslations, translationIds['clear.all'], 'Clear all selected items'), _defineProperty(_defaultTranslations, translationIds['clear.selection'], 'Clear selected item'), _defaultTranslations);
69
+ ListBoxSelection.propTypes = {
70
+ /**
71
+ * Specify a function to be invoked when a user interacts with the clear
72
+ * selection element.
73
+ */
74
+ clearSelection: PropTypes.func.isRequired,
75
+
76
+ /**
77
+ * Specify an optional `selectionCount` value that will be used to determine
78
+ * whether the selection should display a badge or a single clear icon.
79
+ */
80
+ selectionCount: PropTypes.number,
81
+
82
+ /**
83
+ * i18n hook used to provide the appropriate description for the given menu
84
+ * icon. This function takes in an id defined in `translationIds` and should
85
+ * return a string message for that given message id.
86
+ */
87
+ translateWithId: PropTypes.func.isRequired
88
+ };
89
+ ListBoxSelection.defaultProps = {
90
+ translateWithId: function translateWithId(id) {
91
+ return defaultTranslations[id];
92
+ }
93
+ };
94
+
95
+ export default ListBoxSelection;
96
+ export { translationIds };
@@ -0,0 +1,21 @@
1
+ import './ListBoxPropTypes.js';
2
+ import ListBox from './ListBox.js';
3
+ import ListBoxField from './ListBoxField.js';
4
+ import ListBoxMenuItem from './ListBoxMenuItem.js';
5
+ import ListBoxMenu from './ListBoxMenu.js';
6
+ import ListBoxMenuIcon from './ListBoxMenuIcon.js';
7
+ import ListBoxSelection from './ListBoxSelection.js';
8
+
9
+ /**
10
+ * Copyright IBM Corp. 2016, 2018
11
+ *
12
+ * This source code is licensed under the Apache-2.0 license found in the
13
+ * LICENSE file in the root directory of this source tree.
14
+ */
15
+ ListBox.Field = ListBoxField;
16
+ ListBox.Menu = ListBoxMenu;
17
+ ListBox.MenuIcon = ListBoxMenuIcon;
18
+ ListBox.MenuItem = ListBoxMenuItem;
19
+ ListBox.Selection = ListBoxSelection;
20
+
21
+ export default ListBox;
@@ -0,0 +1,36 @@
1
+ import { Children } from 'react';
2
+ import createChainableTypeChecker from './tools/createChainableTypeChecker.js';
3
+ import getDisplayName from './tools/getDisplayName.js';
4
+
5
+ /**
6
+ * Copyright IBM Corp. 2016, 2018
7
+ *
8
+ * This source code is licensed under the Apache-2.0 license found in the
9
+ * LICENSE file in the root directory of this source tree.
10
+ */
11
+ /**
12
+ * `childrenOfType` is used for asserting that children of a given React
13
+ * component are only of a given type. Currently, this supports React elements,
14
+ * Stateless Functional Components, and Class-based components.
15
+ *
16
+ * This prop validator also supports chaining through `isRequired`
17
+ */
18
+
19
+ var childrenOfType = function childrenOfType(expectedChildType) {
20
+ var expectedDisplayName = getDisplayName( // Support both React elements and components by using `type` if it exists
21
+ expectedChildType.type || expectedChildType);
22
+
23
+ var validate = function validate(props, propName, componentName) {
24
+ Children.forEach(props[propName], function (child) {
25
+ var childDisplayName = getDisplayName(child.type);
26
+
27
+ if (child.type !== expectedChildType.type && child.type !== expectedChildType) {
28
+ throw new Error("Invalid prop `children` of type `".concat(childDisplayName, "` ") + "supplied to `".concat(componentName, "`, expected each child to be a ") + "`".concat(expectedDisplayName, "` component."));
29
+ }
30
+ });
31
+ };
32
+
33
+ return createChainableTypeChecker(validate);
34
+ };
35
+
36
+ export default childrenOfType;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2018
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ /**
9
+ * `createChainableTypeChecker` is used inside of our custom prop validators to
10
+ * add in chaining `isRequired` on a given prop validator.
11
+ */
12
+ var createChainableTypeChecker = function createChainableTypeChecker(validate) {
13
+ // `checkType` is borrowed heavily from the `prop-types` package
14
+ var checkType = function checkType(isRequired, props, propName, componentName, location) {
15
+ if (props[propName] == null) {
16
+ if (isRequired) {
17
+ if (props[propName] === null) {
18
+ return new Error("The ".concat(location, " `").concat(propName, "` is marked as required in ") + "".concat(componentName, ", but its value is `null`."));
19
+ }
20
+
21
+ return new Error("The ".concat(location, " `").concat(propName, "` is marked as required in ") + "".concat(componentName, ", but its value is `undefined`."));
22
+ }
23
+
24
+ return null;
25
+ } else {
26
+ return validate(props, propName, componentName, location);
27
+ }
28
+ }; // By default, the validator will have `isRequired` set to false. However, we
29
+ // also define the `isRequired` property on the validtor so that consumers can
30
+ // chain their prop validator and assert that the property is required.
31
+
32
+
33
+ var chainedCheckType = checkType.bind(null, false);
34
+ chainedCheckType.isRequired = checkType.bind(null, true);
35
+ return chainedCheckType;
36
+ };
37
+
38
+ export default createChainableTypeChecker;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2018
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ var cachedDisplayNames = new WeakMap();
8
+ /**
9
+ * `getDisplayName` is a utility function for getting a name from a given
10
+ * component type. It supports names from React elements, Stateless Functional
11
+ * Components, and Class-based Components
12
+ */
13
+
14
+ var getDisplayName = function getDisplayName(type) {
15
+ if (typeof type === 'string') {
16
+ return type;
17
+ }
18
+
19
+ if (cachedDisplayNames.has(type)) {
20
+ return cachedDisplayNames.get(type);
21
+ }
22
+
23
+ var displayName;
24
+
25
+ if (typeof type.displayName === 'string') {
26
+ displayName = type.displayName;
27
+ }
28
+
29
+ if (!displayName) {
30
+ displayName = type.name || 'Unknown';
31
+ }
32
+
33
+ cachedDisplayNames.set(type, displayName);
34
+ return displayName;
35
+ };
36
+
37
+ export default getDisplayName;