notchbar 0.1.0 → 0.2.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,181 +1,193 @@
1
- # notchbar
2
-
3
- A React navbar that hangs from the top edge of the page like a notch, joined to it by curved shoulders.
4
-
5
- At the top of the page it is wide and quiet, in a paper tone. Scroll, and it pulls in to a narrower strip of liquid glass that bends whatever passes under it. Scroll back up and it stretches out again with a little overshoot. Menus open one shared panel that changes size between menus and slides its contents the way your pointer moved.
6
-
7
- ![The tab at the top of the page, in paper](assets/paper.png)
8
- ![The same tab after scrolling, condensed into glass over a striped band](assets/glass.png)
9
- ![The Product menu open under the tab](assets/menu.png)
10
-
11
- ## What it does
12
-
13
- - **One shape, redrawn live.** The tab and its curved shoulders are a single SVG path traced from the tab's current size. The fill, hairline, inner rim and shadow all follow that path, so nothing comes apart mid-animation.
14
- - **Squash and stretch.** As the width springs in, the height dips and then settles, so the tab looks like it keeps its volume. The logo and button trail the edges a little and catch up.
15
- - **Glass that forms.** The paper fades out as the glass forms, a highlight sweeps across it once, and the shadow lands a beat later. In Chromium the backdrop is bent through a displacement filter. Other browsers get plain frosted glass.
16
- - **Menus that change size.** One panel resizes between menus, and the new content slides in from the side your pointer came from.
17
- - **Hover that picks one link.** Pointing at a link dims the rest and draws a hand-drawn marker stroke under it. Links that point to a `#section` underline themselves while that section is on screen.
18
- - **A full phone menu.** Below 768px the links fold into a burger menu, grouped under each menu's heading.
19
- - **Accessible.** It uses real buttons and links, `aria-expanded` and `aria-controls`, and Escape to close. Focus rings show when you use the keyboard. With reduced motion on, the springs are replaced by plain fades.
20
-
21
- ## Install
22
-
23
- ```bash
24
- npm i notchbar motion
25
- ```
26
-
27
- It needs `react` 18 or newer, `react-dom` and [`motion`](https://motion.dev).
28
-
29
- ## Usage
30
-
31
- Import the component and its stylesheet once:
32
-
33
- ```tsx
34
- import { Notchbar, PanelCards, PanelHeader } from "notchbar";
35
- import "notchbar/styles.css";
36
-
37
- export function Header() {
38
- return (
39
- <Notchbar
40
- brand={{ name: "Acme" }}
41
- cta={{ label: "Get started", href: "/signup" }}
42
- items={[
43
- {
44
- label: "Product",
45
- panel: () => (
46
- <>
47
- <PanelHeader title="Product" />
48
- <PanelCards
49
- items={[
50
- { href: "/boards", title: "Boards", text: "Plan the week on one shared surface." },
51
- { href: "/docs", title: "Docs", text: "Specs that stay next to the work." },
52
- ]}
53
- />
54
- </>
55
- ),
56
- mobile: [
57
- { label: "Boards", href: "/boards" },
58
- { label: "Docs", href: "/docs" },
59
- ],
60
- },
61
- { label: "Pricing", href: "#pricing" },
62
- ]}
63
- />
64
- );
65
- }
66
- ```
67
-
68
- The nav is `position: fixed`, so give your page some room at the top (about 80px) so it doesn't sit on top of your content.
69
-
70
- ### Next.js
71
-
72
- The build already starts with `"use client"`. To get client-side navigation, pass your router's link:
73
-
74
- ```tsx
75
- import Link from "next/link";
76
-
77
- <Notchbar linkComponent={Link} brand={{ name: "Acme" }} items={items} />;
78
- ```
79
-
80
- React Router's `Link` works too. It's given `href`, which React Router reads as `to`, so wrap it if you need to:
81
-
82
- ```tsx
83
- const RouterLink = ({ href, ...rest }) => <Link to={href} {...rest} />;
84
- ```
85
-
86
- ## Props
87
-
88
- | Prop | Type | Default | |
89
- |---|---|---|---|
90
- | `brand` | `{ name, href?, mark?, label? }` | | The logo link on the left. `mark` replaces the default square logo. `label` is the accessible name, which defaults to "*name*, home". |
91
- | `items` | `NavItem[]` | | The links in the middle, in order. See below. |
92
- | `cta` | `{ label, href }` | | The button on the right. Leave it out to hide the button. |
93
- | `linkComponent` | `ElementType` | `"a"` | Your router's link component. |
94
- | `accent` | `string` | `#e5484d` | The marker colour, used for the hover strokes, the button's dot and "New" marks. |
95
- | `maxWidth` | `number` | `1024` | How wide the tab gets at the top of the page, in px. |
96
- | `compactAt` | `number` | `56` | How far down (px) the page scrolls before the tab condenses. |
97
- | `expandAt` | `number` | `24` | How close to the top (px) before it stretches out again. The gap between this and `compactAt` stops it flickering. |
98
- | `className` | `string` | | Added to the outer `<header>`. |
99
-
100
- ### Items
101
-
102
- An item is either a plain link or a menu.
103
-
104
- ```ts
105
- type NavLinkItem = { label: string; href: string };
106
-
107
- type NavMenu = {
108
- label: string;
109
- panel: (ctx: { close: () => void; reduced: boolean }) => ReactNode;
110
- width?: string; // the panel's width, any CSS length. Default 36rem
111
- mobile?: MobileLink[]; // what this menu lists in the phone menu
112
- };
113
-
114
- type MobileLink = { label: string; href: string; meta?: string; badge?: ReactNode };
115
- ```
116
-
117
- A link whose `href` starts with `#` marks itself while that section is on screen.
118
-
119
- ## Panel building blocks
120
-
121
- A panel can hold anything. These blocks already match the nav's style and its entrance animation:
122
-
123
- | Block | What it is |
124
- |---|---|
125
- | `PanelHeader` | A small mono heading row, with an optional note on the right. |
126
- | `PanelRows` | One link per row, with a note on the right and an arrow that slides in on hover. |
127
- | `PanelCards` | Links with an icon tile, a title and a line of description. |
128
- | `PanelGrid` | A compact two-column grid of short links. |
129
- | `PanelSplit` | Two columns with a hairline between them. |
130
- | `PanelFooter` | A quiet strip along the bottom. |
131
- | `PanelLink` | A link with an underline that draws in from the left. Made for the footer. |
132
- | `NewMark` | "New", circled in marker. |
133
- | `NavLink` | A plain link that uses your `linkComponent`. |
134
- | `usePanel()` | Returns `{ close, reduced }` for your own panel content. Call `close` when someone picks a link. |
135
-
136
- ```tsx
137
- {
138
- label: "Resources",
139
- width: "40rem",
140
- panel: () => (
141
- <PanelSplit
142
- left={<PanelRows rows={[{ href: "/guides", title: "Guides", meta: "12" }]} />}
143
- right={<PanelGrid title="Popular" links={[{ href: "/roadmaps", label: "Roadmaps" }]} />}
144
- />
145
- ),
146
- }
147
- ```
148
-
149
- ## Theming
150
-
151
- Everything is plain CSS with `nb-` class names and custom properties. Override them on `.nb` or on any ancestor:
152
-
153
- ```css
154
- .nb {
155
- --nb-ink: #111; /* text */
156
- --nb-muted: #8f8f8a; /* secondary text */
157
- --nb-paper: #efefec; /* the tab at the top of the page */
158
- --nb-glass: rgba(255, 255, 255, 0.42); /* the glass tint */
159
- --nb-font-mono: ui-monospace, Menlo, monospace;
160
- --nb-font-marker: "Gochi Hand", "Comic Sans MS", cursive;
161
- }
162
- ```
163
-
164
- The nav takes the font of the page around it. The "New" marks look best with a handwriting font like [Gochi Hand](https://fonts.google.com/specimen/Gochi+Hand).
165
-
166
- ## Browser support
167
-
168
- The tab, the menus and the motion work in every evergreen browser. The bending glass uses an SVG filter inside `backdrop-filter`, which only Chromium supports. Safari and Firefox get frosted glass. When someone has *reduce transparency* turned on, the glass becomes solid.
169
-
170
- ## Run the demo
171
-
172
- ```bash
173
- git clone https://github.com/dhruxvsharma/notchbar
174
- cd notchbar
175
- npm install
176
- npm run demo
177
- ```
178
-
179
- ## License
180
-
181
- MIT
1
+ # notchbar
2
+
3
+ **A React navbar that hangs from the top of your page.**
4
+
5
+ It sits like paper while you read, turns to liquid glass once you scroll, and opens one menu panel that reshapes itself as you move between menus.
6
+
7
+ [![npm](https://img.shields.io/npm/v/notchbar?color=e5484d&label=npm)](https://www.npmjs.com/package/notchbar)
8
+ [![license](https://img.shields.io/npm/l/notchbar?color=121214)](LICENSE)
9
+
10
+ **[See it live →](https://notchbar-kappa.vercel.app/)**
11
+
12
+ ![notchbar in its glass state with the Product menu open](assets/notchbar-hero.png)
13
+
14
+ ## Why you might like it
15
+
16
+ - **It feels physical.** The tab squashes and stretches as it springs, like it has weight.
17
+ - **Glass that forms, not swaps.** The paper dissolves, a glint sweeps across, and in Chrome the edges bend what passes under them.
18
+ - **One panel for every menu.** It resizes between menus and slides in from the side you came from.
19
+ - **Small touches.** Hand-drawn hover strokes, a breathing dot on the button, "New" circled in marker.
20
+ - **Works for everyone.** Real links and buttons, keyboard support, Escape to close, a phone menu below 768px, and plain fades when someone asks for reduced motion.
21
+
22
+ ![The same nav twice: paper at the top of the page, glass once you scroll](assets/notchbar-states.png)
23
+
24
+ ## Get started
25
+
26
+ ```bash
27
+ npm i notchbar motion
28
+ ```
29
+
30
+ ```tsx
31
+ import { Notchbar } from "notchbar";
32
+ import "notchbar/styles.css";
33
+
34
+ export function Header() {
35
+ return (
36
+ <Notchbar
37
+ brand={{ name: "Acme" }}
38
+ items={[
39
+ { label: "Pricing", href: "/pricing" },
40
+ { label: "Docs", href: "/docs" },
41
+ ]}
42
+ cta={{ label: "Sign up", href: "/signup" }}
43
+ />
44
+ );
45
+ }
46
+ ```
47
+
48
+ That's it. The nav is fixed to the top, so leave about 80px of space above your content.
49
+
50
+ Needs React 18 or newer and [motion](https://motion.dev).
51
+
52
+ ## Add a menu
53
+
54
+ Give an item a `panel` instead of an `href`, and build the panel from ready-made blocks:
55
+
56
+ ```tsx
57
+ import { Notchbar, PanelHeader, PanelRows, NewMark } from "notchbar";
58
+
59
+ const items = [
60
+ {
61
+ label: "Product",
62
+ panel: () => (
63
+ <>
64
+ <PanelHeader title="Product" />
65
+ <PanelRows
66
+ rows={[
67
+ { href: "/boards", title: "Boards", meta: "Plan" },
68
+ { href: "/docs", title: "Docs", badge: <NewMark /> },
69
+ ]}
70
+ />
71
+ </>
72
+ ),
73
+ // what this menu shows in the phone menu
74
+ mobile: [
75
+ { label: "Boards", href: "/boards" },
76
+ { label: "Docs", href: "/docs" },
77
+ ],
78
+ },
79
+ { label: "Pricing", href: "/pricing" },
80
+ ];
81
+ ```
82
+
83
+ A panel can hold anything you like. The blocks just save you the styling:
84
+
85
+ | Block | What it is |
86
+ |---|---|
87
+ | `PanelHeader` | A small heading row, with an optional note on the right |
88
+ | `PanelRows` | One link per row, with an arrow that slides in on hover |
89
+ | `PanelCards` | Links with an icon, a title and a line of text |
90
+ | `PanelGrid` | A compact two-column grid of short links |
91
+ | `PanelSplit` | Two columns side by side |
92
+ | `PanelFooter` and `PanelLink` | A quiet strip along the bottom, with an underlined link |
93
+ | `NewMark` | "New", circled in marker |
94
+ | `usePanel()` | Gives you `close()` for your own panel content |
95
+
96
+ Links whose `href` starts with `#` underline themselves while that section is on screen.
97
+
98
+ ## Next.js and React Router
99
+
100
+ Pass your router's link so navigation stays client-side:
101
+
102
+ ```tsx
103
+ import Link from "next/link";
104
+
105
+ <Notchbar linkComponent={Link} brand={{ name: "Acme" }} items={items} />;
106
+ ```
107
+
108
+ The build already includes `"use client"`. For React Router, wrap its `Link` so it reads `href`:
109
+
110
+ ```tsx
111
+ const RouterLink = ({ href, ...rest }) => <Link to={href} {...rest} />;
112
+ ```
113
+
114
+ ## Make it yours
115
+
116
+ One prop sets your colour. It tints the hover strokes, the button's dot and every "New":
117
+
118
+ ```tsx
119
+ <Notchbar accent="#2f6bff" ... />
120
+ ```
121
+
122
+ Everything else is plain CSS variables:
123
+
124
+ ```css
125
+ .nb {
126
+ --nb-ink: #111; /* text */
127
+ --nb-muted: #8f8f8a; /* secondary text */
128
+ --nb-paper: #efefec; /* the tab at the top of the page */
129
+ --nb-glass: rgba(255, 255, 255, 0.42); /* the glass tint */
130
+ --nb-font-marker: "Gochi Hand", cursive; /* for the "New" marks */
131
+ }
132
+ ```
133
+
134
+ The nav uses your page's font. "New" marks look best with a handwriting font like [Gochi Hand](https://fonts.google.com/specimen/Gochi+Hand).
135
+
136
+ ## Props
137
+
138
+ | Prop | Default | What it does |
139
+ |---|---|---|
140
+ | `brand` | required | `{ name, href?, mark?, label? }`. The logo on the left. `mark` swaps in your own logo. |
141
+ | `items` | required | The links and menus in the middle. |
142
+ | `cta` | none | `{ label, href }`. The button on the right. |
143
+ | `accent` | `#e5484d` | The marker colour. |
144
+ | `state` | `"auto"` | `"auto"` follows the scroll. `"paper"` or `"glass"` pins one look. |
145
+ | `maxWidth` | `1024` | How wide the paper tab gets, in px. |
146
+ | `compactAt` | `56` | How far you scroll (px) before it turns to glass. |
147
+ | `expandAt` | `24` | How close to the top (px) before it stretches back. |
148
+ | `linkComponent` | `"a"` | Your router's link. |
149
+ | `className` | none | Added to the outer `<header>`. |
150
+
151
+ <details>
152
+ <summary>Item types</summary>
153
+
154
+ ```ts
155
+ type NavLinkItem = { label: string; href: string };
156
+
157
+ type NavMenu = {
158
+ label: string;
159
+ panel: (ctx: { close: () => void; reduced: boolean }) => ReactNode;
160
+ width?: string; // the panel's width, any CSS length. Default 36rem
161
+ mobile?: MobileLink[]; // what this menu lists in the phone menu
162
+ };
163
+
164
+ type MobileLink = { label: string; href: string; meta?: string; badge?: ReactNode };
165
+ ```
166
+
167
+ </details>
168
+
169
+ <details>
170
+ <summary>Browser support</summary>
171
+
172
+ Everything works in every modern browser. The bending glass uses an SVG filter that only Chromium supports, so Safari and Firefox get clean frosted glass instead. With *reduce transparency* turned on, the glass becomes solid.
173
+
174
+ </details>
175
+
176
+ ## Run the demo locally
177
+
178
+ ```bash
179
+ git clone https://github.com/dhruxvsharma/notchbar
180
+ cd notchbar
181
+ npm install
182
+ npm run demo
183
+ ```
184
+
185
+ ## Made by
186
+
187
+ **Dhruv Sharma** · [X](https://x.com/Dhruxvsharma) · [LinkedIn](https://www.linkedin.com/in/dhruxvsharma/) · [Instagram](https://www.instagram.com/dhruxvsharma/) · [GitHub](https://github.com/dhruxvsharma)
188
+
189
+ If notchbar ends up on your site, I'd love to see it. Tag me on X, or open an issue with a link.
190
+
191
+ ## License
192
+
193
+ MIT © Dhruv Sharma
package/dist/index.cjs CHANGED
@@ -68,11 +68,13 @@ function Notchbar({
68
68
  maxWidth = 1024,
69
69
  compactAt = 56,
70
70
  expandAt = 24,
71
+ state = "auto",
71
72
  className
72
73
  }) {
73
74
  const reduced = (0, import_react.useReducedMotion)() ?? false;
74
75
  const { scrollY } = (0, import_react.useScroll)();
75
- const [compact, setCompact] = (0, import_react2.useState)(false);
76
+ const [scrolled, setScrolled] = (0, import_react2.useState)(false);
77
+ const compact = state === "auto" ? scrolled : state === "glass";
76
78
  const [hover, setHover] = (0, import_react2.useState)(null);
77
79
  const [section, setSection] = (0, import_react2.useState)(null);
78
80
  const [open, setOpen] = (0, import_react2.useState)(null);
@@ -85,8 +87,8 @@ function Notchbar({
85
87
  const rightRef = (0, import_react2.useRef)(null);
86
88
  const panelId = (0, import_react2.useId)();
87
89
  (0, import_react.useMotionValueEvent)(scrollY, "change", (v) => {
88
- if (!compact && v > compactAt) setCompact(true);
89
- else if (compact && v < expandAt) setCompact(false);
90
+ if (!scrolled && v > compactAt) setScrolled(true);
91
+ else if (scrolled && v < expandAt) setScrolled(false);
90
92
  });
91
93
  const height = (0, import_react.useMotionValue)(60);
92
94
  const settled = (0, import_react2.useRef)(false);
@@ -553,10 +555,17 @@ function Cta({ label, href }) {
553
555
  ] });
554
556
  }
555
557
  function Mark() {
556
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { "aria-hidden": true, className: "nb-mark", children: [
557
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "nb-mark-frame" }),
558
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "nb-mark-dot" })
559
- ] });
558
+ const id = (0, import_react2.useId)().replace(/:/g, "");
559
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { "aria-hidden": true, className: "nb-mark", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { viewBox: "0 0 24 24", width: "24", height: "24", children: [
560
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("linearGradient", { id: `${id}-o`, x1: "0", y1: "0", x2: "0", y2: "1", children: [
561
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { offset: "0", stopColor: "#fff" }),
562
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { offset: "0.52", stopColor: "#fff" }),
563
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { offset: "0.86", stopColor: "#fff", stopOpacity: "0.08" }),
564
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { offset: "1", stopColor: "#fff", stopOpacity: "0.3" })
565
+ ] }) }),
566
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ellipse", { cx: "12", cy: "12", rx: "8.9", ry: "5", transform: "rotate(-40 12 12)", fill: "none", stroke: `url(#${id}-o)`, strokeWidth: "1.7" }),
567
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "12", cy: "12", r: "8.9", fill: "none", stroke: "#fff", strokeWidth: "1.8" })
568
+ ] }) });
560
569
  }
561
570
  // Annotate the CommonJS export names for ESM import in node:
562
571
  0 && (module.exports = {