diff --git a/site/src/layouts/Base.astro b/site/src/layouts/Base.astro index 221b5ad..4144bfc 100644 --- a/site/src/layouts/Base.astro +++ b/site/src/layouts/Base.astro @@ -1,6 +1,7 @@ --- import Analytics from '@vercel/analytics/astro'; import { site } from '../data/site.config'; +import { appTokenCss } from '../lib/app-tokens/app-tokens'; import '../styles/index.css'; interface Props { title?: string; description?: string; noindex?: boolean } @@ -35,6 +36,7 @@ const jsonLd = { {noindex && } + diff --git a/site/src/lib/app-tokens/app-tokens.config.ts b/site/src/lib/app-tokens/app-tokens.config.ts new file mode 100644 index 0000000..f46f7f7 --- /dev/null +++ b/site/src/lib/app-tokens/app-tokens.config.ts @@ -0,0 +1,11 @@ +/** + * Which of the app's palettes paints the embedded demos. The landing page is dark only, so the + * demos use the app's default palette in its dark variant. + */ +export const APP_TOKENS = { + selector: ".oi-app", + palette: "default", + scheme: "dark", + chartPrefix: "chart", + wearPrefix: "wear", +} as const; diff --git a/site/src/lib/app-tokens/app-tokens.ts b/site/src/lib/app-tokens/app-tokens.ts new file mode 100644 index 0000000..fba41ab --- /dev/null +++ b/site/src/lib/app-tokens/app-tokens.ts @@ -0,0 +1,24 @@ +import { CHART_PALETTE } from "~/lib/theme/chart-palette.config"; +import { PALETTES } from "~/lib/theme/palettes.config"; +import { THEME_DOM, THEME_TOKENS } from "~/lib/theme/theme.config"; +import { APP_TOKENS } from "./app-tokens.config"; + +const declaration = (name: string, value: string): string => + `${THEME_DOM.tokenPrefix}${name}: ${value};`; + +const numbered = (prefix: string, values: readonly string[]): string[] => + values.map((value, index) => declaration(`${prefix}-${index + 1}`, value)); + +/** + * The app's palette and chart colours as one CSS rule for the demo scope, read straight from the + * app's config at build time so the demos can never drift from the app. + */ +export function appTokenCss(): string { + const variant = PALETTES[APP_TOKENS.palette][APP_TOKENS.scheme]; + const declarations = [ + ...THEME_TOKENS.map((token) => declaration(token, variant[token])), + ...numbered(APP_TOKENS.chartPrefix, CHART_PALETTE.categorical[APP_TOKENS.scheme]), + ...numbered(APP_TOKENS.wearPrefix, CHART_PALETTE.wear[APP_TOKENS.scheme]), + ]; + return `${APP_TOKENS.selector}{${declarations.join("")}}`; +} diff --git a/site/src/mock/demo/items-demo.tsx b/site/src/mock/demo/items-demo.tsx index be4de92..e32f238 100644 --- a/site/src/mock/demo/items-demo.tsx +++ b/site/src/mock/demo/items-demo.tsx @@ -1,3 +1,4 @@ +import { ChevronsUpDown } from "lucide-react"; import { useDeferredValue, useMemo, useState } from "react"; import { ItemTable } from "~/components/item-table/item-table.component"; import { PageHeader } from "~/components/page-header/page-header.component"; @@ -11,8 +12,16 @@ import { useDemoInventory } from "./use-demo-inventory"; const ALL = "all"; /** The demo shows only the first matches; the real app lists everything. */ const ROW_CAP = 12; +/** + * Native selects dressed as the app's Select trigger. The app's own Select places its list with + * `position: fixed`, which lands in the wrong spot inside the scaled demo panels. + */ +const SELECT_WRAP_CLASS = "relative min-w-0 flex-1 sm:w-48 sm:flex-none"; const SELECT_CLASS = - "h-8 min-w-0 flex-1 rounded-md border border-input bg-card px-2.5 outline-none sm:flex-none"; + "h-8 w-full appearance-none rounded-md border border-control bg-background pl-2.5 pr-7 text-foreground transition-colors hover:bg-muted"; +const SELECT_ICON_CLASS = + "pointer-events-none absolute top-1/2 right-2 -translate-y-1/2 text-muted-foreground"; +const SELECT_ICON_SIZE = 14; /** The real Items page body: search, filters, sortable table and the move bar, on sample data. */ export default function ItemsDemo() { @@ -56,30 +65,36 @@ export default function ItemsDemo() { aria-label={COPY.common.searchPlaceholder} className="h-8 w-full rounded-md border border-input bg-card px-2.5 outline-none placeholder:text-muted-foreground focus:border-primary sm:w-44" /> - - +