transformMenu() — ui Function Reference
Architecture documentation for the transformMenu() function in transform-menu.ts from the ui codebase.
Entity Profile
Dependency Diagram
graph TD e42ddf56_51cb_f09b_4144_99b83f037386["transformMenu()"] f4ce2b89_2584_affd_7f0d_945da4db1c0b["transform-menu.ts"] e42ddf56_51cb_f09b_4144_99b83f037386 -->|defined in| f4ce2b89_2584_affd_7f0d_945da4db1c0b style e42ddf56_51cb_f09b_4144_99b83f037386 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/shadcn/src/utils/transformers/transform-menu.ts lines 7–49
export const transformMenu: Transformer = async ({ sourceFile, config }) => {
const menuColor = config.menuColor
// If menuColor is not set or is "default", we remove the placeholder.
const replacement = menuColor === "inverted" ? "dark" : ""
for (const attr of sourceFile.getDescendantsOfKind(SyntaxKind.JsxAttribute)) {
const attrName = attr.getNameNode().getText()
if (attrName !== "className") {
continue
}
const initializer = attr.getInitializer()
if (!initializer) {
continue
}
const text = initializer.getText()
if (!text.includes("cn-menu-target")) {
continue
}
// Replace cn-menu-target with the replacement value.
let newText = text.replace(/cn-menu-target/g, replacement)
// Clean up extra spaces if we removed the class.
if (!replacement) {
// Remove double spaces.
newText = newText.replace(/\s{2,}/g, " ")
// Clean up leading/trailing spaces in strings.
newText = newText.replace(/"\s+/g, '"')
newText = newText.replace(/\s+"/g, '"')
// Clean up empty strings in cn() calls.
newText = newText.replace(/,\s*""\s*,/g, ",")
newText = newText.replace(/\(\s*""\s*,/g, "(")
newText = newText.replace(/,\s*""\s*\)/g, ")")
}
attr.setInitializer(newText)
}
return sourceFile
}
Domain
Subdomains
Source
Frequently Asked Questions
What does transformMenu() do?
transformMenu() is a function in the ui codebase, defined in packages/shadcn/src/utils/transformers/transform-menu.ts.
Where is transformMenu() defined?
transformMenu() is defined in packages/shadcn/src/utils/transformers/transform-menu.ts at line 7.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free