@behivetech/atoms.nav-item 0.0.0-stage → 0.4.3
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/README.md +19 -2
- package/dist/index.cjs +176 -0
- package/dist/index.css +61 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +162 -0
- package/docs.json +43 -0
- package/index.ts +2 -0
- package/nav-item.example.tsx +13 -0
- package/nav-item.module.scss +97 -0
- package/nav-item.tsx +39 -0
- package/package.json +56 -3
package/README.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# NavItem
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A single navigation link with an optional leading icon and active state. The
|
|
4
|
+
`active` modifier is applied on the component's own root element (per BEM),
|
|
5
|
+
so it can be dropped into any nav/sidebar layout.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```jsx
|
|
10
|
+
import { NavItem } from "@behivetech/atoms.nav-item";
|
|
11
|
+
|
|
12
|
+
function Example() {
|
|
13
|
+
const currentPath = "/pages";
|
|
14
|
+
return (
|
|
15
|
+
<NavItem href="/pages" icon="☰" active={currentPath.startsWith("/pages")}>
|
|
16
|
+
Pages
|
|
17
|
+
</NavItem>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
|
|
33
|
+
// ../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js
|
|
34
|
+
var require_classnames = __commonJS({
|
|
35
|
+
"../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js"(exports2, module2) {
|
|
36
|
+
"use strict";
|
|
37
|
+
(function() {
|
|
38
|
+
"use strict";
|
|
39
|
+
var hasOwn = {}.hasOwnProperty;
|
|
40
|
+
function classNames() {
|
|
41
|
+
var classes = "";
|
|
42
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
43
|
+
var arg = arguments[i];
|
|
44
|
+
if (arg) {
|
|
45
|
+
classes = appendClass(classes, parseValue(arg));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return classes;
|
|
49
|
+
}
|
|
50
|
+
function parseValue(arg) {
|
|
51
|
+
if (typeof arg === "string" || typeof arg === "number") {
|
|
52
|
+
return arg;
|
|
53
|
+
}
|
|
54
|
+
if (typeof arg !== "object") {
|
|
55
|
+
return "";
|
|
56
|
+
}
|
|
57
|
+
if (Array.isArray(arg)) {
|
|
58
|
+
return classNames.apply(null, arg);
|
|
59
|
+
}
|
|
60
|
+
if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
|
|
61
|
+
return arg.toString();
|
|
62
|
+
}
|
|
63
|
+
var classes = "";
|
|
64
|
+
for (var key in arg) {
|
|
65
|
+
if (hasOwn.call(arg, key) && arg[key]) {
|
|
66
|
+
classes = appendClass(classes, key);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return classes;
|
|
70
|
+
}
|
|
71
|
+
function appendClass(value, newClass) {
|
|
72
|
+
if (!newClass) {
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
if (value) {
|
|
76
|
+
return value + " " + newClass;
|
|
77
|
+
}
|
|
78
|
+
return value + newClass;
|
|
79
|
+
}
|
|
80
|
+
if (typeof module2 !== "undefined" && module2.exports) {
|
|
81
|
+
classNames.default = classNames;
|
|
82
|
+
module2.exports = classNames;
|
|
83
|
+
} else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
|
|
84
|
+
define("classnames", [], function() {
|
|
85
|
+
return classNames;
|
|
86
|
+
});
|
|
87
|
+
} else {
|
|
88
|
+
window.classNames = classNames;
|
|
89
|
+
}
|
|
90
|
+
})();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// index.ts
|
|
95
|
+
var index_exports = {};
|
|
96
|
+
__export(index_exports, {
|
|
97
|
+
NavItem: () => NavItem
|
|
98
|
+
});
|
|
99
|
+
module.exports = __toCommonJS(index_exports);
|
|
100
|
+
|
|
101
|
+
// ../../../../packages/registry/class-names/dist/index.js
|
|
102
|
+
var import_classnames = __toESM(require_classnames(), 1);
|
|
103
|
+
var getClassName = ({
|
|
104
|
+
className,
|
|
105
|
+
modifiers = {},
|
|
106
|
+
rootClass,
|
|
107
|
+
styles = {}
|
|
108
|
+
}) => {
|
|
109
|
+
function getModifiers() {
|
|
110
|
+
const updatedModifiers = {};
|
|
111
|
+
const modifierKeys = Object.keys(modifiers);
|
|
112
|
+
if (modifierKeys.length) {
|
|
113
|
+
modifierKeys.forEach((modKey) => {
|
|
114
|
+
const classKey = `${rootClass}--${modKey}`;
|
|
115
|
+
const newClassName = styles[classKey] || classKey;
|
|
116
|
+
updatedModifiers[newClassName] = modifiers[modKey] ?? false;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return updatedModifiers;
|
|
120
|
+
}
|
|
121
|
+
function getChildClass(childClassName) {
|
|
122
|
+
const classKey = `${rootClass}__${childClassName}`;
|
|
123
|
+
return styles[classKey] || classKey;
|
|
124
|
+
}
|
|
125
|
+
function getRootStyles() {
|
|
126
|
+
return (0, import_classnames.default)(
|
|
127
|
+
className,
|
|
128
|
+
{
|
|
129
|
+
...getModifiers()
|
|
130
|
+
},
|
|
131
|
+
styles[rootClass] || rootClass
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
return [getRootStyles(), getChildClass];
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// nav-item.module.scss
|
|
138
|
+
var nav_item_module_default = {
|
|
139
|
+
"BHT__NavItem": "BHT__NavItem",
|
|
140
|
+
"BHT__NavItem__icon": "BHT__NavItem__icon",
|
|
141
|
+
"BHT__NavItem--active": "BHT__NavItem--active"
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// nav-item.tsx
|
|
145
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
146
|
+
var NavItem = ({
|
|
147
|
+
className,
|
|
148
|
+
icon,
|
|
149
|
+
active = false,
|
|
150
|
+
children,
|
|
151
|
+
...rest
|
|
152
|
+
}) => {
|
|
153
|
+
const [rootClass, getChildClass] = getClassName({
|
|
154
|
+
className,
|
|
155
|
+
rootClass: "BHT__NavItem",
|
|
156
|
+
modifiers: { active },
|
|
157
|
+
styles: nav_item_module_default
|
|
158
|
+
});
|
|
159
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("a", { ...rest, className: rootClass, children: [
|
|
160
|
+
icon ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: getChildClass("icon"), children: icon }) : null,
|
|
161
|
+
children
|
|
162
|
+
] });
|
|
163
|
+
};
|
|
164
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
165
|
+
0 && (module.exports = {
|
|
166
|
+
NavItem
|
|
167
|
+
});
|
|
168
|
+
/*! Bundled license information:
|
|
169
|
+
|
|
170
|
+
classnames/index.js:
|
|
171
|
+
(*!
|
|
172
|
+
Copyright (c) 2018 Jed Watson.
|
|
173
|
+
Licensed under the MIT License (MIT), see
|
|
174
|
+
http://jedwatson.github.io/classnames
|
|
175
|
+
*)
|
|
176
|
+
*/
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/* esbuild-sass-plugin:css-chunknav-item.module.scss */
|
|
2
|
+
.BHT__NavItem {
|
|
3
|
+
position: relative;
|
|
4
|
+
isolation: isolate;
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
gap: var(--spacing-2, 0.5rem);
|
|
8
|
+
padding: var(--spacing-2, 0.5rem) var(--spacing-3, 0.75rem);
|
|
9
|
+
border-radius: var(--md-sys-shape-corner-full, 9999px);
|
|
10
|
+
color: var(--md-sys-color-on-surface-variant, var(--color-text-muted));
|
|
11
|
+
text-decoration: none;
|
|
12
|
+
font-family: var(--md-sys-typescale-label-large-font, var(--font-body));
|
|
13
|
+
font-size: var(--md-sys-typescale-label-large-size, 0.875rem);
|
|
14
|
+
font-weight: var(--md-sys-typescale-label-large-weight, 500);
|
|
15
|
+
line-height: var(--md-sys-typescale-label-large-line-height, 1.25rem);
|
|
16
|
+
letter-spacing: var(--md-sys-typescale-label-large-tracking, 0.0071em);
|
|
17
|
+
transition: background var(--md-sys-motion-duration-short-3, 150ms) var(--md-sys-motion-easing-standard, ease), color var(--md-sys-motion-duration-short-3, 150ms) var(--md-sys-motion-easing-standard, ease);
|
|
18
|
+
}
|
|
19
|
+
.BHT__NavItem__icon {
|
|
20
|
+
font-size: var(--md-sys-typescale-body-large-size, 1rem);
|
|
21
|
+
width: 1.125rem;
|
|
22
|
+
text-align: center;
|
|
23
|
+
flex-shrink: 0;
|
|
24
|
+
}
|
|
25
|
+
.BHT__NavItem::after {
|
|
26
|
+
content: "";
|
|
27
|
+
position: absolute;
|
|
28
|
+
inset: 0;
|
|
29
|
+
border-radius: inherit;
|
|
30
|
+
background: currentColor;
|
|
31
|
+
opacity: 0;
|
|
32
|
+
pointer-events: none;
|
|
33
|
+
transition: opacity var(--md-sys-motion-duration-short-2, 100ms) var(--md-sys-motion-easing-standard, ease);
|
|
34
|
+
}
|
|
35
|
+
.BHT__NavItem:hover::after {
|
|
36
|
+
opacity: var(--md-sys-state-hover-opacity, 0.08);
|
|
37
|
+
}
|
|
38
|
+
.BHT__NavItem:focus-visible::after {
|
|
39
|
+
opacity: var(--md-sys-state-focus-opacity, 0.1);
|
|
40
|
+
}
|
|
41
|
+
.BHT__NavItem:active::after {
|
|
42
|
+
opacity: var(--md-sys-state-pressed-opacity, 0.1);
|
|
43
|
+
}
|
|
44
|
+
.BHT__NavItem::before {
|
|
45
|
+
content: "";
|
|
46
|
+
position: absolute;
|
|
47
|
+
left: 0;
|
|
48
|
+
right: 0;
|
|
49
|
+
top: 50%;
|
|
50
|
+
translate: 0 -50%;
|
|
51
|
+
height: 100%;
|
|
52
|
+
min-height: 48px;
|
|
53
|
+
}
|
|
54
|
+
.BHT__NavItem:focus-visible {
|
|
55
|
+
outline: 3px solid var(--md-sys-color-secondary, var(--color-border-focus));
|
|
56
|
+
outline-offset: 2px;
|
|
57
|
+
}
|
|
58
|
+
.BHT__NavItem--active.BHT__NavItem {
|
|
59
|
+
background: var(--md-sys-color-secondary-container, var(--color-surface-light));
|
|
60
|
+
color: var(--md-sys-color-on-secondary-container, var(--color-on-surface));
|
|
61
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { AnchorHTMLAttributes, ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
interface NavItemProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
5
|
+
/** Additional class names to merge with the component root element */
|
|
6
|
+
className?: string;
|
|
7
|
+
/** Leading icon rendered before the content */
|
|
8
|
+
icon?: ReactNode;
|
|
9
|
+
/** Whether this item represents the current route */
|
|
10
|
+
active?: boolean;
|
|
11
|
+
/** Content to render inside the component */
|
|
12
|
+
children?: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Single navigation link with an optional leading icon and active state.
|
|
16
|
+
*/
|
|
17
|
+
declare const NavItem: ({ className, icon, active, children, ...rest }: NavItemProps) => react.JSX.Element;
|
|
18
|
+
|
|
19
|
+
export { NavItem, type NavItemProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// ../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js
|
|
28
|
+
var require_classnames = __commonJS({
|
|
29
|
+
"../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js"(exports, module) {
|
|
30
|
+
"use strict";
|
|
31
|
+
(function() {
|
|
32
|
+
"use strict";
|
|
33
|
+
var hasOwn = {}.hasOwnProperty;
|
|
34
|
+
function classNames() {
|
|
35
|
+
var classes = "";
|
|
36
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
37
|
+
var arg = arguments[i];
|
|
38
|
+
if (arg) {
|
|
39
|
+
classes = appendClass(classes, parseValue(arg));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return classes;
|
|
43
|
+
}
|
|
44
|
+
function parseValue(arg) {
|
|
45
|
+
if (typeof arg === "string" || typeof arg === "number") {
|
|
46
|
+
return arg;
|
|
47
|
+
}
|
|
48
|
+
if (typeof arg !== "object") {
|
|
49
|
+
return "";
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(arg)) {
|
|
52
|
+
return classNames.apply(null, arg);
|
|
53
|
+
}
|
|
54
|
+
if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
|
|
55
|
+
return arg.toString();
|
|
56
|
+
}
|
|
57
|
+
var classes = "";
|
|
58
|
+
for (var key in arg) {
|
|
59
|
+
if (hasOwn.call(arg, key) && arg[key]) {
|
|
60
|
+
classes = appendClass(classes, key);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return classes;
|
|
64
|
+
}
|
|
65
|
+
function appendClass(value, newClass) {
|
|
66
|
+
if (!newClass) {
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
if (value) {
|
|
70
|
+
return value + " " + newClass;
|
|
71
|
+
}
|
|
72
|
+
return value + newClass;
|
|
73
|
+
}
|
|
74
|
+
if (typeof module !== "undefined" && module.exports) {
|
|
75
|
+
classNames.default = classNames;
|
|
76
|
+
module.exports = classNames;
|
|
77
|
+
} else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
|
|
78
|
+
define("classnames", [], function() {
|
|
79
|
+
return classNames;
|
|
80
|
+
});
|
|
81
|
+
} else {
|
|
82
|
+
window.classNames = classNames;
|
|
83
|
+
}
|
|
84
|
+
})();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// ../../../../packages/registry/class-names/dist/index.js
|
|
89
|
+
var import_classnames = __toESM(require_classnames(), 1);
|
|
90
|
+
var getClassName = ({
|
|
91
|
+
className,
|
|
92
|
+
modifiers = {},
|
|
93
|
+
rootClass,
|
|
94
|
+
styles = {}
|
|
95
|
+
}) => {
|
|
96
|
+
function getModifiers() {
|
|
97
|
+
const updatedModifiers = {};
|
|
98
|
+
const modifierKeys = Object.keys(modifiers);
|
|
99
|
+
if (modifierKeys.length) {
|
|
100
|
+
modifierKeys.forEach((modKey) => {
|
|
101
|
+
const classKey = `${rootClass}--${modKey}`;
|
|
102
|
+
const newClassName = styles[classKey] || classKey;
|
|
103
|
+
updatedModifiers[newClassName] = modifiers[modKey] ?? false;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return updatedModifiers;
|
|
107
|
+
}
|
|
108
|
+
function getChildClass(childClassName) {
|
|
109
|
+
const classKey = `${rootClass}__${childClassName}`;
|
|
110
|
+
return styles[classKey] || classKey;
|
|
111
|
+
}
|
|
112
|
+
function getRootStyles() {
|
|
113
|
+
return (0, import_classnames.default)(
|
|
114
|
+
className,
|
|
115
|
+
{
|
|
116
|
+
...getModifiers()
|
|
117
|
+
},
|
|
118
|
+
styles[rootClass] || rootClass
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
return [getRootStyles(), getChildClass];
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// nav-item.module.scss
|
|
125
|
+
var nav_item_module_default = {
|
|
126
|
+
"BHT__NavItem": "BHT__NavItem",
|
|
127
|
+
"BHT__NavItem__icon": "BHT__NavItem__icon",
|
|
128
|
+
"BHT__NavItem--active": "BHT__NavItem--active"
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// nav-item.tsx
|
|
132
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
133
|
+
var NavItem = ({
|
|
134
|
+
className,
|
|
135
|
+
icon,
|
|
136
|
+
active = false,
|
|
137
|
+
children,
|
|
138
|
+
...rest
|
|
139
|
+
}) => {
|
|
140
|
+
const [rootClass, getChildClass] = getClassName({
|
|
141
|
+
className,
|
|
142
|
+
rootClass: "BHT__NavItem",
|
|
143
|
+
modifiers: { active },
|
|
144
|
+
styles: nav_item_module_default
|
|
145
|
+
});
|
|
146
|
+
return /* @__PURE__ */ jsxs("a", { ...rest, className: rootClass, children: [
|
|
147
|
+
icon ? /* @__PURE__ */ jsx("span", { className: getChildClass("icon"), children: icon }) : null,
|
|
148
|
+
children
|
|
149
|
+
] });
|
|
150
|
+
};
|
|
151
|
+
export {
|
|
152
|
+
NavItem
|
|
153
|
+
};
|
|
154
|
+
/*! Bundled license information:
|
|
155
|
+
|
|
156
|
+
classnames/index.js:
|
|
157
|
+
(*!
|
|
158
|
+
Copyright (c) 2018 Jed Watson.
|
|
159
|
+
Licensed under the MIT License (MIT), see
|
|
160
|
+
http://jedwatson.github.io/classnames
|
|
161
|
+
*)
|
|
162
|
+
*/
|
package/docs.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://github.com/behivetech/bht-component-registry/docs.schema.json",
|
|
3
|
+
"version": 2,
|
|
4
|
+
"generatedAt": "2026-10-23T16:58:01.789Z",
|
|
5
|
+
"docs": [
|
|
6
|
+
{
|
|
7
|
+
"displayName": "NavItem",
|
|
8
|
+
"description": "Single navigation link with an optional leading icon and active state.",
|
|
9
|
+
"extendsNative": true,
|
|
10
|
+
"props": [
|
|
11
|
+
{
|
|
12
|
+
"name": "active",
|
|
13
|
+
"type": "boolean",
|
|
14
|
+
"required": false,
|
|
15
|
+
"defaultValue": "false",
|
|
16
|
+
"description": "Whether this item represents the current route"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "children",
|
|
20
|
+
"type": "ReactNode",
|
|
21
|
+
"required": false,
|
|
22
|
+
"defaultValue": null,
|
|
23
|
+
"description": "Content to render inside the component"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "className",
|
|
27
|
+
"type": "string",
|
|
28
|
+
"required": false,
|
|
29
|
+
"defaultValue": null,
|
|
30
|
+
"description": "Additional class names to merge with the component root element"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"name": "icon",
|
|
34
|
+
"type": "ReactNode",
|
|
35
|
+
"required": false,
|
|
36
|
+
"defaultValue": null,
|
|
37
|
+
"description": "Leading icon rendered before the content"
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
"functions": []
|
|
43
|
+
}
|
package/index.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Material Design 3 navigation drawer destination.
|
|
2
|
+
//
|
|
3
|
+
// The active item carries the MD3 pill-shaped active indicator
|
|
4
|
+
// (`secondary-container`); inactive items sit directly on the drawer in
|
|
5
|
+
// `on-surface-variant`. Colors previously came from `--admin-sidebar-*`
|
|
6
|
+
// variables that only the CMS admin app defined, so the atom rendered
|
|
7
|
+
// unstyled anywhere else.
|
|
8
|
+
|
|
9
|
+
.BHT__NavItem {
|
|
10
|
+
// `isolation` keeps the state layer's stacking context local to the item.
|
|
11
|
+
position: relative;
|
|
12
|
+
isolation: isolate;
|
|
13
|
+
display: flex;
|
|
14
|
+
align-items: center;
|
|
15
|
+
gap: var(--spacing-2, 0.5rem);
|
|
16
|
+
padding: var(--spacing-2, 0.5rem) var(--spacing-3, 0.75rem);
|
|
17
|
+
border-radius: var(--md-sys-shape-corner-full, 9999px);
|
|
18
|
+
color: var(--md-sys-color-on-surface-variant, var(--color-text-muted));
|
|
19
|
+
text-decoration: none;
|
|
20
|
+
font-family: var(--md-sys-typescale-label-large-font, var(--font-body));
|
|
21
|
+
font-size: var(--md-sys-typescale-label-large-size, 0.875rem);
|
|
22
|
+
font-weight: var(--md-sys-typescale-label-large-weight, 500);
|
|
23
|
+
line-height: var(--md-sys-typescale-label-large-line-height, 1.25rem);
|
|
24
|
+
letter-spacing: var(--md-sys-typescale-label-large-tracking, 0.0071em);
|
|
25
|
+
transition:
|
|
26
|
+
background var(--md-sys-motion-duration-short-3, 150ms)
|
|
27
|
+
var(--md-sys-motion-easing-standard, ease),
|
|
28
|
+
color var(--md-sys-motion-duration-short-3, 150ms)
|
|
29
|
+
var(--md-sys-motion-easing-standard, ease);
|
|
30
|
+
|
|
31
|
+
&__icon {
|
|
32
|
+
font-size: var(--md-sys-typescale-body-large-size, 1rem);
|
|
33
|
+
width: 1.125rem;
|
|
34
|
+
text-align: center;
|
|
35
|
+
flex-shrink: 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// State layer: a veil of the content color, so hover follows the active
|
|
39
|
+
// indicator's `on-secondary-container` as well as the inactive text color.
|
|
40
|
+
&::after {
|
|
41
|
+
content: "";
|
|
42
|
+
position: absolute;
|
|
43
|
+
inset: 0;
|
|
44
|
+
border-radius: inherit;
|
|
45
|
+
background: currentColor;
|
|
46
|
+
opacity: 0;
|
|
47
|
+
pointer-events: none;
|
|
48
|
+
transition: opacity var(--md-sys-motion-duration-short-2, 100ms)
|
|
49
|
+
var(--md-sys-motion-easing-standard, ease);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
&:hover::after {
|
|
53
|
+
opacity: var(--md-sys-state-hover-opacity, 0.08);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
&:focus-visible::after {
|
|
57
|
+
opacity: var(--md-sys-state-focus-opacity, 0.1);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
&:active::after {
|
|
61
|
+
opacity: var(--md-sys-state-pressed-opacity, 0.1);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Touch target: the drawn item is 2.25rem tall, under the 48px floor. This
|
|
65
|
+
// extends the hit area without reflowing the drawer. px, not rem, because a
|
|
66
|
+
// target is sized to the finger, not the type.
|
|
67
|
+
&::before {
|
|
68
|
+
content: "";
|
|
69
|
+
position: absolute;
|
|
70
|
+
left: 0;
|
|
71
|
+
right: 0;
|
|
72
|
+
top: 50%;
|
|
73
|
+
translate: 0 -50%;
|
|
74
|
+
height: 100%;
|
|
75
|
+
min-height: 48px;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
&:focus-visible {
|
|
79
|
+
outline: 3px solid var(--md-sys-color-secondary, var(--color-border-focus));
|
|
80
|
+
outline-offset: 2px;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// This compound previously read `&.NavItem`, which the markup never
|
|
84
|
+
// carries, so the active state never rendered.
|
|
85
|
+
&--active {
|
|
86
|
+
&.BHT__NavItem {
|
|
87
|
+
background: var(
|
|
88
|
+
--md-sys-color-secondary-container,
|
|
89
|
+
var(--color-surface-light)
|
|
90
|
+
);
|
|
91
|
+
color: var(
|
|
92
|
+
--md-sys-color-on-secondary-container,
|
|
93
|
+
var(--color-on-surface)
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
package/nav-item.tsx
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type AnchorHTMLAttributes, type ReactNode } from "react";
|
|
2
|
+
import { getClassName } from "@bht-component-registry/class-names";
|
|
3
|
+
import styles from "./nav-item.module.scss";
|
|
4
|
+
|
|
5
|
+
export interface NavItemProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
6
|
+
/** Additional class names to merge with the component root element */
|
|
7
|
+
className?: string;
|
|
8
|
+
/** Leading icon rendered before the content */
|
|
9
|
+
icon?: ReactNode;
|
|
10
|
+
/** Whether this item represents the current route */
|
|
11
|
+
active?: boolean;
|
|
12
|
+
/** Content to render inside the component */
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Single navigation link with an optional leading icon and active state.
|
|
18
|
+
*/
|
|
19
|
+
export const NavItem = ({
|
|
20
|
+
className,
|
|
21
|
+
icon,
|
|
22
|
+
active = false,
|
|
23
|
+
children,
|
|
24
|
+
...rest
|
|
25
|
+
}: NavItemProps) => {
|
|
26
|
+
const [rootClass, getChildClass] = getClassName({
|
|
27
|
+
className,
|
|
28
|
+
rootClass: "BHT__NavItem",
|
|
29
|
+
modifiers: { active },
|
|
30
|
+
styles,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<a {...rest} className={rootClass}>
|
|
35
|
+
{icon ? <span className={getChildClass("icon")}>{icon}</span> : null}
|
|
36
|
+
{children}
|
|
37
|
+
</a>
|
|
38
|
+
);
|
|
39
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@behivetech/atoms.nav-item",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.4.3",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": false,
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
|
+
},
|
|
13
|
+
"./styles.css": "./dist/index.css"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"index.ts",
|
|
19
|
+
"nav-item.tsx",
|
|
20
|
+
"nav-item.module.scss",
|
|
21
|
+
"*.example.tsx",
|
|
22
|
+
"docs.json"
|
|
23
|
+
],
|
|
24
|
+
"registry": {
|
|
25
|
+
"status": "stable",
|
|
26
|
+
"tags": []
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"react": "^19.2.7",
|
|
30
|
+
"react-dom": "^19.2.7"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/react": "19.2.17",
|
|
34
|
+
"@types/react-dom": "19.2.3",
|
|
35
|
+
"eslint": "^9.39.5",
|
|
36
|
+
"tsup": "^8.5.1",
|
|
37
|
+
"typescript": "^6.0.3",
|
|
38
|
+
"vitest": "^4.1.10",
|
|
39
|
+
"@bht-component-registry/class-names": "0.0.6",
|
|
40
|
+
"@bht-component-registry/env": "0.1.0"
|
|
41
|
+
},
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "https://github.com/behivetech/bht-galaxy.git",
|
|
45
|
+
"directory": "registry/behivetech/atoms/nav-item"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"registry": "https://registry.npmjs.org",
|
|
49
|
+
"access": "public",
|
|
50
|
+
"provenance": true
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsup && bht-registry-docgen",
|
|
54
|
+
"dev": "tsup --watch",
|
|
55
|
+
"lint": "eslint . --max-warnings 0",
|
|
56
|
+
"check-types": "tsc --noEmit",
|
|
57
|
+
"test": "vitest run"
|
|
58
|
+
}
|
|
6
59
|
}
|