MCPcopy Create free account
hub / github.com/pingdotgg/t3code / createIconElement

Function createIconElement

apps/web/src/contextMenuFallback.ts:45–70  ·  view source on GitHub ↗
(name: string, tone: "neutral" | "destructive")

Source from the content-addressed store, hash-verified

43};
44
45function createIconElement(name: string, tone: "neutral" | "destructive"): SVGSVGElement | null {
46 const paths = ICON_PATHS[name];
47 if (!paths) {
48 return null;
49 }
50 const svg = document.createElementNS(SVG_NS, "svg");
51 svg.setAttribute("xmlns", SVG_NS);
52 svg.setAttribute("viewBox", "0 0 24 24");
53 svg.setAttribute("fill", "none");
54 svg.setAttribute("stroke", "currentColor");
55 svg.setAttribute("stroke-width", "2");
56 svg.setAttribute("stroke-linecap", "round");
57 svg.setAttribute("stroke-linejoin", "round");
58 svg.setAttribute(
59 "class",
60 tone === "destructive" ? "size-3.5 shrink-0" : "size-3.5 shrink-0 text-muted-foreground",
61 );
62 for (const node of paths) {
63 const child = document.createElementNS(SVG_NS, node.tag);
64 for (const [key, value] of Object.entries(node.attrs)) {
65 child.setAttribute(key, value);
66 }
67 svg.appendChild(child);
68 }
69 return svg;
70}
71
72function clampMenuPosition(menu: HTMLDivElement, preferredLeft: number, preferredTop: number) {
73 const rect = menu.getBoundingClientRect();

Callers 1

openMenuFunction · 0.85

Calls 1

appendChildMethod · 0.80

Tested by

no test coverage detected