Skip to content

Latest commit

 

History

History
67 lines (52 loc) · 3.09 KB

ui.md

File metadata and controls

67 lines (52 loc) · 3.09 KB

UI & design system

Stack

  • React 18 rendered into the plugin iframe (src/main.tsx).
  • Tailwind v4 (CSS-first) via @tailwindcss/vite.
  • shadcn/ui on the base-ui registry (components.json), initialized from a preset. Primitives live in src/components/ui/.
  • @tabler/icons-react for icons.

Tabs

The shell (app.tsx) is a shadcn Tabs with four panels, each in its own folder:

Tab Folder What it does
Tokens components/tokens/ Editable tables for every token category; import/export TOML; live validation. Line-height & letter-spacing rows have an apply-to-selection button that pushes that token's converted value onto the selected text layers.
Composites components/composites/ Create/edit/delete composites; live resolved preview + Tailwind hint.
Semantics components/semantics/ Map semantic names → composites; apply a style to the current selection.
Sync components/sync/ Create / Safe / Review / Force buttons; result summary; review list.

TokensTab uses a generic MapEditor for add/rename/delete over any Record<string, V>.

Theming — following the Figma editor

The plugin opens its UI with themeColors: true, so Figma injects --figma-color-* CSS variables that already reflect the user's light/dark theme. In src/index.css we map those onto shadcn's design tokens:

:root {
    --background: var(--figma-color-bg, oklch(1 0 0));
    --foreground: var(--figma-color-text, oklch(0.148 0.004 228.8));
    --primary: var(--figma-color-bg-brand, oklch(0.488 0.243 264.376));
    --border: var(--figma-color-border, oklch(0.925 0.005 214.3));
    --destructive: var(--figma-color-text-danger, oklch(0.577 0.245 27.325));
    /* … */
}

Result: every shadcn component (bg-background, text-foreground, border-border, text-destructive, …) automatically tracks the Figma theme. The oklch(...) fallbacks only apply when running outside Figma (npm run dev). A custom --success token (mapped to --figma-color-text-success) and --font-mono are added alongside shadcn's defaults.

Single-file constraint

Figma loads the UI as one HTML file, so vite-plugin-singlefile inlines the JS and CSS into dist/ui.html. There are intentionally no external asset references (no web fonts, no separate chunks) — verify with:

grep -oE '(src|href)="[^"]*"' dist/ui.html | grep -v '="data:'   # should be empty

Conventions

  • All components are arrow functions; styling is Tailwind utilities (no inline style objects).
  • shadcn Button variants used here: default (primary action), outline (secondary), secondary, destructive, ghost (icon buttons).
  • SimpleSelect wraps shadcn's base-ui Select for the common "pick one of a list of strings" case.