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

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 (205) hide show
  1. package/BackgroundColorContext.d.ts +10 -0
  2. package/BackgroundColorContext.js +1 -4
  3. package/ThemeContext.d.ts +15 -0
  4. package/ThemeContext.js +5 -8
  5. package/V3Select/V3Select.js +2 -2
  6. package/V3Textarea/V3Textarea.js +2 -2
  7. package/accordion/Accordion.d.ts +1 -1
  8. package/accordion/Accordion.js +11 -22
  9. package/accordion/Accordion.stories.tsx +307 -0
  10. package/accordion/types.d.ts +4 -8
  11. package/accordion-group/AccordionGroup.js +2 -2
  12. package/accordion-group/AccordionGroup.stories.tsx +225 -0
  13. package/accordion-group/types.d.ts +4 -8
  14. package/alert/Alert.js +2 -2
  15. package/alert/Alert.stories.tsx +170 -0
  16. package/alert/types.d.ts +1 -1
  17. package/badge/Badge.js +1 -1
  18. package/bleed/Bleed.d.ts +3 -0
  19. package/bleed/Bleed.js +84 -0
  20. package/bleed/Bleed.stories.tsx +342 -0
  21. package/bleed/types.d.ts +13 -0
  22. package/bleed/types.js +5 -0
  23. package/box/Box.d.ts +1 -1
  24. package/box/Box.js +4 -7
  25. package/box/types.d.ts +0 -4
  26. package/button/Button.d.ts +1 -1
  27. package/button/Button.js +13 -19
  28. package/button/Button.stories.tsx +222 -241
  29. package/button/types.d.ts +5 -9
  30. package/card/Card.js +5 -6
  31. package/card/Card.stories.tsx +201 -0
  32. package/card/ice-cream.jpg +0 -0
  33. package/card/types.d.ts +4 -6
  34. package/checkbox/Checkbox.js +2 -2
  35. package/checkbox/types.d.ts +2 -2
  36. package/chip/Chip.d.ts +4 -0
  37. package/chip/Chip.js +16 -76
  38. package/chip/Chip.stories.tsx +119 -0
  39. package/chip/types.d.ts +45 -0
  40. package/chip/types.js +5 -0
  41. package/common/variables.js +70 -28
  42. package/date/Date.js +1 -1
  43. package/date-input/DateInput.js +10 -13
  44. package/date-input/DateInput.stories.tsx +138 -0
  45. package/dialog/Dialog.js +4 -3
  46. package/dialog/Dialog.stories.tsx +212 -0
  47. package/dropdown/Dropdown.d.ts +1 -1
  48. package/dropdown/Dropdown.js +13 -35
  49. package/dropdown/Dropdown.stories.tsx +249 -0
  50. package/dropdown/types.d.ts +6 -15
  51. package/file-input/FileInput.d.ts +4 -0
  52. package/file-input/FileInput.js +167 -109
  53. package/file-input/FileInput.stories.tsx +507 -0
  54. package/file-input/FileItem.d.ts +14 -0
  55. package/file-input/FileItem.js +12 -21
  56. package/file-input/types.d.ts +112 -0
  57. package/file-input/types.js +5 -0
  58. package/footer/Footer.d.ts +1 -1
  59. package/footer/Footer.js +28 -36
  60. package/footer/{Footer.stories.jsx → Footer.stories.tsx} +1 -22
  61. package/footer/Icons.d.ts +2 -0
  62. package/footer/Icons.js +3 -3
  63. package/footer/types.d.ts +22 -18
  64. package/header/Header.js +2 -2
  65. package/header/Header.stories.tsx +162 -0
  66. package/header/Icons.d.ts +2 -0
  67. package/header/types.d.ts +4 -2
  68. package/heading/Heading.d.ts +4 -0
  69. package/heading/Heading.js +7 -24
  70. package/heading/Heading.stories.tsx +54 -0
  71. package/heading/types.d.ts +33 -0
  72. package/heading/types.js +5 -0
  73. package/input-text/InputText.js +2 -2
  74. package/inset/Inset.d.ts +3 -0
  75. package/inset/Inset.js +84 -0
  76. package/inset/Inset.stories.tsx +229 -0
  77. package/inset/types.d.ts +13 -0
  78. package/inset/types.js +5 -0
  79. package/layout/ApplicationLayout.d.ts +10 -0
  80. package/layout/ApplicationLayout.js +9 -19
  81. package/layout/ApplicationLayout.stories.tsx +171 -0
  82. package/layout/types.d.ts +57 -0
  83. package/layout/types.js +5 -0
  84. package/link/Link.js +3 -3
  85. package/link/Link.stories.tsx +146 -0
  86. package/list/List.d.ts +4 -0
  87. package/list/List.js +47 -0
  88. package/list/List.stories.tsx +95 -0
  89. package/list/types.d.ts +7 -0
  90. package/list/types.js +5 -0
  91. package/main.d.ts +7 -3
  92. package/main.js +34 -2
  93. package/number-input/NumberInput.d.ts +4 -0
  94. package/number-input/NumberInput.js +5 -50
  95. package/number-input/{NumberInput.stories.jsx → NumberInput.stories.tsx} +0 -0
  96. package/number-input/NumberInputContext.d.ts +4 -0
  97. package/number-input/NumberInputContext.js +5 -2
  98. package/number-input/numberInputContextTypes.d.ts +19 -0
  99. package/number-input/numberInputContextTypes.js +5 -0
  100. package/number-input/types.d.ts +117 -0
  101. package/number-input/types.js +5 -0
  102. package/package.json +4 -2
  103. package/paginator/Paginator.js +2 -8
  104. package/password-input/PasswordInput.js +19 -18
  105. package/password-input/PasswordInput.stories.tsx +3 -3
  106. package/password-input/types.d.ts +17 -10
  107. package/progress-bar/ProgressBar.js +4 -4
  108. package/radio/Radio.js +2 -2
  109. package/radio/types.d.ts +2 -2
  110. package/radio-group/Radio.d.ts +4 -0
  111. package/radio-group/Radio.js +140 -0
  112. package/radio-group/RadioGroup.d.ts +4 -0
  113. package/radio-group/RadioGroup.js +273 -0
  114. package/radio-group/RadioGroup.stories.tsx +79 -0
  115. package/radio-group/RadioGroup.test.js +248 -0
  116. package/radio-group/types.d.ts +36 -0
  117. package/radio-group/types.js +5 -0
  118. package/resultsetTable/ResultsetTable.d.ts +4 -0
  119. package/resultsetTable/ResultsetTable.js +5 -28
  120. package/resultsetTable/ResultsetTable.stories.tsx +275 -0
  121. package/resultsetTable/types.d.ts +67 -0
  122. package/resultsetTable/types.js +5 -0
  123. package/row/Row.d.ts +3 -0
  124. package/row/Row.js +127 -0
  125. package/row/Row.stories.tsx +237 -0
  126. package/row/types.d.ts +10 -0
  127. package/row/types.js +5 -0
  128. package/select/Select.d.ts +4 -0
  129. package/select/Select.js +20 -22
  130. package/select/Select.stories.tsx +572 -0
  131. package/select/types.d.ts +170 -0
  132. package/select/types.js +5 -0
  133. package/sidenav/Sidenav.d.ts +9 -0
  134. package/sidenav/Sidenav.js +6 -15
  135. package/sidenav/Sidenav.stories.tsx +182 -0
  136. package/sidenav/types.d.ts +50 -0
  137. package/sidenav/types.js +5 -0
  138. package/slider/Slider.d.ts +1 -1
  139. package/slider/Slider.js +43 -32
  140. package/slider/Slider.stories.tsx +177 -0
  141. package/slider/types.d.ts +2 -7
  142. package/spinner/Spinner.js +2 -2
  143. package/spinner/Spinner.stories.jsx +1 -0
  144. package/stack/Stack.d.ts +3 -0
  145. package/stack/Stack.js +97 -0
  146. package/stack/Stack.stories.tsx +164 -0
  147. package/stack/types.d.ts +9 -0
  148. package/stack/types.js +5 -0
  149. package/switch/Switch.js +2 -2
  150. package/switch/Switch.stories.tsx +1 -1
  151. package/table/Table.js +3 -3
  152. package/table/Table.stories.jsx +2 -1
  153. package/tabs/Tabs.js +11 -9
  154. package/tabs/Tabs.stories.tsx +120 -0
  155. package/tabs/types.d.ts +25 -18
  156. package/tag/Tag.d.ts +4 -0
  157. package/tag/Tag.js +9 -35
  158. package/tag/{Tag.stories.jsx → Tag.stories.tsx} +15 -22
  159. package/tag/types.d.ts +69 -0
  160. package/tag/types.js +5 -0
  161. package/text/Text.d.ts +7 -0
  162. package/text/Text.js +30 -0
  163. package/text/Text.stories.tsx +19 -0
  164. package/text-input/TextInput.d.ts +4 -0
  165. package/text-input/TextInput.js +54 -85
  166. package/text-input/TextInput.stories.tsx +456 -0
  167. package/text-input/types.d.ts +159 -0
  168. package/text-input/types.js +5 -0
  169. package/textarea/Textarea.d.ts +4 -0
  170. package/textarea/Textarea.js +27 -60
  171. package/textarea/Textarea.stories.jsx +4 -3
  172. package/textarea/types.d.ts +130 -0
  173. package/textarea/types.js +5 -0
  174. package/toggle/Toggle.js +1 -1
  175. package/toggle-group/ToggleGroup.d.ts +4 -0
  176. package/toggle-group/ToggleGroup.js +16 -45
  177. package/toggle-group/ToggleGroup.stories.tsx +173 -0
  178. package/toggle-group/types.d.ts +97 -0
  179. package/toggle-group/types.js +5 -0
  180. package/upload/buttons-upload/ButtonsUpload.js +2 -2
  181. package/upload/dragAndDropArea/DragAndDropArea.js +2 -2
  182. package/upload/file-upload/FileToUpload.js +1 -1
  183. package/upload/files-upload/FilesToUpload.js +1 -1
  184. package/upload/transaction/Transaction.js +2 -2
  185. package/upload/transactions/Transactions.js +1 -1
  186. package/useTheme.d.ts +2 -0
  187. package/useTheme.js +1 -1
  188. package/wizard/Wizard.d.ts +4 -0
  189. package/wizard/Wizard.js +69 -59
  190. package/wizard/Wizard.stories.tsx +224 -0
  191. package/wizard/types.d.ts +60 -0
  192. package/wizard/types.js +5 -0
  193. package/chip/index.d.ts +0 -22
  194. package/file-input/index.d.ts +0 -81
  195. package/heading/index.d.ts +0 -17
  196. package/number-input/index.d.ts +0 -113
  197. package/resultsetTable/index.d.ts +0 -19
  198. package/select/index.d.ts +0 -131
  199. package/sidenav/index.d.ts +0 -13
  200. package/tag/index.d.ts +0 -24
  201. package/text-input/index.d.ts +0 -135
  202. package/textarea/index.d.ts +0 -117
  203. package/toggle-group/index.d.ts +0 -21
  204. package/wizard/Icons.js +0 -65
  205. package/wizard/index.d.ts +0 -18
