@behivetech/organisms.site-header 0.0.0-stage → 0.1.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 CHANGED
@@ -1,3 +1,24 @@
1
- # Temporary Holding Version
1
+ # Site Header
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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
+
5
+ Docs: https://bht-galaxy.vercel.app/behivetech/organisms/site-header
6
+
7
+ ## Usage
8
+
9
+ ```jsx
10
+ <SiteHeader
11
+ brand={<a href="/">The BEhive</a>}
12
+ links={[
13
+ { href: "/guide", label: "Guide", current: true },
14
+ { href: "/gallery", label: "Gallery" },
15
+ ]}
16
+ menuLabel="Menu"
17
+ />
18
+ ```
19
+
20
+ Pass `linkComponent` (for example Next's `Link`) to render the links through your router. The package ships no `"use client"`: it keeps the menu open state, so re-export it from your app's client boundary file.
21
+
22
+ The Drawer's Close button keeps its fixed English "Close" label.
23
+
24
+ The root is an inline-size container, so it needs a definite width: as a flex item without a width, or under `align-items: center`, give it `width: 100%` or it collapses.
package/dist/index.cjs ADDED
@@ -0,0 +1,286 @@
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
+ SiteHeader: () => SiteHeader
98
+ });
99
+ module.exports = __toCommonJS(index_exports);
100
+
101
+ // site-header.tsx
102
+ 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
141
+ var import_atoms = require("@behivetech/atoms.button");
142
+ var import_atoms2 = require("@behivetech/atoms.drawer");
143
+ var import_atoms3 = require("@behivetech/atoms.icon");
144
+ var import_atoms4 = require("@behivetech/atoms.nav-item");
145
+
146
+ // site-header.module.scss
147
+ var site_header_module_default = {
148
+ "BHT__SiteHeader": "BHT__SiteHeader",
149
+ "BHT__SiteHeader__bar": "BHT__SiteHeader__bar",
150
+ "BHT__SiteHeader__brand": "BHT__SiteHeader__brand",
151
+ "BHT__SiteHeader__end": "BHT__SiteHeader__end",
152
+ "BHT__SiteHeader__nav": "BHT__SiteHeader__nav",
153
+ "BHT__SiteHeader__actions": "BHT__SiteHeader__actions",
154
+ "BHT__SiteHeader__menu": "BHT__SiteHeader__menu",
155
+ "BHT__SiteHeader__drawer-nav": "BHT__SiteHeader__drawer-nav"
156
+ };
157
+
158
+ // site-header.tsx
159
+ var import_jsx_runtime = require("react/jsx-runtime");
160
+ var HeaderLinks = ({
161
+ links,
162
+ linkComponent: LinkComponent,
163
+ onNavigate
164
+ }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: links.map(({ href, label, current }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
165
+ import_atoms4.NavItem,
166
+ {
167
+ asChild: true,
168
+ active: current,
169
+ onClick: onNavigate,
170
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LinkComponent, { href, children: label })
171
+ },
172
+ `${href}:${label}`
173
+ )) });
174
+ var MenuDrawer = ({
175
+ links,
176
+ linkComponent,
177
+ menuLabel,
178
+ navClassName,
179
+ onClose
180
+ }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
181
+ import_atoms2.Drawer,
182
+ {
183
+ placement: "right",
184
+ title: menuLabel,
185
+ headingLevel: 2,
186
+ padding: "sm",
187
+ onClose,
188
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("nav", { "aria-label": menuLabel, className: navClassName, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
189
+ HeaderLinks,
190
+ {
191
+ links,
192
+ linkComponent,
193
+ onNavigate: onClose
194
+ }
195
+ ) })
196
+ }
197
+ );
198
+ var useReturnFocus = (isOpen) => {
199
+ const menuButtonRef = (0, import_react.useRef)(null);
200
+ (0, import_react.useEffect)(() => {
201
+ if (!isOpen) {
202
+ menuButtonRef.current?.focus();
203
+ }
204
+ }, [isOpen]);
205
+ return menuButtonRef;
206
+ };
207
+ var HeaderMenu = ({ links, linkComponent, menuLabel }) => {
208
+ const [isMenuOpen, setIsMenuOpen] = (0, import_react.useState)(false);
209
+ const [, getChildClass] = getClassName({
210
+ rootClass: "BHT__SiteHeader",
211
+ styles: site_header_module_default
212
+ });
213
+ const menuButtonRef = useReturnFocus(isMenuOpen);
214
+ const closeMenu = () => setIsMenuOpen(false);
215
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: getChildClass("menu"), children: [
216
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
217
+ import_atoms.Button,
218
+ {
219
+ variant: "ghost",
220
+ size: "lg",
221
+ iconOnly: true,
222
+ "aria-label": menuLabel,
223
+ "aria-haspopup": "dialog",
224
+ "aria-expanded": isMenuOpen,
225
+ onClick: (event) => {
226
+ menuButtonRef.current = event.currentTarget;
227
+ setIsMenuOpen(true);
228
+ },
229
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_atoms3.MenuIcon, {})
230
+ }
231
+ ),
232
+ isMenuOpen ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
233
+ MenuDrawer,
234
+ {
235
+ links,
236
+ linkComponent,
237
+ menuLabel,
238
+ navClassName: getChildClass("drawer-nav"),
239
+ onClose: closeMenu
240
+ }
241
+ ) : null
242
+ ] });
243
+ };
244
+ var SiteHeader = ({
245
+ className,
246
+ brand,
247
+ links,
248
+ actions,
249
+ linkComponent = "a",
250
+ menuLabel,
251
+ ...rest
252
+ }) => {
253
+ const [rootClass, getChildClass] = getClassName({
254
+ className,
255
+ rootClass: "BHT__SiteHeader",
256
+ styles: site_header_module_default
257
+ });
258
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("header", { ...rest, className: rootClass, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: getChildClass("bar"), children: [
259
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: getChildClass("brand"), children: brand }),
260
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: getChildClass("end"), children: [
261
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("nav", { "aria-label": menuLabel, className: getChildClass("nav"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(HeaderLinks, { links, linkComponent }) }),
262
+ actions ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: getChildClass("actions"), children: actions }) : null,
263
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
264
+ HeaderMenu,
265
+ {
266
+ links,
267
+ linkComponent,
268
+ menuLabel
269
+ }
270
+ )
271
+ ] })
272
+ ] }) });
273
+ };
274
+ // Annotate the CommonJS export names for ESM import in node:
275
+ 0 && (module.exports = {
276
+ SiteHeader
277
+ });
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.css ADDED
@@ -0,0 +1,56 @@
1
+ /* esbuild-sass-plugin:css-chunksite-header.module.scss */
2
+ .BHT__SiteHeader {
3
+ container: site-header/inline-size;
4
+ background: var(--md-sys-color-surface);
5
+ color: var(--md-sys-color-on-surface);
6
+ border-bottom: 1px solid var(--md-sys-color-outline-variant);
7
+ }
8
+ .BHT__SiteHeader__bar {
9
+ display: flex;
10
+ align-items: center;
11
+ justify-content: space-between;
12
+ gap: var(--spacing-4, 1rem);
13
+ min-height: 4rem;
14
+ padding: var(--spacing-2, 0.5rem) var(--spacing-4, 1rem);
15
+ }
16
+ .BHT__SiteHeader__brand {
17
+ display: flex;
18
+ align-items: center;
19
+ min-width: 0;
20
+ }
21
+ .BHT__SiteHeader__end {
22
+ display: flex;
23
+ align-items: center;
24
+ gap: var(--spacing-2, 0.5rem);
25
+ }
26
+ .BHT__SiteHeader__nav {
27
+ display: none;
28
+ }
29
+ .BHT__SiteHeader__actions {
30
+ display: flex;
31
+ align-items: center;
32
+ }
33
+ .BHT__SiteHeader__menu {
34
+ display: flex;
35
+ }
36
+ .BHT__SiteHeader__drawer-nav {
37
+ display: flex;
38
+ flex-direction: column;
39
+ gap: var(--spacing-2, 0.5rem);
40
+ }
41
+ @container site-header (min-width: 64rem) {
42
+ .BHT__SiteHeader__bar {
43
+ padding-inline: var(--spacing-8, 2rem);
44
+ }
45
+ .BHT__SiteHeader__end {
46
+ gap: var(--spacing-6, 1.5rem);
47
+ }
48
+ .BHT__SiteHeader__nav {
49
+ display: flex;
50
+ align-items: center;
51
+ gap: var(--spacing-1, 0.25rem);
52
+ }
53
+ .BHT__SiteHeader__menu {
54
+ display: none;
55
+ }
56
+ }
@@ -0,0 +1,44 @@
1
+ import * as react from 'react';
2
+ import { HTMLAttributes, ReactNode, ElementType, AnchorHTMLAttributes } from 'react';
3
+
4
+ /** One navigation link of the header. */
5
+ interface SiteHeaderLink {
6
+ /** Destination of the link */
7
+ href: string;
8
+ /** Visible text of the link, already translated */
9
+ label: string;
10
+ /** Marks the link for the current page: renders `aria-current="page"` */
11
+ current?: boolean;
12
+ }
13
+ /** Props the header passes to `linkComponent` for every link. */
14
+ type SiteHeaderLinkProps = AnchorHTMLAttributes<HTMLAnchorElement> & {
15
+ href: string;
16
+ };
17
+ /** Props of the `SiteHeader` component. */
18
+ interface SiteHeaderProps extends Omit<HTMLAttributes<HTMLElement>, "children"> {
19
+ /** Additional class names to merge with the component root element */
20
+ className?: string;
21
+ /** Brand slot at the start of the bar; rendered as given, so pass your own home link */
22
+ brand: ReactNode;
23
+ /** Navigation links: inline once the header itself is at least `64rem` wide (a container query), in a Drawer when narrower */
24
+ links: SiteHeaderLink[];
25
+ /** Optional actions that stay in the bar at every breakpoint, e.g. a booking button */
26
+ actions?: ReactNode;
27
+ /**
28
+ * Component that renders each link, so a router link such as Next's `Link`
29
+ * can be injected. Receives `href`, `children` and the item's props. Defaults to `a`.
30
+ */
31
+ linkComponent?: ElementType<SiteHeaderLinkProps>;
32
+ /** Accessible name of the menu button, the navigation landmarks and the Drawer title, already translated */
33
+ menuLabel: string;
34
+ }
35
+ /**
36
+ * Site header with a brand slot, navigation links and optional actions. While
37
+ * the header is at least `64rem` wide the links sit inline; narrower, a menu
38
+ * button opens them in a right-hand `Drawer`, which keeps the links in reach of
39
+ * one thumb on a phone. The switch follows the header's own width (a container
40
+ * query), not the viewport.
41
+ */
42
+ declare const SiteHeader: ({ className, brand, links, actions, linkComponent, menuLabel, ...rest }: SiteHeaderProps) => react.JSX.Element;
43
+
44
+ export { SiteHeader, type SiteHeaderLink, type SiteHeaderLinkProps, type SiteHeaderProps };
package/dist/index.js ADDED
@@ -0,0 +1,276 @@
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
+ // site-header.tsx
89
+ import {
90
+ useEffect,
91
+ useRef,
92
+ useState
93
+ } 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
132
+ import { Button } from "@behivetech/atoms.button";
133
+ import { Drawer } from "@behivetech/atoms.drawer";
134
+ import { MenuIcon } from "@behivetech/atoms.icon";
135
+ import { NavItem } from "@behivetech/atoms.nav-item";
136
+
137
+ // site-header.module.scss
138
+ var site_header_module_default = {
139
+ "BHT__SiteHeader": "BHT__SiteHeader",
140
+ "BHT__SiteHeader__bar": "BHT__SiteHeader__bar",
141
+ "BHT__SiteHeader__brand": "BHT__SiteHeader__brand",
142
+ "BHT__SiteHeader__end": "BHT__SiteHeader__end",
143
+ "BHT__SiteHeader__nav": "BHT__SiteHeader__nav",
144
+ "BHT__SiteHeader__actions": "BHT__SiteHeader__actions",
145
+ "BHT__SiteHeader__menu": "BHT__SiteHeader__menu",
146
+ "BHT__SiteHeader__drawer-nav": "BHT__SiteHeader__drawer-nav"
147
+ };
148
+
149
+ // site-header.tsx
150
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
151
+ var HeaderLinks = ({
152
+ links,
153
+ linkComponent: LinkComponent,
154
+ onNavigate
155
+ }) => /* @__PURE__ */ jsx(Fragment, { children: links.map(({ href, label, current }) => /* @__PURE__ */ jsx(
156
+ NavItem,
157
+ {
158
+ asChild: true,
159
+ active: current,
160
+ onClick: onNavigate,
161
+ children: /* @__PURE__ */ jsx(LinkComponent, { href, children: label })
162
+ },
163
+ `${href}:${label}`
164
+ )) });
165
+ var MenuDrawer = ({
166
+ links,
167
+ linkComponent,
168
+ menuLabel,
169
+ navClassName,
170
+ onClose
171
+ }) => /* @__PURE__ */ jsx(
172
+ Drawer,
173
+ {
174
+ placement: "right",
175
+ title: menuLabel,
176
+ headingLevel: 2,
177
+ padding: "sm",
178
+ onClose,
179
+ children: /* @__PURE__ */ jsx("nav", { "aria-label": menuLabel, className: navClassName, children: /* @__PURE__ */ jsx(
180
+ HeaderLinks,
181
+ {
182
+ links,
183
+ linkComponent,
184
+ onNavigate: onClose
185
+ }
186
+ ) })
187
+ }
188
+ );
189
+ var useReturnFocus = (isOpen) => {
190
+ const menuButtonRef = useRef(null);
191
+ useEffect(() => {
192
+ if (!isOpen) {
193
+ menuButtonRef.current?.focus();
194
+ }
195
+ }, [isOpen]);
196
+ return menuButtonRef;
197
+ };
198
+ var HeaderMenu = ({ links, linkComponent, menuLabel }) => {
199
+ const [isMenuOpen, setIsMenuOpen] = useState(false);
200
+ const [, getChildClass] = getClassName({
201
+ rootClass: "BHT__SiteHeader",
202
+ styles: site_header_module_default
203
+ });
204
+ const menuButtonRef = useReturnFocus(isMenuOpen);
205
+ const closeMenu = () => setIsMenuOpen(false);
206
+ return /* @__PURE__ */ jsxs("div", { className: getChildClass("menu"), children: [
207
+ /* @__PURE__ */ jsx(
208
+ Button,
209
+ {
210
+ variant: "ghost",
211
+ size: "lg",
212
+ iconOnly: true,
213
+ "aria-label": menuLabel,
214
+ "aria-haspopup": "dialog",
215
+ "aria-expanded": isMenuOpen,
216
+ onClick: (event) => {
217
+ menuButtonRef.current = event.currentTarget;
218
+ setIsMenuOpen(true);
219
+ },
220
+ children: /* @__PURE__ */ jsx(MenuIcon, {})
221
+ }
222
+ ),
223
+ isMenuOpen ? /* @__PURE__ */ jsx(
224
+ MenuDrawer,
225
+ {
226
+ links,
227
+ linkComponent,
228
+ menuLabel,
229
+ navClassName: getChildClass("drawer-nav"),
230
+ onClose: closeMenu
231
+ }
232
+ ) : null
233
+ ] });
234
+ };
235
+ var SiteHeader = ({
236
+ className,
237
+ brand,
238
+ links,
239
+ actions,
240
+ linkComponent = "a",
241
+ menuLabel,
242
+ ...rest
243
+ }) => {
244
+ const [rootClass, getChildClass] = getClassName({
245
+ className,
246
+ rootClass: "BHT__SiteHeader",
247
+ styles: site_header_module_default
248
+ });
249
+ return /* @__PURE__ */ jsx("header", { ...rest, className: rootClass, children: /* @__PURE__ */ jsxs("div", { className: getChildClass("bar"), children: [
250
+ /* @__PURE__ */ jsx("div", { className: getChildClass("brand"), children: brand }),
251
+ /* @__PURE__ */ jsxs("div", { className: getChildClass("end"), children: [
252
+ /* @__PURE__ */ jsx("nav", { "aria-label": menuLabel, className: getChildClass("nav"), children: /* @__PURE__ */ jsx(HeaderLinks, { links, linkComponent }) }),
253
+ actions ? /* @__PURE__ */ jsx("div", { className: getChildClass("actions"), children: actions }) : null,
254
+ /* @__PURE__ */ jsx(
255
+ HeaderMenu,
256
+ {
257
+ links,
258
+ linkComponent,
259
+ menuLabel
260
+ }
261
+ )
262
+ ] })
263
+ ] }) });
264
+ };
265
+ export {
266
+ SiteHeader
267
+ };
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-10-30T00:03:43.457Z",
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/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ export { SiteHeader } from "./site-header.js";
2
+ export type {
3
+ SiteHeaderLink,
4
+ SiteHeaderLinkProps,
5
+ SiteHeaderProps,
6
+ } from "./site-header.js";
package/package.json CHANGED
@@ -1,6 +1,73 @@
1
1
  {
2
2
  "name": "@behivetech/organisms.site-header",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "license": "MIT",
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
+ "type": "module",
7
+ "private": false,
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ },
14
+ "./styles.css": "./dist/index.css"
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md",
19
+ "index.ts",
20
+ "site-header.tsx",
21
+ "site-header.module.scss",
22
+ "*.example.tsx",
23
+ "docs.json"
24
+ ],
25
+ "registry": {
26
+ "status": "draft",
27
+ "tags": [],
28
+ "design": [
29
+ {
30
+ "label": "Figma",
31
+ "url": "https://www.figma.com/design/thpMGdZrgnoJtKUlGvkt51/the-behive.com?node-id=2046-90"
32
+ }
33
+ ]
34
+ },
35
+ "peerDependencies": {
36
+ "react": "^19.2.7",
37
+ "react-dom": "^19.2.7"
38
+ },
39
+ "devDependencies": {
40
+ "@types/react": "19.2.17",
41
+ "@types/react-dom": "19.2.3",
42
+ "eslint": "^9.39.5",
43
+ "tsup": "^8.5.1",
44
+ "typescript": "^6.0.3",
45
+ "vitest": "^4.1.10",
46
+ "@behivetech/cms.base-styles": "0.3.3",
47
+ "@bht-component-registry/env": "0.1.0",
48
+ "@bht-component-registry/class-names": "0.0.6"
49
+ },
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "https://github.com/behivetech/bht-galaxy.git",
53
+ "directory": "registry/behivetech/organisms/site-header"
54
+ },
55
+ "homepage": "https://bht-galaxy.vercel.app/behivetech/organisms/site-header",
56
+ "publishConfig": {
57
+ "registry": "https://registry.npmjs.org",
58
+ "access": "public"
59
+ },
60
+ "dependencies": {
61
+ "@behivetech/atoms.button": "0.4.4",
62
+ "@behivetech/atoms.icon": "0.3.5",
63
+ "@behivetech/atoms.nav-item": "0.5.0",
64
+ "@behivetech/atoms.drawer": "0.4.5"
65
+ },
66
+ "scripts": {
67
+ "build": "tsup && bht-registry-docgen",
68
+ "dev": "tsup --watch",
69
+ "lint": "eslint . --max-warnings 0",
70
+ "check-types": "tsc --noEmit",
71
+ "test": "vitest run"
72
+ }
6
73
  }
