Skip to content

Astro integration

@nyxwire/astro themes an Astro site. Its integration does two things on every page: it inlines the flavor script in <head>, so the stored flavor is applied before the first paint and before any island hydrates, and it imports the Nyxwire stylesheet. The package also ships three components and the runtime as a library. Fonts, colors and styles are bundled locally; nothing loads from a CDN.

  1. Install the integration and the CSS it imports.

    Terminal window
    pnpm add @nyxwire/astro @nyxwire/css
  2. Register it.

    astro.config.mjs
    import { defineConfig } from 'astro/config'
    import nyxwire from '@nyxwire/astro'
    export default defineConfig({
    integrations: [nyxwire({ flavors: { dark: 'nocturne' }, accent: 'indigo' })],
    })
  3. Use the nw-* classes, or the Layout component for a complete document.

    src/pages/index.astro
    ---
    import Layout from '@nyxwire/astro/components/Layout.astro'
    ---
    <Layout title="Relay status">
    <main class="nw-container nw-stack">
    <h1>Relay status</h1>
    <button class="nw-btn">Connect</button>
    </main>
    </Layout>
Option Values Default
flavors.dark 'abyss', 'nocturne', 'twilight' 'nocturne'
flavors.light 'lumen' 'lumen'
defaultFlavor 'auto', 'abyss', 'nocturne', 'twilight', 'lumen' 'auto'
accent any of the 12 accents none
persist true, false true
styles 'full', 'tokens', false 'full'
css true, false true
  • flavors.dark and flavors.light are the flavors auto resolves to when the system prefers a dark or a light color scheme.
  • defaultFlavor applies when the visitor has stored nothing valid. A stored choice always wins.
  • accent is set as data-accent on <html> and re-points the primary color (links, active states, focus rings). Without it the palette default, indigo, applies.
  • persist: false keeps the visitor’s choices in memory only and ignores stored values.
  • css: false is shorthand for styles: false.
  • Invalid values and unknown option names throw a NyxwireOptionsError at startup, naming the option, the accepted values and what was received.
styles Imports on every page Use when
'full' @nyxwire/css: tokens, fonts, base, components and utilities You use the nw-* classes
'tokens' @nyxwire/css/tokens.css and @nyxwire/css/fonts.css Your own CSS styles elements and components
false nothing Your global stylesheet imports what it needs

The stylesheet is imported through Astro’s page-ssr stage, so it is bundled with each page. With Tailwind, use styles: false and let the stylesheet bring the theme, fonts, tokens and base:

astro.config.mjs
import { defineConfig } from 'astro/config'
import nyxwire from '@nyxwire/astro'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
integrations: [nyxwire({ styles: false })],
vite: { plugins: [tailwindcss()] },
})
src/styles/global.css
@import 'tailwindcss';
@import '@nyxwire/tailwind';
@import '@nyxwire/vue/tailwind.css'; /* with @nyxwire/vue */

Import that stylesheet in your layout. The Vue islands page continues this setup.

The inline script reads localStorage['nyxwire-flavor'] (and the accent from nyxwire-accent), resolves auto through prefers-color-scheme, and sets data-flavor, data-theme, data-nw-flavor-preference, data-accent and color-scheme on <html>. It also updates every <meta name="theme-color"> marked with data-nyxwire-theme-color to the active flavor’s base color. Then it exposes a small controller:

window.nyxwire.getFlavor() // stored preference, 'auto' included
window.nyxwire.resolve() // flavor in use, e.g. 'nocturne'
window.nyxwire.setFlavor('twilight') // persists, applies, dispatches the event
window.nyxwire.getAccent() // 'volt', or null for the palette default
window.nyxwire.setAccent('volt') // persists and sets data-accent
window.nyxwire.setAccent(null) // removes data-accent
document.addEventListener('nyxwire:flavor', ({ detail }) => {
console.log(detail.flavor, detail.resolved, detail.theme, detail.accent)
})

The event fires on start, once the DOM is ready (so theme-color metas parsed after the script are updated), after every setFlavor or setAccent, and on system color scheme changes while the preference is auto. setFlavor and setAccent throw a TypeError for an unknown value before anything changes. When storage is blocked (privacy mode, sandboxed frames), the choice still applies to the current page. To type window.nyxwire and the event in a client script, import the package’s types:

import type {} from '@nyxwire/astro'

Flavors & theming explains the model, and Vue’s useFlavor delegates to this runtime when it is present.

Export Purpose
nyxwire(options?) (default) The integration
buildFlavorScript(options?) The validated inline runtime as a string, for your own <script is:inline>
resolveFlavor(stored, prefersLight, options?) Pure resolution of a stored value to a flavor
flavorRuntime(config) The runtime function itself; buildFlavorScript stringifies it
normalizeOptions(options?), NyxwireOptionsError, isFlavorName, isFlavorPreference, isAccentName Option validation
FLAVOR_STORAGE_KEY, ACCENT_STORAGE_KEY, FLAVOR_CHANGE_EVENT (alias FLAVOR_EVENT) 'nyxwire-flavor', 'nyxwire-accent', 'nyxwire:flavor'
flavorIds (alias FLAVOR_IDS), darkFlavorIds Flavor ids from the palette
import { resolveFlavor } from '@nyxwire/astro'
resolveFlavor('auto', true) // 'lumen'
resolveFlavor(null, false, { flavors: { dark: 'abyss' } }) // 'abyss'
resolveFlavor('neon', false) // 'nocturne': invalid storage falls back to defaultFlavor ('auto')

Types: NyxwireOptions, NyxwireConfig (alias FlavorConfig), FlavorRuntimeConfig, FlavorPreference, StyleMode, FlavorController, NyxwireRuntime, FlavorChangeDetail, FlavorName, DarkFlavorName and AccentName.