@@ -0,0 +1,201 @@
1
+ import React from "react";
2
+ import Title from "../../.storybook/components/Title";
3
+ import ExampleContainer from "../../.storybook/components/ExampleContainer";
4
+ import DxcCard from "./Card";
5
+ import imagePath from "./ice-cream.jpg";
6
+ import { userEvent, within } from "@storybook/testing-library";
7
+
8
+ export default {
9
+ title: "Card",
10
+ component: DxcCard,
11
+ };
12
+
13
+ const Card = () => (
14
+ <>
15
+ <Title title="Default" theme="light" level={4} />
16
+ <ExampleContainer>
17
+ <DxcCard>Default</DxcCard>
18
+ </ExampleContainer>
19
+ <Title title="Not outlined" theme="light" level={4} />
20
+ <ExampleContainer>
21
+ <DxcCard outlined={false}>Not outlined</DxcCard>
22
+ </ExampleContainer>
23
+ <Title title="Default with link" theme="light" level={4} />
24
+ <ExampleContainer>
25
+ <DxcCard linkHref="https://www.dxc.com">Default with link</DxcCard>
26
+ </ExampleContainer>
27
+ <Title title="Focused default with link" theme="light" level={4} />
28
+ <ExampleContainer>
29
+ <DxcCard linkHref="https://www.dxc.com">Focused default with link</DxcCard>
30
+ </ExampleContainer>
31
+ <Title title="Hovered default with link" theme="light" level={4} />
32
+ <ExampleContainer>
33
+ <DxcCard linkHref="https://www.dxc.com">Hovered default with link</DxcCard>
34
+ </ExampleContainer>
35
+ <Title title="Default with action" theme="light" level={4} />
36
+ <ExampleContainer>
37
+ <DxcCard onClick={() => {}}>Default with action</DxcCard>
38
+ </ExampleContainer>
39
+ <Title title="Default with image" theme="light" level={4} />
40
+ <ExampleContainer>
41
+ <DxcCard imageSrc={imagePath}>Default</DxcCard>
42
+ </ExampleContainer>
43
+ <Title title="Default image with background color" theme="light" level={4} />
44
+ <ExampleContainer>
45
+ <DxcCard imageSrc={imagePath} imageBgColor="yellow">
46
+ Background color
47
+ </DxcCard>
48
+ </ExampleContainer>
49
+ <Title title="Default image with position after" theme="light" level={4} />
50
+ <ExampleContainer>
51
+ <DxcCard imageSrc={imagePath} imagePosition="after">
52
+ Position after
53
+ </DxcCard>
54
+ </ExampleContainer>
55
+ <Title title="Image cover" theme="light" level={4} />
56
+ <ExampleContainer>
57
+ <DxcCard imageSrc={imagePath} imageCover>
58
+ Image cover
59
+ </DxcCard>
60
+ </ExampleContainer>
61
+ <Title title="Image cover with position after" theme="light" level={4} />
62
+ <ExampleContainer>
63
+ <DxcCard imageSrc={imagePath} imageCover imagePosition="after">
64
+ Image cover with position after
65
+ </DxcCard>
66
+ </ExampleContainer>
67
+ <Title title="Image padding" theme="light" level={2} />
68
+ <ExampleContainer>
69
+ <Title title="Xxsmall" theme="light" level={4} />
70
+ <DxcCard imageSrc={imagePath} imagePadding="xxsmall" imageCover>
71
+ Xxsmall
72
+ </DxcCard>
73
+ </ExampleContainer>
74
+ <ExampleContainer>
75
+ <Title title="Xsmall" theme="light" level={4} />
76
+ <DxcCard imageSrc={imagePath} imagePadding="xsmall" imageCover>
77
+ Xsmall
78
+ </DxcCard>
79
+ </ExampleContainer>
80
+ <ExampleContainer>
81
+ <Title title="Small" theme="light" level={4} />
82
+ <DxcCard imageSrc={imagePath} imagePadding="small" imageCover>
83
+ Small
84
+ </DxcCard>
85
+ </ExampleContainer>
86
+ <ExampleContainer>
87
+ <Title title="Medium" theme="light" level={4} />
88
+ <DxcCard imageSrc={imagePath} imagePadding="medium" imageCover>
89
+ Medium
90
+ </DxcCard>
91
+ </ExampleContainer>
92
+ <ExampleContainer>
93
+ <Title title="Large" theme="light" level={4} />
94
+ <DxcCard imageSrc={imagePath} imagePadding="large" imageCover>
95
+ Large
96
+ </DxcCard>
97
+ </ExampleContainer>
98
+ <ExampleContainer>
99
+ <Title title="Xlarge" theme="light" level={4} />
100
+ <DxcCard imageSrc={imagePath} imagePadding="xlarge" imageCover>
101
+ Xlarge
102
+ </DxcCard>
103
+ </ExampleContainer>
104
+ <ExampleContainer>
105
+ <Title title="Xxlarge" theme="light" level={4} />
106
+ <DxcCard imageSrc={imagePath} imagePadding="xxlarge" imageCover>
107
+ Xxlarge
108
+ </DxcCard>
109
+ </ExampleContainer>
110
+ <Title title="Content padding" theme="light" level={2} />
111
+ <ExampleContainer>
112
+ <Title title="Xxsmall" theme="light" level={4} />
113
+ <DxcCard contentPadding="xxsmall">Xxsmall</DxcCard>
114
+ </ExampleContainer>
115
+ <ExampleContainer>
116
+ <Title title="Xsmall" theme="light" level={4} />
117
+ <DxcCard contentPadding="xsmall">Xsmall</DxcCard>
118
+ </ExampleContainer>
119
+ <ExampleContainer>
120
+ <Title title="Small" theme="light" level={4} />
121
+ <DxcCard contentPadding="small">Small</DxcCard>
122
+ </ExampleContainer>
123
+ <ExampleContainer>
124
+ <Title title="Medium" theme="light" level={4} />
125
+ <DxcCard contentPadding="medium">Medium</DxcCard>
126
+ </ExampleContainer>
127
+ <ExampleContainer>
128
+ <Title title="Large" theme="light" level={4} />
129
+ <DxcCard contentPadding="large">Large</DxcCard>
130
+ </ExampleContainer>
131
+ <ExampleContainer>
132
+ <Title title="Xlarge" theme="light" level={4} />
133
+ <DxcCard contentPadding="xlarge">Xlarge</DxcCard>
134
+ </ExampleContainer>
135
+ <ExampleContainer>
136
+ <Title title="Xxlarge" theme="light" level={4} />
137
+ <DxcCard contentPadding="xxlarge">Xxlarge</DxcCard>
138
+ </ExampleContainer>
139
+ <Title title="Margin" theme="light" level={2} />
140
+ <ExampleContainer>
141
+ <Title title="Xxsmall" theme="light" level={4} />
142
+ <DxcCard margin="xxsmall">Xxsmall</DxcCard>
143
+ </ExampleContainer>
144
+ <ExampleContainer>
145
+ <Title title="Xsmall" theme="light" level={4} />
146
+ <DxcCard margin="xsmall">Xsmall</DxcCard>
147
+ </ExampleContainer>
148
+ <ExampleContainer>
149
+ <Title title="Small" theme="light" level={4} />
150
+ <DxcCard margin="small">Small</DxcCard>
151
+ </ExampleContainer>
152
+ <ExampleContainer>
153
+ <Title title="Medium" theme="light" level={4} />
154
+ <DxcCard margin="medium">Medium</DxcCard>
155
+ </ExampleContainer>
156
+ <ExampleContainer>
157
+ <Title title="Large" theme="light" level={4} />
158
+ <DxcCard margin="large">Large</DxcCard>
159
+ </ExampleContainer>
160
+ <ExampleContainer>
161
+ <Title title="Xlarge" theme="light" level={4} />
162
+ <DxcCard margin="xlarge">Xlarge</DxcCard>
163
+ </ExampleContainer>
164
+ <ExampleContainer>
165
+ <Title title="Xxlarge" theme="light" level={4} />
166
+ <DxcCard margin="xxlarge">Xxlarge</DxcCard>
167
+ </ExampleContainer>
168
+ </>
169
+ );
170
+
171
+ const actionCard = () => (
172
+ <>
173
+ <ExampleContainer>
174
+ <Title title="Focused default with action" theme="light" level={4} />
175
+ <DxcCard onClick={() => {}}>Focused default with action</DxcCard>
176
+ </ExampleContainer>
177
+ <ExampleContainer expanded>
178
+ <Title title="Hovered default with action" theme="light" level={4} />
179
+ <DxcCard onClick={() => {}}>Hovered default with action</DxcCard>
180
+ </ExampleContainer>
181
+ </>
182
+ );
183
+
184
+ const linkStates = async (focusCard, hoverCard) => {
185
+ await focusCard.focus();
186
+ await userEvent.hover(hoverCard);
187
+ };
188
+
189
+ export const ActionCardStates = actionCard.bind({});
190
+ ActionCardStates.play = async ({ canvasElement }) => {
191
+ const canvas = within(canvasElement);
192
+ await userEvent.tab();
193
+ await userEvent.hover(canvas.getAllByText("Hovered default with action")[1]);
194
+ };
195
+
196
+ export const Chromatic = Card.bind({});
197
+ Chromatic.play = async ({ canvasElement }) => {
198
+ const canvas = within(canvasElement);
199
+ const linkCards = canvas.getAllByRole("link");
200
+ await linkStates(linkCards[1], linkCards[2]);
201
+ };
Binary file
package/card/types.d.ts CHANGED
@@ -42,15 +42,13 @@ declare type Props = {
42
42
  */
43
43
  imageCover?: boolean;
44
44
  /**
45
- * Size of the margin to be applied to the component. You can pass
46
- * an object with 'top', 'bottom', 'left' and 'right' properties
47
- * in order to specify different margin sizes.
45
+ * Size of the margin to be applied to the component ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
46
+ * You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different margin sizes.
48
47
  */
49
48
  margin?: Space | Size;
50
49
  /**
51
- * Size of the padding to be applied to the content area. You can pass
52
- * an object with 'top', 'bottom', 'left' and 'right' properties in
53
- * order to specify different padding sizes.
50
+ * Size of the padding to be applied to the content area ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
51
+ * You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different padding sizes.
54
52
  */
55
53
  contentPadding?: Space | Size;
56
54
  /**
@@ -27,9 +27,9 @@ var _variables = require("../common/variables.js");
27
27
 
28
28
  var _utils = require("../common/utils.js");
29
29
 
30
- var _useTheme = _interopRequireDefault(require("../useTheme.js"));
30
+ var _useTheme = _interopRequireDefault(require("../useTheme"));
31
31
 
32
- var _BackgroundColorContext = _interopRequireDefault(require("../BackgroundColorContext.js"));
32
+ var _BackgroundColorContext = _interopRequireDefault(require("../BackgroundColorContext"));
33
33
 
34
34
  var _templateObject, _templateObject2, _templateObject3;
35
35
 
@@ -19,7 +19,7 @@ declare type Props = {
19
19
  /**
20
20
  * Text to be placed next to the checkbox.
21
21
  */
22
- label: string;
22
+ label?: string;
23
23
  /**
24
24
  * Whether the label should appear after or before the checkbox.
25
25
  */
@@ -49,7 +49,7 @@ declare type Props = {
49
49
  */
50
50
  margin?: Space | Margin;
51
51
  /**
52
- * Size of the component ('small' | 'medium' | 'large' | 'fillParent' | 'fitContent').
52
+ * Size of the component.
53
53
  */
54
54
  size?: "small" | "medium" | "large" | "fillParent" | "fitContent";
55
55
  /**
package/chip/Chip.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import ChipPropsType from "./types";
3
+ declare const DxcChip: ({ label, suffixIcon, prefixIcon, onClickSuffix, onClickPrefix, disabled, margin, tabIndex, }: ChipPropsType) => JSX.Element;
4
+ export default DxcChip;
package/chip/Chip.js CHANGED
@@ -9,23 +9,19 @@ Object.defineProperty(exports, "__esModule", {
9
9
  });
10
10
  exports["default"] = void 0;
11
11
 
12
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
12
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
13
13
 
14
14
  var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
15
15
 
16
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
17
-
18
16
  var _react = _interopRequireDefault(require("react"));
19
17
 
20
18
  var _styledComponents = _interopRequireWildcard(require("styled-components"));
21
19
 
22
- var _propTypes = _interopRequireDefault(require("prop-types"));
23
-
24
20
  var _variables = require("../common/variables.js");
25
21
 
26
22
  var _utils = require("../common/utils.js");
27
23
 
28
- var _useTheme = _interopRequireDefault(require("../useTheme.js"));
24
+ var _useTheme = _interopRequireDefault(require("../useTheme"));
29
25
 
30
26
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
31
27
 
@@ -37,9 +33,7 @@ var DxcChip = function DxcChip(_ref) {
37
33
  var label = _ref.label,
38
34
  suffixIcon = _ref.suffixIcon,
39
35
  prefixIcon = _ref.prefixIcon,
40
- suffixIconSrc = _ref.suffixIconSrc,
41
36
  onClickSuffix = _ref.onClickSuffix,
42
- prefixIconSrc = _ref.prefixIconSrc,
43
37
  onClickPrefix = _ref.onClickPrefix,
44
38
  disabled = _ref.disabled,
45
39
  margin = _ref.margin,
@@ -51,49 +45,33 @@ var DxcChip = function DxcChip(_ref) {
51
45
  }, /*#__PURE__*/_react["default"].createElement(StyledDxcChip, {
52
46
  disabled: disabled,
53
47
  margin: margin
54
- }, prefixIcon ? /*#__PURE__*/_react["default"].createElement(IconContainer, {
48
+ }, prefixIcon && /*#__PURE__*/_react["default"].createElement(IconContainer, {
55
49
  disabled: disabled,
56
50
  prefixIcon: true,
57
51
  label: label,
58
52
  mode: "prefix",
59
53
  tabIndex: typeof onClickPrefix === "function" && !disabled ? tabIndex : -1,
60
54
  onClick: function onClick() {
61
- return onClickPrefix && !disabled && onClickPrefix(label);
62
- },
63
- interactuable: typeof onClickPrefix === "function" && !disabled
64
- }, (0, _typeof2["default"])(prefixIcon) === "object" ? prefixIcon : /*#__PURE__*/_react["default"].createElement(prefixIcon)) : prefixIconSrc && /*#__PURE__*/_react["default"].createElement(PrefixIconContainer, {
65
- disabled: disabled,
66
- src: prefixIconSrc,
67
- label: label,
68
- tabIndex: typeof onClickPrefix === "function" && !disabled ? tabIndex : -1,
69
- onClick: function onClick() {
70
- return onClickPrefix && !disabled && onClickPrefix(label);
55
+ return onClickPrefix && !disabled && onClickPrefix();
71
56
  },
72
57
  interactuable: typeof onClickPrefix === "function" && !disabled
73
- }), label && /*#__PURE__*/_react["default"].createElement(ChipTextContainer, {
74
- disabled: disabled,
75
- prefixIconSrc: prefixIconSrc,
76
- suffixIconSrc: suffixIconSrc
77
- }, label), suffixIcon ? /*#__PURE__*/_react["default"].createElement(IconContainer, {
58
+ }, typeof prefixIcon === "string" ? /*#__PURE__*/_react["default"].createElement(PrefixIconContainer, {
59
+ src: prefixIcon
60
+ }) : prefixIcon), label && /*#__PURE__*/_react["default"].createElement(ChipTextContainer, {
61
+ disabled: disabled
62
+ }, label), suffixIcon && /*#__PURE__*/_react["default"].createElement(IconContainer, {
78
63
  disabled: disabled,
79
64
  suffixIcon: true,
80
65
  mode: "suffix",
81
66
  label: label,
82
67
  tabIndex: typeof onClickSuffix === "function" && !disabled ? tabIndex : -1,
83
68
  onClick: function onClick() {
84
- return onClickSuffix && !disabled && onClickSuffix(label);
69
+ return onClickSuffix && !disabled && onClickSuffix();
85
70
  },
86
71
  interactuable: typeof onClickSuffix === "function" && !disabled
87
- }, (0, _typeof2["default"])(suffixIcon) === "object" ? suffixIcon : /*#__PURE__*/_react["default"].createElement(suffixIcon)) : suffixIconSrc && /*#__PURE__*/_react["default"].createElement(SuffixIconContainer, {
88
- disabled: disabled,
89
- src: suffixIconSrc,
90
- label: label,
91
- tabIndex: typeof onClickSuffix === "function" && !disabled ? tabIndex : -1,
92
- onClick: function onClick() {
93
- return onClickSuffix && !disabled && onClickSuffix(label);
94
- },
95
- interactuable: typeof onClickSuffix === "function" && !disabled
96
- })));
72
+ }, typeof suffixIcon === "string" ? /*#__PURE__*/_react["default"].createElement(SuffixIconContainer, {
73
+ src: suffixIcon
74
+ }) : suffixIcon)));
97
75
  };
98
76
 
99
77
  var getCursor = function getCursor(interactuable, disabled) {
@@ -159,34 +137,14 @@ var ChipTextContainer = _styledComponents["default"].span(_templateObject2 || (_
159
137
  return disabled && "not-allowed" || "default";
160
138
  });
161
139
 
162
- var SuffixIconContainer = _styledComponents["default"].img(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n ", "\n margin-left: ", ";\n width: ", ";\n height: ", ";\n"])), function (props) {
163
- return props.disabled ? props.theme.disabledIconColor : props.theme.iconColor;
164
- }, function (props) {
165
- return getCursor(props.interactuable, props.disabled);
166
- }, function (props) {
167
- return (props.label || props.suffixIconSrc) && props.theme.iconSpacing || props.prefixIconSrc && "5px";
168
- }, function (props) {
169
- return props.theme.iconSize;
170
- }, function (props) {
171
- return props.theme.iconSize;
172
- });
140
+ var SuffixIconContainer = _styledComponents["default"].img(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])([""])));
173
141
 
174
- var PrefixIconContainer = _styledComponents["default"].img(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n ", "\n margin-right: ", ";\n width: ", ";\n height: ", ";\n"])), function (props) {
175
- return props.disabled ? props.theme.disabledIconColor : props.theme.iconColor;
176
- }, function (props) {
177
- return getCursor(props.interactuable, props.disabled);
178
- }, function (props) {
179
- return (props.label || props.suffixIconSrc) && props.theme.iconSpacing || props.prefixIconSrc && "5px";
180
- }, function (props) {
181
- return props.theme.iconSize;
182
- }, function (props) {
183
- return props.theme.iconSize;
184
- });
142
+ var PrefixIconContainer = _styledComponents["default"].img(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])([""])));
185
143
 
