Skip to content

Commit aea36ea

Browse files
committed
add comments for functions
1 parent 613a6b2 commit aea36ea

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

packages/react-icons/src/createIcon.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export interface SVGIconProps extends Omit<React.HTMLProps<SVGElement>, 'ref'> {
5151

5252
let currentId = 0;
5353

54+
/** Returns path data from `svgPathData` or deprecated `svgPath` (prefers `svgPathData` when both exist). */
5455
function resolveSvgPathData(icon: IconDefinition): string | SVGPathObject[] {
5556
if ('svgPathData' in icon && icon.svgPathData !== undefined) {
5657
return icon.svgPathData;
@@ -61,6 +62,7 @@ function resolveSvgPathData(icon: IconDefinition): string | SVGPathObject[] {
6162
throw new Error('@patternfly/react-icons: IconDefinition must define svgPathData or svgPath');
6263
}
6364

65+
/** Produces a single {@link IconDefinitionWithSvgPathData} for internal rendering. */
6466
function normalizeIconDefinition(icon: IconDefinition): IconDefinitionWithSvgPathData {
6567
return {
6668
name: icon.name,
@@ -73,6 +75,7 @@ function normalizeIconDefinition(icon: IconDefinition): IconDefinitionWithSvgPat
7375
};
7476
}
7577

78+
/** True when the argument uses the nested `CreateIconProps` shape (`icon` and/or `rhUiIcon` keys). */
7679
function isNestedCreateIconProps(arg: object): arg is CreateIconProps {
7780
return 'icon' in arg || 'rhUiIcon' in arg;
7881
}
@@ -84,6 +87,10 @@ interface NormalizedCreateIconProps {
8487
rhUiIcon: IconDefinitionWithSvgPathData | null;
8588
}
8689

90+
/**
91+
* Coerces legacy flat or nested props into normalized {@link NormalizedCreateIconProps}.
92+
* Nested input must include a non-null `icon` or throws.
93+
*/
8794
function normalizeCreateIconArg(arg: CreateIconProps | LegacyFlatIconDefinition): NormalizedCreateIconProps {
8895
if (isNestedCreateIconProps(arg)) {
8996
const p = arg as CreateIconProps;
@@ -106,6 +113,7 @@ function normalizeCreateIconArg(arg: CreateIconProps | LegacyFlatIconDefinition)
106113
};
107114
}
108115

116+
/** Renders an inner `<svg>` with viewBox and path(s) for the dual-SVG (CSS swap) layout. */
109117
const createSvg = (icon: IconDefinitionWithSvgPathData, iconClassName: string) => {
110118
const { xOffset, yOffset, width, height, svgPathData, svgClassName } = icon ?? {};
111119
const _xOffset = xOffset ?? 0;
@@ -170,6 +178,7 @@ export function createIcon(arg: CreateIconProps | LegacyFlatIconDefinition): Rea
170178

171179
id = `icon-title-${currentId++}`;
172180

181+
/** Renders one root `<svg>`; either a single variant or nested inner SVGs for RH UI swap. */
173182
render() {
174183
const { title, className: propsClassName, set, ...props } = this.props;
175184

0 commit comments

Comments
 (0)