@dxc-technology/halstack-react 8.0.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/HalstackContext.js +94 -45
  2. package/accordion/Accordion.js +7 -13
  3. package/accordion/Accordion.stories.tsx +102 -13
  4. package/alert/Alert.stories.tsx +28 -0
  5. package/box/Box.js +1 -3
  6. package/box/Box.stories.tsx +15 -0
  7. package/button/Button.js +11 -13
  8. package/button/Button.stories.tsx +150 -8
  9. package/checkbox/Checkbox.stories.tsx +52 -0
  10. package/chip/Chip.js +16 -22
  11. package/chip/Chip.stories.tsx +96 -9
  12. package/common/variables.js +280 -288
  13. package/date-input/Calendar.d.ts +1 -1
  14. package/date-input/Calendar.js +43 -43
  15. package/date-input/DateInput.js +74 -32
  16. package/date-input/DateInput.stories.tsx +183 -30
  17. package/date-input/DateInput.test.js +120 -37
  18. package/date-input/DatePicker.js +38 -52
  19. package/date-input/Icons.d.ts +6 -0
  20. package/date-input/Icons.js +75 -0
  21. package/date-input/YearPicker.d.ts +1 -1
  22. package/date-input/YearPicker.js +23 -12
  23. package/date-input/types.d.ts +6 -8
  24. package/dialog/Dialog.js +60 -73
  25. package/dialog/Dialog.stories.tsx +211 -159
  26. package/dialog/Dialog.test.js +301 -2
  27. package/dropdown/Dropdown.js +3 -6
  28. package/dropdown/Dropdown.stories.tsx +210 -84
  29. package/dropdown/DropdownMenu.js +8 -18
  30. package/dropdown/DropdownMenuItem.js +4 -15
  31. package/file-input/FileInput.js +3 -6
  32. package/file-input/FileInput.stories.tsx +85 -2
  33. package/file-input/FileInput.test.js +0 -41
  34. package/file-input/FileItem.js +1 -0
  35. package/footer/Footer.stories.tsx +91 -0
  36. package/header/Header.js +18 -20
  37. package/header/Header.stories.tsx +149 -6
  38. package/link/Link.stories.tsx +60 -0
  39. package/main.d.ts +1 -1
  40. package/main.js +1 -1
  41. package/{tabs-nav → nav-tabs}/NavTabs.js +1 -1
  42. package/{tabs-nav → nav-tabs}/NavTabs.stories.tsx +96 -6
  43. package/{tabs-nav → nav-tabs}/Tab.js +35 -15
  44. package/package.json +1 -1
  45. package/paginator/Icons.d.ts +5 -0
  46. package/paginator/Icons.js +16 -28
  47. package/paginator/Paginator.js +5 -11
  48. package/paginator/Paginator.stories.tsx +24 -0
  49. package/paginator/Paginator.test.js +17 -10
  50. package/progress-bar/ProgressBar.js +4 -4
  51. package/progress-bar/ProgressBar.stories.jsx +35 -2
  52. package/quick-nav/QuickNav.stories.tsx +14 -0
  53. package/radio-group/RadioGroup.stories.tsx +131 -18
  54. package/resultsetTable/ResultsetTable.test.js +17 -22
  55. package/select/Listbox.d.ts +1 -1
  56. package/select/Listbox.js +5 -34
  57. package/select/Option.js +11 -24
  58. package/select/Select.js +43 -24
  59. package/select/Select.stories.tsx +492 -145
  60. package/select/Select.test.js +17 -22
  61. package/select/types.d.ts +2 -2
  62. package/sidenav/Sidenav.js +8 -10
  63. package/sidenav/Sidenav.stories.tsx +148 -46
  64. package/slider/Slider.js +4 -4
  65. package/slider/Slider.stories.tsx +57 -0
  66. package/spinner/Spinner.js +2 -2
  67. package/spinner/Spinner.stories.jsx +27 -1
  68. package/switch/Switch.js +1 -1
  69. package/switch/Switch.stories.tsx +33 -0
  70. package/table/Table.stories.jsx +80 -1
  71. package/tabs/Tab.js +3 -5
  72. package/tabs/Tabs.js +3 -3
  73. package/tabs/Tabs.stories.tsx +45 -5
  74. package/tag/Tag.stories.tsx +14 -1
  75. package/text-input/Suggestion.js +32 -5
  76. package/text-input/TextInput.js +7 -11
  77. package/text-input/TextInput.stories.tsx +92 -4
  78. package/text-input/TextInput.test.js +125 -25
  79. package/textarea/Textarea.stories.jsx +60 -1
  80. package/toggle-group/ToggleGroup.stories.tsx +42 -0
  81. package/utils/FocusLock.d.ts +13 -0
  82. package/utils/FocusLock.js +139 -0
  83. package/wizard/Wizard.stories.tsx +20 -0
  84. /package/{tabs-nav → nav-tabs}/NavTabs.d.ts +0 -0
  85. /package/{tabs-nav → nav-tabs}/NavTabs.test.js +0 -0
  86. /package/{tabs-nav → nav-tabs}/Tab.d.ts +0 -0
  87. /package/{tabs-nav → nav-tabs}/types.d.ts +0 -0
  88. /package/{tabs-nav → nav-tabs}/types.js +0 -0
