@dxc-technology/halstack-react 0.0.0-ee92231 → 0.0.0-efa7c74

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 (92) hide show
  1. package/alert/Alert.stories.tsx +170 -0
  2. package/alert/types.d.ts +1 -1
  3. package/box/Box.d.ts +1 -1
  4. package/box/Box.js +2 -5
  5. package/box/types.d.ts +0 -4
  6. package/button/Button.d.ts +1 -1
  7. package/button/Button.js +4 -2
  8. package/button/Button.stories.tsx +216 -233
  9. package/button/types.d.ts +2 -2
  10. package/card/Card.js +4 -5
  11. package/card/Card.stories.tsx +201 -0
  12. package/card/ice-cream.jpg +0 -0
  13. package/card/types.d.ts +4 -6
  14. package/checkbox/types.d.ts +1 -1
  15. package/chip/Chip.stories.tsx +121 -0
  16. package/common/variables.js +13 -5
  17. package/date-input/DateInput.stories.tsx +138 -0
  18. package/dialog/Dialog.stories.tsx +212 -0
  19. package/file-input/FileInput.d.ts +4 -0
  20. package/file-input/FileInput.js +7 -28
  21. package/file-input/FileItem.d.ts +14 -0
  22. package/file-input/FileItem.js +4 -15
  23. package/file-input/types.d.ts +87 -0
  24. package/file-input/types.js +5 -0
  25. package/footer/types.d.ts +1 -1
  26. package/header/Header.stories.tsx +162 -0
  27. package/header/types.d.ts +4 -2
  28. package/heading/Heading.d.ts +4 -0
  29. package/heading/Heading.js +6 -23
  30. package/heading/Heading.stories.tsx +53 -0
  31. package/heading/types.d.ts +33 -0
  32. package/heading/types.js +5 -0
  33. package/link/Link.js +2 -2
  34. package/link/Link.stories.tsx +146 -0
  35. package/number-input/NumberInput.d.ts +4 -0
  36. package/number-input/NumberInput.js +2 -44
  37. package/number-input/{NumberInput.stories.jsx → NumberInput.stories.tsx} +0 -0
  38. package/number-input/NumberInputContext.d.ts +4 -0
  39. package/number-input/NumberInputContext.js +5 -2
  40. package/number-input/numberInputContextTypes.d.ts +19 -0
  41. package/number-input/numberInputContextTypes.js +5 -0
  42. package/number-input/types.d.ts +117 -0
  43. package/number-input/types.js +5 -0
  44. package/package.json +1 -1
  45. package/password-input/types.d.ts +13 -8
  46. package/radio/types.d.ts +2 -2
  47. package/resultsetTable/ResultsetTable.d.ts +4 -0
  48. package/resultsetTable/ResultsetTable.js +0 -25
  49. package/resultsetTable/types.d.ts +63 -0
  50. package/resultsetTable/types.js +5 -0
  51. package/select/Select.stories.tsx +572 -0
  52. package/sidenav/Sidenav.d.ts +9 -0
  53. package/sidenav/Sidenav.js +4 -13
  54. package/sidenav/Sidenav.stories.tsx +165 -0
  55. package/sidenav/types.d.ts +50 -0
  56. package/sidenav/types.js +5 -0
  57. package/slider/Slider.d.ts +1 -1
  58. package/slider/Slider.js +41 -30
  59. package/slider/Slider.stories.tsx +177 -0
  60. package/slider/types.d.ts +2 -7
  61. package/table/Table.js +1 -1
  62. package/tabs/Tabs.js +3 -1
  63. package/tabs/Tabs.stories.tsx +121 -0
  64. package/tabs/types.d.ts +2 -3
  65. package/tag/Tag.d.ts +4 -0
  66. package/tag/Tag.js +3 -24
  67. package/tag/{Tag.stories.jsx → Tag.stories.tsx} +0 -0
  68. package/tag/types.d.ts +60 -0
  69. package/tag/types.js +5 -0
  70. package/text-input/TextInput.d.ts +4 -0
  71. package/text-input/TextInput.js +4 -44
  72. package/text-input/types.d.ts +157 -0
  73. package/text-input/types.js +5 -0
  74. package/toggle-group/ToggleGroup.d.ts +4 -0
  75. package/toggle-group/ToggleGroup.js +5 -31
  76. package/toggle-group/ToggleGroup.stories.tsx +178 -0
  77. package/toggle-group/types.d.ts +84 -0
  78. package/toggle-group/types.js +5 -0
  79. package/wizard/Wizard.d.ts +4 -0
  80. package/wizard/Wizard.js +11 -51
  81. package/wizard/Wizard.stories.jsx +224 -0
  82. package/wizard/types.d.ts +64 -0
  83. package/wizard/types.js +5 -0
  84. package/file-input/index.d.ts +0 -81
  85. package/heading/index.d.ts +0 -17
  86. package/number-input/index.d.ts +0 -113
  87. package/resultsetTable/index.d.ts +0 -19
  88. package/sidenav/index.d.ts +0 -13
  89. package/tag/index.d.ts +0 -24
  90. package/text-input/index.d.ts +0 -135
  91. package/toggle-group/index.d.ts +0 -21
  92. package/wizard/index.d.ts +0 -18
@@ -0,0 +1,121 @@
1
+ import React from "react";
2
+ import { userEvent, within } from "@storybook/testing-library";
3
+ import DxcTabs from "./Tabs";
4
+ import Title from "../../.storybook/components/Title";
5
+ import ExampleContainer from "../../.storybook/components/ExampleContainer";
6
+
7
+ export default {
8
+ title: "Tabs",
9
+ component: DxcTabs,
10
+ };
11
+
12
+ const iconSVG = () => {
13
+ return (
14
+ <svg viewBox="0 0 24 24" fill="currentColor">
15
+ <path d="M0 0h24v24H0z" fill="none" />
16
+ <path d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z" />
17
+ </svg>
18
+ );
19
+ };
20
+
21
+ const tabs: any = [
22
+ {
23
+ label: "Tab 1",
24
+ },
25
+ {
26
+ label: "Tab 2",
27
+ },
28
+ {
29
+ label: "Tab 3",
30
+ isDisabled: true,
31
+ },
32
+ {
33
+ label: "Tab 4",
34
+ },
35
+ ];
36
+
37
+ const tabsNotification = tabs.map((tab, index) => ({
38
+ ...tab,
39
+ notificationNumber: (index === 0 && true) || (index === 1 && 5) || (index === 2 && 200),
40
+ }));
41
+
42
+ const tabsIcon = tabs.map((tab) => ({ ...tab, icon: iconSVG }));
43
+
44
+ const tabsNotificationIcon = tabsNotification.map((tab) => ({ ...tab, icon: iconSVG }));
45
+
46
+ export const Chromatic = () => (
47
+ <>
48
+ <ExampleContainer>
49
+ <Title title="Only label" theme="light" level={4} />
50
+ <DxcTabs tabs={tabs} />
51
+ </ExampleContainer>
52
+ <ExampleContainer pseudoState="pseudo-hover">
53
+ <Title title="Hovered tabs" theme="light" level={4} />
54
+ <DxcTabs tabs={tabs} />
55
+ </ExampleContainer>
56
+ <ExampleContainer pseudoState="pseudo-focus">
57
+ <Title title="Focused tabs" theme="light" level={4} />
58
+ <DxcTabs tabs={tabs} />
59
+ </ExampleContainer>
60
+ <ExampleContainer pseudoState="pseudo-active">
61
+ <Title title="Actived tabs" theme="light" level={4} />
62
+ <DxcTabs tabs={tabs} />
63
+ </ExampleContainer>
64
+ <ExampleContainer>
65
+ <Title title="With notification number" theme="light" level={4} />
66
+ <DxcTabs tabs={tabsNotification} />
67
+ </ExampleContainer>
68
+ <ExampleContainer>
69
+ <Title title="With icon position top" theme="light" level={4} />
70
+ <DxcTabs tabs={tabsIcon} />
71
+ </ExampleContainer>
72
+ <ExampleContainer>
73
+ <Title title="With icon position left" theme="light" level={4} />
74
+ <DxcTabs tabs={tabsIcon} iconPosition="left" />
75
+ </ExampleContainer>
76
+ <ExampleContainer>
77
+ <Title title="With icon and notification number" theme="light" level={4} />
78
+ <DxcTabs tabs={tabsNotificationIcon} />
79
+ </ExampleContainer>
80
+ <ExampleContainer>
81
+ <Title title="With icon on the left and notification number" theme="light" level={4} />
82
+ <DxcTabs tabs={tabsNotificationIcon} iconPosition="left" />
83
+ </ExampleContainer>
84
+ <ExampleContainer>
85
+ <Title title="Scrollable" theme="light" level={4} />
86
+ <div style={{ width: "400px" }}>
87
+ <DxcTabs tabs={tabsNotificationIcon} iconPosition="left" activeTabIndex={1} />
88
+ </div>
89
+ </ExampleContainer>
90
+
91
+ <Title title="Margins" theme="light" level={2} />
92
+ <ExampleContainer>
93
+ <Title title="Xxsmall margin" theme="light" level={4} />
94
+ <DxcTabs tabs={tabs} margin="xxsmall" />
95
+ </ExampleContainer>
96
+ <ExampleContainer>
97
+ <Title title="Xsmall margin" theme="light" level={4} />
98
+ <DxcTabs tabs={tabs} margin="xsmall" />
99
+ </ExampleContainer>
100
+ <ExampleContainer>
101
+ <Title title="Small margin" theme="light" level={4} />
102
+ <DxcTabs tabs={tabs} margin="small" />
103
+ </ExampleContainer>
104
+ <ExampleContainer>
105
+ <Title title="Medium margin" theme="light" level={4} />
106
+ <DxcTabs tabs={tabs} margin="medium" />
107
+ </ExampleContainer>
108
+ <ExampleContainer>
109
+ <Title title="Large margin" theme="light" level={4} />
110
+ <DxcTabs tabs={tabs} margin="large" />
111
+ </ExampleContainer>
112
+ <ExampleContainer>
113
+ <Title title="Xlarge margin" theme="light" level={4} />
114
+ <DxcTabs tabs={tabs} margin="xlarge" />
115
+ </ExampleContainer>
116
+ <ExampleContainer>
117
+ <Title title="Xxlarge margin" theme="light" level={4} />
118
+ <DxcTabs tabs={tabs} margin="xxlarge" />
119
+ </ExampleContainer>
120
+ </>
121
+ );
package/tabs/types.d.ts CHANGED
@@ -58,9 +58,8 @@ declare type Props = {
58
58
  */
59
59
  onTabHover?: (tabIndex: number) => void;
60
60
  /**
61
- * Size of the margin to be applied to the component. You can pass an object
62
- * with 'top', 'bottom', 'left' and 'right' properties in order to specify
63
- * different margin sizes.
61
+ * Size of the margin to be applied to the component ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
62
+ * You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different margin sizes.
64
63
  */
65
64
  margin?: Space | Margin;
66
65
  /**
package/tag/Tag.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import TagPropsType from "./types";
3
+ declare const DxcTag: ({ icon, iconSrc, label, linkHref, onClick, iconBgColor, labelPosition, newWindow, margin, size, tabIndex, }: TagPropsType) => JSX.Element;
4
+ export default DxcTag;
package/tag/Tag.js CHANGED
@@ -9,8 +9,6 @@ Object.defineProperty(exports, "__esModule", {
9
9
  });
10
10
  exports["default"] = void 0;
11
11
 
12
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
-
14
12
  var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
15
13
 
16
14
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
@@ -21,8 +19,6 @@ var _react = _interopRequireWildcard(require("react"));
21
19
 
22
20
  var _styledComponents = _interopRequireWildcard(require("styled-components"));
23
21
 
24
- var _propTypes = _interopRequireDefault(require("prop-types"));
25
-
26
22
  var _variables = require("../common/variables.js");
27
23
 
28
24
  var _useTheme = _interopRequireDefault(require("../useTheme.js"));
@@ -40,8 +36,8 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
40
36
  var DxcTag = function DxcTag(_ref) {
41
37
  var icon = _ref.icon,
42
38
  iconSrc = _ref.iconSrc,
43
- label = _ref.label,
44
- margin = _ref.margin,
39
+ _ref$label = _ref.label,
40
+ label = _ref$label === void 0 ? "" : _ref$label,
45
41
  linkHref = _ref.linkHref,
46
42
  onClick = _ref.onClick,
47
43
  _ref$iconBgColor = _ref.iconBgColor,
@@ -50,6 +46,7 @@ var DxcTag = function DxcTag(_ref) {
50
46
  labelPosition = _ref$labelPosition === void 0 ? "after" : _ref$labelPosition,
51
47
  _ref$newWindow = _ref.newWindow,
52
48
  newWindow = _ref$newWindow === void 0 ? false : _ref$newWindow,
49
+ margin = _ref.margin,
53
50
  _ref$size = _ref.size,
54
51
  size = _ref$size === void 0 ? "fitContent" : _ref$size,
55
52
  _ref$tabIndex = _ref.tabIndex,
@@ -192,23 +189,5 @@ var TagLabel = _styledComponents["default"].div(_templateObject8 || (_templateOb
192
189
  return props.theme.labelPaddingRight;
193
190
  });
194
191
 
195
- DxcTag.propTypes = {
196
- size: _propTypes["default"].oneOf((0, _toConsumableArray2["default"])(Object.keys(sizes))),
197
- icon: _propTypes["default"].oneOfType([_propTypes["default"].element, _propTypes["default"].func]),
198
- iconSrc: _propTypes["default"].string,
199
- iconBgColor: _propTypes["default"].string,
200
- label: _propTypes["default"].string,
201
- labelPosition: _propTypes["default"].oneOf(["before", "after"]),
202
- linkHref: _propTypes["default"].string,
203
- onClick: _propTypes["default"].func,
204
- newWindow: _propTypes["default"].bool,
205
- margin: _propTypes["default"].oneOfType([_propTypes["default"].shape({
206
- top: _propTypes["default"].oneOf(Object.keys(_variables.spaces)),
207
- bottom: _propTypes["default"].oneOf(Object.keys(_variables.spaces)),
208
- left: _propTypes["default"].oneOf(Object.keys(_variables.spaces)),
209
- right: _propTypes["default"].oneOf(Object.keys(_variables.spaces))
210
- }), _propTypes["default"].oneOf((0, _toConsumableArray2["default"])(Object.keys(_variables.spaces)))]),
211
- tabIndex: _propTypes["default"].number
212
- };
213
192
  var _default = DxcTag;
214
193
  exports["default"] = _default;
File without changes
package/tag/types.d.ts ADDED
@@ -0,0 +1,60 @@
1
+ /// <reference types="react" />
2
+ declare type Space = "xxsmall" | "xsmall" | "small" | "medium" | "large" | "xlarge" | "xxlarge";
3
+ declare type Margin = {
4
+ top?: Space;
5
+ bottom?: Space;
6
+ left?: Space;
7
+ right?: Space;
8
+ };
9
+ declare type SVG = React.SVGProps<SVGSVGElement> | React.FunctionComponent<React.SVGProps<SVGSVGElement>>;
10
+ declare type Props = {
11
+ /**
12
+ * Element used as the icon that will be placed next to the label.
13
+ */
14
+ icon?: SVG;
15
+ /**
16
+ * @deprecated URL of the icon.
17
+ */
18
+ iconSrc?: string;
19
+ /**
20
+ * Text to be placed next inside the tag.
21
+ */
22
+ label?: string;
23
+ /**
24
+ * If defined, the tag will be displayed as an anchor, using this prop as "href".
25
+ * Component will show some visual feedback on hover.
26
+ */
27
+ linkHref?: string;
28
+ /**
29
+ * If defined, the tag will be displayed as a button. This function will
30
+ * be called when the user clicks the tag. Component will show some
31
+ * visual feedback on hover.
32
+ */
33
+ onClick?: () => void;
34
+ /**
35
+ * Background color of the icon section of the tag.
36
+ */
37
+ iconBgColor?: string;
38
+ /**
39
+ * Whether the label should appear after or before the icon.
40
+ */
41
+ labelPosition?: "before" | "after";
42
+ /**
43
+ * If true, the page is opened in a new browser tab.
44
+ */
45
+ newWindow?: boolean;
46
+ /**
47
+ * Size of the margin to be applied to the component ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
48
+ * You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different margin sizes.
49
+ */
50
+ margin?: Space | Margin;
51
+ /**
52
+ * Size of the component.
53
+ */
54
+ size?: "small" | "medium" | "large" | "fillParent" | "fitContent";
55
+ /**
56
+ * Value of the tabindex attribute.
57
+ */
58
+ tabIndex?: number;
59
+ };
60
+ export default Props;
package/tag/types.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ import TextInputPropsType from "./types";
3
+ declare const DxcTextInput: React.ForwardRefExoticComponent<TextInputPropsType & React.RefAttributes<HTMLDivElement>>;
4
+ export default DxcTextInput;
@@ -9,8 +9,6 @@ Object.defineProperty(exports, "__esModule", {
9
9
  });
10
10
  exports["default"] = void 0;
11
11
 
12
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
-
14
12
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
15
13
 
16
14
  var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
@@ -23,8 +21,6 @@ var _styledComponents = _interopRequireWildcard(require("styled-components"));
23
21
 
24
22
  var _useTheme = _interopRequireDefault(require("../useTheme.js"));
25
23
 
26
- var _propTypes = _interopRequireDefault(require("prop-types"));
27
-
28
24
  var _variables = require("../common/variables.js");
29
25
 
30
26
  var _utils = require("../common/utils.js");
@@ -33,7 +29,7 @@ var _uuid = require("uuid");
33
29
 
34
30
  var _BackgroundColorContext = _interopRequireDefault(require("../BackgroundColorContext.js"));
35
31
 
36
- var _NumberInputContext = _interopRequireDefault(require("../number-input/NumberInputContext.js"));
32
+ var _NumberInputContext = _interopRequireDefault(require("../number-input/NumberInputContext"));
37
33
 
38
34
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17, _templateObject18;
39
35
 
@@ -317,7 +313,7 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref
317
313
  switch (event.keyCode) {
318
314
  case 40:
319
315
  // Arrow Down
320
- if (numberInputContext) {
316
+ if ((numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.typeNumber) === "number") {
321
317
  decrementNumber();
322
318
  event.preventDefault();
323
319
  } else {
@@ -335,7 +331,7 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref
335
331
 
336
332
  case 38:
337
333
  // Arrow Up
338
- if (numberInputContext) {
334
+ if ((numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.typeNumber) === "number") {
339
335
  incrementNumber();
340
336
  event.preventDefault();
341
337
  } else {
@@ -474,7 +470,7 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref
474
470
  changeVisualFocusedSuggIndex(-1);
475
471
  }
476
472
 
477
- numberInputContext && setNumberProps(numberInputContext.typeNumber, numberInputContext.minNumber, numberInputContext.maxNumber, numberInputContext.stepNumber);
473
+ (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.typeNumber) === "number" && setNumberProps(numberInputContext.typeNumber, numberInputContext.minNumber, numberInputContext.maxNumber, numberInputContext.stepNumber);
478
474
  }, [value, innerValue, suggestions, numberInputContext]);
479
475
 
480
476
  var HighlightedSuggestion = function HighlightedSuggestion(_ref2) {
@@ -785,41 +781,5 @@ var SuggestionsError = _styledComponents["default"].span(_templateObject18 || (_
785
781
  return props.theme.errorListDialogFontColor;
786
782
  });
787
783
 
788
- DxcTextInput.propTypes = {
789
- label: _propTypes["default"].string,
790
- name: _propTypes["default"].string,
791
- value: _propTypes["default"].string,
792
- helperText: _propTypes["default"].string,
793
- placeholder: _propTypes["default"].string,
794
- action: _propTypes["default"].shape({
795
- onClick: _propTypes["default"].func.isRequired,
796
- icon: _propTypes["default"].oneOfType([_propTypes["default"].shape({
797
- type: _propTypes["default"].oneOf(["svg"])
798
- }), _propTypes["default"].string]).isRequired
799
- }),
800
- clearable: _propTypes["default"].bool,
801
- disabled: _propTypes["default"].bool,
802
- optional: _propTypes["default"].bool,
803
- prefix: _propTypes["default"].string,
804
- suffix: _propTypes["default"].string,
805
- onChange: _propTypes["default"].func,
806
- onBlur: _propTypes["default"].func,
807
- error: _propTypes["default"].string,
808
- autocomplete: _propTypes["default"].string,
809
- margin: _propTypes["default"].oneOfType([_propTypes["default"].shape({
810
- top: _propTypes["default"].oneOf(Object.keys(_variables.spaces)),
811
- bottom: _propTypes["default"].oneOf(Object.keys(_variables.spaces)),
812
- left: _propTypes["default"].oneOf(Object.keys(_variables.spaces)),
813
- right: _propTypes["default"].oneOf(Object.keys(_variables.spaces))
814
- }), _propTypes["default"].oneOf((0, _toConsumableArray2["default"])(Object.keys(_variables.spaces)))]),
815
- size: _propTypes["default"].oneOf((0, _toConsumableArray2["default"])(Object.keys(sizes))),
816
- suggestions: _propTypes["default"].oneOfType([_propTypes["default"].func, _propTypes["default"].array]),
817
- pattern: _propTypes["default"].string,
818
- length: _propTypes["default"].shape({
819
- min: _propTypes["default"].number,
820
- max: _propTypes["default"].number
821
- }),
822
- tabIndex: _propTypes["default"].number
823
- };
824
784
  var _default = DxcTextInput;
825
785
  exports["default"] = _default;
@@ -0,0 +1,157 @@
1
+ /// <reference types="react" />
2
+ declare type Space = "xxsmall" | "xsmall" | "small" | "medium" | "large" | "xlarge" | "xxlarge";
3
+ declare type Margin = {
4
+ top?: Space;
5
+ bottom?: Space;
6
+ left?: Space;
7
+ right?: Space;
8
+ };
9
+ declare type SVG = React.SVGProps<SVGSVGElement> | React.FunctionComponent<React.SVGProps<SVGSVGElement>>;
10
+ declare type Action = {
11
+ /**
12
+ * This function will be called when the user clicks the action.
13
+ */
14
+ onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
15
+ /**
16
+ * Icon to be shown in the action.
17
+ */
18
+ icon: string | SVG;
19
+ /**
20
+ * Title of the action.
21
+ */
22
+ title?: string;
23
+ };
24
+ declare type RequiredMinLength = {
25
+ min: number;
26
+ max?: number;
27
+ };
28
+ declare type RequiredMaxLength = {
29
+ min?: number;
30
+ max: number;
31
+ };
32
+ declare type Props = {
33
+ /**
34
+ * Text to be placed above the input. This label will be used as the aria-label attribute of the list of suggestions.
35
+ */
36
+ label?: string;
37
+ /**
38
+ * Name attribute of the input element.
39
+ */
40
+ name?: string;
41
+ /**
42
+ * Value of the input. If undefined, the component will be uncontrolled and the value will be managed internally by the component.
43
+ */
44
+ value?: string;
45
+ /**
46
+ * Helper text to be placed above the input.
47
+ */
48
+ helperText?: string;
49
+ /**
50
+ * Text to be put as placeholder of the input.
51
+ */
52
+ placeholder?: string;
53
+ /**
54
+ * Action to be shown in the input. This is an object composed of an onClick function and an icon,
55
+ * being the latter either an inline svg or a URL to the image.
56
+ */
57
+ action?: Action;
58
+ /**
59
+ * If true, the input will have an action to clear the entered value.
60
+ */
61
+ clearable?: boolean;
62
+ /**
63
+ * If true, the component will be disabled.
64
+ */
65
+ disabled?: boolean;
66
+ /**
67
+ * If true, the input will be optional, showing '(Optional)'
68
+ * next to the label. Otherwise, the field will be considered required and an error will be
69
+ * passed as a parameter to the OnBlur and onChange functions when it has
70
+ * not been filled.
71
+ */
72
+ optional?: boolean;
73
+ /**
74
+ * Prefix to be placed before the input value.
75
+ */
76
+ prefix?: string;
77
+ /**
78
+ * Suffix to be placed after the input value.
79
+ */
80
+ suffix?: string;
81
+ /**
82
+ * This function will be called when the user types within the input
83
+ * element of the component. An object including the current value and
84
+ * the error (if the value entered is not valid) will be passed to this
85
+ * function. If there is no error, error will be null.
86
+ */
87
+ onChange?: (val: {
88
+ value: string;
89
+ error: string | null;
90
+ }) => void;
91
+ /**
92
+ * This function will be called when the input element loses the focus.
93
+ * An object including the input value and the error (if the value
94
+ * entered is not valid) will be passed to this function. If there is no error,
95
+ * error will be null.
96
+ */
97
+ onBlur?: (val: {
98
+ value: string;
99
+ error: string | null;
100
+ }) => void;
101
+ /**
102
+ * If it is defined, the component will change its appearance, showing
103
+ * the error below the input component. If it is not defined, the error
104
+ * messages will be managed internally, but never displayed on its own.
105
+ */
106
+ error?: string;
107
+ /**
108
+ * These are the options to be displayed as suggestions. It can be either an array or a function:
109
+ * - Array: Array of options that will be filtered by the component.
110
+ * - Function: This function will be called when the user changes the value, we will send as a parameter the new value;
111
+ * apart from that this function should return one promise on which we should make 'then' to get the suggestions filtered.
112
+ */
113
+ suggestions?: string[] | ((value: string) => Promise<string[]>);
114
+ /**
115
+ * Regular expression that defines the valid format allowed by the input.
116
+ * This will be checked both when the input element loses the focus and
117
+ * while typing within it. If the string entered does not match the
118
+ * pattern, the onBlur and onChange functions will be called with the
119
+ * current value and an internal error informing that this value does not
120
+ * match the pattern. If the pattern is met, the error parameter of both
121
+ * events will be null.
122
+ */
123
+ pattern?: string;
124
+ /**
125
+ * Specifies the minimun and maximum length allowed by the input.
126
+ * This will be checked both when the input element loses the
127
+ * focus and while typing within it. If the string entered does not
128
+ * comply the length, the onBlur and onChange functions will be called
129
+ * with the current value and an internal error informing that the value
130
+ * length does not comply the specified range. If a valid length is
131
+ * reached, the error parameter of both events will be null.
132
+ */
133
+ length?: RequiredMinLength | RequiredMaxLength;
134
+ /**
135
+ * HTML autocomplete attribute. Lets the user specify if any permission the user agent has to provide automated assistance in filling out the input value.
136
+ * Its value must be one of all the possible values of the HTML autocomplete attribute: 'on', 'off', 'email', 'username', 'new-password', ...
137
+ */
138
+ autocomplete?: string;
139
+ /**
140
+ * Size of the margin to be applied to the component ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
141
+ * You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different margin sizes.
142
+ */
143
+ margin?: Space | Margin;
144
+ /**
145
+ * Size of the component ('small' | 'medium' | 'large' | 'fillParent').
146
+ */
147
+ size?: "small" | "medium" | "large" | "fillParent";
148
+ /**
149
+ * Value of the tabindex attribute.
150
+ */
151
+ tabIndex?: number;
152
+ };
153
+ /**
154
+ * Reference to the component.
155
+ */
156
+ export declare type RefType = HTMLDivElement;
157
+ export default Props;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import ToogleGroupPropsType from "./types";
3
+ declare const DxcToggleGroup: ({ label, helperText, value, onChange, disabled, options, margin, multiple, tabIndex, }: ToogleGroupPropsType) => JSX.Element;
4
+ export default DxcToggleGroup;
@@ -9,8 +9,6 @@ Object.defineProperty(exports, "__esModule", {
9
9
  });
10
10
  exports["default"] = void 0;
11
11
 
12
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
-
14
12
  var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
15
13
 
16
14
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
@@ -23,8 +21,6 @@ var _styledComponents = _interopRequireWildcard(require("styled-components"));
23
21
 
24
22
  var _uuid = require("uuid");
25
23
 
26
- var _propTypes = _interopRequireDefault(require("prop-types"));
27
-
28
24
  var _variables = require("../common/variables.js");
29
25
 
30
26
  var _useTheme = _interopRequireDefault(require("../useTheme.js"));
@@ -42,8 +38,7 @@ var DxcToggleGroup = function DxcToggleGroup(_ref) {
42
38
  onChange = _ref.onChange,
43
39
  _ref$disabled = _ref.disabled,
44
40
  disabled = _ref$disabled === void 0 ? false : _ref$disabled,
45
- _ref$options = _ref.options,
46
- options = _ref$options === void 0 ? [] : _ref$options,
41
+ options = _ref.options,
47
42
  margin = _ref.margin,
48
43
  _ref$multiple = _ref.multiple,
49
44
  multiple = _ref$multiple === void 0 ? false : _ref$multiple,
@@ -51,7 +46,7 @@ var DxcToggleGroup = function DxcToggleGroup(_ref) {
51
46
  tabIndex = _ref$tabIndex === void 0 ? 0 : _ref$tabIndex;
52
47
  var colorsTheme = (0, _useTheme["default"])();
53
48
 
54
- var _useState = (0, _react.useState)(multiple ? [] : null),
49
+ var _useState = (0, _react.useState)(multiple ? [] : ""),
55
50
  _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
56
51
  selectedValue = _useState2[0],
57
52
  setSelectedValue = _useState2[1];
@@ -64,7 +59,7 @@ var DxcToggleGroup = function DxcToggleGroup(_ref) {
64
59
  var newSelectedOptions;
65
60
 
66
61
  if (value == null) {
67
- if (multiple) {
62
+ if (multiple && Array.isArray(selectedValue)) {
68
63
  newSelectedOptions = selectedValue.map(function (value) {
69
64
  return value;
70
65
  });
@@ -79,9 +74,9 @@ var DxcToggleGroup = function DxcToggleGroup(_ref) {
79
74
  setSelectedValue(newSelectedOptions);
80
75
  } else setSelectedValue(selectedOption === selectedValue ? null : selectedOption);
81
76
  } else if (multiple) {
82
- newSelectedOptions = value.map(function (v) {
77
+ newSelectedOptions = Array.isArray(value) ? value.map(function (v) {
83
78
  return v;
84
- });
79
+ }) : value;
85
80
 
86
81
  if (newSelectedOptions.includes(selectedOption)) {
87
82
  var _index = newSelectedOptions.indexOf(selectedOption);
@@ -218,26 +213,5 @@ var IconContainer = _styledComponents["default"].div(_templateObject9 || (_templ
218
213
  return props.optionLabel && props.theme.iconMarginRight;
219
214
  });
220
215
 
221
- DxcToggleGroup.propTypes = {
222
- label: _propTypes["default"].string,
223
- helperText: _propTypes["default"].string,
224
- value: _propTypes["default"].any,
225
- onChange: _propTypes["default"].func,
226
- disabled: _propTypes["default"].bool,
227
- multiple: _propTypes["default"].bool,
228
- options: _propTypes["default"].arrayOf(_propTypes["default"].shape({
229
- value: _propTypes["default"].any.isRequired,
230
- label: _propTypes["default"].string,
231
- icon: _propTypes["default"].oneOfType([_propTypes["default"].element, _propTypes["default"].func]),
232
- iconSrc: _propTypes["default"].string
233
- })),
234
- margin: _propTypes["default"].oneOfType([_propTypes["default"].shape({
235
- top: _propTypes["default"].oneOf(Object.keys(_variables.spaces)),
236
- bottom: _propTypes["default"].oneOf(Object.keys(_variables.spaces)),
237
- left: _propTypes["default"].oneOf(Object.keys(_variables.spaces)),
238
- right: _propTypes["default"].oneOf(Object.keys(_variables.spaces))
239
- }), _propTypes["default"].oneOf((0, _toConsumableArray2["default"])(Object.keys(_variables.spaces)))]),
240
- tabIndex: _propTypes["default"].number
241
- };
242
216
  var _default = DxcToggleGroup;
243
217
  exports["default"] = _default;