Skip to content

feat(ui): white-label brand palette for the embedded widget #16

Closed

Description

@Ardnived

Summary

Let each host site render <syatlas-map> in its own brand colors from a single
embed snippet, so the widget feels native on shrimataji.org, sahajayoga.org, and
future tenants. Today the palette is hardcoded in tailwind.config.js (the
wemeditate teal/orange) and baked into the build. This adds runtime theming by
overriding NextUI's CSS variables on a widget-root wrapper, driven by a palette
resolved as prop ?? client-record field ?? built-in default. When no palette is
supplied the build output and appearance are unchanged.

Sampled tenant palettes (live, June 2026): shrimataji #64032E/#7A404E on cream
#F0ECE2; sahajayoga #468503/#4C6539 on white; wemeditate #82B1AE/#E08E79
(current default).

Proposed changes

  • Palette generator — new src/config/theme/palette.ts (+ palette.test.ts):
    • buildScale(seedHex) → { DEFAULT, '10', '50'…'900', foreground } as HSL-channel
      strings (e.g. "178 18% 60%"), mirroring the existing teal ramp's per-step
      lightness so generated scales match today's visual weight. Foreground picked
      black/white by WCAG contrast (colord a11y).
    • applyPalette(rootEl, { primary?, secondary?, background? }, mode) sets
      --nextui-<token>-<shade> inline on rootEl; mode-aware DEFAULT + foreground
      (light → ~500–600 step, dark → ~200–300 step). No-ops for omitted roles.
  • Dependency — add colord + a11y plugin.
  • Resolve + apply — new src/config/theme/BrandTheme.tsx: holds the wrapper ref,
    applies prop palette immediately at mount (themes the loading fallback), merges the
    client-record palette once ['client', apiKey] resolves (prop wins), and reapplies
    DEFAULT/foreground on light/dark flip.
  • Widget props — src/Widget.tsx: add primaryColor / secondaryColor /
    backgroundColor to WidgetProps and the r2wc props map; render a wrapper <div>
    that owns the light/dark class + brand vars, wrapping <App>.
  • Scope the theme root — src/hooks/use-theme.ts: target a configurable root
    (default document.documentElement standalone; the widget wrapper when embedded)
    instead of always mutating the host page's <html>.
  • Drop the swap + stabilize danger — tailwind.config.js: dark primary keeps the
    brand hue (no flip to secondary); danger becomes a fixed warning hue independent of
    the tenant's secondary.
  • Server field — src/types/client.ts: extend ClientSchema with optional/nullable
    primaryColor / secondaryColor / backgroundColor. Forward-compatible; inert until
    the SahajCloud backend returns them. Consumed where the client is already read
    (src/App.tsx:52).
  • Ladle preview — .ladle/components.tsx: palette switcher (teal/default,
    maroon/shrimataji, green/sahajayoga) calling the same applyPalette on the story
    wrapper.

Acceptance criteria

  • <syatlas-map primaryColor="#64032E" secondaryColor="#7A404E"> repaints chips,
    buttons, links, active nav, and panels in maroon with readable foregrounds; the
    green set does likewise.
  • Per-embed props override the client-record palette; client-record palette applies
    when no prop is set; built-in teal/orange default when neither is set.
  • Dark mode keeps the tenant hue at a lighter/desaturated tone with readable
    contrast (no vanishing primary); the tenant background override applies to light
    mode only, dark keeps its dark neutral.
  • danger is unaffected by the tenant palette.
  • The host page's <html> is not mutated by the embedded widget (vars + theme
    class are scoped to the widget wrapper).
  • Default build (no palette) is visually unchanged from today.
  • palette.ts unit tests: monotonic-lightness scale, foreground flips at the
    contrast boundary, buildScale('#82b1ae') ≈ the hand-tuned TEAL_COLOR.
  • Ladle palette switcher previews all three presets across atoms/molecules.
  • Lint + typecheck + build + test:run pass.
  • Verified in the running widget via Playwright (maroon + green sets, light & dark).

Files affected

  • New: src/config/theme/palette.ts, src/config/theme/palette.test.ts,
    src/config/theme/BrandTheme.tsx
  • Edit: src/Widget.tsx, src/hooks/use-theme.ts, tailwind.config.js,
    src/types/client.ts, .ladle/components.tsx, package.json

References

  • NextUI emits colors as HSL-channel CSS vars (--nextui-primary,
    --nextui-primary-{10,50…900}, --nextui-primary-foreground) under .light/.dark.
  • Dark-mode tone shift follows Material 3 tonal-palette guidance (preserve hue, shift
    tone, desaturate slightly).
  • Client fetch: src/App.tsx:52 (useSuspenseQuery(['client', apiKey])).
  • Blocked downstream: branding the map itself — see the on-hold map-branding ticket.

Activity

  1. added a commit that references this issue on Jun 30, 2026
    c39dfda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Hold Until

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions