# Vibe Flags — Full Documentation > Offline-first feature flag toolkit that lives in your HTML. No servers. No config files. No build step. Made for agents and LLMs. Vibe Flags is a set of web components for managing feature flags entirely in the browser. Add one CDN script tag, write HTML, and toggle features with a floating toolbar. State persists in localStorage. --- ## Getting Started Add one script tag, write some HTML. That's it. ### Quick Start ```html
Welcome to the beta! This banner is controlled by a feature flag.
``` A toggle button appears on the right edge of your page. Click it to open the toolbar, flip some flags, and watch the page react. Values persist across refreshes. No JavaScript. No config objects. No build step. ### How It Works 1. Each flag component self-registers when it connects to the DOM 2. `` discovers all registered flags and renders controls 3. Toggling a flag updates `localStorage` and re-evaluates every flag 4. Children stay hidden until JS confirms they should be visible — no flash of content ### URL Overrides Override any flag via URL query parameter without persisting to localStorage: ``` https://yourapp.com?vf:darkMode=true&vf:theme=dark ``` - Format: `?vf:=` - URL params take priority over localStorage values - URL params are ephemeral — not saved across page loads - Boolean flags: accept `true` or `false` only; any other value is ignored - Select flags: value must be a valid option; unrecognized values are ignored ### Installation CDN (recommended): ```html ``` npm: ```bash npm install @vibe-flags/core ``` Then import in your code: ```ts import '@vibe-flags/core'; ``` --- ## Flag Types ### Boolean Flags `` is a simple on/off toggle. Starts as `false`. ```html
Dark mode is active!
``` | Attribute | Required | Default | Description | |-----------|----------|---------|-------------| | `name` | Yes | — | Unique identifier for the flag | | `description` | No | `""` | Label shown in the toolbar (falls back to `name`) | | `value` | No | `""` | Expected value to show children. If omitted, children are always shown. | #### Showing content for both states Use two elements with `value="true"` and `value="false"`: ```html ``` ### Select Flags `` lets users pick from a list. Starts as the first option. Each choice is a ``. ```html
Light theme
Dark theme
Auto theme
``` | Attribute | Required | Default | Description | |-----------|----------|---------|-------------| | `name` | Yes | — | Unique identifier for the flag | | `description` | No | `""` | Label shown in the toolbar (falls back to `name`) | #### `` | Attribute | Required | Description | |-----------|----------|-------------| | `value` | Yes | The option value. Children are shown only when this option is active. | ### URL Query Parameter Overrides Override any flag's value via URL without touching localStorage: ``` https://yourapp.com?vf:dark-mode=true&vf:theme=dark ``` **Rules:** - URL params take priority over localStorage values when present. - URL params are **ephemeral** — not written to localStorage, do not persist across page loads. - Boolean flags accept `true` or `false`; any other value is ignored and falls back to localStorage or default. - Select flags accept any value in the options list; unrecognized values are ignored. --- ## API Reference — Components ### `` Declares a boolean flag and conditionally renders its children. Self-registers with the store on connect. Starts as `false`. #### Attributes | Attribute | Type | Default | Description | |-----------|------|---------|-------------| | `name` | `string` | `''` | Unique flag identifier | | `description` | `string` | `''` | Label shown in the toolbar (falls back to `name`) | | `value` | `string` | `''` | Expected value to show children. If omitted, children are always shown. | #### Example ```html
Always visible
Dark mode active
Light mode active
``` ### `` Declares a select flag. Options are defined as `` children — only the active option's children are rendered. Starts as the first option. #### Attributes | Attribute | Type | Default | Description | |-----------|------|---------|-------------| | `name` | `string` | `''` | Unique flag identifier | | `description` | `string` | `''` | Label shown in the toolbar (falls back to `name`) | #### Example ```html

Welcome to V1

Welcome to V2

``` ### `` A single option inside ``. Its children are shown only when this option is the active selection. #### Attributes | Attribute | Type | Default | Description | |-----------|------|---------|-------------| | `value` | `string` | `''` | The option value | ### `` Floating toggle button + slide-out sidebar. Automatically discovers all registered flags and renders controls (toggle switches for booleans, dropdowns for selects). Uses Shadow DOM with `all: initial` on the host element — global page styles (font size, colors, spacing, etc.) cannot leak into the toolbar. #### Example ```html

Beta content

``` --- ## API Reference — Store The `vibeFlagsStore` provides an imperative API for managing flags programmatically. ```ts import { vibeFlagsStore } from 'vibe-flags'; ``` ### `register(config: VibeFlagsConfig)` Register a single flag. Reads existing value from `localStorage`, falling back to `false` for booleans or the first option for selects. This is called automatically by `` and `` elements. ```ts vibeFlagsStore.register({ key: 'beta', type: 'boolean', label: 'Beta Mode' }); vibeFlagsStore.register({ key: 'theme', type: 'select', options: ['light', 'dark'], label: 'Theme' }); ``` ### `unregister(key: string)` Remove a flag from the store. ```ts vibeFlagsStore.unregister('beta'); ``` ### `get(key: string): VibeFlagsValue | undefined` Get the current value of a flag. ```ts vibeFlagsStore.get('beta'); // false vibeFlagsStore.get('theme'); // 'light' ``` ### `set(key: string, value: VibeFlagsValue): void` Set a flag value. Validates the value against the flag's type and options. Persists to `localStorage` and dispatches a change event. ```ts vibeFlagsStore.set('beta', true); vibeFlagsStore.set('theme', 'dark'); // Invalid values are silently ignored: vibeFlagsStore.set('beta', 'yes'); // ignored (not a boolean) vibeFlagsStore.set('theme', 'neon'); // ignored (not in options) ``` ### `getAll(): VibeFlagsState` Get all current flag values as a plain object. ```ts vibeFlagsStore.getAll(); // { beta: false, theme: 'light' } ``` ### `getConfig(): VibeFlagsConfig[]` Get all registered flag configurations. ### `getConfigForKey(key: string): VibeFlagsConfig | undefined` Get the configuration for a specific flag. ### `reset(): void` Reset all flags to their initial values (`false` for booleans, first option for selects) and clear `localStorage`. ```ts vibeFlagsStore.reset(); ``` ### Events #### `vibe-flags-changed` Dispatched on `window` whenever a flag value changes. ```ts window.addEventListener('vibe-flags-changed', (e) => { const { key, state } = e.detail; console.log(`Flag "${key}" changed`); console.log('All flags:', state); }); ``` | Property | Type | Description | |----------|------|-------------| | `detail.key` | `string \| undefined` | The flag that changed, or `undefined` for bulk changes (reset) | | `detail.state` | `VibeFlagsState` | Snapshot of all current flag values | --- ## API Reference — Types All types are exported from the package: ```ts import type { VibeFlagsConfig, VibeFlagsConfigBoolean, VibeFlagsConfigSelect, VibeFlagsValue, VibeFlagsState, } from 'vibe-flags'; ``` ### `VibeFlagsConfigBoolean` ```ts interface VibeFlagsConfigBoolean { key: string; type: 'boolean'; label?: string; } ``` ### `VibeFlagsConfigSelect` ```ts interface VibeFlagsConfigSelect { key: string; type: 'select'; options: string[]; label?: string; } ``` ### `VibeFlagsConfig` ```ts type VibeFlagsConfig = VibeFlagsConfigBoolean | VibeFlagsConfigSelect; ``` ### `VibeFlagsValue` ```ts type VibeFlagsValue = boolean | string; ``` ### `VibeFlagsState` ```ts interface VibeFlagsState { [key: string]: VibeFlagsValue; } ``` --- ## Examples ### Basic Usage ```html Vibe Flags Demo

My App

Welcome to the beta! This banner is controlled by a feature flag.
``` ### Multiple Boolean Flags ```html
    Debug info appears here
  
``` ### Select Flags — Layout Selector ```html
Card 1
Card 2
Card 3
Item 1
Item 2
Item 3
Row 1
Row 2
Row 3
``` --- ## React Integration `@vibe-flags/core` includes React utilities under the `@vibe-flags/core/react` sub-path. React 18 or 19 is required as a peer dependency. ### `useVibeFlags()` ```ts // Subscribe to an already-registered flag by key useVibeFlags(key: string): VibeFlagsValue | undefined // Register a flag from config and subscribe useVibeFlags(config: VibeFlagsConfig): VibeFlagsValue ``` Reads the current value of a feature flag and re-renders the component whenever the flag changes (via the `vibe-flags-changed` window event). ### `VibeFlagsToolbar` A React component that renders the Vibe Flags floating toolbar. No props required. Handles custom element registration automatically. ```tsx import { VibeFlagsToolbar } from '@vibe-flags/core/react'; function App() { return ( <> ); } ``` ### Examples **Boolean flag (pre-registered):** ```tsx import { useVibeFlags } from '@vibe-flags/core/react'; import { vibeFlagsStore } from '@vibe-flags/core'; vibeFlagsStore.register({ key: 'darkMode', type: 'boolean', default: false }); function App() { const darkMode = useVibeFlags('darkMode'); return
Hello
; } ``` **Register from config:** ```tsx import { useVibeFlags } from '@vibe-flags/core/react'; function ThemePicker() { const theme = useVibeFlags({ key: 'theme', type: 'select', options: ['light', 'dark', 'auto'], default: 'light', }); return

Current theme: {theme}

; } ``` **Full example with `VibeFlagsToolbar`:** ```tsx import { useVibeFlags, VibeFlagsToolbar } from '@vibe-flags/core/react'; function App() { const showBanner = useVibeFlags({ key: 'showBanner', type: 'boolean', default: true }); return ( <> {showBanner &&
Welcome to the beta!
} ); } ``` ### `VibeFlagsBoolean` React wrapper for ``. Renders children when the flag matches `value`. ```tsx import { VibeFlagsBoolean } from '@vibe-flags/core/react'; ``` Props: `name` (required), `description`, `value`, `default` (boolean), `children`. ### `VibeFlagsSelect` and `VibeFlagsOption` React wrappers for `` / ``. Only the active option renders. ```tsx import { VibeFlagsSelect, VibeFlagsOption } from '@vibe-flags/core/react'; ``` `VibeFlagsSelect` props: `name` (required), `description`, `default`, `children`. `VibeFlagsOption` props: `value` (required), `children`. --- ## Playground An interactive playground is available under `/playground/`. Each example has its own page with a live StackBlitz embed — no install or build step required. Pages: - `/playground/boolean-flag` — toggle a boolean flag on/off - `/playground/select-flag` — switch between options with a select flag --- ## Source - GitHub: https://github.com/Meldiron/vibe-flags - npm: https://www.npmjs.com/package/@vibe-flags/core - License: MIT