Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: normalize renderIcon types #18683

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions packages/react/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2016, 2023
* Copyright IBM Corp. 2016, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -88,8 +88,7 @@ export interface ButtonBaseProps
rel?: React.AnchorHTMLAttributes<HTMLAnchorElement>['rel'];

/**
* Optional prop to allow overriding the icon rendering.
* Can be a React component class
* A component used to render an icon.
*/
renderIcon?: React.ElementType;

Expand Down Expand Up @@ -344,8 +343,7 @@ const Button: ButtonComponent = React.forwardRef(
rel: PropTypes.string,

/**
* Optional prop to allow overriding the icon rendering.
* Can be a React component class
* A component used to render an icon.
*/
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),

Expand Down
9 changes: 4 additions & 5 deletions packages/react/src/components/ChatButton/ChatButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2024
* Copyright IBM Corp. 2024, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -45,9 +45,9 @@ export interface ChatButtonProps
* Specify the kind of `ChatButton` you want to create
*/
kind?: ChatButtonKind;

/**
* Optional prop to specify an icon to be rendered.
* Can be a React component class
* A component used to render an icon.
*/
renderIcon?: ComponentType | FunctionComponent;
/**
Expand Down Expand Up @@ -142,8 +142,7 @@ ChatButton.propTypes = {
]),

/**
* Optional prop to specify an icon to be rendered.
* Can be a React component class
* A component used to render an icon.
*/
// @ts-expect-error: PropTypes are not expressive enough to cover this case
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2022
* Copyright IBM Corp. 2022, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -42,7 +42,7 @@ interface ContainedListItemProps {
onClick?: () => void;

/**
* Provide an optional icon to render in front of the item's content.
* A component used to render an icon.
*/
renderIcon?: ComponentType | FunctionComponent;
}
Expand Down Expand Up @@ -130,7 +130,7 @@ ContainedListItem.propTypes = {
onClick: PropTypes.func,

/**
* Provide an optional icon to render in front of the item's content.
* A component used to render an icon.
*/
// @ts-expect-error: PropTypes are not expressive enough to cover this case
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2016, 2023
* Copyright IBM Corp. 2016, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand All @@ -24,7 +24,7 @@ export interface TableBatchActionProps
iconDescription?: string;

/**
* Optional function to render your own icon in the underlying button
* A component used to render an icon.
*/
renderIcon?: React.ElementType;
}
Expand Down Expand Up @@ -61,7 +61,7 @@ TableBatchAction.propTypes = {
},

/**
* Optional function to render your own icon in the underlying button
* A component used to render an icon.
*/
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2016, 2023
* Copyright IBM Corp. 2016, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -34,7 +34,7 @@ export interface TableToolbarMenuProps
menuOptionsClass?: string;

/**
* Optional prop to allow overriding the default menu icon
* A component used to render an icon.
*/
renderIcon?: any;
}
Expand Down Expand Up @@ -90,7 +90,7 @@ TableToolbarMenu.propTypes = {
menuOptionsClass: PropTypes.string,

/**
* Optional prop to allow overriding the default menu icon
* A component used to render an icon.
*/
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
};
Expand Down
8 changes: 3 additions & 5 deletions packages/react/src/components/Link/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2016, 2023
* Copyright IBM Corp. 2016, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -51,8 +51,7 @@ export interface LinkBaseProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
inline?: boolean;

/**
* @description Optional prop to render an icon next to the link.
* Can be a React component class
* A component used to render an icon.
*/
renderIcon?: ComponentType;

Expand Down Expand Up @@ -168,8 +167,7 @@ const Link: LinkComponent = React.forwardRef(
inline: PropTypes.bool,

/**
* Optional prop to render an icon next to the link.
* Can be a React component class
* A component used to render an icon.
*/
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),

Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/components/Menu/MenuItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2023
* Copyright IBM Corp. 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -77,7 +77,7 @@ export interface MenuItemProps extends LiHTMLAttributes<HTMLLIElement> {
) => void;

/**
* Only applicable if the parent menu is in `basic` mode. Sets the menu item's icon.
* A component used to render an icon.
*/
renderIcon?: FC;