@@ -0,0 +1,28 @@
1
+ import { Button } from "@behivetech/atoms.button";
2
+ import { SiteHeader } from "./site-header.js";
3
+
4
+ const LINKS = [
5
+ { href: "/guide", label: "Guide", current: true },
6
+ { href: "/gallery", label: "Gallery" },
7
+ { href: "/art", label: "Art" },
8
+ { href: "/artists", label: "Artists" },
9
+ ];
10
+
11
+ /** Brand, four links and no actions. Narrow the header below 64rem to get the menu button and Drawer. */
12
+ export const BasicSiteHeader = () => (
13
+ <SiteHeader
14
+ brand={<a href="/">The BEhive</a>}
15
+ links={LINKS}
16
+ menuLabel="Menu"
17
+ />
18
+ );
19
+
20
+ /** An action stays in the bar at every breakpoint. */
21
+ export const SiteHeaderWithActions = () => (
22
+ <SiteHeader
23
+ brand={<a href="/">The BEhive</a>}
24
+ links={LINKS}
25
+ menuLabel="Menu"
26
+ actions={<Button size="sm">Book direct</Button>}
27
+ />
28
+ );
@@ -0,0 +1,77 @@
1
+ @use "@behivetech/cms.base-styles/breakpoints.scss" as breakpoints;
2
+
3
+ // Surface bar with a hairline divider. The root is a named inline-size
4
+ // container, so the links go inline once the header itself is 64rem wide and
5
+ // the menu button opens them in a Drawer below that. A container cannot style
6
+ // itself, so the layout lives on the inner `__bar`.
7
+ .BHT__SiteHeader {
8
+ container: site-header / inline-size;
9
+ background: var(--md-sys-color-surface);
10
+ color: var(--md-sys-color-on-surface);
11
+ border-bottom: 1px solid var(--md-sys-color-outline-variant);
12
+
13
+ &__bar {
14
+ display: flex;
15
+ align-items: center;
16
+ justify-content: space-between;
17
+ gap: var(--spacing-4, 1rem);
18
+ min-height: 4rem;
19
+ padding: var(--spacing-2, 0.5rem) var(--spacing-4, 1rem);
20
+ }
21
+
22
+ &__brand {
23
+ display: flex;
24
+ align-items: center;
25
+ min-width: 0;
26
+ }
27
+
28
+ &__end {
29
+ display: flex;
30
+ align-items: center;
31
+ gap: var(--spacing-2, 0.5rem);
32
+ }
33
+
34
+ &__nav {
35
+ display: none;
36
+ }
37
+
38
+ &__actions {
39
+ display: flex;
40
+ align-items: center;
41
+ }
42
+
43
+ &__menu {
44
+ display: flex;
45
+ }
46
+
47
+ // Full-width stacked items; the gap keeps their 48px touch targets apart.
48
+ &__drawer-nav {
49
+ display: flex;
50
+ flex-direction: column;
51
+ gap: var(--spacing-2, 0.5rem);
52
+ }
53
+
54
+ // A container query on the header's own width, not a media query (base-styles'
55
+ // `lg` mixin): the header can sit in a narrow column of a wide page. The
56
+ // threshold is the shared `$breakpoint-lg`. It sits last so it wins over the
57
+ // narrow rules of the same elements.
58
+ @container site-header (min-width: #{breakpoints.$breakpoint-lg}) {
59
+ &__bar {
60
+ padding-inline: var(--spacing-8, 2rem);
61
+ }
62
+
63
+ &__end {
64
+ gap: var(--spacing-6, 1.5rem);
65
+ }
66
+
67
+ &__nav {
68
+ display: flex;
69
+ align-items: center;
70
+ gap: var(--spacing-1, 0.25rem);
71
+ }
72
+
73
+ &__menu {
74
+ display: none;
75
+ }
76
+ }
77
+ }
@@ -0,0 +1,217 @@
1
+ import {
2
+ type AnchorHTMLAttributes,
3
+ type ElementType,
4
+ type HTMLAttributes,
5
+ type ReactNode,
6
+ useEffect,
7
+ useRef,
8
+ useState,
9
+ } from "react";
10
+ import { getClassName } from "@bht-component-registry/class-names";
11
+ import { Button } from "@behivetech/atoms.button";
12
+ import { Drawer } from "@behivetech/atoms.drawer";
13
+ import { MenuIcon } from "@behivetech/atoms.icon";
14
+ import { NavItem } from "@behivetech/atoms.nav-item";
15
+ import styles from "./site-header.module.scss";
16
+
17
+ /** One navigation link of the header. */
18
+ export interface SiteHeaderLink {
19
+ /** Destination of the link */
20
+ href: string;
21
+ /** Visible text of the link, already translated */
22
+ label: string;
23
+ /** Marks the link for the current page: renders `aria-current="page"` */
24
+ current?: boolean;
25
+ }
26
+
27
+ /** Props the header passes to `linkComponent` for every link. */
28
+ export type SiteHeaderLinkProps = AnchorHTMLAttributes<HTMLAnchorElement> & {
29
+ href: string;
30
+ };
31
+
32
+ /** Props of the `SiteHeader` component. */
33
+ export interface SiteHeaderProps extends Omit<
34
+ HTMLAttributes<HTMLElement>,
35
+ "children"
36
+ > {
37
+ /** Additional class names to merge with the component root element */
38
+ className?: string;
39
+ /** Brand slot at the start of the bar; rendered as given, so pass your own home link */
40
+ brand: ReactNode;
41
+ /** Navigation links: inline once the header itself is at least `64rem` wide (a container query), in a Drawer when narrower */
42
+ links: SiteHeaderLink[];
43
+ /** Optional actions that stay in the bar at every breakpoint, e.g. a booking button */
44
+ actions?: ReactNode;
45
+ /**
46
+ * Component that renders each link, so a router link such as Next's `Link`
47
+ * can be injected. Receives `href`, `children` and the item's props. Defaults to `a`.
48
+ */
49
+ linkComponent?: ElementType<SiteHeaderLinkProps>;
50
+ /** Accessible name of the menu button, the navigation landmarks and the Drawer title, already translated */
51
+ menuLabel: string;
52
+ }
53
+
54
+ interface HeaderLinksProps {
55
+ links: SiteHeaderLink[];
56
+ linkComponent: ElementType<SiteHeaderLinkProps>;
57
+ onNavigate?: () => void;
58
+ }
59
+
60
+ const HeaderLinks = ({
61
+ links,
62
+ linkComponent: LinkComponent,
63
+ onNavigate,
64
+ }: HeaderLinksProps) => (
65
+ <>
66
+ {links.map(({ href, label, current }) => (
67
+ <NavItem
68
+ asChild
69
+ key={`${href}:${label}`}
70
+ active={current}
71
+ onClick={onNavigate}
72
+ >
73
+ <LinkComponent href={href}>{label}</LinkComponent>
74
+ </NavItem>
75
+ ))}
76
+ </>
77
+ );
78
+
79
+ interface MenuDrawerProps {
80
+ links: SiteHeaderLink[];
81
+ linkComponent: ElementType<SiteHeaderLinkProps>;
82
+ menuLabel: string;
83
+ navClassName: string;
84
+ onClose: () => void;
85
+ }
86
+
87
+ /** The Drawer that holds the links while the header is narrow. */
88
+ const MenuDrawer = ({
89
+ links,
90
+ linkComponent,
91
+ menuLabel,
92
+ navClassName,
93
+ onClose,
94
+ }: MenuDrawerProps) => (
95
+ <Drawer
96
+ placement="right"
97
+ title={menuLabel}
98
+ headingLevel={2}
99
+ padding="sm"
100
+ onClose={onClose}
101
+ >
102
+ <nav aria-label={menuLabel} className={navClassName}>
103
+ <HeaderLinks
104
+ links={links}
105
+ linkComponent={linkComponent}
106
+ onNavigate={onClose}
107
+ />
108
+ </nav>
109
+ </Drawer>
110
+ );
111
+
112
+ interface HeaderMenuProps {
113
+ links: SiteHeaderLink[];
114
+ linkComponent: ElementType<SiteHeaderLinkProps>;
115
+ menuLabel: string;
116
+ }
117
+
118
+ /**
119
+ * Returns a ref for the menu button and puts focus back on it once the Drawer
120
+ * closes. The Drawer unmounts with its Radix Dialog, so Radix has no trigger
121
+ * to hand focus back to.
122
+ */
123
+ const useReturnFocus = (isOpen: boolean) => {
124
+ const menuButtonRef = useRef<HTMLElement | null>(null);
125
+
126
+ useEffect(() => {
127
+ if (!isOpen) {
128
+ menuButtonRef.current?.focus();
129
+ }
130
+ }, [isOpen]);
131
+
132
+ return menuButtonRef;
133
+ };
134
+
135
+ /** Menu button and the Drawer it opens; shown only while the header is narrow. */
136
+ const HeaderMenu = ({ links, linkComponent, menuLabel }: HeaderMenuProps) => {
137
+ const [isMenuOpen, setIsMenuOpen] = useState(false);
138
+ const [, getChildClass] = getClassName({
139
+ rootClass: "BHT__SiteHeader",
140
+ styles,
141
+ });
142
+ const menuButtonRef = useReturnFocus(isMenuOpen);
143
+
144
+ const closeMenu = () => setIsMenuOpen(false);
145
+
146
+ return (
147
+ <div className={getChildClass("menu")}>
148
+ <Button
149
+ variant="ghost"
150
+ size="lg"
151
+ iconOnly
152
+ aria-label={menuLabel}
153
+ aria-haspopup="dialog"
154
+ aria-expanded={isMenuOpen}
155
+ onClick={(event) => {
156
+ menuButtonRef.current = event.currentTarget;
157
+ setIsMenuOpen(true);
158
+ }}
159
+ >
160
+ <MenuIcon />
161
+ </Button>
162
+ {isMenuOpen ? (
163
+ <MenuDrawer
164
+ links={links}
165
+ linkComponent={linkComponent}
166
+ menuLabel={menuLabel}
167
+ navClassName={getChildClass("drawer-nav")}
168
+ onClose={closeMenu}
169
+ />
170
+ ) : null}
171
+ </div>
172
+ );
173
+ };
174
+
175
+ /**
176
+ * Site header with a brand slot, navigation links and optional actions. While
177
+ * the header is at least `64rem` wide the links sit inline; narrower, a menu
178
+ * button opens them in a right-hand `Drawer`, which keeps the links in reach of
179
+ * one thumb on a phone. The switch follows the header's own width (a container
180
+ * query), not the viewport.
181
+ */
182
+ export const SiteHeader = ({
183
+ className,
184
+ brand,
185
+ links,
186
+ actions,
187
+ linkComponent = "a",
188
+ menuLabel,
189
+ ...rest
190
+ }: SiteHeaderProps) => {
191
+ const [rootClass, getChildClass] = getClassName({
192
+ className,
193
+ rootClass: "BHT__SiteHeader",
194
+ styles,
195
+ });
196
+
197
+ return (
198
+ <header {...rest} className={rootClass}>
199
+ <div className={getChildClass("bar")}>
200
+ <div className={getChildClass("brand")}>{brand}</div>
201
+ <div className={getChildClass("end")}>
202
+ <nav aria-label={menuLabel} className={getChildClass("nav")}>
203
+ <HeaderLinks links={links} linkComponent={linkComponent} />
204
+ </nav>
205
+ {actions ? (
206
+ <div className={getChildClass("actions")}>{actions}</div>
207
+ ) : null}
208
+ <HeaderMenu
209
+ links={links}
210
+ linkComponent={linkComponent}
211
+ menuLabel={menuLabel}
212
+ />
213
+ </div>
214
+ </div>
215
+ </header>
216
+ );
217
+ };