@behivetech/organisms.site-header 0.1.3 → 1.0.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.
- package/README.md +1 -1
- package/dist/index.cjs +25 -123
- package/dist/index.js +21 -139
- package/docs.json +57 -0
- package/package.json +16 -12
- package/site-header.tsx +53 -21
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
A site header with a brand slot, navigation links and optional actions; once the header itself is at least `64rem` wide the links sit inline, and narrower a menu button opens them in a right-hand Drawer.
|
|
4
4
|
|
|
5
|
-
Docs: https://
|
|
5
|
+
Docs: https://platform.behivetech.com/behivetech/organisms/site-header
|
|
6
6
|
|
|
7
7
|
## Usage
|
|
8
8
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
"use strict";
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
@@ -5,9 +6,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
8
|
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
9
|
var __export = (target, all) => {
|
|
12
10
|
for (var name in all)
|
|
13
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -30,67 +28,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
28
|
));
|
|
31
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
30
|
|
|
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
31
|
// index.ts
|
|
95
32
|
var index_exports = {};
|
|
96
33
|
__export(index_exports, {
|
|
@@ -100,48 +37,10 @@ module.exports = __toCommonJS(index_exports);
|
|
|
100
37
|
|
|
101
38
|
// site-header.tsx
|
|
102
39
|
var import_react = require("react");
|
|
103
|
-
|
|
104
|
-
// ../../../../packages/registry/class-names/dist/index.js
|
|
105
|
-
var import_classnames = __toESM(require_classnames(), 1);
|
|
106
|
-
var getClassName = ({
|
|
107
|
-
className,
|
|
108
|
-
modifiers = {},
|
|
109
|
-
rootClass,
|
|
110
|
-
styles = {}
|
|
111
|
-
}) => {
|
|
112
|
-
function getModifiers() {
|
|
113
|
-
const updatedModifiers = {};
|
|
114
|
-
const modifierKeys = Object.keys(modifiers);
|
|
115
|
-
if (modifierKeys.length) {
|
|
116
|
-
modifierKeys.forEach((modKey) => {
|
|
117
|
-
const classKey = `${rootClass}--${modKey}`;
|
|
118
|
-
const newClassName = styles[classKey] || classKey;
|
|
119
|
-
updatedModifiers[newClassName] = modifiers[modKey] ?? false;
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
return updatedModifiers;
|
|
123
|
-
}
|
|
124
|
-
function getChildClass(childClassName) {
|
|
125
|
-
const classKey = `${rootClass}__${childClassName}`;
|
|
126
|
-
return styles[classKey] || classKey;
|
|
127
|
-
}
|
|
128
|
-
function getRootStyles() {
|
|
129
|
-
return (0, import_classnames.default)(
|
|
130
|
-
className,
|
|
131
|
-
{
|
|
132
|
-
...getModifiers()
|
|
133
|
-
},
|
|
134
|
-
styles[rootClass] || rootClass
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
return [getRootStyles(), getChildClass];
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
// site-header.tsx
|
|
40
|
+
var import_get_class_name = require("@behivetech/get-class-name");
|
|
141
41
|
var import_atoms = require("@behivetech/atoms.button");
|
|
142
|
-
var
|
|
143
|
-
var
|
|
144
|
-
var import_atoms4 = require("@behivetech/atoms.nav-item");
|
|
42
|
+
var import_icons = require("@behivetech/icons.menu");
|
|
43
|
+
var import_atoms2 = require("@behivetech/atoms.nav-item");
|
|
145
44
|
|
|
146
45
|
// site-header.module.scss
|
|
147
46
|
var site_header_module_default = {
|
|
@@ -157,12 +56,19 @@ var site_header_module_default = {
|
|
|
157
56
|
|
|
158
57
|
// site-header.tsx
|
|
159
58
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
59
|
+
var loadDrawer = () => import("@behivetech/atoms.drawer").then((module2) => ({
|
|
60
|
+
default: module2.Drawer
|
|
61
|
+
}));
|
|
62
|
+
var Drawer = (0, import_react.lazy)(loadDrawer);
|
|
63
|
+
var prefetchDrawer = () => {
|
|
64
|
+
loadDrawer().catch(() => void 0);
|
|
65
|
+
};
|
|
160
66
|
var HeaderLinks = ({
|
|
161
67
|
links,
|
|
162
68
|
linkComponent: LinkComponent,
|
|
163
69
|
onNavigate
|
|
164
70
|
}) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: links.map(({ href, label, current }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
165
|
-
|
|
71
|
+
import_atoms2.NavItem,
|
|
166
72
|
{
|
|
167
73
|
asChild: true,
|
|
168
74
|
active: current,
|
|
@@ -177,8 +83,8 @@ var MenuDrawer = ({
|
|
|
177
83
|
menuLabel,
|
|
178
84
|
navClassName,
|
|
179
85
|
onClose
|
|
180
|
-
}) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
181
|
-
|
|
86
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
87
|
+
Drawer,
|
|
182
88
|
{
|
|
183
89
|
placement: "right",
|
|
184
90
|
title: menuLabel,
|
|
@@ -194,7 +100,7 @@ var MenuDrawer = ({
|
|
|
194
100
|
}
|
|
195
101
|
) })
|
|
196
102
|
}
|
|
197
|
-
);
|
|
103
|
+
) });
|
|
198
104
|
var useReturnFocus = (isOpen) => {
|
|
199
105
|
const menuButtonRef = (0, import_react.useRef)(null);
|
|
200
106
|
(0, import_react.useEffect)(() => {
|
|
@@ -206,7 +112,7 @@ var useReturnFocus = (isOpen) => {
|
|
|
206
112
|
};
|
|
207
113
|
var HeaderMenu = ({ links, linkComponent, menuLabel }) => {
|
|
208
114
|
const [isMenuOpen, setIsMenuOpen] = (0, import_react.useState)(false);
|
|
209
|
-
const [, getChildClass] = getClassName({
|
|
115
|
+
const [, getChildClass] = (0, import_get_class_name.getClassName)({
|
|
210
116
|
rootClass: "BHT__SiteHeader",
|
|
211
117
|
styles: site_header_module_default
|
|
212
118
|
});
|
|
@@ -222,11 +128,16 @@ var HeaderMenu = ({ links, linkComponent, menuLabel }) => {
|
|
|
222
128
|
"aria-label": menuLabel,
|
|
223
129
|
"aria-haspopup": "dialog",
|
|
224
130
|
"aria-expanded": isMenuOpen,
|
|
131
|
+
onPointerEnter: prefetchDrawer,
|
|
132
|
+
onFocus: prefetchDrawer,
|
|
225
133
|
onClick: (event) => {
|
|
226
|
-
|
|
227
|
-
|
|
134
|
+
const button = event.currentTarget;
|
|
135
|
+
loadDrawer().then(() => {
|
|
136
|
+
menuButtonRef.current = button;
|
|
137
|
+
setIsMenuOpen(true);
|
|
138
|
+
}).catch(() => void 0);
|
|
228
139
|
},
|
|
229
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
140
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.MenuIcon, {})
|
|
230
141
|
}
|
|
231
142
|
),
|
|
232
143
|
isMenuOpen ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
@@ -250,7 +161,7 @@ var SiteHeader = ({
|
|
|
250
161
|
menuLabel,
|
|
251
162
|
...rest
|
|
252
163
|
}) => {
|
|
253
|
-
const [rootClass, getChildClass] = getClassName({
|
|
164
|
+
const [rootClass, getChildClass] = (0, import_get_class_name.getClassName)({
|
|
254
165
|
className,
|
|
255
166
|
rootClass: "BHT__SiteHeader",
|
|
256
167
|
styles: site_header_module_default
|
|
@@ -275,12 +186,3 @@ var SiteHeader = ({
|
|
|
275
186
|
0 && (module.exports = {
|
|
276
187
|
SiteHeader
|
|
277
188
|
});
|
|
278
|
-
/*! Bundled license information:
|
|
279
|
-
|
|
280
|
-
classnames/index.js:
|
|
281
|
-
(*!
|
|
282
|
-
Copyright (c) 2018 Jed Watson.
|
|
283
|
-
Licensed under the MIT License (MIT), see
|
|
284
|
-
http://jedwatson.github.io/classnames
|
|
285
|
-
*)
|
|
286
|
-
*/
|
package/dist/index.js
CHANGED
|
@@ -1,137 +1,16 @@
|
|
|
1
|
-
|
|
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
|
-
});
|
|
1
|
+
"use client";
|
|
87
2
|
|
|
88
3
|
// site-header.tsx
|
|
89
4
|
import {
|
|
5
|
+
Suspense,
|
|
6
|
+
lazy,
|
|
90
7
|
useEffect,
|
|
91
8
|
useRef,
|
|
92
9
|
useState
|
|
93
10
|
} from "react";
|
|
94
|
-
|
|
95
|
-
// ../../../../packages/registry/class-names/dist/index.js
|
|
96
|
-
var import_classnames = __toESM(require_classnames(), 1);
|
|
97
|
-
var getClassName = ({
|
|
98
|
-
className,
|
|
99
|
-
modifiers = {},
|
|
100
|
-
rootClass,
|
|
101
|
-
styles = {}
|
|
102
|
-
}) => {
|
|
103
|
-
function getModifiers() {
|
|
104
|
-
const updatedModifiers = {};
|
|
105
|
-
const modifierKeys = Object.keys(modifiers);
|
|
106
|
-
if (modifierKeys.length) {
|
|
107
|
-
modifierKeys.forEach((modKey) => {
|
|
108
|
-
const classKey = `${rootClass}--${modKey}`;
|
|
109
|
-
const newClassName = styles[classKey] || classKey;
|
|
110
|
-
updatedModifiers[newClassName] = modifiers[modKey] ?? false;
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
return updatedModifiers;
|
|
114
|
-
}
|
|
115
|
-
function getChildClass(childClassName) {
|
|
116
|
-
const classKey = `${rootClass}__${childClassName}`;
|
|
117
|
-
return styles[classKey] || classKey;
|
|
118
|
-
}
|
|
119
|
-
function getRootStyles() {
|
|
120
|
-
return (0, import_classnames.default)(
|
|
121
|
-
className,
|
|
122
|
-
{
|
|
123
|
-
...getModifiers()
|
|
124
|
-
},
|
|
125
|
-
styles[rootClass] || rootClass
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
return [getRootStyles(), getChildClass];
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
// site-header.tsx
|
|
11
|
+
import { getClassName } from "@behivetech/get-class-name";
|
|
132
12
|
import { Button } from "@behivetech/atoms.button";
|
|
133
|
-
import {
|
|
134
|
-
import { MenuIcon } from "@behivetech/atoms.icon";
|
|
13
|
+
import { MenuIcon } from "@behivetech/icons.menu";
|
|
135
14
|
import { NavItem } from "@behivetech/atoms.nav-item";
|
|
136
15
|
|
|
137
16
|
// site-header.module.scss
|
|
@@ -148,6 +27,13 @@ var site_header_module_default = {
|
|
|
148
27
|
|
|
149
28
|
// site-header.tsx
|
|
150
29
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
30
|
+
var loadDrawer = () => import("@behivetech/atoms.drawer").then((module) => ({
|
|
31
|
+
default: module.Drawer
|
|
32
|
+
}));
|
|
33
|
+
var Drawer = lazy(loadDrawer);
|
|
34
|
+
var prefetchDrawer = () => {
|
|
35
|
+
loadDrawer().catch(() => void 0);
|
|
36
|
+
};
|
|
151
37
|
var HeaderLinks = ({
|
|
152
38
|
links,
|
|
153
39
|
linkComponent: LinkComponent,
|
|
@@ -168,7 +54,7 @@ var MenuDrawer = ({
|
|
|
168
54
|
menuLabel,
|
|
169
55
|
navClassName,
|
|
170
56
|
onClose
|
|
171
|
-
}) => /* @__PURE__ */ jsx(
|
|
57
|
+
}) => /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(
|
|
172
58
|
Drawer,
|
|
173
59
|
{
|
|
174
60
|
placement: "right",
|
|
@@ -185,7 +71,7 @@ var MenuDrawer = ({
|
|
|
185
71
|
}
|
|
186
72
|
) })
|
|
187
73
|
}
|
|
188
|
-
);
|
|
74
|
+
) });
|
|
189
75
|
var useReturnFocus = (isOpen) => {
|
|
190
76
|
const menuButtonRef = useRef(null);
|
|
191
77
|
useEffect(() => {
|
|
@@ -213,9 +99,14 @@ var HeaderMenu = ({ links, linkComponent, menuLabel }) => {
|
|
|
213
99
|
"aria-label": menuLabel,
|
|
214
100
|
"aria-haspopup": "dialog",
|
|
215
101
|
"aria-expanded": isMenuOpen,
|
|
102
|
+
onPointerEnter: prefetchDrawer,
|
|
103
|
+
onFocus: prefetchDrawer,
|
|
216
104
|
onClick: (event) => {
|
|
217
|
-
|
|
218
|
-
|
|
105
|
+
const button = event.currentTarget;
|
|
106
|
+
loadDrawer().then(() => {
|
|
107
|
+
menuButtonRef.current = button;
|
|
108
|
+
setIsMenuOpen(true);
|
|
109
|
+
}).catch(() => void 0);
|
|
219
110
|
},
|
|
220
111
|
children: /* @__PURE__ */ jsx(MenuIcon, {})
|
|
221
112
|
}
|
|
@@ -265,12 +156,3 @@ var SiteHeader = ({
|
|
|
265
156
|
export {
|
|
266
157
|
SiteHeader
|
|
267
158
|
};
|
|
268
|
-
/*! Bundled license information:
|
|
269
|
-
|
|
270
|
-
classnames/index.js:
|
|
271
|
-
(*!
|
|
272
|
-
Copyright (c) 2018 Jed Watson.
|
|
273
|
-
Licensed under the MIT License (MIT), see
|
|
274
|
-
http://jedwatson.github.io/classnames
|
|
275
|
-
*)
|
|
276
|
-
*/
|
package/docs.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://github.com/behivetech/bht-component-registry/docs.schema.json",
|
|
3
|
+
"version": 2,
|
|
4
|
+
"generatedAt": "2026-11-17T07:20:13.899Z",
|
|
5
|
+
"docs": [
|
|
6
|
+
{
|
|
7
|
+
"displayName": "SiteHeader",
|
|
8
|
+
"description": "Site header with a brand slot, navigation links and optional actions. While\nthe header is at least `64rem` wide the links sit inline; narrower, a menu\nbutton opens them in a right-hand `Drawer`, which keeps the links in reach of\none thumb on a phone. The switch follows the header's own width (a container\nquery), not the viewport.",
|
|
9
|
+
"extendsNative": true,
|
|
10
|
+
"props": [
|
|
11
|
+
{
|
|
12
|
+
"name": "brand",
|
|
13
|
+
"type": "ReactNode",
|
|
14
|
+
"required": true,
|
|
15
|
+
"defaultValue": null,
|
|
16
|
+
"description": "Brand slot at the start of the bar; rendered as given, so pass your own home link"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "links",
|
|
20
|
+
"type": "SiteHeaderLink[]",
|
|
21
|
+
"required": true,
|
|
22
|
+
"defaultValue": null,
|
|
23
|
+
"description": "Navigation links: inline once the header itself is at least `64rem` wide (a container query), in a Drawer when narrower"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "menuLabel",
|
|
27
|
+
"type": "string",
|
|
28
|
+
"required": true,
|
|
29
|
+
"defaultValue": null,
|
|
30
|
+
"description": "Accessible name of the menu button, the navigation landmarks and the Drawer title, already translated"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"name": "actions",
|
|
34
|
+
"type": "ReactNode",
|
|
35
|
+
"required": false,
|
|
36
|
+
"defaultValue": null,
|
|
37
|
+
"description": "Optional actions that stay in the bar at every breakpoint, e.g. a booking button"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"name": "className",
|
|
41
|
+
"type": "string",
|
|
42
|
+
"required": false,
|
|
43
|
+
"defaultValue": null,
|
|
44
|
+
"description": "Additional class names to merge with the component root element"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"name": "linkComponent",
|
|
48
|
+
"type": "ElementType<SiteHeaderLinkProps>",
|
|
49
|
+
"required": false,
|
|
50
|
+
"defaultValue": "a",
|
|
51
|
+
"description": "Component that renders each link, so a router link such as Next's `Link`\ncan be injected. Receives `href`, `children` and the item's props. Defaults to `a`."
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
"functions": []
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@behivetech/organisms.site-header",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "A site header with a brand slot, navigation links and optional actions; once the header itself is at least `64rem` wide the links sit inline, and narrower a menu button opens them in a right-hand Drawer.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"private": false,
|
|
8
|
+
"sideEffects": [
|
|
9
|
+
"**/*.css"
|
|
10
|
+
],
|
|
8
11
|
"exports": {
|
|
9
12
|
".": {
|
|
10
13
|
"types": "./dist/index.d.ts",
|
|
@@ -32,37 +35,38 @@
|
|
|
32
35
|
}
|
|
33
36
|
]
|
|
34
37
|
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@behivetech/atoms.button": "1.0.0",
|
|
40
|
+
"@behivetech/atoms.drawer": "1.0.0",
|
|
41
|
+
"@behivetech/icons.base": "1.0.0",
|
|
42
|
+
"@behivetech/atoms.nav-item": "1.0.0",
|
|
43
|
+
"@behivetech/cms.base-styles": "1.0.0",
|
|
44
|
+
"@behivetech/get-class-name": "1.0.0",
|
|
45
|
+
"@behivetech/icons.menu": "1.0.0"
|
|
46
|
+
},
|
|
35
47
|
"peerDependencies": {
|
|
36
48
|
"react": "^19.2.7",
|
|
37
49
|
"react-dom": "^19.2.7"
|
|
38
50
|
},
|
|
39
51
|
"devDependencies": {
|
|
52
|
+
"@bht-component-registry/env": "0.2.0",
|
|
40
53
|
"@types/react": "19.2.17",
|
|
41
54
|
"@types/react-dom": "19.2.3",
|
|
42
55
|
"eslint": "^9.39.5",
|
|
43
56
|
"tsup": "^8.5.1",
|
|
44
57
|
"typescript": "^6.0.3",
|
|
45
|
-
"vitest": "^4.1.10"
|
|
46
|
-
"@behivetech/cms.base-styles": "0.5.0",
|
|
47
|
-
"@bht-component-registry/class-names": "0.0.6",
|
|
48
|
-
"@bht-component-registry/env": "0.1.0"
|
|
58
|
+
"vitest": "^4.1.10"
|
|
49
59
|
},
|
|
50
60
|
"repository": {
|
|
51
61
|
"type": "git",
|
|
52
62
|
"url": "https://github.com/behivetech/bht-galaxy.git",
|
|
53
63
|
"directory": "registry/behivetech/organisms/site-header"
|
|
54
64
|
},
|
|
55
|
-
"homepage": "https://
|
|
65
|
+
"homepage": "https://platform.behivetech.com/behivetech/organisms/site-header",
|
|
56
66
|
"publishConfig": {
|
|
57
67
|
"registry": "https://registry.npmjs.org",
|
|
58
68
|
"access": "public"
|
|
59
69
|
},
|
|
60
|
-
"dependencies": {
|
|
61
|
-
"@behivetech/atoms.button": "0.5.0",
|
|
62
|
-
"@behivetech/atoms.drawer": "0.4.7",
|
|
63
|
-
"@behivetech/atoms.icon": "0.3.7",
|
|
64
|
-
"@behivetech/atoms.nav-item": "0.5.0"
|
|
65
|
-
},
|
|
66
70
|
"scripts": {
|
|
67
71
|
"build": "tsup && bht-registry-docgen",
|
|
68
72
|
"dev": "tsup --watch",
|
package/site-header.tsx
CHANGED
|
@@ -3,17 +3,35 @@ import {
|
|
|
3
3
|
type ElementType,
|
|
4
4
|
type HTMLAttributes,
|
|
5
5
|
type ReactNode,
|
|
6
|
+
Suspense,
|
|
7
|
+
lazy,
|
|
6
8
|
useEffect,
|
|
7
9
|
useRef,
|
|
8
10
|
useState,
|
|
9
11
|
} from "react";
|
|
10
|
-
import { getClassName } from "@
|
|
12
|
+
import { getClassName } from "@behivetech/get-class-name";
|
|
11
13
|
import { Button } from "@behivetech/atoms.button";
|
|
12
|
-
import {
|
|
13
|
-
import { MenuIcon } from "@behivetech/atoms.icon";
|
|
14
|
+
import { MenuIcon } from "@behivetech/icons.menu";
|
|
14
15
|
import { NavItem } from "@behivetech/atoms.nav-item";
|
|
15
16
|
import styles from "./site-header.module.scss";
|
|
16
17
|
|
|
18
|
+
/** Loads the Drawer module; repeat calls share the one request. */
|
|
19
|
+
const loadDrawer = () =>
|
|
20
|
+
import("@behivetech/atoms.drawer").then((module) => ({
|
|
21
|
+
default: module.Drawer,
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
// The Drawer (Radix Dialog and its focus handling) is about 10 KB gzipped and
|
|
25
|
+
// opens only after a tap at phone width, so it is fetched on demand: ahead of
|
|
26
|
+
// the tap when the reader's pointer or focus reaches the menu button, and at
|
|
27
|
+
// the latest when the button is pressed.
|
|
28
|
+
const Drawer = lazy(loadDrawer);
|
|
29
|
+
|
|
30
|
+
/** Starts the request ahead of the tap; a failure here is retried by the tap itself. */
|
|
31
|
+
const prefetchDrawer = () => {
|
|
32
|
+
loadDrawer().catch(() => undefined);
|
|
33
|
+
};
|
|
34
|
+
|
|
17
35
|
/** One navigation link of the header. */
|
|
18
36
|
export interface SiteHeaderLink {
|
|
19
37
|
/** Destination of the link */
|
|
@@ -84,7 +102,7 @@ interface MenuDrawerProps {
|
|
|
84
102
|
onClose: () => void;
|
|
85
103
|
}
|
|
86
104
|
|
|
87
|
-
/** The Drawer that holds the links while the header is narrow. */
|
|
105
|
+
/** The Drawer that holds the links while the header is narrow; nothing shows while its code loads. */
|
|
88
106
|
const MenuDrawer = ({
|
|
89
107
|
links,
|
|
90
108
|
linkComponent,
|
|
@@ -92,21 +110,23 @@ const MenuDrawer = ({
|
|
|
92
110
|
navClassName,
|
|
93
111
|
onClose,
|
|
94
112
|
}: MenuDrawerProps) => (
|
|
95
|
-
<
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
<
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
113
|
+
<Suspense fallback={null}>
|
|
114
|
+
<Drawer
|
|
115
|
+
placement="right"
|
|
116
|
+
title={menuLabel}
|
|
117
|
+
headingLevel={2}
|
|
118
|
+
padding="sm"
|
|
119
|
+
onClose={onClose}
|
|
120
|
+
>
|
|
121
|
+
<nav aria-label={menuLabel} className={navClassName}>
|
|
122
|
+
<HeaderLinks
|
|
123
|
+
links={links}
|
|
124
|
+
linkComponent={linkComponent}
|
|
125
|
+
onNavigate={onClose}
|
|
126
|
+
/>
|
|
127
|
+
</nav>
|
|
128
|
+
</Drawer>
|
|
129
|
+
</Suspense>
|
|
110
130
|
);
|
|
111
131
|
|
|
112
132
|
interface HeaderMenuProps {
|
|
@@ -152,9 +172,21 @@ const HeaderMenu = ({ links, linkComponent, menuLabel }: HeaderMenuProps) => {
|
|
|
152
172
|
aria-label={menuLabel}
|
|
153
173
|
aria-haspopup="dialog"
|
|
154
174
|
aria-expanded={isMenuOpen}
|
|
175
|
+
onPointerEnter={prefetchDrawer}
|
|
176
|
+
onFocus={prefetchDrawer}
|
|
155
177
|
onClick={(event) => {
|
|
156
|
-
|
|
157
|
-
|
|
178
|
+
const button = event.currentTarget;
|
|
179
|
+
|
|
180
|
+
// The menu counts as open (and `aria-expanded` turns true) only once
|
|
181
|
+
// the Drawer's code is here, so assistive technology is never told
|
|
182
|
+
// about a dialog that is not there yet. A failed request leaves the
|
|
183
|
+
// menu closed, and the next tap asks again.
|
|
184
|
+
loadDrawer()
|
|
185
|
+
.then(() => {
|
|
186
|
+
menuButtonRef.current = button;
|
|
187
|
+
setIsMenuOpen(true);
|
|
188
|
+
})
|
|
189
|
+
.catch(() => undefined);
|
|
158
190
|
}}
|
|
159
191
|
>
|
|
160
192
|
<MenuIcon />
|