Embed as a React component
Most consumers mount the bundled SPA via a framework adapter and never install React. For teams that want the dashboard inside an existing React app:
import { FlagsDashboard } from "@xtandard/flags/react";import "@xtandard/flags/react/styles.css";
// Point it at wherever the panel API (+ /config) is mounted:export default function FlagsPage() { return <FlagsDashboard apiBaseUrl="/flags" />;}react and react-dom are (optional) peer dependencies in this mode; TanStack
Query and styles are bundled. The component ships as dist/react.js + a single
dist/react.css. See examples/react-embed for a
working host app (Vite dev proxy → standalone panel).
The whole dashboard (surfaces, text, borders, dialogs, toasts, the JSON editor
and diff viewers) always resolves to one theme, applied as data-theme on
the dashboard’s own wrapper. The host document is never modified. The theme
prop picks who decides:
theme |
Behavior |
|---|---|
"auto" (default) |
The dashboard’s own system/light/dark switcher, persisted in localStorage. |
"inherit" |
Follow the host page, live. Reads a dark/light class, a data-theme (or data-mode/data-color-scheme) attribute, or an inline color-scheme on <html>, then <body>; falls back to the OS prefers-color-scheme only when the host sets none. No switcher. |
"light"/"dark" |
Fixed. Pass your app’s resolved theme to drive it directly. No switcher. |
// Host with class-based dark mode (`<html class="dark">`), e.g. a Tailwind/shadcn app:<FlagsDashboard apiBaseUrl="/flags" theme="inherit" />
// Or hand over the theme your app already resolved:<FlagsDashboard apiBaseUrl="/flags" theme={resolvedTheme === "dark" ? "dark" : "light"} />Pre-selecting the project/environment
Section titled “Pre-selecting the project/environment”By default the dashboard opens on the server’s configured defaults. An embed host can pre-select a different pair — e.g. an admin panel rendering one dashboard per tenant/environment:
<FlagsDashboard apiBaseUrl="/flags" initialProjectKey="billing" initialEnvironmentKey="staging" />Precedence: the URL wins when it names one (?project= / ?env= — deep
links restore context and the in-app switcher keeps working), then the
initial* props, then the server /config defaults.
Cross-origin embed (dashboard and panel on different origins)
Section titled “Cross-origin embed (dashboard and panel on different origins)”When the app hosting <FlagsDashboard> is served from a different origin
than the panel API (e.g. SPA on app.example.com, panel on
api.example.com/flags), cookie-based auth needs two matching settings — one on
each side:
Client — send credentials cross-origin (default is same-origin, which
drops the cookie):
<FlagsDashboard apiBaseUrl="https://api.example.com/flags" credentials="include" />For a non-cookie scheme (bearer token, extra headers), pass a custom fetch
instead:
<FlagsDashboard apiBaseUrl="https://api.example.com/flags" fetch={(input, init) => fetch(input, { ...init, headers: { ...init?.headers, authorization: `Bearer ${token}` } }) }/>Server — enable CORS on the panel itself so it returns the required headers
and answers the OPTIONS preflight, independent of the host framework’s own
CORS middleware (which may not wrap a mounted sub-handler):
flagsPanel({ basePath: "/flags", sourceStorage, cors: { origin: "https://app.example.com", credentials: true }, // exact origin, not "*" auth, authorization,});cors.origin accepts an exact origin, "*", a list, or a predicate
(origin) => boolean. With credentials: true the browser forbids "*", so the
handler echoes the caller’s exact origin (and adds Vary: Origin). Also
supports methods, headers, and maxAge.
Who owns CORS — set it on exactly one layer. The panel does not inherit your host framework’s CORS middleware; it’s a standalone handler. Whether that middleware even reaches the panel depends on how you integrate:
- Mounted handler (
Elysia.mount/ Hono / Express sub-app): the host’scors()plugin generally does not wrap a mounted handler, so the panel gets no CORS from it → use the panel’scorsoption. - Typed plugin (e.g.
flagsElysia): declares real routes the hostcors()does wrap → leave the panelcorsunset and let the host handle it.
Never both: two Access-Control-Allow-Origin headers on one response make the
browser reject it. You also don’t need to re-list headers — the preflight
reflects the request’s Access-Control-Request-Headers by default.