()
| 151 | |
| 152 | // Generate styled-components with improved naming and formatting |
| 153 | export 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 |
| 180 | export function getReactComponentName(node: any): string { |
no outgoing calls
no test coverage detected