Files
HMDesign/packages/sw/ai/examples/ExampleB-ViewerHeader.tsx
T
shkim4andClaude Opus 5.5 e27385e0f0 feat(sw): prepare reusable AI-friendly component package
- Ship an AI guide in the package (ai/: usage rules, component catalog,
  design rules, composition patterns) via package.json files.
- Add examples A-D that import only public exports: default header,
  viewer header, feature header, and a consumer-side search extension
  that reuses SWHeaderInput and the public SW tokens.
- Add SW-only checks: docs/API consistency, tarball consumer project
  (React 19 + TS + Vite typecheck/build) and a browser check (27/27).
- No runtime source or public API change; README gains a pointer section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 11:22:07 +09:00

51 lines
2.5 KiB
TypeScript

// Example B — composition (2nd priority): a simplified viewer header
// Logo → File → Layer → Color → K
// Only public components; the layout is the consumer's (example-layout.css) and <SWTheme> provides tokens.
import { useState } from "react"
import {
SWHeaderActions, SWHeaderColorMenu, SWHeaderDocumentTitle, SWHeaderHome, SWHeaderLayerMenu, SWTheme,
type SWHeaderColorMode, type SWHeaderColorValue,
} from "@hm-design/sw"
import { colors, documents, layers } from "./sample-data"
import "./example-layout.css"
export function ExampleBViewerHeader({ onEvent }: { onEvent?: (name: string) => void }) {
const [activeDocumentId, setActiveDocumentId] = useState(documents[0].id)
const [activeLayerId, setActiveLayerId] = useState("0")
const [color, setColor] = useState<SWHeaderColorValue>({ value: "ByLayer", swatch: "#ffffff" })
const [colorMode, setColorMode] = useState<SWHeaderColorMode | null>("byLayer")
return (
<SWTheme className="app-sw-bar" role="banner" aria-label="뷰어 헤더">
<SWHeaderHome logoAlt="뷰어" onClick={() => onEvent?.("home")} />
<SWHeaderDocumentTitle
title={documents.find(item => item.id === activeDocumentId)?.name ?? ""}
documents={documents}
activeDocumentId={activeDocumentId}
onDocumentSelect={document => { setActiveDocumentId(document.id); onEvent?.(`document:${document.id}`) }}
onNew={() => onEvent?.("document:new")}
onOpen={() => onEvent?.("document:open")}
/>
<div className="app-sw-surface" role="toolbar" aria-label="보기 설정">
<SWHeaderLayerMenu
value={{ name: "0" }}
layers={layers}
activeLayerId={activeLayerId}
onLayerSelect={layer => { setActiveLayerId(layer.id); onEvent?.(`layer:${layer.id}`) }}
onVisibilityChange={(layer, next) => onEvent?.(`layer-visible:${layer.id}:${next}`)}
/>
<SWHeaderColorMenu
value={color}
colors={colors}
mode={colorMode}
onColorSelect={option => { setColor({ value: option.label ?? option.color, swatch: option.color }); setColorMode(null); onEvent?.(`color:${option.id}`) }}
onModeChange={mode => { setColorMode(mode); onEvent?.(`colorMode:${mode}`) }}
/>
</div>
<div className="app-sw-window">
{/* K only: the existing actions pill with print removed. */}
<SWHeaderActions showPrint={false} onPopupGuide={() => onEvent?.("popupGuide")} />
</div>
</SWTheme>
)
}