Skip to content

Commit a5ffaf6

Browse files
committed
simplify logic into more generic prop
1 parent 0ffa255 commit a5ffaf6

2 files changed

Lines changed: 11 additions & 17 deletions

File tree

packages/react-icons/src/__tests__/createIcon.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ test('sets correct svgClassName by default', () => {
6565
expect(screen.getByRole('img', { hidden: true })).toHaveClass('pf-v6-icon-rh-standard');
6666
});
6767

68-
test('sets svgClassName when noStandardSetStyling is false', () => {
69-
render(<RhStandardIcon noStandardSetStyling={false} />);
68+
test('sets svgClassName when noDefaultStyle is false', () => {
69+
render(<RhStandardIcon noDefaultStyle={false} />);
7070
expect(screen.getByRole('img', { hidden: true })).toHaveClass('pf-v6-icon-rh-standard');
7171
});
7272

73-
test('does not set svgClassName when noStandardSetStyling is true', () => {
74-
render(<RhStandardIcon noStandardSetStyling />);
73+
test('does not set svgClassName when noDefaultStyle is true', () => {
74+
render(<RhStandardIcon noDefaultStyle />);
7575
expect(screen.getByRole('img', { hidden: true })).not.toHaveClass('pf-v6-icon-rh-standard');
7676
});
7777

packages/react-icons/src/createIcon.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ export interface CreateIconProps {
2424
export interface SVGIconProps extends Omit<React.HTMLProps<SVGElement>, 'ref'> {
2525
title?: string;
2626
className?: string;
27-
/* Indicates the icon should render using alternate svg data for unified theme */
27+
/** Indicates the icon should render using alternate svg data for the unified theme */
2828
set?: 'default' | 'rh-ui';
29-
/** Applicable to RH standard icons only. Indicates the icon should render without the standard set styling. */
30-
noStandardSetStyling?: boolean;
29+
/** Indicates the icon should render without its default styling specified in its IconDefinition.svgClassName. */
30+
noDefaultStyle?: boolean;
3131
}
3232

3333
let currentId = 0;
@@ -73,15 +73,15 @@ export function createIcon({ name, icon, rhUiIcon = null }: CreateIconProps): Re
7373
id = `icon-title-${currentId++}`;
7474

7575
static defaultProps: SVGIconProps = {
76-
noStandardSetStyling: false
76+
noDefaultStyle: false
7777
};
7878

7979
constructor(props: SVGIconProps) {
8080
super(props);
8181
}
8282

8383
render() {
84-
const { title, className: propsClassName, set, noStandardSetStyling, ...props } = this.props;
84+
const { title, className: propsClassName, set, noDefaultStyle, ...props } = this.props;
8585

8686
const hasTitle = Boolean(title);
8787
const classNames = ['pf-v6-svg'];
@@ -104,14 +104,8 @@ export function createIcon({ name, icon, rhUiIcon = null }: CreateIconProps): Re
104104
const _yOffset = yOffset ?? 0;
105105
const viewBox = [_xOffset, _yOffset, width, height].join(' ');
106106

107-
if (svgClassName) {
108-
if (svgClassName !== 'pf-v6-icon-rh-standard') {
109-
classNames.push(svgClassName);
110-
} else {
111-
if (!noStandardSetStyling) {
112-
classNames.push(svgClassName);
113-
}
114-
}
107+
if (svgClassName && !noDefaultStyle) {
108+
classNames.push(svgClassName);
115109
}
116110

117111
const svgPaths =

0 commit comments

Comments
 (0)