octupub-navbar
v0.0.3
Published
Octupub navbar (React): logo, app and pricing links, language dropdown, auth links and profile menu.
Readme
octupub-navbar
The Octupub navbar as a React component: logo, App and Pricing links, language dropdown, Log In / Sign Up links, and a profile menu once the user is logged in.
Install
npm install octupub-navbarreact and react-dom (v19) are peer dependencies.
Use
---
import { NavBar } from "octupub-navbar";
---
<NavBar client:load lang="en" path="/" />lang: current language code (defaults toen).path: current page path without the language prefix, e.g./pricing. The language dropdown uses it to link to the same page in other languages.
Other exports: Logo (the wordmark), octupub-navbar/store (useNavStore, holds user, userLoaded and selectedLang), octupub-navbar/getUserInfo, octupub-navbar/content.
Styling
The component uses Tailwind v4 classes and the Octupub theme tokens (brand, brand-dark, ink, sucker, mist). The app that uses it must:
- Define the same tokens in its
@theme(the landing page'ssrc/styles/global.cssalready does). - Tell Tailwind to scan the package, in the same CSS file:
@source "../../node_modules/octupub-navbar/src";Auth
On load, the navbar reads the userInfo cookie. If that cookie is missing, it calls GET /auth/user with credentials (http://localhost:3000/auth/user in dev). A { success: true, data: UserInfo } response shows the profile menu. Any other response shows the Log In and Sign Up links.
Links it expects the app to serve: /app, /pricing, /login, /register, /settings, /auth/logout. With a language other than English, they get the /<lang> prefix (except /auth/logout).
Adding a language
- Copy
src/content/content.tstosrc/content/content-<code>.tsand translate it. - Add the language to
languagesandcontentMapinsrc/languages.ts.
Develop
npm install
npm run devsrc/pages/index.astro is a preview page and isn't published.
