"use client"; import { useSyncExternalStore } from "react"; import { FoxBadge } from "../core/components/fox-badge"; import { cx } from "../core/utils"; import { COMPONENT_EXAMPLES } from "./component-registry"; import { ComponentEmpty, ComponentView } from "./component-view"; import type { CssSection } from "./read-css-tokens"; import { ThemeSwitch } from "./theme-switch"; import { TokenView } from "./token-view"; import { useCssTokens } from "./use-css-tokens"; import styles from "./dev-test.module.scss"; // 선택 상태는 URL 해시가 SSOT다. 형식: `#token:light` / `#component:fox-button` function subscribeHash(onChange: () => void): () => void { window.addEventListener("hashchange", onChange); return () => window.removeEventListener("hashchange", onChange); } function getHash(): string { return window.location.hash.slice(1); } function getServerHash(): string { return ""; } function useSelection(): { kind: string; id: string } | null { const hash = useSyncExternalStore(subscribeHash, getHash, getServerHash); const [kind, id] = hash.split(":"); return kind && id ? { kind, id } : null; } function select(kind: string, id: string): void { window.location.hash = `${kind}:${id}`; } const GUIDE_ID = "guide"; function isRegistered(id: string): boolean { return COMPONENT_EXAMPLES.some((example) => example.id === id); } /** Figma 변수 페이지와 대조하는 화면이라 우리 CSS 그룹이 아닌 원본 구획을 따른다. */ function groupedSections(sections: CssSection[]) { const groups: { category: string | null; sections: CssSection[] }[] = []; for (const section of sections) { const last = groups[groups.length - 1]; if (last && last.category === section.category && section.category !== null) { last.sections.push(section); } else { groups.push({ category: section.category, sections: [section] }); } } return groups; } export function DevTestPage() { const selection = useSelection(); const sections = useCssTokens(); if (!sections) { return (

스타일시트를 읽는 중…

); } const totalTokens = sections.reduce((sum, section) => sum + section.tokens.length, 0); const current = selection ?? { kind: "token", id: sections[0]?.id ?? "" }; const activeSection = sections.find((section) => section.id === current.id); return (
{current.kind === "component" ? ( (() => { const example = COMPONENT_EXAMPLES.find((entry) => entry.id === current.id); return example ? : ; })() ) : activeSection ? ( ) : (

선택한 토큰 섹션이 없습니다.

)}
); }