@dxc-technology/halstack-react 12.1.0 → 12.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/HalstackContext.d.ts +23 -0
  2. package/HalstackContext.js +31 -21
  3. package/breadcrumbs/types.d.ts +24 -0
  4. package/common/coreTokens.d.ts +0 -1
  5. package/common/coreTokens.js +0 -1
  6. package/common/variables.d.ts +29 -0
  7. package/common/variables.js +25 -2
  8. package/container/types.d.ts +113 -11
  9. package/contextual-menu/ContextualMenu.js +33 -5
  10. package/contextual-menu/ContextualMenu.stories.tsx +46 -38
  11. package/contextual-menu/ItemAction.js +47 -9
  12. package/contextual-menu/types.d.ts +4 -0
  13. package/divider/Divider.stories.tsx +2 -1
  14. package/file-input/FileItem.js +1 -1
  15. package/icon/Icon.stories.tsx +1 -1
  16. package/number-input/NumberInput.js +5 -2
  17. package/number-input/NumberInput.stories.tsx +9 -0
  18. package/package.json +4 -3
  19. package/password-input/PasswordInput.js +6 -3
  20. package/password-input/PasswordInput.stories.tsx +9 -0
  21. package/resultset-table/ResultsetTable.js +33 -9
  22. package/resultset-table/ResultsetTable.stories.tsx +1 -1
  23. package/resultset-table/ResultsetTable.test.js +101 -30
  24. package/resultset-table/types.d.ts +3 -2
  25. package/select/Select.js +3 -1
  26. package/select/Select.stories.tsx +10 -1
  27. package/text-input/TextInput.js +3 -1
  28. package/text-input/TextInput.stories.tsx +9 -0
  29. package/tooltip/Tooltip.accessibility.test.d.ts +1 -0
  30. package/tooltip/Tooltip.accessibility.test.js +144 -0
  31. package/tooltip/Tooltip.d.ts +4 -0
  32. package/tooltip/Tooltip.js +50 -0
  33. package/tooltip/Tooltip.stories.tsx +111 -0
  34. package/tooltip/Tooltip.test.d.ts +1 -0
  35. package/tooltip/Tooltip.test.js +112 -0
  36. package/tooltip/types.d.ts +16 -0
  37. package/tooltip/types.js +5 -0
  38. package/typography/Typography.test.js +23 -0
  39. package/useTheme.d.ts +23 -0
  40. package/utils/BaseTypography.js +44 -40
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
5
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
6
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
7
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _react2 = require("@testing-library/react");
10
+ var _Tooltip = _interopRequireDefault(require("./Tooltip"));
11
+ var _Button = _interopRequireDefault(require("../button/Button"));
12
+ var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
13
+ require("@testing-library/jest-dom");
14
+ global.globalThis = global;
15
+ global.DOMRect = {
16
+ fromRect: function fromRect() {
17
+ return {
18
+ top: 0,
19
+ left: 0,
20
+ bottom: 0,
21
+ right: 0,
22
+ width: 0,
23
+ height: 0,
24
+ x: 0,
25
+ y: 0
26
+ };
27
+ }
28
+ };
29
+ global.ResizeObserver = /*#__PURE__*/function () {
30
+ function ResizeObserver() {
31
+ (0, _classCallCheck2["default"])(this, ResizeObserver);
32
+ }
33
+ return (0, _createClass2["default"])(ResizeObserver, [{
34
+ key: "observe",
35
+ value: function observe() {}
36
+ }, {
37
+ key: "unobserve",
38
+ value: function unobserve() {}
39
+ }, {
40
+ key: "disconnect",
41
+ value: function disconnect() {}
42
+ }]);
43
+ }();
44
+ describe("Tooltip component tests", function () {
45
+ test("Tooltip does not render by default", /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
46
+ var _render, queryByRole;
47
+ return _regenerator["default"].wrap(function _callee$(_context) {
48
+ while (1) switch (_context.prev = _context.next) {
49
+ case 0:
50
+ _render = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Tooltip["default"], {
51
+ label: "Tooltip Test"
52
+ }, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
53
+ label: "Hoverable button"
54
+ }))), queryByRole = _render.queryByRole;
55
+ _context.next = 3;
56
+ return (0, _react2.waitFor)(function () {
57
+ var tooltipElement = queryByRole("tooltip");
58
+ expect(tooltipElement).toBeFalsy();
59
+ });
60
+ case 3:
61
+ case "end":
62
+ return _context.stop();
63
+ }
64
+ }, _callee);
65
+ })));
66
+ test("Tooltip renders with correct label on hover", /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
67
+ var _render2, getByText, triggerElement;
68
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
69
+ while (1) switch (_context2.prev = _context2.next) {
70
+ case 0:
71
+ _render2 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Tooltip["default"], {
72
+ label: "Tooltip Test"
73
+ }, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
74
+ label: "Hoverable button"
75
+ }))), getByText = _render2.getByText;
76
+ triggerElement = getByText("Hoverable button");
77
+ _userEvent["default"].hover(triggerElement);
78
+ _context2.next = 5;
79
+ return _react2.screen.findByRole("tooltip", {
80
+ name: "Tooltip Test"
81
+ });
82
+ case 5:
83
+ case "end":
84
+ return _context2.stop();
85
+ }
86
+ }, _callee2);
87
+ })));
88
+ test("Tooltip stops being rendered when hover is stopped", /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
89
+ var _render3, getByText, queryByRole, triggerElement;
90
+ return _regenerator["default"].wrap(function _callee3$(_context3) {
91
+ while (1) switch (_context3.prev = _context3.next) {
92
+ case 0:
93
+ _render3 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Tooltip["default"], {
94
+ label: "Tooltip Test"
95
+ }, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
96
+ label: "Hoverable button"
97
+ }))), getByText = _render3.getByText, queryByRole = _render3.queryByRole;
98
+ triggerElement = getByText("Hoverable button");
99
+ _userEvent["default"].hover(triggerElement);
100
+ _userEvent["default"].unhover(triggerElement);
101
+ _context3.next = 6;
102
+ return (0, _react2.waitFor)(function () {
103
+ var tooltipElement = queryByRole("tooltip");
104
+ expect(tooltipElement).toBeFalsy();
105
+ });
106
+ case 6:
107
+ case "end":
108
+ return _context3.stop();
109
+ }
110
+ }, _callee3);
111
+ })));
112
+ });
@@ -0,0 +1,16 @@
1
+ /// <reference types="react" />
2
+ type Props = {
3
+ /**
4
+ * Preferred position for displaying the tooltip. It may adjust automatically based on available space.
5
+ */
6
+ position?: "bottom" | "top" | "left" | "right";
7
+ /**
8
+ * Text to be displayed inside the tooltip.
9
+ */
10
+ label: string;
11
+ /**
12
+ * Content in which the Tooltip will be displayed.
13
+ */
14
+ children: React.ReactNode;
15
+ };
16
+ export default Props;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _react = _interopRequireDefault(require("react"));
5
+ var _react2 = require("@testing-library/react");
6
+ var _Typography = _interopRequireDefault(require("./Typography"));
7
+ describe("Typography component tests", function () {
8
+ test("Renders as the selected component", function () {
9
+ var _render = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
10
+ as: "h1"
11
+ }, "Test H1 Text")),
12
+ container = _render.container;
13
+ expect(container.querySelector('h1')).not.toBeNull();
14
+ });
15
+ test("Renders as span if it receives invalid tag", function () {
16
+ var _render2 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
17
+ as: "br"
18
+ }, "Test BR Text")),
19
+ container = _render2.container;
20
+ expect(container.querySelector('br')).toBeNull();
21
+ expect(container.querySelector('span')).not.toBeNull();
22
+ });
23
+ });
package/useTheme.d.ts CHANGED
@@ -217,6 +217,29 @@ declare const useTheme: () => {
217
217
  focusBorderThickness: string;
218
218
  focusBorderRadius: string;
219
219
  }>;
