Skip to content

Commit d950238

Browse files
committed
more fixes from review comments
1 parent 7f2f760 commit d950238

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

packages/react-icons/src/createIcon.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function getSvgPaths(svgPathData: string | SVGPathObject[] | undefined): ReactNo
7474
}
7575

7676
const createSvg = (icon: IconDefinition, iconClassName: string) => {
77-
const { xOffset, yOffset, width, height, svgPathData, svgClassName } = icon ?? {};
77+
const { xOffset, yOffset, width, height, svgPathData, svgPath, svgClassName } = icon ?? {};
7878
const _xOffset = xOffset ?? 0;
7979
const _yOffset = yOffset ?? 0;
8080
const viewBox = [_xOffset, _yOffset, width, height].join(' ');
@@ -90,7 +90,7 @@ const createSvg = (icon: IconDefinition, iconClassName: string) => {
9090

9191
return (
9292
<svg viewBox={viewBox} className={classNames.join(' ')}>
93-
{getSvgPaths(svgPathData)}
93+
{getSvgPaths(svgPathData ?? svgPath)}
9494
</svg>
9595
);
9696
};
@@ -104,6 +104,11 @@ export function createIconBase({
104104
icon,
105105
rhUiIcon = null
106106
}: CreateIconBaseProps): React.ComponentClass<SVGIconProps> {
107+
if (icon == null) {
108+
throw new Error(
109+
`@patternfly/react-icons: createIconBase requires an \`icon\` definition (name: ${name ?? 'unknown'}).`
110+
);
111+
}
107112
return class SVGIcon extends Component<SVGIconProps> {
108113
static displayName = name;
109114

@@ -133,7 +138,7 @@ export function createIconBase({
133138

134139
if ((set === undefined && rhUiIcon === null) || set !== undefined) {
135140
const iconData = set !== undefined && set === 'rh-ui' && rhUiIcon !== null ? rhUiIcon : icon;
136-
const { xOffset, yOffset, width, height, svgPathData, svgClassName } = iconData ?? {};
141+
const { xOffset, yOffset, width, height, svgPathData, svgPath, svgClassName } = iconData ?? {};
137142
const _xOffset = xOffset ?? 0;
138143
const _yOffset = yOffset ?? 0;
139144
const viewBox = [_xOffset, _yOffset, width, height].join(' ');
@@ -155,7 +160,7 @@ export function createIconBase({
155160
{...(props as Omit<React.SVGProps<SVGElement>, 'ref'>)} // Lie.
156161
>
157162
{hasTitle && <title id={this.id}>{title}</title>}
158-
{getSvgPaths(svgPathData)}
163+
{getSvgPaths(svgPathData ?? svgPath)}
159164
</svg>
160165
);
161166
}

0 commit comments

Comments
 (0)