Skip to content

Commit 85abaf2

Browse files
authored
fix: classname color not applying (#60)
1 parent a214426 commit 85abaf2

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

.changeset/strong-pants-act.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@jengaicons/react": minor
3+
---
4+
5+
fix: classname color not applying

examples/next-ts-app-dir/app/page.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default function Home() {
77
<ActivityFill color='blue' />
88
<Record />
99
<RecordFill size={300} className='stroke-black' />
10+
<Record size={300} className='text-purple-200' />
1011
</div>
1112
</main>
1213
)

scripts/generate-jengaicons-react/transform.tsx

+19-11
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ const genSVG = (childrenAST: svgson.INode[], data: TransformData) => {
2424
case "stroke":
2525
case "fill":
2626
// check if the value is a hex color
27-
if (/^#.+/.test(attrVal))
28-
_attrVal = `{color || colorCtx || "${data.defaultColor}"}`
27+
if (/^#.+/.test(attrVal)) _attrVal = `{_color}`
2928
break
3029

3130
// Replace StrokeWidth for weight prop
3231
case "strokeWidth":
33-
if (data.variant === "regular")
34-
_attrVal = `{weight || weightCtx || "${data.defaultWeight}"}`
32+
if (data.variant === "regular") _attrVal = `{_weight}`
3533
else _attrVal = `"${data.defaultWeight}"`
3634
break
3735
}
@@ -50,13 +48,16 @@ style={{
5048
...styleCtx,
5149
...style,
5250
...props.style,
53-
}}`
51+
}}
52+
color={_color}
53+
`
5454

5555
const getRegularComponent = (
5656
transformData: TransformData,
5757
svgAST: svgson.INode,
5858
) => {
59-
const { componentName, defaultSize, defaultWeight } = transformData
59+
const { componentName, defaultSize, defaultWeight, defaultColor } =
60+
transformData
6061

6162
return `
6263
import * as React from 'react'
@@ -82,10 +83,13 @@ const getRegularComponent = (
8283
style: styleCtx
8384
} = useContext(JengaIconContext as Context<JengaIconRegularProps>)
8485
86+
const _size = size || sizeCtx || ${defaultSize}
87+
const _weight = weight || weightCtx || ${defaultWeight}
88+
const _color = color || colorCtx || "${defaultColor}"
8589
8690
return <svg
87-
width={size || sizeCtx || ${defaultSize}}
88-
height={size || sizeCtx || ${defaultSize}}
91+
width={_size}
92+
height={_size}
8993
strokeWidth={weight || weightCtx || ${defaultWeight}}
9094
ref={ref}
9195
${genAttrString(svgAST.attributes)}
@@ -110,7 +114,7 @@ const getFillComponent = (
110114
transformData: TransformData,
111115
svgAST: svgson.INode,
112116
) => {
113-
const { componentName, defaultSize } = transformData
117+
const { componentName, defaultSize, defaultColor } = transformData
114118

115119
return `
116120
import * as React from 'react'
@@ -135,10 +139,14 @@ const getFillComponent = (
135139
style: styleCtx
136140
} = useContext(JengaIconContext)
137141
142+
143+
const _size = size || sizeCtx || ${defaultSize}
144+
const _color = color || colorCtx || "${defaultColor}"
145+
138146
139147
return <svg
140-
width={size || sizeCtx || ${defaultSize}}
141-
height={size || sizeCtx || ${defaultSize}}
148+
width={_size}
149+
height={_size}
142150
ref={ref}
143151
${genAttrString(svgAST.attributes)}
144152
${CommonSVGRootProps}

0 commit comments

Comments
 (0)