@@ -2,6 +2,7 @@ import React from "react";
2
2
  import ExampleContainer from "../../.storybook/components/ExampleContainer";
3
3
  import Title from "../../.storybook/components/Title";
4
4
  import DxcRadioGroup from "./RadioGroup";
5
+ import { HalstackProvider } from "../HalstackContext";
5
6
 
6
7
  export default {
7
8
  title: "Radio Group",
@@ -19,83 +20,195 @@ const options = [
19
20
 
20
21
  const single_disabled_options = [{ label: "Option A", value: "A", disabled: true }];
21
22
 
23
+ const opinionatedTheme = {
24
+ radioGroup: {
25
+ baseColor: "#0086e6",
26
+ fontColor: "#000000",
27
+ },
28
+ };
29
+
22
30
  export const Chromatic = () => (
23
31
  <>
24
32
  <Title title="Radio input states" theme="light" level={2} />
25
33
  <ExampleContainer>
26
34
  <Title title="Enabled" theme="light" level={4} />
27
- <DxcRadioGroup label="Example" defaultValue="A" options={single_option} />
35
+ <DxcRadioGroup label="Label" helperText="Helper text" defaultValue="A" options={single_option} />
28
36
  </ExampleContainer>
29
37
  <ExampleContainer pseudoState="pseudo-hover">
30
38
  <Title title="Hovered" theme="light" level={4} />
31
- <DxcRadioGroup label="Example" defaultValue="A" options={single_option} />
39
+ <DxcRadioGroup label="Label" helperText="Helper text" defaultValue="A" options={single_option} />
32
40
  </ExampleContainer>
33
41
  <ExampleContainer pseudoState="pseudo-active">
34
42
  <Title title="Active" theme="light" level={4} />
35
- <DxcRadioGroup label="Example" defaultValue="A" options={single_option} />
43
+ <DxcRadioGroup label="Label" helperText="Helper text" defaultValue="A" options={single_option} />
36
44
  </ExampleContainer>
37
45
  <ExampleContainer pseudoState="pseudo-focus">
38
46
  <Title title="Focused" theme="light" level={4} />
39
- <DxcRadioGroup label="Example" defaultValue="A" options={single_option} />
47
+ <DxcRadioGroup label="Label" helperText="Helper text" defaultValue="A" options={single_option} />
40
48
  </ExampleContainer>
41
49
  <ExampleContainer>
42
50
  <Title title="Disabled" theme="light" level={4} />
43
- <DxcRadioGroup label="Example" options={single_disabled_options} defaultValue="A" />
51
+ <DxcRadioGroup label="Label" helperText="Helper text" options={single_disabled_options} defaultValue="A" />
44
52
  </ExampleContainer>
45
53
  <Title title="Readonly radio input sub-states" theme="light" level={3} />
46
54
  <ExampleContainer>
47
55
  <Title title="Enabled" theme="light" level={4} />
48
- <DxcRadioGroup label="Example" options={single_option} defaultValue="A" readonly />
56
+ <DxcRadioGroup label="Label" helperText="Helper text" options={single_option} defaultValue="A" readonly />
49
57
  </ExampleContainer>
50
58
  <ExampleContainer pseudoState="pseudo-hover">
51
59
  <Title title="Hovered" theme="light" level={4} />
52
- <DxcRadioGroup label="Example" options={single_option} defaultValue="A" readonly />
60
+ <DxcRadioGroup label="Label" helperText="Helper text" options={single_option} defaultValue="A" readonly />
53
61
  </ExampleContainer>
54
62
  <ExampleContainer pseudoState="pseudo-active">
55
63
  <Title title="Active" theme="light" level={4} />
56
- <DxcRadioGroup label="Example" options={single_option} defaultValue="A" readonly />
64
+ <DxcRadioGroup label="Label" helperText="Helper text" options={single_option} defaultValue="A" readonly />
57
65
  </ExampleContainer>
58
66
  <Title title="Error radio input sub-states" theme="light" level={3} />
59
67
  <ExampleContainer>
60
68
  <Title title="Enabled" theme="light" level={4} />
61
- <DxcRadioGroup label="Example" options={single_option} defaultValue="A" error="Error message" />
69
+ <DxcRadioGroup
70
+ label="Label"
71
+ helperText="Helper text"
72
+ options={single_option}
73
+ defaultValue="A"
74
+ error="Error message"
75
+ />
62
76
  </ExampleContainer>
63
77
  <ExampleContainer pseudoState="pseudo-hover">
64
78
  <Title title="Hovered" theme="light" level={4} />
65
- <DxcRadioGroup label="Example" options={single_option} defaultValue="A" readonly error="Error message" />
79
+ <DxcRadioGroup
80
+ label="Label"
81
+ helperText="Helper text"
82
+ options={single_option}
83
+ defaultValue="A"
84
+ readonly
85
+ error="Error message"
86
+ />
66
87
  </ExampleContainer>
67
88
  <ExampleContainer pseudoState="pseudo-active">
68
89
  <Title title="Active" theme="light" level={4} />
69
- <DxcRadioGroup label="Example" options={single_option} defaultValue="A" readonly error="Error message" />
90
+ <DxcRadioGroup
91
+ label="Label"
92
+ helperText="Helper text"
93
+ options={single_option}
94
+ defaultValue="A"
95
+ readonly
96
+ error="Error message"
97
+ />
70
98
  </ExampleContainer>
71
99
  <Title title="Variants" theme="light" level={2} />
72
100
  <ExampleContainer>
73
101
  <Title title="Column" theme="light" level={4} />
74
- <DxcRadioGroup label="Example" helperText="Helper text" options={options} />
102
+ <DxcRadioGroup label="Label" helperText="Helper text" options={options} />
75
103
  </ExampleContainer>
76
104
  <ExampleContainer>
77
105
  <Title title="Row" theme="light" level={4} />
78
- <DxcRadioGroup label="Example" helperText="Helper text" options={options} stacking="row" />
106
+ <DxcRadioGroup label="Label" helperText="Helper text" options={options} stacking="row" />
79
107
  </ExampleContainer>
80
108
  <ExampleContainer>
81
109
  <Title title="Optional" theme="light" level={4} />
82
- <DxcRadioGroup label="Example" optional helperText="Helper text" options={options} stacking="row" />
110
+ <DxcRadioGroup label="Label" optional helperText="Helper text" options={options} stacking="row" />
83
111
  </ExampleContainer>
84
112
  <ExampleContainer>
85
113
  <Title title="Disabled" theme="light" level={4} />
86
- <DxcRadioGroup label="Example" helperText="Helper text" options={options} disabled />
114
+ <DxcRadioGroup label="Label" helperText="Helper text" options={options} disabled />
87
115
  </ExampleContainer>
88
116
  <ExampleContainer>
89
117
  <Title title="Readonly" theme="light" level={4} />
90
- <DxcRadioGroup label="Example" readonly helperText="Helper text" options={options} />
118
+ <DxcRadioGroup label="Label" readonly helperText="Helper text" options={options} />
91
119
  </ExampleContainer>
92
120
  <ExampleContainer>
93
121
  <Title title="Error space reserved" theme="light" level={4} />
94
- <DxcRadioGroup label="Example" error="" helperText="Helper text" options={options} />
122
+ <DxcRadioGroup label="Label" error="" helperText="Helper text" options={options} />
95
123
  </ExampleContainer>
96
124
  <ExampleContainer>
97
125
  <Title title="Error" theme="light" level={4} />
98
- <DxcRadioGroup label="Example" error="Error message" helperText="Helper text" options={options} />
126
+ <DxcRadioGroup label="Label" error="Error message" helperText="Helper text" options={options} />
127
+ </ExampleContainer>
128
+ <Title title="Opinionated theme" theme="light" level={2} />
129
+ <ExampleContainer>
130
+ <Title title="Enabled" theme="light" level={4} />
131
+ <HalstackProvider theme={opinionatedTheme}>
132
+ <DxcRadioGroup label="Label" helperText="Helper text" defaultValue="A" options={single_option} />
133
+ </HalstackProvider>
134
+ </ExampleContainer>
135
+ <ExampleContainer pseudoState="pseudo-hover">
136
+ <Title title="Hovered" theme="light" level={4} />
137
+ <HalstackProvider theme={opinionatedTheme}>
138
+ <DxcRadioGroup label="Label" helperText="Helper text" defaultValue="A" options={single_option} />
139
+ </HalstackProvider>
140
+ </ExampleContainer>
141
+ <ExampleContainer pseudoState="pseudo-active">
142
+ <Title title="Active" theme="light" level={4} />
143
+ <HalstackProvider theme={opinionatedTheme}>
144
+ <DxcRadioGroup label="Label" helperText="Helper text" defaultValue="A" options={single_option} />
145
+ </HalstackProvider>
146
+ </ExampleContainer>
147
+ <ExampleContainer pseudoState="pseudo-focus">
148
+ <Title title="Focused" theme="light" level={4} />
149
+ <HalstackProvider theme={opinionatedTheme}>
150
+ <DxcRadioGroup label="Label" helperText="Helper text" defaultValue="A" options={single_option} />
151
+ </HalstackProvider>
152
+ </ExampleContainer>
153
+ <ExampleContainer>
154
+ <Title title="Disabled" theme="light" level={4} />
155
+ <HalstackProvider theme={opinionatedTheme}>
156
+ <DxcRadioGroup label="Label" helperText="Helper text" options={single_disabled_options} defaultValue="A" />
157
+ </HalstackProvider>
158
+ </ExampleContainer>
159
+ <ExampleContainer>
160
+ <Title title="Readonly enabled" theme="light" level={4} />
161
+ <HalstackProvider theme={opinionatedTheme}>
162
+ <DxcRadioGroup label="Label" options={single_option} defaultValue="A" readonly />
163
+ </HalstackProvider>
164
+ </ExampleContainer>
165
+ <ExampleContainer pseudoState="pseudo-hover">
166
+ <Title title="Readonly hovered" theme="light" level={4} />
167
+ <HalstackProvider theme={opinionatedTheme}>
168
+ <DxcRadioGroup label="Label" options={single_option} defaultValue="A" readonly />
169
+ </HalstackProvider>
170
+ </ExampleContainer>
171
+ <ExampleContainer pseudoState="pseudo-active">
172
+ <Title title="Readonly active" theme="light" level={4} />
173
+ <HalstackProvider theme={opinionatedTheme}>
174
+ <DxcRadioGroup label="Label" options={single_option} defaultValue="A" readonly />
175
+ </HalstackProvider>
176
+ </ExampleContainer>
177
+ <ExampleContainer pseudoState="pseudo-focus">
178
+ <Title title="Readonly focused" theme="light" level={4} />
179
+ <HalstackProvider theme={opinionatedTheme}>
180
+ <DxcRadioGroup label="Label" options={single_option} defaultValue="A" readonly />
181
+ </HalstackProvider>
182
+ </ExampleContainer>
183
+ <ExampleContainer>
184
+ <Title title="Enabled" theme="light" level={4} />
185
+ <HalstackProvider theme={opinionatedTheme}>
186
+ <DxcRadioGroup label="Label" options={single_option} defaultValue="A" error="Error message" />
187
+ </HalstackProvider>
188
+ </ExampleContainer>
189
+ <ExampleContainer pseudoState="pseudo-hover">
190
+ <Title title="Hovered" theme="light" level={4} />
191
+ <HalstackProvider theme={opinionatedTheme}>
192
+ <DxcRadioGroup label="Label" options={single_option} defaultValue="A" error="Error message" />
193
+ </HalstackProvider>
194
+ </ExampleContainer>
195
+ <ExampleContainer pseudoState="pseudo-active">
196
+ <Title title="Active" theme="light" level={4} />
197
+ <HalstackProvider theme={opinionatedTheme}>
198
+ <DxcRadioGroup label="Label" options={single_option} defaultValue="A" error="Error message" />
199
+ </HalstackProvider>
200
+ </ExampleContainer>
201
+ <ExampleContainer pseudoState="pseudo-focus">
202
+ <Title title="Focused" theme="light" level={4} />
203
+ <HalstackProvider theme={opinionatedTheme}>
204
+ <DxcRadioGroup label="Label" options={single_option} defaultValue="A" error="Error message" />
205
+ </HalstackProvider>
206
+ </ExampleContainer>
207
+ <ExampleContainer>
208
+ <Title title="Disabled" theme="light" level={4} />
209
+ <HalstackProvider theme={opinionatedTheme}>
210
+ <DxcRadioGroup label="Label" helperText="Helper text" options={options} disabled defaultValue="A" />
211
+ </HalstackProvider>
99
212
  </ExampleContainer>
100
213
  </>
101
214
  );
@@ -16,42 +16,37 @@ var _ResultsetTable = _interopRequireDefault(require("./ResultsetTable"));
16
16
 
17
17
  // Mocking DOMRect for Radix Primitive Popover
18
18
  global.globalThis = global;
19
+ global.DOMRect = {
20
+ fromRect: function fromRect() {
21
+ return {
22
+ top: 0,
23
+ left: 0,
24
+ bottom: 0,
25
+ right: 0,
26
+ width: 0,
27
+ height: 0
28
+ };
29
+ }
30
+ };
19
31
 
20
32
  global.ResizeObserver = /*#__PURE__*/function () {
21
- function ResizeObserver(cb) {
33
+ function ResizeObserver() {
22
34
  (0, _classCallCheck2["default"])(this, ResizeObserver);
23
- this.cb = cb;
24
35
  }
25
36
 
26
37
  (0, _createClass2["default"])(ResizeObserver, [{
27
38
  key: "observe",
28
- value: function observe() {
29
- this.cb([{
30
- borderBoxSize: {
31
- inlineSize: 0,
32
- blockSize: 0
33
- }
34
- }]);
35
- }
39
+ value: function observe() {}
36
40
  }, {
37
41
  key: "unobserve",
38
42
  value: function unobserve() {}
43
+ }, {
44
+ key: "disconnect",
45
+ value: function disconnect() {}
39
46
  }]);
40
47
  return ResizeObserver;
41
48
  }();
42
49
 
43
- global.DOMRect = {
44
- fromRect: function fromRect() {
45
- return {
46
- top: 0,
47
- left: 0,
48
- bottom: 0,
49
- right: 0,
50
- width: 0,
51
- height: 0
52
- };
53
- }
54
- };
55
50
  var columns = [{
56
51
  displayValue: "Id",
57
52
  isSortable: false
@@ -1,4 +1,4 @@
1
1
  import React from "react";
2
2
  import { ListboxProps } from "./types";
3
- declare const _default: React.MemoExoticComponent<({ id, currentValue, options, visualFocusIndex, lastOptionIndex, multiple, optional, optionalItem, searchable, handleOptionOnClick, getSelectWidth, }: ListboxProps) => JSX.Element>;
3
+ declare const _default: React.MemoExoticComponent<({ id, currentValue, options, visualFocusIndex, lastOptionIndex, multiple, optional, optionalItem, searchable, handleOptionOnClick, styles, }: ListboxProps) => JSX.Element>;
4
4
  export default _default;
package/select/Listbox.js CHANGED
@@ -11,13 +11,9 @@ exports["default"] = void 0;
11
11
 
12
12
  var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
13
13
 
14
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
-
16
14
  var _react = _interopRequireWildcard(require("react"));
17
15
 
18
- var _styledComponents = _interopRequireWildcard(require("styled-components"));
19
-
20
- var _useTheme = _interopRequireDefault(require("../useTheme"));
16
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
21
17
 
22
18
  var _useTranslatedLabels = _interopRequireDefault(require("../useTranslatedLabels"));
23
19
 
@@ -50,17 +46,10 @@ var Listbox = function Listbox(_ref) {
50
46
  optionalItem = _ref.optionalItem,
51
47
  searchable = _ref.searchable,
52
48
  handleOptionOnClick = _ref.handleOptionOnClick,
53
- getSelectWidth = _ref.getSelectWidth;
54
- var colorsTheme = (0, _useTheme["default"])();
49
+ styles = _ref.styles;
55
50
  var translatedLabels = (0, _useTranslatedLabels["default"])();
56
51
  var listboxRef = (0, _react.useRef)(null);
57
-
58
- var _useState = (0, _react.useState)(null),
59
- _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
60
- styles = _useState2[0],
61
- setStyles = _useState2[1];
62
-
63
- var globalIndex = optional && !multiple ? 0 : -1; // index for options, starting from 0 to options.length -1
52
+ var globalIndex = optional && !multiple ? 0 : -1;
64
53
 
65
54
  var mapOptionFunc = function mapOptionFunc(option, mapIndex) {
66
55
  if (option.options) {
@@ -122,25 +111,7 @@ var Listbox = function Listbox(_ref) {
122
111
  inline: "start"
123
112
  });
124
113
  }, [visualFocusIndex]);
125
-
126
- var handleResize = function handleResize() {
127
- setStyles({
128
- width: getSelectWidth()
129
- });
130
- };
131
-
132
- (0, _react.useLayoutEffect)(function () {
133
- handleResize();
134
- }, [getSelectWidth]);
135
- (0, _react.useEffect)(function () {
136
- window.addEventListener("resize", handleResize);
137
- return function () {
138
- window.removeEventListener("resize", handleResize);
139
- };
140
- }, [getSelectWidth]);
141
- return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
142
- theme: colorsTheme.select
143
- }, /*#__PURE__*/_react["default"].createElement(ListboxContainer, {
114
+ return /*#__PURE__*/_react["default"].createElement(ListboxContainer, {
144
115
  id: id,
145
116
  onClick: function onClick(event) {
146
117
  event.stopPropagation();
@@ -162,7 +133,7 @@ var Listbox = function Listbox(_ref) {
162
133
  isGroupedOption: false,
163
134
  isLastOption: lastOptionIndex === 0,
164
135
  isSelected: multiple ? currentValue.includes(optionalItem.value) : currentValue === optionalItem.value
165
- }), options.map(mapOptionFunc)));
136
+ }), options.map(mapOptionFunc));
166
137
  };
167
138
 
168
139
  var ListboxContainer = _styledComponents["default"].ul(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n box-sizing: border-box;\n max-height: 304px;\n overflow-y: auto;\n margin: 0;\n padding: 0.25rem 0;\n background-color: ", ";\n border: 1px solid ", ";\n border-radius: 0.25rem;\n box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);\n cursor: default;\n color: ", ";\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n"])), function (props) {
package/select/Option.js CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
- var _typeof = require("@babel/runtime/helpers/typeof");
6
-
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
@@ -13,19 +11,13 @@ var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/hel
13
11
 
14
12
  var _react = _interopRequireDefault(require("react"));
15
13
 
16
- var _styledComponents = _interopRequireWildcard(require("styled-components"));
17
-
18
- var _useTheme = _interopRequireDefault(require("../useTheme"));
14
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
19
15
 
20
16
  var _Checkbox = _interopRequireDefault(require("../checkbox/Checkbox"));
21
17
 
22
18
  var _Icons = _interopRequireDefault(require("./Icons"));
23
19
 
24
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7;
25
-
26
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
-
28
- 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
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
29
21
 
30
22
  var Option = function Option(_ref) {
31
23
  var id = _ref.id,
@@ -37,10 +29,7 @@ var Option = function Option(_ref) {
37
29
  isGroupedOption = _ref$isGroupedOption === void 0 ? false : _ref$isGroupedOption,
38
30
  isLastOption = _ref.isLastOption,
39
31
  isSelected = _ref.isSelected;
40
- var colorsTheme = (0, _useTheme["default"])();
41
- return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
42
- theme: colorsTheme.select
43
- }, /*#__PURE__*/_react["default"].createElement(OptionItem, {
32
+ return /*#__PURE__*/_react["default"].createElement(OptionItem, {
44
33
  id: id,
45
34
  onClick: function onClick() {
46
35
  _onClick(option);
@@ -62,13 +51,13 @@ var Option = function Option(_ref) {
62
51
  grouped: isGroupedOption,
63
52
  multiple: multiple,
64
53
  role: !(typeof option.icon === "string") ? "img" : undefined
65
- }, typeof option.icon === "string" ? /*#__PURE__*/_react["default"].createElement(OptionIconImg, {
54
+ }, typeof option.icon === "string" ? /*#__PURE__*/_react["default"].createElement("img", {
66
55
  src: option.icon
67
56
  }) : option.icon), /*#__PURE__*/_react["default"].createElement(OptionContent, {
68
57
  grouped: isGroupedOption,
69
58
  hasIcon: option.icon ? true : false,
70
59
  multiple: multiple
71
- }, /*#__PURE__*/_react["default"].createElement(OptionLabel, null, option.label), !multiple && isSelected && /*#__PURE__*/_react["default"].createElement(OptionSelectedIndicator, null, _Icons["default"].selected)))));
60
+ }, /*#__PURE__*/_react["default"].createElement(OptionLabel, null, option.label), !multiple && isSelected && /*#__PURE__*/_react["default"].createElement(OptionSelectedIndicator, null, _Icons["default"].selected))));
72
61
  };
