@spaced-out/ui-design-system 0.1.15 → 0.1.17

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 (102) hide show
  1. package/.cspell/custom-words.txt +3 -0
  2. package/.flowconfig +1 -1
  3. package/CHANGELOG.md +15 -0
  4. package/CONTRIBUTING.md +52 -6
  5. package/README.md +144 -8
  6. package/gulpfile.js +1 -0
  7. package/lib/components/Avatar/Avatar.module.css +8 -2
  8. package/lib/components/AvatarGroup/AvatarGroup.js +25 -14
  9. package/lib/components/AvatarGroup/AvatarGroup.js.flow +118 -103
  10. package/lib/components/Badge/Badge.js +4 -3
  11. package/lib/components/Badge/Badge.js.flow +21 -21
  12. package/lib/components/Badge/index.js +11 -7
  13. package/lib/components/Badge/index.js.flow +1 -2
  14. package/lib/components/Banner/Banner.js +3 -2
  15. package/lib/components/Banner/Banner.js.flow +42 -35
  16. package/lib/components/Button/Button.js +50 -10
  17. package/lib/components/Button/Button.js.flow +87 -23
  18. package/lib/components/Button/Button.module.css +14 -0
  19. package/lib/components/ButtonTabs/ButtonTab/ButtonTab.js +3 -2
  20. package/lib/components/ButtonTabs/ButtonTab/ButtonTab.js.flow +48 -38
  21. package/lib/components/ButtonTabs/ButtonTabs.js +3 -2
  22. package/lib/components/ButtonTabs/ButtonTabs.js.flow +50 -41
  23. package/lib/components/Card/Card.js +16 -7
  24. package/lib/components/Card/Card.js.flow +73 -55
  25. package/lib/components/Checkbox/Checkbox.js +15 -10
  26. package/lib/components/Checkbox/Checkbox.js.flow +121 -100
  27. package/lib/components/Checkbox/Checkbox.module.css +4 -1
  28. package/lib/components/Checkbox/CheckboxGroup.js +4 -3
  29. package/lib/components/Checkbox/CheckboxGroup.js.flow +76 -65
  30. package/lib/components/Chip/Chip.js +3 -2
  31. package/lib/components/Chip/Chip.js.flow +66 -59
  32. package/lib/components/CircularLoader/CircularLoader.js +9 -4
  33. package/lib/components/CircularLoader/CircularLoader.js.flow +38 -24
  34. package/lib/components/CollapsibleCard/CollapsibleCard.js +4 -3
  35. package/lib/components/CollapsibleCard/CollapsibleCard.js.flow +68 -59
  36. package/lib/components/Dropdown/Dropdown.js +4 -3
  37. package/lib/components/Dropdown/Dropdown.js.flow +83 -74
  38. package/lib/components/EmptyState/EmptyState.js +4 -3
  39. package/lib/components/EmptyState/EmptyState.js.flow +53 -44
  40. package/lib/components/ErrorMessage/ErrorMessage.js +4 -3
  41. package/lib/components/ErrorMessage/ErrorMessage.js.flow +58 -49
  42. package/lib/components/InContextAlert/InContextAlert.js +4 -3
  43. package/lib/components/InContextAlert/InContextAlert.js.flow +79 -73
  44. package/lib/components/InlineDropdown/InlineDropdown.js +4 -3
  45. package/lib/components/InlineDropdown/InlineDropdown.js.flow +94 -85
  46. package/lib/components/LinearLoader/LinearLoader.js +4 -3
  47. package/lib/components/LinearLoader/LinearLoader.js.flow +20 -18
  48. package/lib/components/Link/Link.js +8 -1
  49. package/lib/components/Link/Link.js.flow +44 -36
  50. package/lib/components/Notification/Notification.js +8 -6
  51. package/lib/components/Notification/Notification.js.flow +96 -84
  52. package/lib/components/OptionButton/OptionButton.js +7 -4
  53. package/lib/components/OptionButton/OptionButton.js.flow +69 -59
  54. package/lib/components/PageTitle/PageTitle.js +4 -3
  55. package/lib/components/PageTitle/PageTitle.js.flow +46 -44
  56. package/lib/components/Pagination/PaginationItem.js +2 -2
  57. package/lib/components/Pagination/PaginationItem.js.flow +2 -2
  58. package/lib/components/RadioButton/RadioButton.js +15 -9
  59. package/lib/components/RadioButton/RadioButton.js.flow +91 -70
  60. package/lib/components/RadioButton/RadioButton.module.css +4 -1
  61. package/lib/components/RadioButton/RadioGroup.js +4 -3
  62. package/lib/components/RadioButton/RadioGroup.js.flow +56 -47
  63. package/lib/components/SearchInput/SearchInput.js +3 -2
  64. package/lib/components/SearchInput/SearchInput.js.flow +59 -50
  65. package/lib/components/SideMenuLink/SideMenuLink.js +4 -3
  66. package/lib/components/SideMenuLink/SideMenuLink.js.flow +54 -45
  67. package/lib/components/StatusIndicator/StatusIndicator.js +3 -2
  68. package/lib/components/StatusIndicator/StatusIndicator.js.flow +32 -23
  69. package/lib/components/SubMenu/SubMenu.js +4 -3
  70. package/lib/components/SubMenu/SubMenu.js.flow +41 -38
  71. package/lib/components/Table/StaticTable.js +3 -0
  72. package/lib/components/Table/StaticTable.js.flow +3 -0
  73. package/lib/components/Table/Table.js +10 -0
  74. package/lib/components/Table/Table.js.flow +10 -0
  75. package/lib/components/Table/hooks.js +1 -0
  76. package/lib/components/Table/hooks.js.flow +1 -0
  77. package/lib/components/Tabs/TabList/TabList.js +3 -2
  78. package/lib/components/Tabs/TabList/TabList.js.flow +127 -117
  79. package/lib/components/Toast/Toast.js +8 -10
  80. package/lib/components/Toast/Toast.js.flow +19 -27
  81. package/lib/components/Toast/Toast.module.css +8 -0
  82. package/lib/components/Toggle/Toggle.js +11 -7
  83. package/lib/components/Toggle/Toggle.js.flow +16 -12
  84. package/lib/components/Toggle/Toggle.module.css +2 -0
  85. package/lib/components/Toggle/index.js +11 -7
  86. package/lib/components/Toggle/index.js.flow +1 -1
  87. package/lib/components/Tooltip/Tooltip.js.flow +2 -2
  88. package/lib/components/index.js +511 -0
  89. package/lib/components/index.js.flow +48 -0
  90. package/lib/index.js +60 -0
  91. package/lib/index.js.flow +7 -0
  92. package/lib/styles/index.css +15 -0
  93. package/lib/styles/index.js +104 -0
  94. package/lib/styles/index.js.flow +12 -0
  95. package/lib/styles/typography.module.css +0 -1
  96. package/lib/styles/utils.module.css +26 -0
  97. package/lib/types/index.js +38 -0
  98. package/lib/types/index.js.flow +5 -0
  99. package/lib/utils/click-away.js.flow +1 -1
  100. package/lib/utils/index.js +93 -0
  101. package/lib/utils/index.js.flow +10 -0
  102. package/package.json +2 -1
