Skip to content

Commit 58797eb

Browse files
authored
Fix incorrect code panel content for icons (#109)
1 parent 1eafb22 commit 58797eb

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/utils/code.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,21 @@ const buildBlock = ({
4646
const componentName = capitalize(childComponent.type)
4747
let propsContent = ''
4848

49-
const propsNames = Object.keys(childComponent.props)
49+
const propsNames = Object.keys(childComponent.props).filter(propName => {
50+
if (childComponent.type === 'Icon') {
51+
return propName !== 'icon'
52+
}
53+
54+
return true
55+
})
5056

5157
propsNames.forEach((propName: string) => {
5258
const propsValue = childComponent.props[propName]
5359

54-
if (propName.toLowerCase().includes('icon')) {
60+
if (
61+
propName.toLowerCase().includes('icon') &&
62+
childComponent.type !== 'Icon'
63+
) {
5564
if (Object.keys(icons).includes(propsValue)) {
5665
let operand = `={<${propsValue} />}`
5766

@@ -79,6 +88,8 @@ const buildBlock = ({
7988
childComponent.children.length === 0
8089
) {
8190
content += `<${componentName} ${propsContent}>${childComponent.props.children}</${componentName}>`
91+
} else if (childComponent.type === 'Icon') {
92+
content += `<${childComponent.props.icon} ${propsContent} />`
8293
} else if (childComponent.children.length) {
8394
content += `<${componentName} ${propsContent}>
8495
${buildBlock({ component: childComponent, components, forceBuildBlock })}
@@ -152,7 +163,7 @@ const getIconsImports = (components: IComponents) => {
152163
export const generateCode = async (components: IComponents) => {
153164
let code = buildBlock({ component: components.root, components })
154165
let componentsCodes = buildComponents(components)
155-
const iconImports = getIconsImports(components)
166+
const iconImports = [...new Set(getIconsImports(components))]
156167

157168
const imports = [
158169
...new Set(

0 commit comments

Comments
 (0)