73
62
 
74
63
  var OptionItem = _styledComponents["default"].li(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n padding: 0 0.5rem;\n box-shadow: inset 0 0 0 2px transparent;\n ", "\n ", ";\n line-height: 1.715em;\n cursor: pointer;\n\n &:hover {\n ", ";\n }\n &:active {\n ", ";\n }\n"])), function (props) {
@@ -87,21 +76,19 @@ var StyledOption = _styledComponents["default"].span(_templateObject2 || (_templ
87
76
  return props.last || props.visualFocused || props.selected ? "border-bottom: 1px solid transparent" : "border-bottom: 1px solid ".concat(props.theme.listOptionDividerColor);
88
77
  });
89
78
 
90
- var OptionIcon = _styledComponents["default"].span(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-wrap: wrap;\n align-content: center;\n height: 24px;\n width: 24px;\n ", "\n color: ", ";\n"])), function (props) {
91
- return props.grouped && !props.multiple ? "padding-left: 16px;" : "padding-left: 8px;";
79
+ var OptionIcon = _styledComponents["default"].span(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n padding: 0.125rem;\n margin-left: ", ";\n color: ", ";\n\n svg,\n img {\n height: 20px;\n width: 20px;\n }\n"])), function (props) {
80
+ return props.grouped && !props.multiple ? "16px" : "8px";
92
81
  }, function (props) {
93
82
  return props.theme.listOptionIconColor;
94
83
  });
95
84
 
96
- var OptionContent = _styledComponents["default"].span(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n justify-content: space-between;\n width: 100%;\n overflow: hidden;\n ", "\n"])), function (props) {
97
- return props.grouped && !props.multiple && !props.hasIcon ? "padding-left: 16px;" : "padding-left: 8px;";
85
+ var OptionContent = _styledComponents["default"].span(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n justify-content: space-between;\n gap: 0.25rem;\n width: 100%;\n overflow: hidden;\n margin-left: ", ";\n"])), function (props) {
86
+ return props.grouped && !props.multiple && !props.hasIcon ? "16px" : "8px";
98
87
  });
99
88
 
100
- var OptionIconImg = _styledComponents["default"].img(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2["default"])(["\n width: 16px;\n height: 16px;\n"])));
101
-
102
- var OptionLabel = _styledComponents["default"].span(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteral2["default"])(["\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n"])));
89
+ var OptionLabel = _styledComponents["default"].span(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2["default"])(["\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n"])));
103
90
 