@@ -7,13 +7,12 @@ exports.Checkbox = void 0;
7
7
  var React = _interopRequireWildcard(require("react"));
8
8
  var _classify = _interopRequireDefault(require("../../utils/classify"));
9
9
  var _Icon = require("../Icon");
10
- var _Text = require("../Text/Text");
11
10
  var _CheckboxModule = _interopRequireDefault(require("./Checkbox.module.css"));
12
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
12
  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); }
14
13
  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; }
15
14
 
16
- const Checkbox = _ref => {
15
+ const Checkbox = /*#__PURE__*/React.forwardRef((_ref, forwardRef) => {
17
16
  let {
18
17
  name = 'checkbox',
19
18
  value = '',
@@ -26,9 +25,11 @@ const Checkbox = _ref => {
26
25
  onChange,
27
26
  align,
28
27
  classNames,
29
- tabIndex = 0
28
+ tabIndex = 0,
29
+ ariaLabel = ''
30
30
  } = _ref;
31
31
  const checkboxInput = /*#__PURE__*/React.createRef();
32
+ React.useImperativeHandle(forwardRef, () => checkboxInput.current);
32
33
  const handleOnChange = () => {
33
34
  if (!disabled) {
34
35
  onChange && onChange({
@@ -50,17 +51,21 @@ const Checkbox = _ref => {
50
51
  checkboxInput.current.indeterminate = false;
51
52
  }
52
53
  }, [indeterminate]);
53
- return /*#__PURE__*/React.createElement("label", {
54
+ const onClickHandler = () => {
55
+ checkboxInput.current?.click();
56
+ };
57
+ return /*#__PURE__*/React.createElement("div", {
54
58
  "data-testid": "checkbox",
55
59
  className: (0, _classify.default)(_CheckboxModule.default.checkboxContainer, {
56
60
  [_CheckboxModule.default.disabled]: disabled,
57
61
  [_CheckboxModule.default.horizontalCheckbox]: align === 'horizontal-fixed',
58
62
  [_CheckboxModule.default.fluidCheckbox]: align === 'horizontal-fluid'
59
- }, classNames?.wrapper)
63
+ }, classNames?.wrapper),
64
+ onClick: onClickHandler
60
65
  }, /*#__PURE__*/React.createElement("span", {
61
66
  className: (0, _classify.default)(_CheckboxModule.default.checkboxSquare, {
62
67
  [_CheckboxModule.default.disabled]: disabled
63
- })
68
+ }, classNames?.checkboxSquare)
64
69
  }, /*#__PURE__*/React.createElement("input", {
65
70
  tabIndex: disabled ? -1 : tabIndex,
66
71
  type: "checkbox",
@@ -70,7 +75,8 @@ const Checkbox = _ref => {
70
75
  onChange: handleOnChange,
71
76
  className: (0, _classify.default)(_CheckboxModule.default.inputCheckbox),
72
77
  disabled: disabled,
73
- name: name
78
+ name: name,
79
+ "aria-label": ariaLabel || children
74
80
  }), /*#__PURE__*/React.createElement("span", {
75
81
  className: (0, _classify.default)(_CheckboxModule.default.checkboxSquareInner, {
76
82
  [_CheckboxModule.default.enabled]: !disabled && !error,
@@ -87,9 +93,8 @@ const Checkbox = _ref => {
87
93
  name: "check",
88
94
  size: "small",
89
95
  type: "regular"
90
- }))), React.Children.count(children) > 0 && /*#__PURE__*/React.createElement(_Text.FormLabelMedium, {
91
- color: "secondary",
96
+ }))), React.Children.count(children) > 0 && /*#__PURE__*/React.createElement("div", {
92
97
  className: (0, _classify.default)(_CheckboxModule.default.checkboxLabel, classNames?.label)
93
98
  }, children));
94
- };
99
+ });
95
100
  exports.Checkbox = Checkbox;
@@ -5,12 +5,15 @@ import * as React from 'react';
5
5
  import type {GroupAlign} from '../../types/common';
6
6
  import classify from '../../utils/classify';
7
7
  import {Icon} from '../Icon';
8
- import {FormLabelMedium} from '../Text/Text';
9
8
 
10
9
  import css from './Checkbox.module.css';
11
10
 
12
11
 
13
- type ClassNames = $ReadOnly<{wrapper?: string, label?: string}>;
12
+ type ClassNames = $ReadOnly<{
13
+ wrapper?: string,
14
+ checkboxSquare?: string,
15
+ label?: string,
16
+ }>;
14
17
 
15
18
  /*
16
19
  Note: An indeterminate state has a higher priority.
@@ -30,111 +33,129 @@ export type CheckboxProps = {
30
33
  align?: GroupAlign,
31
34
  classNames?: ClassNames,
32
35
  tabIndex?: number,
36
+ ariaLabel?: string,
33
37
  };
34
38
 
35
- export const Checkbox = ({
36
- name = 'checkbox',
37
- value = '',
38
- children,
39
- checked = false,
40
- indeterminate = false,
41
- focused = false,
42
- disabled = false,
43
- error = false,
44
- onChange,
45
- align,
46
- classNames,
47
- tabIndex = 0,
48
- }: CheckboxProps): React.Node => {
49
- const checkboxInput = React.createRef<HTMLInputElement>();
39
+ export const Checkbox: React$AbstractComponent<
40
+ CheckboxProps,
41
+ HTMLInputElement,
42
+ > = React.forwardRef<CheckboxProps, HTMLInputElement>(
43
+ (
44
+ {
45
+ name = 'checkbox',
46
+ value = '',
47
+ children,
48
+ checked = false,
49
+ indeterminate = false,
50
+ focused = false,
51
+ disabled = false,
52
+ error = false,
53
+ onChange,
54
+ align,
55
+ classNames,
56
+ tabIndex = 0,
57
+ ariaLabel = '',
58
+ }: CheckboxProps,
59
+ forwardRef,
60
+ ): React.Node => {
61
+ const checkboxInput = React.createRef<HTMLInputElement>();
62
+ React.useImperativeHandle(forwardRef, () => checkboxInput.current);
50
63
 
51
- const handleOnChange = () => {
52
- if (!disabled) {
53
- onChange &&
54
- onChange({
55
- value,
56
- checked: !checked,
57
- });
58
- }
59
- };
64
+ const handleOnChange = () => {
65
+ if (!disabled) {
66
+ onChange &&
67
+ onChange({
68
+ value,
69
+ checked: !checked,
70
+ });
71
+ }
72
+ };
60
73
 
61
- React.useEffect(() => {
62
- if (checkboxInput.current && focused) {
63
- checkboxInput.current.focus();
64
- }
65
- }, [focused]);
74
+ React.useEffect(() => {
75
+ if (checkboxInput.current && focused) {
76
+ checkboxInput.current.focus();
77
+ }
78
+ }, [focused]);
66
79
 
67
- React.useEffect(() => {
68
- if (checkboxInput.current && indeterminate) {
69
- checkboxInput.current.indeterminate = true;
70
- }
71
- if (checkboxInput.current && !indeterminate) {
72
- checkboxInput.current.indeterminate = false;
73
- }
74
- }, [indeterminate]);
80
+ React.useEffect(() => {
81
+ if (checkboxInput.current && indeterminate) {
82
+ checkboxInput.current.indeterminate = true;
83
+ }
84
+ if (checkboxInput.current && !indeterminate) {
85
+ checkboxInput.current.indeterminate = false;
86
+ }
87
+ }, [indeterminate]);
75
88
 
76
- return (
77
- <label
78
- data-testid="checkbox"
79
- className={classify(
80
- css.checkboxContainer,
81
- {
82
- [css.disabled]: disabled,
83
- [css.horizontalCheckbox]: align === 'horizontal-fixed',
84
- [css.fluidCheckbox]: align === 'horizontal-fluid',
85
- },
86
- classNames?.wrapper,
87
- )}
88
- >
89
- <span
90
- className={classify(css.checkboxSquare, {
91
- [css.disabled]: disabled,
92
- })}
89
+ const onClickHandler = () => {
90
+ checkboxInput.current?.click();
91
+ };
92
+
93
+ return (
94
+ <div
95
+ data-testid="checkbox"
96
+ className={classify(
97
+ css.checkboxContainer,
98
+ {
99
+ [css.disabled]: disabled,
100
+ [css.horizontalCheckbox]: align === 'horizontal-fixed',
101
+ [css.fluidCheckbox]: align === 'horizontal-fluid',
102
+ },
103
+ classNames?.wrapper,
104
+ )}
105
+ onClick={onClickHandler}
93
106
  >
94
- <input
95
- tabIndex={disabled ? -1 : tabIndex}
96
- type="checkbox"
97
- value={value}
98
- checked={checked}
99
- ref={checkboxInput}
100
- onChange={handleOnChange}
101
- className={classify(css.inputCheckbox)}
102
- disabled={disabled}
103
- name={name}
104
- />
105
107
  <span
106
- className={classify(css.checkboxSquareInner, {
107
- [css.enabled]: !disabled && !error,
108
- [css.disabled]: disabled,
109
- [css.error]: error && !disabled,
110
- })}
111
- >
112
- {indeterminate && (
113
- <Icon
114
- color={disabled ? 'disabled' : 'inversePrimary'}
115
- name="hyphen"
116
- size="small"
117
- type="regular"
118
- />
108
+ className={classify(
109
+ css.checkboxSquare,
110
+ {
111
+ [css.disabled]: disabled,
112
+ },
113
+ classNames?.checkboxSquare,
119
114
  )}
120
- {checked && !indeterminate && (
121
- <Icon
122
- color={disabled ? 'disabled' : 'inversePrimary'}
123
- name="check"
124
- size="small"
125
- type="regular"
126
- />
127
- )}
128
- </span>
129
- </span>
130
- {React.Children.count(children) > 0 && (
131
- <FormLabelMedium
132
- color="secondary"
133
- className={classify(css.checkboxLabel, classNames?.label)}
134
115
  >
135
- {children}
136
- </FormLabelMedium>
137
- )}
138
- </label>
139
- );
140
- };
116
+ <input
117
+ tabIndex={disabled ? -1 : tabIndex}
118
+ type="checkbox"
119
+ value={value}
120
+ checked={checked}
121
+ ref={checkboxInput}
122
+ onChange={handleOnChange}
123
+ className={classify(css.inputCheckbox)}
124
+ disabled={disabled}
125
+ name={name}
126
+ aria-label={ariaLabel || children}
127
+ />
128
+ <span
129
+ className={classify(css.checkboxSquareInner, {
130
+ [css.enabled]: !disabled && !error,
131
+ [css.disabled]: disabled,
132
+ [css.error]: error && !disabled,
133
+ })}
134
+ >
135
+ {indeterminate && (
136
+ <Icon
137
+ color={disabled ? 'disabled' : 'inversePrimary'}
138
+ name="hyphen"
139
+ size="small"
140
+ type="regular"
141
+ />
142
+ )}
143
+ {checked && !indeterminate && (
144
+ <Icon
145
+ color={disabled ? 'disabled' : 'inversePrimary'}
146
+ name="check"
147
+ size="small"
148
+ type="regular"
149
+ />
150
+ )}
151
+ </span>
152
+ </span>
153
+ {React.Children.count(children) > 0 && (
154
+ <div className={classify(css.checkboxLabel, classNames?.label)}>
155
+ {children}
156
+ </div>
157
+ )}
158
+ </div>
159
+ );
160
+ },
161
+ );
@@ -58,6 +58,8 @@
58
58
  .checkboxSquare {
59
59
  width: size24;
60
60
  height: size24;
61
+ min-width: size24;
62
+ min-height: size24;
61
63
  box-sizing: border-box;
62
64
  display: flex;
63
65
  align-items: center;
@@ -158,5 +160,6 @@ input[type='checkbox']:checked + .error {
158
160
  }
159
161
 
160
162
  .checkboxLabel {
161
- composes: truncate from '../../styles/typography.module.css';
163
+ composes: formLabelMedium from '../../styles/typography.module.css';
164
+ composes: secondary from '../../styles/typography.module.css';
162
165
  }
@@ -12,7 +12,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
12
12
  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); }
13
13
  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; }
14
14
 
15
- const CheckboxGroup = _ref => {
15
+ const CheckboxGroup = /*#__PURE__*/React.forwardRef((_ref, forwardRef) => {
16
16
  let {
17
17
  align = 'vertical',
18
18
  disabled = false,
@@ -72,10 +72,11 @@ const CheckboxGroup = _ref => {
72
72
  [_CheckboxGroupModule.default.vertical]: align === 'vertical',
73
73
  [_CheckboxGroupModule.default.horizontal]: align === 'horizontal-fixed',
74
74
  [_CheckboxGroupModule.default.horizontalFluid]: align === 'horizontal-fluid'
75
- }, classNames?.checkboxGroup)
75
+ }, classNames?.checkboxGroup),
76
+ ref: forwardRef
76
77
  }, childrenWithProps), error && /*#__PURE__*/React.createElement(_Text.BodySmall, {
77
78
  className: (0, _classify.default)(classNames?.errorText),
78
79
  color: "danger"
79
80
  }, errorText));
