import { IconStyle } from "@phosphor-icons/core"; import { SnippetType } from "@/lib"; export function getCodeSnippets({ name, displayName, weight, size, color, }: { name: string; displayName: string; weight: IconStyle; size: number; color: string; }): Record { const isDefaultWeight = weight === "regular"; const isDefaultColor = color === "#000000"; const elmName = displayName.replace(/^\w/, (c) => c.toLowerCase()); const elmWeight = weight.replace(/^\w/, (c) => c.toUpperCase()); return { [SnippetType.HTML]: ``, [SnippetType.REACT]: `<${displayName} size={${size}} ${ !isDefaultColor ? `color="${color}" ` : "" }${isDefaultWeight ? "" : `weight="${weight}" `}/>`, [SnippetType.VUE]: ``, [SnippetType.FLUTTER]: `Icon(\n PhosphorIcons.${displayName.replace( /^\w/, (c) => c.toLowerCase() )}${ isDefaultWeight ? "" : weight.replace(/^\w/, (c) => c.toUpperCase()) },\n size: ${size.toFixed(1)},\n${ !isDefaultColor ? ` color: Color(0xff${color.replace("#", "")}),\n` : "" })`, [SnippetType.ELM]: `Phosphor.${elmName}${ isDefaultWeight ? "" : " " + elmWeight } |> withSize ${size} |> withSizeUnit "px" |> toHtml []`, }; } export function supportsWeight({ type, weight, }: { type: SnippetType; weight: IconStyle; }): boolean { if (type !== SnippetType.HTML && type !== SnippetType.FLUTTER) return true; return weight !== IconStyle.DUOTONE; }