@nice-digital/nds-horizontal-nav 4.0.1-alpha.0 → 4.0.2
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/HorizontalNav.js
CHANGED
|
@@ -31,6 +31,6 @@ const HorizontalNavLink = (_a) => {
|
|
|
31
31
|
className: (0, classnames_1.default)("horizontal-nav__link", className),
|
|
32
32
|
[method || (ElementType === "a" && "href") || "to"]: destination
|
|
33
33
|
};
|
|
34
|
-
return ((0, jsx_runtime_1.jsx)("li", Object.assign({ className: "horizontal-nav__item" }, { children: (0, jsx_runtime_1.jsx)(ElementType, Object.assign({}, props, rest, { children: title || children || destination || "No Link" })) })));
|
|
34
|
+
return ((0, jsx_runtime_1.jsx)("li", Object.assign({ className: "horizontal-nav__item", "data-component": "horizontal-nav" }, { children: (0, jsx_runtime_1.jsx)(ElementType, Object.assign({}, props, rest, { children: title || children || destination || "No Link" })) })));
|
|
35
35
|
};
|
|
36
36
|
exports.HorizontalNavLink = HorizontalNavLink;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HorizontalNav.js","names":["React","PropTypes","classnames","HorizontalNav","className","children","rest","HorizontalNavLink","title","isCurrent","destination","elementType","ElementType","method","props","propTypes","node","string","bool","isRequired"],"sources":["../src/HorizontalNav.js"],"sourcesContent":["import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport classnames from \"classnames\";\n\nimport \"./../scss/horizontal-nav.scss\";\n\nexport const HorizontalNav = ({ className, children, ...rest }) => {\n\treturn (\n\t\t<nav className={classnames(\"horizontal-nav\", className)} {...rest}>\n\t\t\t<ul className=\"horizontal-nav__list\">{children}</ul>\n\t\t</nav>\n\t);\n};\n\nexport const HorizontalNavLink = ({\n\ttitle,\n\tisCurrent = false,\n\tdestination,\n\telementType: ElementType = \"a\",\n\tchildren,\n\tclassName,\n\tmethod,\n\t...rest\n}) => {\n\t// Would like to make method a required prop in the future but not possible without a breaking change\n\tconst props = {\n\t\t\"aria-current\": isCurrent,\n\t\tclassName: classnames(\"horizontal-nav__link\", className),\n\t\t[method || (ElementType === \"a\" && \"href\") || \"to\"]: destination\n\t};\n\treturn (\n\t\t<li className=\"horizontal-nav__item\">\n\t\t\t<ElementType {...props} {...rest}>\n\t\t\t\t{title || children || destination || \"No Link\"}\n\t\t\t</ElementType>\n\t\t</li>\n\t);\n};\n\nHorizontalNav.propTypes = {\n\tchildren: PropTypes.node,\n\tclassName: PropTypes.string\n};\n\nHorizontalNavLink.propTypes = {\n\tchildren: PropTypes.node,\n\ttitle: PropTypes.string,\n\tisCurrent: PropTypes.bool,\n\tdestination: PropTypes.string.isRequired,\n\telementType: PropTypes.elementType,\n\tclassName: PropTypes.string,\n\tmethod: PropTypes.string\n};\n"],"mappings":";;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,SAAP,MAAsB,YAAtB;AACA,OAAOC,UAAP,MAAuB,YAAvB;AAEA,OAAO,+BAAP;AAEA,OAAO,IAAMC,aAAa,GAAG,SAAhBA,aAAgB,OAAsC;EAAA,IAAnCC,SAAmC,QAAnCA,SAAmC;EAAA,IAAxBC,QAAwB,QAAxBA,QAAwB;EAAA,IAAXC,IAAW;;EAClE,oBACC;IAAK,SAAS,EAAEJ,UAAU,CAAC,gBAAD,EAAmBE,SAAnB;EAA1B,GAA6DE,IAA7D,gBACC;IAAI,SAAS,EAAC;EAAd,GAAsCD,QAAtC,CADD,CADD;AAKA,CANM;AAQP,OAAO,IAAME,iBAAiB,GAAG,SAApBA,iBAAoB,QAS3B;EAAA;;EAAA,IARLC,KAQK,SARLA,KAQK;EAAA,4BAPLC,SAOK;EAAA,IAPLA,SAOK,gCAPO,KAOP;EAAA,IANLC,WAMK,SANLA,WAMK;EAAA,8BALLC,WAKK;EAAA,IALQC,WAKR,kCALsB,GAKtB;EAAA,IAJLP,QAIK,SAJLA,QAIK;EAAA,IAHLD,SAGK,SAHLA,SAGK;EAAA,IAFLS,MAEK,SAFLA,MAEK;EAAA,IADFP,IACE;;EACL;EACA,IAAMQ,KAAK;IACV,gBAAgBL,SADN;IAEVL,SAAS,EAAEF,UAAU,CAAC,sBAAD,EAAyBE,SAAzB;EAFX,UAGTS,MAAM,IAAKD,WAAW,KAAK,GAAhB,IAAuB,MAAlC,IAA6C,IAHpC,IAG2CF,WAH3C,SAAX;EAKA,oBACC;IAAI,SAAS,EAAC;EAAd,gBACC,oBAAC,WAAD,eAAiBI,KAAjB,EAA4BR,IAA5B,GACEE,KAAK,IAAIH,QAAT,IAAqBK,WAArB,IAAoC,SADtC,CADD,CADD;AAOA,CAvBM;AAyBPP,aAAa,CAACY,SAAd,GAA0B;EACzBV,QAAQ,EAAEJ,SAAS,CAACe,IADK;EAEzBZ,SAAS,EAAEH,SAAS,CAACgB;AAFI,CAA1B;AAKAV,iBAAiB,CAACQ,SAAlB,GAA8B;EAC7BV,QAAQ,EAAEJ,SAAS,CAACe,IADS;EAE7BR,KAAK,EAAEP,SAAS,CAACgB,MAFY;EAG7BR,SAAS,EAAER,SAAS,CAACiB,IAHQ;EAI7BR,WAAW,EAAET,SAAS,CAACgB,MAAV,CAAiBE,UAJD;EAK7BR,WAAW,EAAEV,SAAS,CAACU,WALM;EAM7BP,SAAS,EAAEH,SAAS,CAACgB,MANQ;EAO7BJ,MAAM,EAAEZ,SAAS,CAACgB;AAPW,CAA9B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nice-digital/nds-horizontal-nav",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Horizontal navigation component for the NICE Design System",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"navigation"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"url": "https://github.com/nice-digital/nice-design-system/issues"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@nice-digital/nds-core": "^4.0.
|
|
34
|
+
"@nice-digital/nds-core": "^4.0.2",
|
|
35
35
|
"classnames": "^2.2.6"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"@types/node": "^18.11.9",
|
|
47
47
|
"typescript": "^4.8.4"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "d8feb7beba5fffa49da42d6a550cb8f67a50727d"
|
|
50
50
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/es/HorizontalNav.test.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
-
const react_1 = require("@testing-library/react");
|
|
5
|
-
const HorizontalNav_1 = require("./HorizontalNav");
|
|
6
|
-
const Link = () => (0, jsx_runtime_1.jsx)("div", { "data-type": "link" });
|
|
7
|
-
const links = [
|
|
8
|
-
{
|
|
9
|
-
title: "Link One",
|
|
10
|
-
destination: "/formgroup",
|
|
11
|
-
className: "one"
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
title: "Link Two",
|
|
15
|
-
destination: "/pageheader",
|
|
16
|
-
isCurrent: true,
|
|
17
|
-
elementType: Link,
|
|
18
|
-
className: "two"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
title: "Link Three",
|
|
22
|
-
destination: "/stackednav",
|
|
23
|
-
method: "pigeon",
|
|
24
|
-
className: "three"
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
title: "Link Four",
|
|
28
|
-
destination: "/alert",
|
|
29
|
-
elementType: Link,
|
|
30
|
-
method: "to",
|
|
31
|
-
className: "four"
|
|
32
|
-
}
|
|
33
|
-
];
|
|
34
|
-
describe("Horizontal Nav Component", () => {
|
|
35
|
-
it("should match the default snapshot", () => {
|
|
36
|
-
const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(HorizontalNav_1.HorizontalNav, { children: links.map((link) => ((0, jsx_runtime_1.jsx)(HorizontalNav_1.HorizontalNavLink, Object.assign({}, link, { className: "monkey", "data-track": "monkey" }), link.title))) }));
|
|
37
|
-
expect(wrapper).toMatchSnapshot();
|
|
38
|
-
});
|
|
39
|
-
it("should render the name of the destination as the link text if no title or child is supplied ", () => {
|
|
40
|
-
const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(HorizontalNav_1.HorizontalNav, { children: (0, jsx_runtime_1.jsx)(HorizontalNav_1.HorizontalNavLink, { destination: "/testing" }) }));
|
|
41
|
-
expect(wrapper.getByRole("link", { name: "/testing" })).toBeInTheDocument();
|
|
42
|
-
});
|
|
43
|
-
describe("HorizontalNav", () => {
|
|
44
|
-
it("should pass additional props to the container", () => {
|
|
45
|
-
const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(HorizontalNav_1.HorizontalNav, Object.assign({ autoglassrepair: "autoglass replace" }, { children: (0, jsx_runtime_1.jsx)(HorizontalNav_1.HorizontalNavLink, Object.assign({ destination: "#" }, { children: "Link text" })) })));
|
|
46
|
-
expect(wrapper.getByRole("navigation").getAttribute("autoglassrepair")).toBe("autoglass replace");
|
|
47
|
-
});
|
|
48
|
-
it("should merge additional classes onto the container", () => {
|
|
49
|
-
const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(HorizontalNav_1.HorizontalNav, Object.assign({ className: "classy" }, { children: (0, jsx_runtime_1.jsx)(HorizontalNav_1.HorizontalNavLink, Object.assign({ destination: "#" }, { children: "Link text" })) })));
|
|
50
|
-
expect(wrapper.getByRole("navigation")).toHaveClass("classy");
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
describe("HorizontalNavLink", () => {
|
|
54
|
-
it("NavLink should pass additional props directly to the link", () => {
|
|
55
|
-
const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(HorizontalNav_1.HorizontalNav, { children: (0, jsx_runtime_1.jsx)(HorizontalNav_1.HorizontalNavLink, Object.assign({ destination: "#", dancing: "is what we do" }, { children: "Link text" })) }));
|
|
56
|
-
expect(wrapper.getByRole("link").getAttribute("dancing")).toBe("is what we do");
|
|
57
|
-
});
|
|
58
|
-
it("should merge additional classes onto the anchor", () => {
|
|
59
|
-
const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(HorizontalNav_1.HorizontalNav, { children: (0, jsx_runtime_1.jsx)(HorizontalNav_1.HorizontalNavLink, Object.assign({ destination: "#", className: "very-classy" }, { children: "Link text" })) }));
|
|
60
|
-
expect(wrapper.getByRole("link")).toHaveClass("very-classy");
|
|
61
|
-
});
|
|
62
|
-
it("should use a custom navigation attribute if supplied, otherwise fall back to href if anchor or to if not", () => {
|
|
63
|
-
var _a, _b;
|
|
64
|
-
const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(HorizontalNav_1.HorizontalNav, { children: links.map((link) => ((0, jsx_runtime_1.jsx)(HorizontalNav_1.HorizontalNavLink, Object.assign({}, link), link.title))) }));
|
|
65
|
-
expect((_a = container.querySelector("a.three")) === null || _a === void 0 ? void 0 : _a.getAttribute("pigeon")).toBeTruthy();
|
|
66
|
-
expect((_b = container.querySelector("a.one")) === null || _b === void 0 ? void 0 : _b.getAttribute("href")).toBeTruthy();
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
});
|