80
- };
81
+ });
81
82
  exports.CheckboxGroup = CheckboxGroup;
@@ -31,75 +31,86 @@ export type CheckboxGroupProps = {
31
31
  children?: React.Node,
32
32
  };
33
33
 
34
- export const CheckboxGroup = ({
35
- align = 'vertical',
36
- disabled = false,
37
- name,
38
- value: checkedList,
39
- onChange,
40
- classNames,
41
- error = false,
42
- errorText = '',
43
- children,
44
- }: CheckboxGroupProps): React.Node => {
45
- const onChangeHandler = ({value, checked}) => {
46
- const checkedListTemp = checkedList ? [...checkedList] : [];
47
- if (checked && !checkedListTemp.includes(value)) {
48
- checkedListTemp.push(value);
49
- } else if (!checked && checkedListTemp.includes(value)) {
50
- for (let i = 0; i < checkedListTemp.length; i++) {
51
- if (checkedListTemp[i] === value) {
52
- checkedListTemp.splice(i, 1);
53
- break;
34
+ export const CheckboxGroup: React$AbstractComponent<
35
+ CheckboxGroupProps,
36
+ HTMLDivElement,
37
+ > = React.forwardRef<CheckboxGroupProps, HTMLDivElement>(
38
+ (
39
+ {
40
+ align = 'vertical',
41
+ disabled = false,
42
+ name,
43
+ value: checkedList,
44
+ onChange,
45
+ classNames,
46
+ error = false,
47
+ errorText = '',
48
+ children,
49
+ }: CheckboxGroupProps,
50
+ forwardRef,
51
+ ): React.Node => {
52
+ const onChangeHandler = ({value, checked}) => {
53
+ const checkedListTemp = checkedList ? [...checkedList] : [];
54
+ if (checked && !checkedListTemp.includes(value)) {
55
+ checkedListTemp.push(value);
56
+ } else if (!checked && checkedListTemp.includes(value)) {
57
+ for (let i = 0; i < checkedListTemp.length; i++) {
58
+ if (checkedListTemp[i] === value) {
59
+ checkedListTemp.splice(i, 1);
60
+ break;
61
+ }
54
62
  }
55
63
  }
56
- }
57
- onChange && onChange(checkedListTemp);
58
- };
64
+ onChange && onChange(checkedListTemp);
65
+ };
59
66
 
60
- const childrenWithProps = React.Children.map(children, (child) => {
61
- if (React.isValidElement(child)) {
62
- const {
63
- value,
64
- disabled: disabledChild,
65
- error: errorChild,
66
- onChange,
67
- } = child.props;
68
- const childOnChange = (...params) => {
69
- onChangeHandler(...params);
70
- onChange && onChange(...params);
71
- };
72
- return React.cloneElement(child, {
73
- name,
74
- checked: !!checkedList?.includes(value),
75
- onChange: childOnChange,
76
- align,
77
- error: errorChild || error,
78
- disabled: disabledChild || disabled,
79
- });
80
- }
81
- return child;
82
- });
67
+ const childrenWithProps = React.Children.map(children, (child) => {
68
+ if (React.isValidElement(child)) {
69
+ const {
70
+ value,
71
+ disabled: disabledChild,
72
+ error: errorChild,
73
+ onChange,
74
+ } = child.props;
75
+ const childOnChange = (...params) => {
76
+ onChangeHandler(...params);
77
+ onChange && onChange(...params);
78
+ };
79
+ return React.cloneElement(child, {
80
+ name,
81
+ checked: !!checkedList?.includes(value),
82
+ onChange: childOnChange,
83
+ align,
84
+ error: errorChild || error,
85
+ disabled: disabledChild || disabled,
86
+ });
87
+ }
88
+ return child;
89
+ });
83
90
 
84
- return (
85
- <div className={classify(css.checkboxGroupContainer, classNames?.wrapper)}>
91
+ return (
86
92
  <div
87
- className={classify(
88
- {
89
- [css.vertical]: align === 'vertical',
90
- [css.horizontal]: align === 'horizontal-fixed',
91
- [css.horizontalFluid]: align === 'horizontal-fluid',
92
- },
93
- classNames?.checkboxGroup,
94
- )}
93
+ className={classify(css.checkboxGroupContainer, classNames?.wrapper)}
95
94
  >
96
- {childrenWithProps}
95
+ <div
96
+ className={classify(
97
+ {
98
+ [css.vertical]: align === 'vertical',
99
+ [css.horizontal]: align === 'horizontal-fixed',
100
+ [css.horizontalFluid]: align === 'horizontal-fluid',
101
+ },
102
+ classNames?.checkboxGroup,
103
+ )}
104
+ ref={forwardRef}
105
+ >
106
+ {childrenWithProps}
107
+ </div>
108
+ {error && (
109
+ <BodySmall className={classify(classNames?.errorText)} color="danger">
110
+ {errorText}
111
+ </BodySmall>
112
+ )}
97
113
  </div>
98
- {error && (
99
- <BodySmall className={classify(classNames?.errorText)} color="danger">
100
- {errorText}
101
- </BodySmall>
102
- )}
103
- </div>
104
- );
105
- };
114
+ );
115
+ },
116
+ );
@@ -22,7 +22,7 @@ const CHIP_SEMANTIC = Object.freeze({
22
22
  secondary: 'secondary'
23
23
  });
24
24
  exports.CHIP_SEMANTIC = CHIP_SEMANTIC;
25
- const Chip = _ref => {
25
+ const Chip = /*#__PURE__*/React.forwardRef((_ref, ref) => {
26
26
  let {
27
27
  classNames,
28
28
  semantic = 'primary',
@@ -39,6 +39,7 @@ const Chip = _ref => {
39
39
  return /*#__PURE__*/React.createElement("div", _extends({
40
40
  "data-testid": "Chip"
41
41
  }, rest, {
42
+ ref: ref,
42
43
  className: (0, _classify.classify)(_ChipModule.default.chipWrapper, {
43
44
  [_ChipModule.default.primary]: semantic === CHIP_SEMANTIC.primary,
44
45
  [_ChipModule.default.information]: semantic === CHIP_SEMANTIC.information,
@@ -70,5 +71,5 @@ const Chip = _ref => {
70
71
  }
71
72
  }
72
73
  }));
73
- };
74
+ });
74
75
  exports.Chip = Chip;
@@ -48,64 +48,71 @@ export type SmallChipProps = {
48
48
  };
49
49
 
50
50
  export type ChipProps = MediumChipProps | SmallChipProps;
51
- export const Chip = ({
52
- classNames,
53
- semantic = 'primary',
54
- size = 'medium',
55
- children,
56
- iconName = '',
57
- iconType = 'regular',
58
- dismissable = false,
59
- onDismiss = () => null,
60
- onClick,
61
- disabled,
62
- ...rest
63
- }: ChipProps): React.Node => (
64
- <div
65
- data-testid="Chip"
66
- {...rest}
67
- className={classify(
68
- css.chipWrapper,
51
+ export const Chip: React$AbstractComponent<ChipProps, HTMLDivElement> =
52
+ React.forwardRef<ChipProps, HTMLDivElement>(
53
+ (
69
54
  {
70
- [css.primary]: semantic === CHIP_SEMANTIC.primary,
71
- [css.information]: semantic === CHIP_SEMANTIC.information,
72
- [css.success]: semantic === CHIP_SEMANTIC.success,
73
- [css.warning]: semantic === CHIP_SEMANTIC.warning,
74
- [css.danger]: semantic === CHIP_SEMANTIC.danger,
75
- [css.secondary]: semantic === CHIP_SEMANTIC.secondary,
76
- [css.medium]: size === 'medium',
77
- [css.small]: size === 'small',
78
- [css.dismissable]: dismissable,
79
- [css.withIcon]: !!iconName && size !== 'small',
80
- [css.disabled]: disabled,
81
- },
82
- classNames?.wrapper,
83
- )}
84
- onClick={onClick}
85
- >
86
- {iconName && size !== 'small' && (
87
- <Icon
88
- className={css.chipIcon}
89
- name={iconName}
90
- type={iconType}
91
- size="small"
92
- />
93
- )}
94
- <Truncate>{children}</Truncate>
55
+ classNames,
56
+ semantic = 'primary',
57
+ size = 'medium',
58
+ children,
59
+ iconName = '',
60
+ iconType = 'regular',
61
+ dismissable = false,
62
+ onDismiss = () => null,
63
+ onClick,
64
+ disabled,
65
+ ...rest
66
+ }: ChipProps,
67
+ ref,
68
+ ): React.Node => (
69
+ <div
70
+ data-testid="Chip"
71
+ {...rest}
72
+ ref={ref}
73
+ className={classify(
74
+ css.chipWrapper,
75
+ {
76
+ [css.primary]: semantic === CHIP_SEMANTIC.primary,
77
+ [css.information]: semantic === CHIP_SEMANTIC.information,
78
+ [css.success]: semantic === CHIP_SEMANTIC.success,
79
+ [css.warning]: semantic === CHIP_SEMANTIC.warning,
80
+ [css.danger]: semantic === CHIP_SEMANTIC.danger,
81
+ [css.secondary]: semantic === CHIP_SEMANTIC.secondary,
82
+ [css.medium]: size === 'medium',
83
+ [css.small]: size === 'small',
84
+ [css.dismissable]: dismissable,
85
+ [css.withIcon]: !!iconName && size !== 'small',
86
+ [css.disabled]: disabled,
87
+ },
88
+ classNames?.wrapper,
89
+ )}
90
+ onClick={onClick}
91
+ >
92
+ {iconName && size !== 'small' && (
93
+ <Icon
94
+ className={css.chipIcon}
95
+ name={iconName}
96
+ type={iconType}
97
+ size="small"
98
+ />
99
+ )}
100
+ <Truncate>{children}</Truncate>
95
101
 
96
- {dismissable && size !== 'small' && (
97
- <Icon
98
- className={css.dismissIcon}
99
- name="xmark"
100
- type={iconType}
101
- size="small"
102
- onClick={(event) => {
103
- event.stopPropagation();
104
- if (!disabled && onDismiss) {
105
- onDismiss(event);
106
- }
107
- }}
108
- />
109
- )}
110
- </div>
111
- );
102
+ {dismissable && size !== 'small' && (
103
+ <Icon
104
+ className={css.dismissIcon}
105
+ name="xmark"
106
+ type={iconType}
107
+ size="small"
108
+ onClick={(event) => {
109
+ event.stopPropagation();
110
+ if (!disabled && onDismiss) {
111
+ onDismiss(event);
112
+ }
113
+ }}
114
+ />
115
+ )}
116
+ </div>
117
+ ),
118
+ );