@nice-digital/nds-button 4.0.4-alpha.0 → 4.0.5

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.
package/es/Button.js CHANGED
@@ -48,7 +48,7 @@ const Button = (props) => {
48
48
  [`btn--${variant}`]: variant !== exports.buttonVariants.primary,
49
49
  [`${className}`]: !!className
50
50
  });
51
- return ((0, jsx_runtime_1.jsx)(ButtonTagType, Object.assign({}, buttonProps, attributes, { children: children })));
51
+ return ((0, jsx_runtime_1.jsx)(ButtonTagType, Object.assign({}, buttonProps, attributes, { "data-component": `button${variant ? `--${variant}` : ""}${buttonType ? `--${buttonType}` : ""}` }, { children: children })));
52
52
  };
53
53
  exports.Button = Button;
54
54
  // Legacy references - deprecated!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nice-digital/nds-button",
3
- "version": "4.0.4-alpha.0",
3
+ "version": "4.0.5",
4
4
  "description": "Button component for the NICE Design System",
5
5
  "author": "Ian Routledge <ian.routledge@nice.org.uk>",
6
6
  "homepage": "https://design-system.nice.org.uk/",
@@ -27,7 +27,7 @@
27
27
  "url": "https://github.com/nice-digital/nice-design-system/issues"
28
28
  },
29
29
  "dependencies": {
30
- "@nice-digital/nds-core": "^4.0.2-alpha.0",
30
+ "@nice-digital/nds-core": "^4.0.3",
31
31
  "classnames": "^2.2.6"
32
32
  },
33
33
  "peerDependencies": {
@@ -42,5 +42,5 @@
42
42
  "@types/node": "^18.11.9",
43
43
  "typescript": "^4.8.4"
44
44
  },
45
- "gitHead": "0a6b742ccd11300f0586abf5dc3790e217f70c21"
45
+ "gitHead": "ae51389ba2e51dbe9ee3849e71d44fd567fb2822"
46
46
  }
@@ -1 +0,0 @@
1
- export {};
package/es/Button.test.js DELETED
@@ -1,108 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const jsx_runtime_1 = require("react/jsx-runtime");
16
- const react_1 = require("@testing-library/react");
17
- const user_event_1 = __importDefault(require("@testing-library/user-event"));
18
- const Button_1 = require("./Button");
19
- describe("@nice-digital/nds-button", () => {
20
- it("should render a button tag", () => {
21
- const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(Button_1.Button, { children: "Example" }));
22
- expect(wrapper.getByRole("button")).toBeInTheDocument();
23
- });
24
- it("should match snapshot", () => {
25
- const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(Button_1.Button, { children: "Example" }));
26
- expect(wrapper).toMatchSnapshot();
27
- });
28
- describe("contents", () => {
29
- it("should render children prop into button contents", () => {
30
- const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(Button_1.Button, { children: "Test contents" }));
31
- expect(wrapper.getByRole("button", { name: "Test contents" })).toBeInTheDocument();
32
- });
33
- it("should render multiple children as content", () => {
34
- const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsxs)(Button_1.Button, { children: [(0, jsx_runtime_1.jsx)("span", { children: "1" }), (0, jsx_runtime_1.jsx)("span", { children: "2" })] }));
35
- expect(wrapper.getByRole("button").querySelectorAll("span").length).toBe(2);
36
- });
37
- });
38
- describe("button types", () => {
39
- it("should pass buttonType prop into type attribute on rendered button", () => {
40
- const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(Button_1.Button, Object.assign({ buttonType: "submit" }, { children: "Test contents" })));
41
- expect(wrapper.getByRole("button").getAttribute("type")).toBe("submit");
42
- });
43
- });
44
- describe("variants", () => {
45
- it("should just use btn class for primary variant", () => {
46
- const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(Button_1.Button, Object.assign({ variant: "primary" }, { children: "Primary" })));
47
- expect(wrapper.getByRole("button")).toHaveClass("btn");
48
- });
49
- it("should append cta modifier class for cta variant", () => {
50
- const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(Button_1.Button, Object.assign({ variant: "cta" }, { children: "CTA" })));
51
- expect(wrapper.getByRole("button")).toHaveClass("btn btn--cta");
52
- });
53
- it("should append secondary modifier class for secondary variant", () => {
54
- const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(Button_1.Button, Object.assign({ variant: "secondary" }, { children: "Secondary" })));
55
- expect(wrapper.getByRole("button")).toHaveClass("btn btn--secondary");
56
- });
57
- it("should append inverse modifier class for inverse variant", () => {
58
- const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(Button_1.Button, Object.assign({ variant: "inverse" }, { children: "Inverse" })));
59
- expect(wrapper.getByRole("button")).toHaveClass("btn btn--inverse");
60
- });
61
- });
62
- describe("anchors", () => {
63
- it("should render an anchor when to prop is passed", () => {
64
- const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(Button_1.Button, Object.assign({ to: "/test" }, { children: "Test" })));
65
- expect(wrapper.getByRole("link")).toBeInTheDocument();
66
- });
67
- it("should render an href attribute with value from to prop", () => {
68
- const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(Button_1.Button, Object.assign({ type: "anchor", to: "/test" }, { children: "Test" })));
69
- expect(wrapper.getByRole("link").getAttribute("href")).toBe("/test");
70
- });
71
- });
72
- describe("props", () => {
73
- it("should pass props as attributes on rendered element", () => {
74
- const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(Button_1.Button, Object.assign({ type: "submit", disabled: true, variant: "cta" }, { children: "txt" })));
75
- const button = wrapper.getByRole("button", {
76
- name: "txt"
77
- });
78
- expect(button).toHaveClass("btn btn--cta");
79
- expect(button.getAttribute("type")).toBe("submit");
80
- expect(button.disabled).toBe(true);
81
- });
82
- it("should append given className prop to rendered className attribute", () => {
83
- const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(Button_1.Button, Object.assign({ className: "mt--0", to: "/test" }, { children: "txt" })));
84
- expect(wrapper.getByRole("link", { name: "txt" }).getAttribute("href")).toBe("/test");
85
- expect(wrapper.getByRole("link", { name: "txt" })).toHaveClass("btn mt--0");
86
- });
87
- it("should call onClick handler", () => __awaiter(void 0, void 0, void 0, function* () {
88
- const clickHandler = jest.fn();
89
- const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(Button_1.Button, Object.assign({ onClick: clickHandler }, { children: "Test" })));
90
- const button = wrapper.getByRole("button");
91
- user_event_1.default.click(button);
92
- yield (0, react_1.waitFor)(() => {
93
- expect(clickHandler).toHaveBeenCalled();
94
- });
95
- }));
96
- });
97
- describe("should render the appropriate link method for the supplied elementType and method", () => {
98
- it("should use any supplied method", () => {
99
- var _a;
100
- const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(Button_1.Button, Object.assign({ method: "pigeon", to: "/one", className: "one" }, { children: "One" })) }));
101
- expect((_a = container.querySelector(".one")) === null || _a === void 0 ? void 0 : _a.getAttribute("pigeon")).toBe("/one");
102
- });
103
- it("should use href if elementType is anchor", () => {
104
- const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(Button_1.Button, Object.assign({ elementType: "a", to: "/two", className: "two" }, { children: "Two" })));
105
- expect(wrapper.getByRole("link", { name: "Two" }).getAttribute("href")).toBe("/two");
106
- });
107
- });
108
- });