MCPcopy Index your code
hub / github.com/bernaferrari/FigmaToCode / generateStyledComponents

Function generateStyledComponents

packages/backend/src/html/htmlMain.ts:153–177  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

151
152// Generate styled-components with improved naming and formatting
153export function generateStyledComponents(): string {
154 const components: string[] = [];
155
156 Object.entries(cssCollection).forEach(
157 ([className, { styles, componentName, element, nodeType }]) => {
158 // Skip if no styles
159 if (!styles.length) return;
160
161 // Determine base HTML element - defaults to div
162 const baseElement = element || (nodeType === "TEXT" ? "p" : "div");
163
164 const styledComponent = `const ${componentName} = styled.${baseElement}\`
165 ${styles.join(";\n ")}${styles.length ? ";" : ""}
166\`;`;
167
168 components.push(styledComponent);
169 },
170 );
171
172 if (components.length === 0) {
173 return "";
174 }
175
176 return `${components.join("\n\n")}`;
177}
178
179// Get a valid React component name from a layer name
180export function getReactComponentName(node: any): string {

Callers 1

generateReactComponentFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected