@dxc-technology/halstack-react 0.0.0-9253572 → 0.0.0-9439a0d

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 (209) hide show
  1. package/BackgroundColorContext.js +8 -4
  2. package/ThemeContext.js +84 -88
  3. package/V3Select/V3Select.js +33 -127
  4. package/V3Textarea/V3Textarea.js +10 -14
  5. package/accordion/Accordion.d.ts +4 -0
  6. package/accordion/Accordion.js +35 -130
  7. package/accordion/types.d.ts +68 -0
  8. package/accordion/types.js +5 -0
  9. package/accordion-group/AccordionGroup.d.ts +7 -0
  10. package/accordion-group/AccordionGroup.js +65 -81
  11. package/accordion-group/types.d.ts +72 -0
  12. package/accordion-group/types.js +5 -0
  13. package/alert/Alert.d.ts +4 -0
  14. package/alert/Alert.js +38 -151
  15. package/alert/Alert.stories.tsx +170 -0
  16. package/alert/types.d.ts +49 -0
  17. package/alert/types.js +5 -0
  18. package/badge/Badge.js +9 -13
  19. package/box/Box.d.ts +4 -0
  20. package/box/Box.js +13 -43
  21. package/box/Box.stories.tsx +132 -0
  22. package/box/types.d.ts +43 -0
  23. package/box/types.js +5 -0
  24. package/button/Button.d.ts +4 -0
  25. package/button/Button.js +22 -83
  26. package/button/Button.stories.tsx +276 -0
  27. package/button/types.d.ts +57 -0
  28. package/button/types.js +5 -0
  29. package/card/Card.d.ts +4 -0
  30. package/card/Card.js +33 -123
  31. package/card/Card.stories.tsx +201 -0
  32. package/card/ice-cream.jpg +0 -0
  33. package/card/types.d.ts +69 -0
  34. package/card/types.js +5 -0
  35. package/checkbox/Checkbox.d.ts +4 -0
  36. package/checkbox/Checkbox.js +13 -59
  37. package/checkbox/Checkbox.stories.tsx +192 -0
  38. package/checkbox/types.d.ts +60 -0
  39. package/checkbox/types.js +5 -0
  40. package/chip/Chip.js +17 -61
  41. package/chip/Chip.stories.tsx +121 -0
  42. package/common/RequiredComponent.js +3 -11
  43. package/common/variables.js +33 -23
  44. package/date/Date.js +16 -22
  45. package/date-input/DateInput.d.ts +4 -0
  46. package/date-input/DateInput.js +22 -61
  47. package/date-input/DateInput.stories.tsx +138 -0
  48. package/date-input/types.d.ts +100 -0
  49. package/date-input/types.js +5 -0
  50. package/dialog/Dialog.d.ts +4 -0
  51. package/dialog/Dialog.js +20 -73
  52. package/dialog/Dialog.stories.tsx +212 -0
  53. package/dialog/types.d.ts +43 -0
  54. package/dialog/types.js +5 -0
  55. package/dropdown/Dropdown.d.ts +4 -0
  56. package/dropdown/Dropdown.js +44 -171
  57. package/dropdown/types.d.ts +89 -0
  58. package/dropdown/types.js +5 -0
  59. package/file-input/FileInput.d.ts +4 -0
  60. package/file-input/FileInput.js +55 -188
  61. package/file-input/FileItem.d.ts +14 -0
  62. package/file-input/FileItem.js +33 -138
  63. package/file-input/types.d.ts +87 -0
  64. package/file-input/types.js +5 -0
  65. package/footer/Footer.d.ts +4 -0
  66. package/footer/Footer.js +38 -193
  67. package/footer/Footer.stories.jsx +151 -0
  68. package/footer/Icons.js +13 -13
  69. package/footer/types.d.ts +61 -0
  70. package/footer/types.js +5 -0
  71. package/header/Header.d.ts +7 -0
  72. package/header/Header.js +60 -206
  73. package/header/Header.stories.tsx +162 -0
  74. package/header/Icons.js +7 -32
  75. package/header/types.d.ts +45 -0
  76. package/header/types.js +5 -0
  77. package/heading/Heading.d.ts +4 -0
  78. package/heading/Heading.js +24 -95
  79. package/heading/types.d.ts +33 -0
  80. package/heading/types.js +5 -0
  81. package/input-text/Icons.js +2 -2
  82. package/input-text/InputText.js +33 -127
  83. package/layout/ApplicationLayout.js +31 -123
  84. package/layout/Icons.js +7 -7
  85. package/link/Link.d.ts +3 -0
  86. package/link/Link.js +18 -94
  87. package/link/Link.stories.tsx +146 -0
  88. package/link/types.d.ts +74 -0
  89. package/link/types.js +5 -0
  90. package/main.d.ts +44 -40
  91. package/main.js +91 -87
  92. package/number-input/NumberInput.d.ts +4 -0
  93. package/number-input/NumberInput.js +7 -57
  94. package/number-input/NumberInput.stories.tsx +115 -0
  95. package/number-input/NumberInputContext.js +1 -1
  96. package/number-input/types.d.ts +117 -0
  97. package/number-input/types.js +5 -0
  98. package/package.json +15 -12
  99. package/paginator/Icons.js +9 -9
  100. package/paginator/Paginator.d.ts +4 -0
  101. package/paginator/Paginator.js +24 -131
  102. package/paginator/Paginator.stories.tsx +63 -0
  103. package/paginator/types.d.ts +38 -0
  104. package/paginator/types.js +5 -0
  105. package/password-input/PasswordInput.d.ts +4 -0
  106. package/password-input/PasswordInput.js +18 -59
  107. package/password-input/PasswordInput.stories.tsx +131 -0
  108. package/password-input/types.d.ts +100 -0
  109. package/password-input/types.js +5 -0
  110. package/progress-bar/ProgressBar.d.ts +4 -0
  111. package/progress-bar/ProgressBar.js +20 -92
  112. package/progress-bar/ProgressBar.stories.jsx +58 -0
  113. package/progress-bar/types.d.ts +37 -0
  114. package/progress-bar/types.js +5 -0
  115. package/radio/Radio.d.ts +4 -0
  116. package/radio/Radio.js +15 -50
  117. package/radio/Radio.stories.tsx +192 -0
  118. package/radio/types.d.ts +54 -0
  119. package/radio/types.js +5 -0
  120. package/resultsetTable/ResultsetTable.js +35 -119
  121. package/select/Select.js +161 -434
  122. package/select/Select.stories.tsx +572 -0
  123. package/select/index.d.ts +4 -4
  124. package/sidenav/Sidenav.d.ts +9 -0
  125. package/sidenav/Sidenav.js +19 -62
  126. package/sidenav/types.d.ts +50 -0
  127. package/sidenav/types.js +5 -0
  128. package/slider/Slider.d.ts +4 -0
  129. package/slider/Slider.js +71 -158
  130. package/slider/Slider.stories.tsx +177 -0
  131. package/slider/types.d.ts +78 -0
  132. package/slider/types.js +5 -0
  133. package/spinner/Spinner.d.ts +4 -0
  134. package/spinner/Spinner.js +43 -174
  135. package/spinner/Spinner.stories.jsx +102 -0
  136. package/spinner/types.d.ts +32 -0
  137. package/spinner/types.js +5 -0
  138. package/switch/Switch.d.ts +4 -0
  139. package/switch/Switch.js +26 -69
  140. package/switch/Switch.stories.tsx +160 -0
  141. package/switch/types.d.ts +58 -0
  142. package/switch/types.js +5 -0
  143. package/table/Table.d.ts +4 -0
  144. package/table/Table.js +10 -24
  145. package/table/Table.stories.jsx +276 -0
  146. package/table/types.d.ts +21 -0
  147. package/table/types.js +5 -0
  148. package/tabs/Tabs.d.ts +4 -0
  149. package/tabs/Tabs.js +29 -161
  150. package/tabs/types.d.ts +71 -0
  151. package/tabs/types.js +5 -0
  152. package/tag/Tag.d.ts +4 -0
  153. package/tag/Tag.js +37 -126
  154. package/tag/Tag.stories.tsx +145 -0
  155. package/tag/types.d.ts +60 -0
  156. package/tag/types.js +5 -0
  157. package/text-input/TextInput.js +104 -271
  158. package/text-input/index.d.ts +2 -2
  159. package/textarea/Textarea.js +20 -72
  160. package/textarea/Textarea.stories.jsx +135 -0
  161. package/toggle/Toggle.js +15 -49
  162. package/toggle-group/ToggleGroup.js +23 -107
  163. package/toggle-group/ToggleGroup.stories.tsx +178 -0
  164. package/upload/Upload.js +11 -15
  165. package/upload/buttons-upload/ButtonsUpload.js +13 -37
  166. package/upload/buttons-upload/Icons.js +7 -7
  167. package/upload/dragAndDropArea/DragAndDropArea.js +24 -128
  168. package/upload/dragAndDropArea/Icons.js +6 -6
  169. package/upload/file-upload/FileToUpload.js +16 -90
  170. package/upload/file-upload/Icons.js +13 -13
  171. package/upload/files-upload/FilesToUpload.js +12 -26
  172. package/upload/transaction/Icons.js +31 -31
  173. package/upload/transaction/Transaction.js +17 -61
  174. package/upload/transactions/Transactions.js +13 -57
  175. package/wizard/Icons.js +8 -8
  176. package/wizard/Wizard.d.ts +4 -0
  177. package/wizard/Wizard.js +32 -206
  178. package/wizard/Wizard.stories.jsx +224 -0
  179. package/wizard/types.d.ts +64 -0
  180. package/wizard/types.js +5 -0
  181. package/accordion/index.d.ts +0 -28
  182. package/accordion-group/index.d.ts +0 -16
  183. package/alert/index.d.ts +0 -51
  184. package/box/index.d.ts +0 -25
  185. package/button/Button.stories.js +0 -27
  186. package/button/index.d.ts +0 -24
  187. package/card/index.d.ts +0 -22
  188. package/checkbox/index.d.ts +0 -24
  189. package/date-input/index.d.ts +0 -95
  190. package/dialog/index.d.ts +0 -18
  191. package/dropdown/index.d.ts +0 -26
  192. package/file-input/index.d.ts +0 -81
  193. package/footer/index.d.ts +0 -25
  194. package/header/index.d.ts +0 -25
  195. package/heading/index.d.ts +0 -17
  196. package/link/index.d.ts +0 -23
  197. package/number-input/index.d.ts +0 -113
  198. package/paginator/index.d.ts +0 -20
  199. package/password-input/index.d.ts +0 -94
  200. package/progress-bar/index.d.ts +0 -18
  201. package/radio/index.d.ts +0 -23
  202. package/sidenav/index.d.ts +0 -13
  203. package/slider/index.d.ts +0 -29
  204. package/spinner/index.d.ts +0 -17
  205. package/switch/index.d.ts +0 -24
  206. package/table/index.d.ts +0 -13
  207. package/tabs/index.d.ts +0 -19
  208. package/tag/index.d.ts +0 -24
  209. package/wizard/index.d.ts +0 -18
@@ -0,0 +1,71 @@
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 Tab = {
11
+ /**
12
+ * Tab label.
13
+ */
14
+ label?: string;
15
+ /**
16
+ * Element used as the icon that will be displayed in the tab.
17
+ */
18
+ icon?: SVG;
19
+ /**
20
+ * @deprecated URL of the icon to be displayed in the tab.
21
+ */
22
+ iconSrc?: string;
23
+ /**
24
+ * Whether the tab is disabled or not.
25
+ */
26
+ isDisabled?: boolean;
27
+ /**
28
+ * If the value is 'true', an empty badge will appear.
29
+ * If it is 'false', no badge will appear.
30
+ * If a number is put it will be shown as the label of the notification
31
+ * in the tab, taking into account that if that number is greater than 99,
32
+ * it will appear as '+99' in the badge.
33
+ */
34
+ notificationNumber?: boolean | number;
35
+ };
36
+ declare type Props = {
37
+ /**
38
+ * An array of objects representing the tabs.
39
+ */
40
+ tabs: [Tab, ...Tab[]];
41
+ /**
42
+ * Whether the icon should appear above or to the left of the label.
43
+ */
44
+ iconPosition?: "top" | "left";
45
+ /**
46
+ * The index of the active tab. If undefined, the component will be
47
+ * uncontrolled and the active tab will be managed internally by the component.
48
+ */
49
+ activeTabIndex?: number;
50
+ /**
51
+ * This function will be called when the user clicks on a tab. The index of the
52
+ * clicked tab will be passed as a parameter.
53
+ */
54
+ onTabClick?: (tabIndex: number) => void;
55
+ /**
56
+ * This function will be called when the user hovers a tab.The index of the
57
+ * hovered tab will be passed as a parameter.
58
+ */
59
+ onTabHover?: (tabIndex: number) => void;
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.
64
+ */
65
+ margin?: Space | Margin;
66
+ /**
67
+ * Value of the tabindex for each tab.
68
+ */
69
+ tabIndex?: number;
70
+ };
71
+ export default Props;
package/tabs/types.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
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
@@ -1,16 +1,14 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
-
5
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
4
 