186
144
  var IconContainer = _styledComponents["default"].div(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n ", "\n ", "\n width: ", ";\n height: ", ";\n overflow: hidden;\n\n img,\n svg {\n height: 100%;\n width: 100%;\n }\n &:focus {\n outline-color: ", ";\n outline-width: 2px;\n ", "\n }\n"])), function (props) {
187
145
  return props.disabled ? props.theme.disabledIconColor : props.theme.iconColor;
188
146
  }, function (props) {
189
- return props.prefixIcon ? "margin-right: ".concat((props.label || props.suffixIcon || props.suffixIconSrc) && props.theme.iconSpacing || (props.prefixIcon || props.prefixIconSrc) && "0", ";") : "margin-left: ".concat((props.label || props.prefixIcon || props.prefixIconSrc) && props.theme.iconSpacing || (props.prefixIcon || props.prefixIconSrc) && "0", ";");
147
+ return props.prefixIcon ? "margin-right: ".concat((props.label || props.suffixIcon) && props.theme.iconSpacing || props.prefixIcon && "0", ";") : "margin-left: ".concat((props.label || props.prefixIcon) && props.theme.iconSpacing || props.prefixIcon && "0", ";");
190
148
  }, function (props) {
191
149
  return getCursor(props.interactuable, props.disabled);
192
150
  }, function (props) {
@@ -199,23 +157,5 @@ var IconContainer = _styledComponents["default"].div(_templateObject5 || (_templ
199
157
  return props.disabled && "outline: none;";
200
158
  });
201
159
 
202
- DxcChip.propTypes = {
203
- label: _propTypes["default"].string,
204
- disabled: _propTypes["default"].bool,
205
- theme: _propTypes["default"].oneOf(["dark", "light"]),
206
- suffixIcon: _propTypes["default"].oneOfType([_propTypes["default"].element, _propTypes["default"].func]),
207
- prefixIcon: _propTypes["default"].oneOfType([_propTypes["default"].element, _propTypes["default"].func]),
208
- suffixIconSrc: _propTypes["default"].string,
209
- prefixIconSrc: _propTypes["default"].string,
210
- onClickSuffix: _propTypes["default"].func,
211
- onClickPrefix: _propTypes["default"].func,
212
- margin: _propTypes["default"].oneOfType([_propTypes["default"].shape({
213
- top: _propTypes["default"].oneOf(Object.keys(_variables.spaces)),
214
- bottom: _propTypes["default"].oneOf(Object.keys(_variables.spaces)),
215
- left: _propTypes["default"].oneOf(Object.keys(_variables.spaces)),
216
- right: _propTypes["default"].oneOf(Object.keys(_variables.spaces))
217
- }), _propTypes["default"].oneOf((0, _toConsumableArray2["default"])(Object.keys(_variables.spaces)))]),
218
- tabIndex: _propTypes["default"].number
219
- };
220
160
  var _default = DxcChip;
221
161
  exports["default"] = _default;
@@ -0,0 +1,119 @@
1
+ import React from "react";
2
+ import { userEvent, within } from "@storybook/testing-library";
3
+ import DxcChip from "./Chip";
4
+ import Title from "../../.storybook/components/Title";
5
+ import ExampleContainer from "../../.storybook/components/ExampleContainer";
6
+
7
+ export default {
8
+ title: "Chip",
9
+ component: DxcChip,
10
+ };
11
+
12
+ const iconSVG = (
13
+ <svg viewBox="0 0 24 24" fill="currentColor">
14
+ <path d="M0 0h24v24H0z" fill="none" />
15
+ <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" />
16
+ </svg>
17
+ );
18
+
19
+ export const Chromatic = () => (
20
+ <>
21
+ <ExampleContainer>
22
+ <Title title="Basic chip" theme="light" level={4} />
23
+ <DxcChip label="Default Chip" />
24
+ </ExampleContainer>
25
+ <ExampleContainer>
26
+ <Title title="Chip with prefix" theme="light" level={4} />
27
+ <DxcChip label="Chip with prefix" prefixIcon={iconSVG} />
28
+ </ExampleContainer>
29
+ <ExampleContainer>
30
+ <Title title="Chip with suffix" theme="light" level={4} />
31
+ <DxcChip label="Chip with suffix" suffixIcon={iconSVG} />
32
+ </ExampleContainer>
33
+ <ExampleContainer>
34
+ <Title title="Chip with prefix and suffix" theme="light" level={4} />
35
+ <DxcChip label="Chip with prefix and suffix" prefixIcon={iconSVG} suffixIcon={iconSVG} />
36
+ </ExampleContainer>
37
+ <ExampleContainer>
38
+ <Title title="Disabled chip" theme="light" level={4} />
39
+ <DxcChip label="Disabled" disabled prefixIcon={iconSVG} suffixIcon={iconSVG} />
40
+ </ExampleContainer>
41
+ <ExampleContainer>
42
+ <Title title="Chip with ellipsis" theme="light" level={4} />
43
+ <DxcChip label="With ellipsis asdfasdf asdf asdfasdf asdf asdfasdf asdfasdf asdf asdf adfasrfasf afsdg afgasfg asdf asdf asdf asdf asdf asdf asdf afdg asfg asdfg asdf asdf asdf asdfasdf asd fas df asd asdf asdf asdfasd fg ssssssssssss ssss" />
44
+ </ExampleContainer>
45
+ <ExampleContainer>
46
+ <Title title="Chip with ellipsis and suffix" theme="light" level={4} />
47
+ <DxcChip
48
+ suffixIcon={iconSVG}
49
+ label="With ellipsis asdfasdf asdf asdfasdf asdf asdfasdf asdfasdf asdf asdf adfasrfasf afsdg afgasfg asdf asdf asdf asdf asdf asdf asdf afdg asfg asdfg asdf asdf asdf asdfasdf asd fas df asd asdf asdf asdfasd fgsss"
50
+ />
51
+ </ExampleContainer>
52
+ <ExampleContainer>
53
+ <Title title="Chip with ellipsis and prefix" theme="light" level={4} />
54
+ <DxcChip
55
+ prefixIcon={iconSVG}
56
+ label="With ellipsis asdfasdf asdf asdfasdf asdf asdfasdf asdfasdf asdf asdf adfasrfasf afsdg afgasfg asdf asdf asdf asdf asdf asdf asdf afdg asfg asdfg asdf asdf asdf asdfasdf asd fas df asd asdf asdf asdfasd fgsss"
57
+ />
58
+ </ExampleContainer>
59
+ <ExampleContainer>
60
+ <Title title="Chip with ellipsis, suffix and prefix" theme="light" level={4} />
61
+ <DxcChip
62
+ prefixIcon={iconSVG}
63
+ suffixIcon={iconSVG}
64
+ label="With ellipsis asdfasdf asdf asdfasdf asdf asdfasdf asdfasdf asdf asdf adfasrfasf afsdg afgasfg asdf asdf asdf asdf asdf asdf asdf afdg asfg asdfg asdf asdf asdf asdfasdf asd fas df asd asdf asdf asdfasdf"
65
+ />
66
+ </ExampleContainer>
67
+ <Title title="Margins" theme="light" level={2} />
68
+ <ExampleContainer>
69
+ <Title title="Xxsmall margin" theme="light" level={4} />
70
+ <DxcChip label="xxsmall" margin="xxsmall" />
71
+ </ExampleContainer>
72
+ <ExampleContainer>
73
+ <Title title="Xsmall margin" theme="light" level={4} />
74
+ <DxcChip label="xsmall" margin="xsmall" />
75
+ </ExampleContainer>
76
+ <ExampleContainer>
77
+ <Title title="Small margin" theme="light" level={4} />
78
+ <DxcChip label="small" margin="small" />
79
+ </ExampleContainer>
80
+ <ExampleContainer>
81
+ <Title title="Medium margin" theme="light" level={4} />
82
+ <DxcChip label="medium" margin="medium" />
83
+ </ExampleContainer>
84
+ <ExampleContainer>
85
+ <Title title="Large margin" theme="light" level={4} />
86
+ <DxcChip label="large" margin="large" />
87
+ </ExampleContainer>
88
+ <ExampleContainer>
89
+ <Title title="Xlarge margin" theme="light" level={4} />
90
+ <DxcChip label="xlarge" margin="xlarge" />
91
+ </ExampleContainer>
92
+ <ExampleContainer>
93
+ <Title title="Xxlarge margin" theme="light" level={4} />
94
+ <DxcChip label="xxlarge" margin="xxlarge" />
95
+ </ExampleContainer>
96
+ </>
97
+ );
98
+ const ChipPrefixFocused = () => (
99
+ <ExampleContainer>
100
+ <Title title="Chip with prefix" theme="light" level={4} />
101
+ <DxcChip label="Chip with prefix" prefixIcon={iconSVG} onClickPrefix={() => {}} />
102
+ </ExampleContainer>
103
+ );
104
+ const ChipSuffixFocused = () => (
105
+ <ExampleContainer>
106
+ <Title title="Chip with suffix" theme="light" level={4} />
107
+ <DxcChip label="Chip with suffix" suffixIcon={iconSVG} onClickSuffix={() => {}} />
108
+ </ExampleContainer>
109
+ );
110
+
111
+ export const PrefixFocused = ChipPrefixFocused.bind({});
112
+ PrefixFocused.play = async ({ canvasElement }) => {
113
+ await userEvent.tab();
114
+ };
115
+
116
+ export const SuffixFocused = ChipSuffixFocused.bind({});
117
+ SuffixFocused.play = async ({ canvasElement }) => {
118
+ await userEvent.tab();
119
+ };
@@ -0,0 +1,45 @@
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>;
10
+ declare type Props = {
11
+ /**
12
+ * Text to be placed on the chip.
13
+ */
14
+ label?: string;
15
+ /**
16
+ * Element or path used as icon to be placed after the chip label.
17
+ */
18
+ suffixIcon?: string | SVG;
19
+ /**
20
+ * Element or path used as icon to be placed before the chip label.
21
+ */
22
+ prefixIcon?: string | SVG;
23
+ /**
24
+ * This function will be called when the suffix is clicked.
25
+ */
26
+ onClickSuffix?: () => void;
27
+ /**
28
+ * This function will be called when the prefix is clicked.
29
+ */
30
+ onClickPrefix?: () => void;
31
+ /**
32
+ * If true, the component will be disabled.
33
+ */
34
+ disabled?: boolean;
35
+ /**
36
+ * Size of the margin to be applied to the component ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
37
+ * You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different margin sizes.
38
+ */
39
+ margin?: Space | Margin;
40
+ /**
41
+ * Value of the tabindex attribute.
42
+ */
43
+ tabIndex?: number;
44
+ };
45
+ export default Props;
package/chip/types.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });