@keypuncherlabs/storybook-utils
v0.0.2
Published
Runtime helpers for a Storybook preview: resolve the initial theme context (URL/localStorage) and load design-token web fonts.
Maintainers
Readme
storybook-utils
Small runtime helpers for a Storybook preview: resolve the initial theme context and load design-token web fonts. Zero dependencies, browser-only.
Install
npm install @keypuncherlabs/storybook-utilsUsage
resolveInitialContext — pick the initial theme context
Resolves which context (theme) to apply on load. Precedence: URL ?context= →
localStorage → fallback ("default"). A value is only honored when it's in the known
contexts list, if one is provided.
import { resolveInitialContext } from "@keypuncherlabs/storybook-utils"
const context = resolveInitialContext({ contexts: ["default", "dark", "light"] })loadFonts — inject design-token web fonts
Injects a webfont stylesheet (plus preconnect hints) into <head>. Idempotent — safe to
call repeatedly. Supports Google Fonts (default) and Bunny Fonts.
import { loadFonts } from "@keypuncherlabs/storybook-utils"
loadFonts([{ family: "Inter", weights: [400, 600] }])
loadFonts(fonts, { provider: "bunny" })API
resolveInitialContext, loadFonts, fontsHref, buildHref, preconnectHosts,
DEFAULT_CONTEXT, plus the related types (Context, ResolveContextOptions, FontDef,
FontProvider, FontsHrefOptions, LoadFontsOptions).
License
MIT
