Skip to content

Commit 06cf7c3

Browse files
committed
feat: add name prop to IconBase for dynamic class and testID generation
1 parent ae16180 commit 06cf7c3

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

generator/generate-svg.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ import IconBase from "../lib/icon-base";
147147
import weights from '../defs/${component}'
148148
149149
function ${componentName}({...props }: IconProps) {
150-
return (<IconBase {...props} weights={weights} />)
150+
return (<IconBase {...props} weights={weights} name="${icon}" />)
151151
}
152152
153153
export default ${componentName}`;

src/lib/icon-base.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ interface IconBaseProps extends IconProps {
77
IconWeight,
88
ReactElement | FC<{ duotoneColor?: string; duotoneOpacity?: number }>
99
>;
10+
name: string;
1011
}
1112

1213
function IconBase({
@@ -19,6 +20,7 @@ function IconBase({
1920
duotoneOpacity,
2021
title,
2122
titleId,
23+
name,
2224
weights,
2325
...props
2426
}: IconBaseProps) {
@@ -43,8 +45,8 @@ function IconBase({
4345
}),
4446
},
4547
]}
46-
className={`acorn-${weight}__svg-icon-phosphor`}
47-
testID={props.testID ?? 'phosphor-react-native-acorn-bold'}
48+
className={`${name}-${weight}__svg-icon-phosphor`}
49+
testID={props.testID ?? `phosphor-react-native-${name}-${weight}`}
4850
fill="currentColor"
4951
viewBox="0 0 256 256"
5052
width={size ?? contextSize}

0 commit comments

Comments
 (0)