104
- var OptionSelectedIndicator = _styledComponents["default"].span(_templateObject7 || (_templateObject7 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n height: 16px;\n width: 16px;\n margin-left: 4px;\n color: ", ";\n"])), function (props) {
91
+ var OptionSelectedIndicator = _styledComponents["default"].span(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n align-items: center;\n color: ", ";\n\n svg {\n width: 16px;\n height: 16px;\n }\n"])), function (props) {
105
92
  return props.theme.selectedListOptionIconColor;
106
93
  });
107
94
 
package/select/Select.js CHANGED
@@ -140,6 +140,28 @@ var notOptionalCheck = function notOptionalCheck(value, multiple, optional) {
140
140
  return !optional && (multiple ? value.length === 0 : value === "");
141
141
  };
142
142
 
143
+ var useWidth = function useWidth(target) {
144
+ var _useState = (0, _react.useState)(0),
145
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
146
+ width = _useState2[0],
147
+ setWidth = _useState2[1];
148
+
149
+ (0, _react.useEffect)(function () {
150
+ if (target != null) {
151
+ setWidth(target.getBoundingClientRect().width);
152
+ var triggerObserver = new ResizeObserver(function (entries) {
153
+ var rect = entries[0].target.getBoundingClientRect();
154
+ setWidth(rect === null || rect === void 0 ? void 0 : rect.width);
155
+ });
156
+ triggerObserver.observe(target);
157
+ return function () {
158
+ triggerObserver.unobserve(target);
159
+ };
160
+ }
161
+ }, [target]);
162
+ return width;
163
+ };
164
+
143
165
  var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
144
166
  var _selectedOption$label;
145
167
 
@@ -169,36 +191,37 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
169
191
  _ref$tabIndex = _ref.tabIndex,
170
192
  tabIndex = _ref$tabIndex === void 0 ? 0 : _ref$tabIndex;
171
193
 
172
- var _useState = (0, _react.useState)("select-".concat((0, _uuid.v4)())),
173
- _useState2 = (0, _slicedToArray2["default"])(_useState, 1),
174
- selectId = _useState2[0];
194
+ var _useState3 = (0, _react.useState)("select-".concat((0, _uuid.v4)())),
195
+ _useState4 = (0, _slicedToArray2["default"])(_useState3, 1),
196
+ selectId = _useState4[0];
175
197
 
176
198
  var selectLabelId = "label-".concat(selectId);
177
199
  var errorId = "error-".concat(selectId);
178
200
  var optionsListId = "".concat(selectId, "-listbox");
179
201
 
180
- var _useState3 = (0, _react.useState)(defaultValue !== null && defaultValue !== void 0 ? defaultValue : multiple ? [] : ""),
181
- _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
182
- innerValue = _useState4[0],
183
- setInnerValue = _useState4[1];
184
-
185
- var _useState5 = (0, _react.useState)(""),
202
+ var _useState5 = (0, _react.useState)(defaultValue !== null && defaultValue !== void 0 ? defaultValue : multiple ? [] : ""),
186
203
  _useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
187
- searchValue = _useState6[0],
188
- setSearchValue = _useState6[1];
204
+ innerValue = _useState6[0],
205
+ setInnerValue = _useState6[1];
189
206
 
190
- var _useState7 = (0, _react.useState)(-1),
207
+ var _useState7 = (0, _react.useState)(""),
191
208
  _useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
192
- visualFocusIndex = _useState8[0],
193
- changeVisualFocusIndex = _useState8[1];
209
+ searchValue = _useState8[0],
210
+ setSearchValue = _useState8[1];
194
211
 
195
- var _useState9 = (0, _react.useState)(false),
212
+ var _useState9 = (0, _react.useState)(-1),
196
213
  _useState10 = (0, _slicedToArray2["default"])(_useState9, 2),
197
- isOpen = _useState10[0],
198
- changeIsOpen = _useState10[1];
214
+ visualFocusIndex = _useState10[0],
215
+ changeVisualFocusIndex = _useState10[1];
216
+
217
+ var _useState11 = (0, _react.useState)(false),
218
+ _useState12 = (0, _slicedToArray2["default"])(_useState11, 2),
219
+ isOpen = _useState12[0],
220
+ changeIsOpen = _useState12[1];
199
221
 
200
222
  var selectRef = (0, _react.useRef)(null);
201
223
  var selectSearchInputRef = (0, _react.useRef)(null);
224
+ var width = useWidth(selectRef.current);
202
225
  var colorsTheme = (0, _useTheme["default"])();
203
226
  var translatedLabels = (0, _useTranslatedLabels["default"])();
204
227
  var optionalItem = {
@@ -359,12 +382,6 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
359
382
  !multiple && closeOptions();
360
383
  setSearchValue("");
361
384
  }, [handleSelectChangeValue, closeOptions, multiple]);
362
- var getSelectWidth = (0, _react.useCallback)(function () {
363
- var _selectRef$current;
364
-
365
- var rect = selectRef === null || selectRef === void 0 ? void 0 : (_selectRef$current = selectRef.current) === null || _selectRef$current === void 0 ? void 0 : _selectRef$current.getBoundingClientRect();
366
- return rect === null || rect === void 0 ? void 0 : rect.width;
367
- }, []);
368
385
  return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
369
386
  theme: colorsTheme.select
370
387
  }, /*#__PURE__*/_react["default"].createElement(SelectContainer, {
@@ -471,7 +488,9 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
471
488
  optionalItem: optionalItem,
472
489
  searchable: searchable,
473
490
  handleOptionOnClick: handleOptionOnClick,
474
- getSelectWidth: getSelectWidth
491
+ styles: {
492
+ width: width
493
+ }
475
494
  }))), !disabled && typeof error === "string" && /*#__PURE__*/_react["default"].createElement(Error, {
476
495
  id: errorId,
477
496
  "aria-live": error ? "assertive" : "off"