Expand Down Expand Up @@ -322,7 +322,7 @@ MenuItem.propTypes = {
onClick: PropTypes.func,

/**
* Only applicable if the parent menu is in `basic` mode. Sets the menu item's icon.
* A component used to render an icon.
*/
// @ts-ignore-next-line -- avoid spurious (?) TS2322 error
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
Expand Down
14 changes: 4 additions & 10 deletions packages/react/src/components/Notification/Notification.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2016, 2023
* Copyright IBM Corp. 2016, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand All @@ -9,8 +9,6 @@ import PropTypes from 'prop-types';
import React, {
type ReactNode,
type MouseEvent,
type ComponentType,
type FunctionComponent,
type ButtonHTMLAttributes,
type HTMLAttributes,
useEffect,
Expand Down Expand Up @@ -171,12 +169,9 @@ export interface NotificationButtonProps
notificationType?: 'toast' | 'inline' | 'actionable';

/**
* Optional prop to allow overriding the icon rendering.
* Can be a React component class
* A component used to render an icon.
*/
renderIcon?:
| ComponentType<{ className?: string; name?: string }>
| FunctionComponent<{ className?: string; name?: string }>;
renderIcon?: React.ElementType;
}

export function NotificationButton({
Expand Down Expand Up @@ -244,8 +239,7 @@ NotificationButton.propTypes = {
notificationType: PropTypes.oneOf(['toast', 'inline', 'actionable']),

/**
* Optional prop to allow overriding the icon rendering.
* Can be a React component class
* A component used to render an icon.
*/
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),

Expand Down
15 changes: 5 additions & 10 deletions packages/react/src/components/OverflowMenu/OverflowMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2016, 2023
* Copyright IBM Corp. 2016, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand All @@ -9,7 +9,7 @@ import FloatingMenu, {
DIRECTION_BOTTOM,
DIRECTION_TOP,
} from '../../internal/FloatingMenu';
import React, { ComponentType } from 'react';
import React from 'react';
import { matches as keyCodeMatches, keys } from '../../internal/keyboard';

import ClickListener from '../../internal/ClickListener';
Expand Down Expand Up @@ -93,11 +93,6 @@ interface Offset {
left?: number | null | undefined;
}

type IconProps = {
className?: string;
'aria-label'?: string;
};

export interface OverflowMenuProps {
/**
* Specify a label to be read by screen readers on the container node
Expand Down Expand Up @@ -193,9 +188,9 @@ export interface OverflowMenuProps {
open?: boolean;

/**
* Function called to override icon rendering.
* A component used to render an icon.
*/
renderIcon?: ComponentType<IconProps>;
renderIcon?: React.ElementType;

/**
* Specify a CSS selector that matches the DOM element that should
Expand Down Expand Up @@ -358,7 +353,7 @@ class OverflowMenu extends React.Component<
open: PropTypes.bool,

/**
* Function called to override icon rendering.
* A component used to render an icon.
*/
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),

Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/components/OverflowMenu/next/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2020, 2023
* Copyright IBM Corp. 2020, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -69,7 +69,7 @@ interface OverflowMenuProps {
menuAlignment?: 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end';

/**
* Optionally provide a custom icon to be rendered on the trigger button.
* A component used to render an icon.
*/
renderIcon?: ComponentType | FunctionComponent;

Expand Down Expand Up @@ -276,7 +276,7 @@ OverflowMenu.propTypes = {
]),

/**
* Optionally provide a custom icon to be rendered on the trigger button.
* A component used to render an icon.
*/
// @ts-expect-error: PropTypes are not expressive enough to cover this case
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
Expand Down
8 changes: 3 additions & 5 deletions packages/react/src/components/Search/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2016, 2023
* Copyright IBM Corp. 2016, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -96,8 +96,7 @@ export interface SearchProps extends InputPropsBase {
placeholder?: string;

/**
* Rendered icon for the Search.
* Can be a React component class
* A component used to render an icon.
*/
renderIcon?: ComponentType | FunctionComponent;

Expand Down Expand Up @@ -358,8 +357,7 @@ Search.propTypes = {
placeholder: PropTypes.string,

/**
* Rendered icon for the Search.
* Can be a React component class
* A component used to render an icon.
*/
// @ts-expect-error: PropTypes are not expressive enough to cover this case
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
Expand Down
20 changes: 9 additions & 11 deletions packages/react/src/components/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2016, 2023
* Copyright IBM Corp. 2016, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -1176,10 +1176,9 @@ export interface TabProps extends HTMLAttributes<HTMLElement> {
renderButton?(): ReactNode;

/**
* Optional prop to render an icon next to the label.
* Can be a React component class
* A component used to render an icon.
*/
renderIcon?: ComponentType<{ size: number }>;
renderIcon?: React.ElementType;

/**
* An optional label to render under the primary tab label.
Expand Down Expand Up @@ -1479,24 +1478,23 @@ Tab.propTypes = {
*/
onKeyDown: PropTypes.func,

/*
/**
* An optional parameter to allow overriding the anchor rendering.
* Useful for using Tab along with react-router or other client
* side router libraries.
**/
*/
renderButton: PropTypes.func,

/**
* Optional prop to render an icon next to the label.
* Can be a React component class
* A component used to render an icon.
*/
// @ts-expect-error: Invalid prop type derivation
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),

/*
/**
* An optional label to render under the primary tab label.
/* This prop is only useful for contained tabs
**/
* Only useful for contained tabs.
*/
secondaryLabel: PropTypes.string,
};

Expand Down
Loading
Loading