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 +193 -181
- package/dist/index.cjs +16 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +16 -7
- package/dist/index.js.map +1 -1
- package/dist/styles.css +510 -510
- package/package.json +82 -68
package/README.md
CHANGED
|
@@ -1,181 +1,193 @@
|
|
|
1
|
-
# notchbar
|
|
2
|
-
|
|
3
|
-
A React navbar that hangs from the top
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
](https://www.npmjs.com/package/notchbar)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
|
|
10
|
+
**[See it live →](https://notchbar-kappa.vercel.app/)**
|
|
11
|
+
|
|
12
|
+

|
|
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
|
+

|
|
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 [
|
|
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 (!
|
|
89
|
-
else if (
|
|
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
|
-
|
|
557
|
-
|
|
558
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("
|
|
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 = {
|