"use client"; /** * Figma: "Asset / Diagram Glyph" (25359:65776) */ import Image from "next/image"; import { memo } from "react"; import AdviceGlyph from "./advice.svg"; import AuthorityGlyph from "./authority.svg"; import ConflictGlyph from "./conflict.svg"; import ConsensusGlyph from "./consensus.svg"; import DiscussionGlyph from "./discussion.svg"; import GroupGlyph from "./group.svg"; import LadderGlyph from "./ladder.svg"; import MembraneGlyph from "./membrane.svg"; import MoneyGlyph from "./money.svg"; import PersonGlyph from "./person.svg"; import PodGlyph from "./pod.svg"; import PrivacyGlyph from "./privacy.svg"; import RecordsGlyph from "./records.svg"; import RotationGlyph from "./rotation.svg"; import SortitionGlyph from "./sortition.svg"; import TermGlyph from "./term.svg"; import VoteGlyph from "./vote.svg"; export const DIAGRAM_GLYPH_OPTIONS = [ "group", "pod", "membrane", "person", "authority", "advice", "rotation", "ladder", "conflict", "consensus", "vote", "sortition", "term", "discussion", "records", "privacy", "money", ] as const; export type DiagramGlyphName = (typeof DIAGRAM_GLYPH_OPTIONS)[number]; export const DIAGRAM_GLYPH_SIZE_OPTIONS = [24, 48] as const; export type DiagramGlyphSize = (typeof DIAGRAM_GLYPH_SIZE_OPTIONS)[number]; type SvgComponent = | React.ComponentType> | { default: React.ComponentType> }; const glyphMap: Record = { group: GroupGlyph, pod: PodGlyph, membrane: MembraneGlyph, person: PersonGlyph, authority: AuthorityGlyph, advice: AdviceGlyph, rotation: RotationGlyph, ladder: LadderGlyph, conflict: ConflictGlyph, consensus: ConsensusGlyph, vote: VoteGlyph, sortition: SortitionGlyph, term: TermGlyph, discussion: DiscussionGlyph, records: RecordsGlyph, privacy: PrivacyGlyph, money: MoneyGlyph, }; function resolveSvgComponent(module: SvgComponent) { if (typeof module === "object" && module !== null && "default" in module) { return ( module as { default: React.ComponentType>; } ).default; } return module as React.ComponentType>; } export interface DiagramGlyphProps { glyph: DiagramGlyphName; className?: string; /** Width and height. Figma grid is 48; diagrams also use 24. */ size?: DiagramGlyphSize | number; /** * Accessible name when the glyph sits in a diagram. Omit for a decorative * mark (empty alt / `aria-hidden`). */ title?: string; /** Follows `title` when the glyph is named in a diagram. */ description?: string; } function DiagramGlyphComponent({ glyph, className = "", size = 48, title, description, }: DiagramGlyphProps) { const SvgModule = glyphMap[glyph]; if (!SvgModule) return null; const resolved = resolveSvgComponent(SvgModule); const decorative = !title; const label = [title, description].filter(Boolean).join(". "); if (typeof resolved === "string") { return ( {decorative ); } if (resolved == null) return null; const Svg = resolved as React.ComponentType>; if (decorative) { return ( ); } return ( ); } const DiagramGlyph = memo(DiagramGlyphComponent); DiagramGlyph.displayName = "DiagramGlyph"; export default DiagramGlyph;