220
+ contextualMenu?: Partial<{
221
+ fontFamily: string;
222
+ backgroundColor: string;
223
+ borderColor: string;
224
+ menuItemFontColor: string;
225
+ menuItemFontSize: string;
226
+ menuItemFontStyle: string;
227
+ menuItemFontWeight: string;
228
+ menuItemLineHeight: string;
229
+ hoverMenuItemBackgroundColor: string;
230
+ activeMenuItemBackgroundColor: string;
231
+ selectedMenuItemBackgroundColor: string;
232
+ hoverSelectedMenuItemBackgroundColor: string;
233
+ activeSelectedMenuItemBackgroundColor: string;
234
+ selectedMenuItemFontWeight: string;
235
+ sectionTitleFontColor: string;
236
+ sectionTitleFontSize: string;
237
+ sectionTitleFontStyle: string;
238
+ sectionTitleFontWeight: string;
239
+ sectionTitleLineHeight: string;
240
+ iconColor: string;
241
+ iconSize: string;
242
+ }>;
220
243
  dateInput?: Partial<{
221
244
  pickerBackgroundColor: string;
222
245
  pickerFontColor: string;
@@ -13,6 +13,10 @@ var _templateObject;
13
13
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
14
14
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
15
15
  var TypographyContext = /*#__PURE__*/_react["default"].createContext(null);
16
+ var ValidTypographyTags = ["a", "blockquote", "cite", "code", "div", "em", "figcaption", "h1", "h2", "h3", "h4", "h5", "h6", "p", "pre", "small", "span", "strong"];
17
+ var isValidTypography = function isValidTypography(tag) {
18
+ return ValidTypographyTags.includes(tag);
19
+ };
16
20
  var BaseTypography = function BaseTypography(_ref) {
17
21
  var as = _ref.as,
18
22
  display = _ref.display,
@@ -30,65 +34,65 @@ var BaseTypography = function BaseTypography(_ref) {
30
34
  children = _ref.children;
31
35
  var componentContext = (0, _react.useContext)(TypographyContext);
32
36
  var contextValue = (0, _react.useMemo)(function () {
33
- var _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _ref10, _ref11, _ref12, _ref13, _ref14;
37
+ var _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _ref10, _ref11, _ref12, _ref13;
34
38
  return {
35
- as: (_ref2 = as !== null && as !== void 0 ? as : componentContext === null || componentContext === void 0 ? void 0 : componentContext.as) !== null && _ref2 !== void 0 ? _ref2 : "span",
36
- display: (_ref3 = display !== null && display !== void 0 ? display : componentContext === null || componentContext === void 0 ? void 0 : componentContext.display) !== null && _ref3 !== void 0 ? _ref3 : "inline",
37
- fontFamily: (_ref4 = fontFamily !== null && fontFamily !== void 0 ? fontFamily : componentContext === null || componentContext === void 0 ? void 0 : componentContext.fontFamily) !== null && _ref4 !== void 0 ? _ref4 : "Open Sans, sans-serif",
38
- fontSize: (_ref5 = fontSize !== null && fontSize !== void 0 ? fontSize : componentContext === null || componentContext === void 0 ? void 0 : componentContext.fontSize) !== null && _ref5 !== void 0 ? _ref5 : "1rem",
39
- fontStyle: (_ref6 = fontStyle !== null && fontStyle !== void 0 ? fontStyle : componentContext === null || componentContext === void 0 ? void 0 : componentContext.fontStyle) !== null && _ref6 !== void 0 ? _ref6 : "normal",
40
- fontWeight: (_ref7 = fontWeight !== null && fontWeight !== void 0 ? fontWeight : componentContext === null || componentContext === void 0 ? void 0 : componentContext.fontWeight) !== null && _ref7 !== void 0 ? _ref7 : "400",
41
- letterSpacing: (_ref8 = letterSpacing !== null && letterSpacing !== void 0 ? letterSpacing : componentContext === null || componentContext === void 0 ? void 0 : componentContext.letterSpacing) !== null && _ref8 !== void 0 ? _ref8 : "0em",
42
- lineHeight: (_ref9 = lineHeight !== null && lineHeight !== void 0 ? lineHeight : componentContext === null || componentContext === void 0 ? void 0 : componentContext.lineHeight) !== null && _ref9 !== void 0 ? _ref9 : "1.5em",
43
- textAlign: (_ref10 = textAlign !== null && textAlign !== void 0 ? textAlign : componentContext === null || componentContext === void 0 ? void 0 : componentContext.textAlign) !== null && _ref10 !== void 0 ? _ref10 : "left",
44
- color: (_ref11 = color !== null && color !== void 0 ? color : componentContext === null || componentContext === void 0 ? void 0 : componentContext.color) !== null && _ref11 !== void 0 ? _ref11 : "#000000",
45
- textDecoration: (_ref12 = textDecoration !== null && textDecoration !== void 0 ? textDecoration : componentContext === null || componentContext === void 0 ? void 0 : componentContext.textDecoration) !== null && _ref12 !== void 0 ? _ref12 : "none",
46
- textOverflow: (_ref13 = textOverflow !== null && textOverflow !== void 0 ? textOverflow : componentContext === null || componentContext === void 0 ? void 0 : componentContext.textOverflow) !== null && _ref13 !== void 0 ? _ref13 : "unset",
47
- whiteSpace: (_ref14 = whiteSpace !== null && whiteSpace !== void 0 ? whiteSpace : componentContext === null || componentContext === void 0 ? void 0 : componentContext.whiteSpace) !== null && _ref14 !== void 0 ? _ref14 : "normal"
39
+ as: isValidTypography(as) ? as : isValidTypography(componentContext === null || componentContext === void 0 ? void 0 : componentContext.as) ? componentContext === null || componentContext === void 0 ? void 0 : componentContext.as : "span",
40
+ display: (_ref2 = display !== null && display !== void 0 ? display : componentContext === null || componentContext === void 0 ? void 0 : componentContext.display) !== null && _ref2 !== void 0 ? _ref2 : "inline",
41
+ fontFamily: (_ref3 = fontFamily !== null && fontFamily !== void 0 ? fontFamily : componentContext === null || componentContext === void 0 ? void 0 : componentContext.fontFamily) !== null && _ref3 !== void 0 ? _ref3 : "Open Sans, sans-serif",
42
+ fontSize: (_ref4 = fontSize !== null && fontSize !== void 0 ? fontSize : componentContext === null || componentContext === void 0 ? void 0 : componentContext.fontSize) !== null && _ref4 !== void 0 ? _ref4 : "1rem",
43
+ fontStyle: (_ref5 = fontStyle !== null && fontStyle !== void 0 ? fontStyle : componentContext === null || componentContext === void 0 ? void 0 : componentContext.fontStyle) !== null && _ref5 !== void 0 ? _ref5 : "normal",
44
+ fontWeight: (_ref6 = fontWeight !== null && fontWeight !== void 0 ? fontWeight : componentContext === null || componentContext === void 0 ? void 0 : componentContext.fontWeight) !== null && _ref6 !== void 0 ? _ref6 : "400",
45
+ letterSpacing: (_ref7 = letterSpacing !== null && letterSpacing !== void 0 ? letterSpacing : componentContext === null || componentContext === void 0 ? void 0 : componentContext.letterSpacing) !== null && _ref7 !== void 0 ? _ref7 : "0em",
46
+ lineHeight: (_ref8 = lineHeight !== null && lineHeight !== void 0 ? lineHeight : componentContext === null || componentContext === void 0 ? void 0 : componentContext.lineHeight) !== null && _ref8 !== void 0 ? _ref8 : "1.5em",
47
+ textAlign: (_ref9 = textAlign !== null && textAlign !== void 0 ? textAlign : componentContext === null || componentContext === void 0 ? void 0 : componentContext.textAlign) !== null && _ref9 !== void 0 ? _ref9 : "left",
48
+ color: (_ref10 = color !== null && color !== void 0 ? color : componentContext === null || componentContext === void 0 ? void 0 : componentContext.color) !== null && _ref10 !== void 0 ? _ref10 : "#000000",
49
+ textDecoration: (_ref11 = textDecoration !== null && textDecoration !== void 0 ? textDecoration : componentContext === null || componentContext === void 0 ? void 0 : componentContext.textDecoration) !== null && _ref11 !== void 0 ? _ref11 : "none",
50
+ textOverflow: (_ref12 = textOverflow !== null && textOverflow !== void 0 ? textOverflow : componentContext === null || componentContext === void 0 ? void 0 : componentContext.textOverflow) !== null && _ref12 !== void 0 ? _ref12 : "unset",
51
+ whiteSpace: (_ref13 = whiteSpace !== null && whiteSpace !== void 0 ? whiteSpace : componentContext === null || componentContext === void 0 ? void 0 : componentContext.whiteSpace) !== null && _ref13 !== void 0 ? _ref13 : "normal"
48
52
  };
49
53
  }, [as, display, fontFamily, fontSize, fontStyle, fontWeight, letterSpacing, lineHeight, textAlign, color, textDecoration, textOverflow, whiteSpace]);
50
54
  return /*#__PURE__*/_react["default"].createElement(TypographyContext.Provider, {
51
55
  value: contextValue
52
56
  }, /*#__PURE__*/_react["default"].createElement(StyledTypography, contextValue, children));
53
57
  };
54
- var StyledTypography = _styledComponents["default"].span(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n display: ", ";\n color: ", ";\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n letter-spacing: ", ";\n line-height: ", ";\n text-align: ", ";\n text-decoration: ", ";\n text-overflow: ", ";\n white-space: ", ";\n overflow: ", ";\n margin: 0;\n"])), function (_ref15) {
55
- var display = _ref15.display;
58
+ var StyledTypography = _styledComponents["default"].span(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n display: ", ";\n color: ", ";\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n letter-spacing: ", ";\n line-height: ", ";\n text-align: ", ";\n text-decoration: ", ";\n text-overflow: ", ";\n white-space: ", ";\n overflow: ", ";\n margin: 0;\n"])), function (_ref14) {
59
+ var display = _ref14.display;
56
60
  return display;
57
- }, function (_ref16) {
58
- var color = _ref16.color;
61
+ }, function (_ref15) {
62
+ var color = _ref15.color;
59
63
  return color;
60
- }, function (_ref17) {
61
- var fontFamily = _ref17.fontFamily;
64
+ }, function (_ref16) {
65
+ var fontFamily = _ref16.fontFamily;
62
66
  return fontFamily;
63
- }, function (_ref18) {
64
- var fontSize = _ref18.fontSize;
67
+ }, function (_ref17) {
68
+ var fontSize = _ref17.fontSize;
65
69
  return fontSize;
66
- }, function (_ref19) {
67
- var fontStyle = _ref19.fontStyle;
70
+ }, function (_ref18) {
71
+ var fontStyle = _ref18.fontStyle;
68
72
  return fontStyle;
69
- }, function (_ref20) {
70
- var fontWeight = _ref20.fontWeight;
73
+ }, function (_ref19) {
74
+ var fontWeight = _ref19.fontWeight;
71
75
  return fontWeight;
72
- }, function (_ref21) {
73
- var letterSpacing = _ref21.letterSpacing;
76
+ }, function (_ref20) {
77
+ var letterSpacing = _ref20.letterSpacing;
74
78
  return letterSpacing;
75
- }, function (_ref22) {
76
- var lineHeight = _ref22.lineHeight;
79
+ }, function (_ref21) {
80
+ var lineHeight = _ref21.lineHeight;
77
81
  return lineHeight;
78
- }, function (_ref23) {
79
- var textAlign = _ref23.textAlign;
82
+ }, function (_ref22) {
83
+ var textAlign = _ref22.textAlign;
80
84
  return textAlign;
81
- }, function (_ref24) {
82
- var textDecoration = _ref24.textDecoration;
85
+ }, function (_ref23) {
86
+ var textDecoration = _ref23.textDecoration;
83
87
  return textDecoration;
84
- }, function (_ref25) {
85
- var textOverflow = _ref25.textOverflow;
88
+ }, function (_ref24) {
89
+ var textOverflow = _ref24.textOverflow;
86
90
  return textOverflow;
87
- }, function (_ref26) {
88
- var whiteSpace = _ref26.whiteSpace;
91
+ }, function (_ref25) {
92
+ var whiteSpace = _ref25.whiteSpace;
89
93
  return whiteSpace;
90
- }, function (_ref27) {
91
- var textOverflow = _ref27.textOverflow;
94
+ }, function (_ref26) {
95
+ var textOverflow = _ref26.textOverflow;
92
96
  return textOverflow !== "unset" ? "hidden" : "visible";
93
97
  });
94
98
  var _default = exports["default"] = BaseTypography;