5
+ var _typeof3 = require("@babel/runtime/helpers/typeof");
6
+
7
7
  Object.defineProperty(exports, "__esModule", {
8
8
  value: true
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,99 +19,25 @@ 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"));
29
25
 
30
- var _Box = _interopRequireDefault(require("../box/Box"));
31
-
32
- function _templateObject8() {
33
- var data = (0, _taggedTemplateLiteral2["default"])(["\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n color: ", ";\n padding-top: ", ";\n padding-bottom: ", ";\n padding-left: ", ";\n padding-right: ", ";\n flex-grow: 1;\n text-align: center;\n text-overflow: ellipsis;\n overflow: hidden;\n white-space: nowrap;\n"]);
34
-
35
- _templateObject8 = function _templateObject8() {
36
- return data;
37
- };
38
-
39
- return data;
40
- }
41
-
42
- function _templateObject7() {
43
- var data = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n background: ", ";\n width: ", ";\n height: 100%;\n justify-content: center;\n align-items: center;\n color: ", ";\n"]);
44
-
45
- _templateObject7 = function _templateObject7() {
46
- return data;
47
- };
48
-
49
- return data;
50
- }
51
-
52
- function _templateObject6() {
53
- var data = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n justify-content: center;\n align-items: center;\n overflow: hidden;\n\n img,\n svg {\n width: ", ";\n height: ", ";\n }\n"]);
54
-
55
- _templateObject6 = function _templateObject6() {
56
- return data;
57
- };
58
-
59
- return data;
60
- }
61
-
62
- function _templateObject5() {
63
- var data = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n justify-content: center;\n align-items: center;\n overflow: hidden;\n width: ", ";\n height: ", ";\n"]);
64
-
65
- _templateObject5 = function _templateObject5() {
66
- return data;
67
- };
68
-
69
- return data;
70
- }
71
-
72
- function _templateObject4() {
73
- var data = (0, _taggedTemplateLiteral2["default"])(["\n background: none;\n border-radius: 4px;\n border: none;\n padding: 0;\n cursor: pointer;\n font-family: inherit;\n\n :focus {\n outline: 2px solid ", ";\n }\n"]);
26
+ var _utils = require("../common/utils.js");
74
27
 
75
- _templateObject4 = function _templateObject4() {
76
- return data;
77
- };
78
-
79
- return data;
80
- }
81
-
82
- function _templateObject3() {
83
- var data = (0, _taggedTemplateLiteral2["default"])(["\n text-decoration: none;\n border-radius: 4px;\n\n :focus {\n outline: 2px solid ", ";\n outline-offset: 0px;\n }\n"]);
84
-
85
- _templateObject3 = function _templateObject3() {
86
- return data;
87
- };
88
-
89
- return data;
90
- }
91
-
92
- function _templateObject2() {
93
- var data = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n align-items: center;\n flex-direction: ", ";\n width: ", ";\n height: ", ";\n"]);
94
-
95
- _templateObject2 = function _templateObject2() {
96
- return data;
97
- };
98
-
99
- return data;
100
- }
28
+ var _Box = _interopRequireDefault(require("../box/Box"));
101
29
 
102
- function _templateObject() {
103
- var data = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n cursor: ", ";\n margin: ", ";\n margin-top: ", ";\n margin-right: ", ";\n margin-bottom: ", ";\n margin-left: ", ";\n"]);
30
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8;
104
31
 
105
- _templateObject = function _templateObject() {
106
- return data;
107
- };
32
+ 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); }
108
33
 
109
- return data;
110
- }
34
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(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; }
111
35
 
112
36
  var DxcTag = function DxcTag(_ref) {
113
37
  var icon = _ref.icon,
114
38
  iconSrc = _ref.iconSrc,
115
- label = _ref.label,
116
- margin = _ref.margin,
39
+ _ref$label = _ref.label,
40
+ label = _ref$label === void 0 ? "" : _ref$label,
117
41
  linkHref = _ref.linkHref,
118
42
  onClick = _ref.onClick,
119
43
  _ref$iconBgColor = _ref.iconBgColor,
@@ -122,6 +46,7 @@ var DxcTag = function DxcTag(_ref) {
122
46
  labelPosition = _ref$labelPosition === void 0 ? "after" : _ref$labelPosition,
123
47
  _ref$newWindow = _ref.newWindow,
124
48
  newWindow = _ref$newWindow === void 0 ? false : _ref$newWindow,
49
+ margin = _ref.margin,
125
50
  _ref$size = _ref.size,
126
51
  size = _ref$size === void 0 ? "fitContent" : _ref$size,
127
52
  _ref$tabIndex = _ref.tabIndex,
@@ -137,22 +62,22 @@ var DxcTag = function DxcTag(_ref) {
137
62
  onClick && onClick();
138
63
  };
139
64
 
140
- var tagContent = _react["default"].createElement(_Box["default"], {
65
+ var tagContent = /*#__PURE__*/_react["default"].createElement(_Box["default"], {
141
66
  size: size,
142
67
  shadowDepth: isHovered && (onClick || linkHref) && 2 || 1
143
- }, _react["default"].createElement(TagContent, {
144
- labelPosition: labelPosition,
145
- size: size
146
- }, _react["default"].createElement(IconContainer, {
68
+ }, /*#__PURE__*/_react["default"].createElement(TagContent, {
69
+ labelPosition: labelPosition
70
+ }, /*#__PURE__*/_react["default"].createElement(IconContainer, {
147
71
  iconBgColor: iconBgColor
148
- }, icon ? _react["default"].createElement(TagIconContainer, null, (0, _typeof2["default"])(icon) === "object" ? icon : _react["default"].createElement(icon)) : _react["default"].createElement(TagIcon, {
72
+ }, icon ? /*#__PURE__*/_react["default"].createElement(TagIconContainer, null, (0, _typeof2["default"])(icon) === "object" ? icon : /*#__PURE__*/_react["default"].createElement(icon)) : /*#__PURE__*/_react["default"].createElement(TagIcon, {
149
73
  src: iconSrc
150
- })), size !== "small" && _react["default"].createElement(TagLabel, null, label)));
74
+ })), size !== "small" && /*#__PURE__*/_react["default"].createElement(TagLabel, null, label)));
151
75
 
152
- return _react["default"].createElement(_styledComponents.ThemeProvider, {
76
+ return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
153
77
  theme: colorsTheme.tag
154
- }, _react["default"].createElement(StyledDxcTag, {
78
+ }, /*#__PURE__*/_react["default"].createElement(StyledDxcTag, {
155
79
  margin: margin,
80
+ size: size,
156
81
  onMouseEnter: function onMouseEnter() {
157
82
  return changeIsHovered(true);
158
83
  },
@@ -161,9 +86,9 @@ var DxcTag = function DxcTag(_ref) {
161
86
  },
162
87
  onClick: clickHandler,
163
88
  hasAction: onClick || linkHref
164
- }, onClick ? _react["default"].createElement(StyledButton, {
89
+ }, onClick ? /*#__PURE__*/_react["default"].createElement(StyledButton, {
165
90
  tabIndex: tabIndex
166
- }, tagContent) : linkHref ? _react["default"].createElement(StyledLink, {
91
+ }, tagContent) : linkHref ? /*#__PURE__*/_react["default"].createElement(StyledLink, {
167
92
  tabIndex: tabIndex,
168
93
  href: linkHref,
169
94
  target: newWindow ? "_blank" : "_self"
@@ -178,11 +103,11 @@ var sizes = {
178
103
  fitContent: "unset"
179
104
  };
180
105
 
181
- var calculateWidth = function calculateWidth(size) {
182
- return sizes[size];
106
+ var calculateWidth = function calculateWidth(margin, size) {
107
+ return size === "fillParent" ? "calc(".concat(sizes[size], " - ").concat((0, _utils.getMargin)(margin, "left"), " - ").concat((0, _utils.getMargin)(margin, "right"), ")") : sizes[size];
183
108
  };
184
109
 
185
- var StyledDxcTag = _styledComponents["default"].div(_templateObject(), function (_ref2) {
110
+ var StyledDxcTag = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n cursor: ", ";\n margin: ", ";\n margin-top: ", ";\n margin-right: ", ";\n margin-bottom: ", ";\n margin-left: ", ";\n width: ", ";\n height: ", ";\n"])), function (_ref2) {
186
111
  var hasAction = _ref2.hasAction;
187
112
  return hasAction && "pointer" || "unset";
188
113
  }, function (_ref3) {
@@ -200,47 +125,51 @@ var StyledDxcTag = _styledComponents["default"].div(_templateObject(), function
200
125
  }, function (_ref7) {
201
126
  var margin = _ref7.margin;
202
127
  return margin && margin.left ? _variables.spaces[margin.left] : "";
128
+ }, function (props) {
129
+ return calculateWidth(props.margin, props.size);
130
+ }, function (props) {
131
+ return props.theme.height;
203
132
  });
204
133
 
205
- var TagContent = _styledComponents["default"].div(_templateObject2(), function (_ref8) {
134
+ var TagContent = _styledComponents["default"].div(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n align-items: center;\n flex-direction: ", ";\n width: 100%;\n height: ", ";\n"])), function (_ref8) {
206
135
  var labelPosition = _ref8.labelPosition;
207
136
  return labelPosition === "before" && "row-reverse" || "row";
208
- }, function (props) {
209
- return calculateWidth(props.size);
210
137
  }, function (props) {
211
138
  return props.theme.height;
212
139
  });
213
140
 
214
- var StyledLink = _styledComponents["default"].a(_templateObject3(), function (props) {
141
+ var StyledLink = _styledComponents["default"].a(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])(["\n text-decoration: none;\n border-radius: 4px;\n width: 100%;\n :focus {\n outline: 2px solid ", ";\n outline-offset: 0px;\n }\n"])), function (props) {
215
142
  return props.theme.focusColor;
216
143
  });
217
144
 
218
- var StyledButton = _styledComponents["default"].button(_templateObject4(), function (props) {
145
+ var StyledButton = _styledComponents["default"].button(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["\n background: none;\n border-radius: 4px;\n border: none;\n padding: 0;\n cursor: pointer;\n font-family: inherit;\n width: 100%;\n :focus {\n outline: 2px solid ", ";\n }\n"])), function (props) {
219
146
  return props.theme.focusColor;
220
147
  });
221
148
 
222
- var TagIcon = _styledComponents["default"].img(_templateObject5(), function (props) {
149
+ var TagIcon = _styledComponents["default"].img(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n justify-content: center;\n align-items: center;\n overflow: hidden;\n width: ", ";\n height: ", ";\n"])), function (props) {
223
150
  return props.theme.iconWidth;
224
151
  }, function (props) {
225
152
  return props.theme.iconHeight;
226
153
  });
227
154
 
228
- var TagIconContainer = _styledComponents["default"].div(_templateObject6(), function (props) {
155
+ var TagIconContainer = _styledComponents["default"].div(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n justify-content: center;\n align-items: center;\n overflow: hidden;\n\n img,\n svg {\n width: ", ";\n height: ", ";\n }\n"])), function (props) {
229
156
  return props.theme.iconWidth;
230
157
  }, function (props) {
231
158
  return props.theme.iconHeight;
232
159
  });
233
160
 
234
- var IconContainer = _styledComponents["default"].div(_templateObject7(), function (_ref9) {
161
+ var IconContainer = _styledComponents["default"].div(_templateObject7 || (_templateObject7 = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n background: ", ";\n width: ", ";\n height: 100%;\n justify-content: center;\n align-items: center;\n color: ", ";\n min-width: ", ";\n"])), function (_ref9) {
235
162
  var iconBgColor = _ref9.iconBgColor;
236
163
  return iconBgColor;
237
164
  }, function (props) {
238
165
  return props.theme.iconSectionWidth;
239
166
  }, function (props) {
240
167
  return props.theme.iconColor;
168
+ }, function (props) {
169
+ return props.theme.iconSectionWidth;
241
170
  });
242
171
 
243
- var TagLabel = _styledComponents["default"].div(_templateObject8(), function (props) {
172
+ var TagLabel = _styledComponents["default"].div(_templateObject8 || (_templateObject8 = (0, _taggedTemplateLiteral2["default"])(["\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n color: ", ";\n padding-top: ", ";\n padding-bottom: ", ";\n padding-left: ", ";\n padding-right: ", ";\n flex-grow: 1;\n text-align: center;\n text-overflow: ellipsis;\n overflow: hidden;\n white-space: nowrap;\n"])), function (props) {
244
173
  return props.theme.fontFamily;
245
174
  }, function (props) {
246
175
  return props.theme.fontSize;
@@ -260,23 +189,5 @@ var TagLabel = _styledComponents["default"].div(_templateObject8(), function (pr
260
189
  return props.theme.labelPaddingRight;
261
190
  });
262
191
 
263
- DxcTag.propTypes = {
264
- size: _propTypes["default"].oneOf((0, _toConsumableArray2["default"])(Object.keys(sizes))),
265
- icon: _propTypes["default"].oneOfType([_propTypes["default"].element, _propTypes["default"].func]),
266
- iconSrc: _propTypes["default"].string,
267
- iconBgColor: _propTypes["default"].string,
268
- label: _propTypes["default"].string,
269
- labelPosition: _propTypes["default"].oneOf(["before", "after"]),
270
- linkHref: _propTypes["default"].string,
271
- onClick: _propTypes["default"].func,
272
- newWindow: _propTypes["default"].bool,
273
- margin: _propTypes["default"].oneOfType([_propTypes["default"].shape({
274
- top: _propTypes["default"].oneOf(Object.keys(_variables.spaces)),
275
- bottom: _propTypes["default"].oneOf(Object.keys(_variables.spaces)),
276
- left: _propTypes["default"].oneOf(Object.keys(_variables.spaces)),
277
- right: _propTypes["default"].oneOf(Object.keys(_variables.spaces))
278
- }), _propTypes["default"].oneOf((0, _toConsumableArray2["default"])(Object.keys(_variables.spaces)))]),
279
- tabIndex: _propTypes["default"].number
280
- };
281
192
  var _default = DxcTag;
282
193
  exports["default"] = _default;
@@ -0,0 +1,145 @@
1
+ import React from "react";
2
+ import { userEvent, within } from "@storybook/testing-library";
3
+ import Title from "../../.storybook/components/Title";
4
+ import ExampleContainer from "../../.storybook/components/ExampleContainer";
5
+ import DxcTag from "./Tag";
6
+
7
+ export default {
8
+ title: "Tag",
9
+ component: DxcTag,
10
+ };
11
+
12
+ const icon = () => {
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
+ const largeIcon = () => {
21
+ return (
22
+ <svg xmlns="http://www.w3.org/2000/svg" height="48px" viewBox="0 0 24 24" width="48px" fill="currentColor">
23
+ <path d="M0 0h24v24H0V0z" fill="none" />
24
+ <path d="M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm.5-13H11v6l5.25 3.15.75-1.23-4.5-2.67z" />
25
+ </svg>
26
+ );
27
+ };
28
+
29
+ export const Chromatic = () => (
30
+ <>
31
+ <ExampleContainer>
32
+ <Title title="Without label" theme="light" level={4} />
33
+ <DxcTag />
34
+ </ExampleContainer>
35
+ <ExampleContainer>
36
+ <Title title="With icon" theme="light" level={4} />
37
+ <DxcTag icon={icon} />
38
+ </ExampleContainer>
39
+ <ExampleContainer>
40
+ <Title title="With large icon" theme="light" level={4} />
41
+ <DxcTag icon={largeIcon} />
42
+ </ExampleContainer>
43
+ <ExampleContainer>
44
+ <Title title="With label" theme="light" level={4} />
45
+ <DxcTag label="Tag" />
46
+ </ExampleContainer>
47
+ <ExampleContainer>
48
+ <Title title="With label and icon" theme="light" level={4} />
49
+ <DxcTag label="Tag" icon={icon} />
50
+ </ExampleContainer>
51
+ <ExampleContainer>
52
+ <Title title="With right icon" theme="light" level={4} />
53
+ <DxcTag label="Tag" icon={icon} labelPosition="before" />
54
+ </ExampleContainer>
55
+ <ExampleContainer>
56
+ <Title title="Icon background color" theme="light" level={4} />
57
+ <DxcTag label="Tag" icon={icon} iconBgColor="#fabada" />
58
+ </ExampleContainer>
59
+ <ExampleContainer pseudoState="pseudo-focus">
60
+ <Title title="With link focused" theme="light" level={4} />
61
+ <DxcTag icon={icon} label="Tag" linkHref="https://www.dxc.com" />
62
+ </ExampleContainer>
63
+ <ExampleContainer pseudoState="pseudo-focus">
64
+ <Title title="With action focused" theme="light" level={4} />
65
+ <DxcTag
66
+ icon={icon}
67
+ label="Tag"
68
+ onClick={() => {
69
+ console.log("click");
70
+ }}
71
+ />
72
+ </ExampleContainer>
73
+ <Title title="Margins" theme="light" level={2} />
74
+ <ExampleContainer>
75
+ <Title title="Xxsmall margin" theme="light" level={4} />
76
+ <DxcTag label="Xxsmall" margin="xxsmall" />
77
+ </ExampleContainer>
78
+ <ExampleContainer>
79
+ <Title title="Xsmall margin" theme="light" level={4} />
80
+ <DxcTag label="Xsmall" margin="xsmall" />
81
+ </ExampleContainer>
82
+ <ExampleContainer>
83
+ <Title title="Small margin" theme="light" level={4} />
84
+ <DxcTag label="Small" margin="small" />
85
+ </ExampleContainer>
86
+ <ExampleContainer>
87
+ <Title title="Medium margin" theme="light" level={4} />
88
+ <DxcTag label="Medium" margin="medium" />
89
+ </ExampleContainer>
90
+ <ExampleContainer>
91
+ <Title title="Large margin" theme="light" level={4} />
92
+ <DxcTag label="Large" margin="large" />
93
+ </ExampleContainer>
94
+ <ExampleContainer>
95
+ <Title title="Xlarge margin" theme="light" level={4} />
96
+ <DxcTag label="Xlarge" margin="xlarge" />
97
+ </ExampleContainer>
98
+ <ExampleContainer>
99
+ <Title title="Xxlarge margin" theme="light" level={4} />
100
+ <DxcTag label="Xxlarge" margin="xxlarge" />
101
+ </ExampleContainer>
102
+ <Title title="Sizes" theme="light" level={2} />
103
+ <ExampleContainer>
104
+ <Title title="Small size" theme="light" level={4} />
105
+ <DxcTag label="Small" size="small" />
106
+ </ExampleContainer>
107
+ <ExampleContainer>
108
+ <Title title="Medium size" theme="light" level={4} />
109
+ <DxcTag label="Medium size medium s" size="medium" />
110
+ </ExampleContainer>
111
+ <ExampleContainer>
112
+ <Title title="Medium size with ellipsis" theme="light" level={4} />
113
+ <DxcTag label="Medium size medium si medium" size="medium" />
114
+ </ExampleContainer>
115
+ <ExampleContainer>
116
+ <Title title="Large size" theme="light" level={4} />
117
+ <DxcTag label="Large size large size large size large size large size" size="large" />
118
+ </ExampleContainer>
119
+ <ExampleContainer>
120
+ <Title title="Large size with ellipsis" theme="light" level={4} />
121
+ <DxcTag label="Large size large size large size large size large size large size" size="large" />
122
+ </ExampleContainer>
123
+ <ExampleContainer>
124
+ <Title title="FillParent size" theme="light" level={4} />
125
+ <DxcTag label="FillParent" size="fillParent" />
126
+ </ExampleContainer>
127
+ <ExampleContainer>
128
+ <Title title="FitContent size" theme="light" level={4} />
129
+ <DxcTag label="FitContent" size="fitContent" />
130
+ </ExampleContainer>
131
+ </>
132
+ );
133
+
134
+ const LinkTag = () => (
135
+ <ExampleContainer>
136
+ <Title title="Hover link tag" theme="light" level={4} />
137
+ <DxcTag label="Tag" icon={icon} linkHref="https://www.dxc.com" />
138
+ </ExampleContainer>
139
+ );
140
+
141
+ export const HoverLinkTag = LinkTag.bind({});
142
+ HoverLinkTag.play = async ({ canvasElement }) => {
143
+ const canvas = within(canvasElement);
144
+ await userEvent.hover(canvas.getByText("Tag"));
145
+ };
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
+ });