Skip to content

Commit

Permalink
Fix Button and IconButton types when used with experimental React (#2335
Browse files Browse the repository at this point in the history
)
  • Loading branch information
connor-baer authored Dec 11, 2023
1 parent 19de567 commit 5a5eccd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-suns-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/circuit-ui': patch
---

Fixed the prop types of the Button and IconButton components when used with experimental versions of React.
11 changes: 9 additions & 2 deletions packages/circuit-ui/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
* limitations under the License.
*/

import type { ReactNode } from 'react';
import type {
ForwardRefExoticComponent,
PropsWithoutRef,
ReactNode,
RefAttributes,
} from 'react';
import type { IconComponentType } from '@sumup/icons';

import { CircuitError } from '../../util/errors.js';
Expand Down Expand Up @@ -57,7 +62,9 @@ export type ButtonProps = SharedButtonProps & {
* The Button component enables the user to perform an action or navigate
* to a different screen.
*/
export const Button = createButtonComponent<ButtonProps>(
export const Button: ForwardRefExoticComponent<
PropsWithoutRef<ButtonProps> & RefAttributes<any>
> = createButtonComponent<ButtonProps>(
'Button',
({ className, size: legacySize = 'm', stretch, ...props }) => {
const size = legacyButtonSizeMap[legacySize] || legacySize;
Expand Down
13 changes: 11 additions & 2 deletions packages/circuit-ui/components/Button/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@
* limitations under the License.
*/

import { Children, cloneElement, type ReactElement } from 'react';
import {
Children,
cloneElement,
type ForwardRefExoticComponent,
type PropsWithoutRef,
type ReactElement,
type RefAttributes,
} from 'react';
import type { IconComponentType, IconProps } from '@sumup/icons';

import { clsx } from '../../styles/clsx.js';
Expand Down Expand Up @@ -53,7 +60,9 @@ export type IconButtonProps = SharedButtonProps & {
* The IconButton component enables the user to perform an action or navigate
* to a different screen.
*/
export const IconButton = createButtonComponent<IconButtonProps>(
export const IconButton: ForwardRefExoticComponent<
PropsWithoutRef<IconButtonProps> & RefAttributes<any>
> = createButtonComponent<IconButtonProps>(
'IconButton',
({
className,
Expand Down
6 changes: 3 additions & 3 deletions packages/circuit-ui/components/Button/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

import {
forwardRef,
ButtonHTMLAttributes,
AnchorHTMLAttributes,
ReactNode,
type ButtonHTMLAttributes,
type AnchorHTMLAttributes,
type ReactNode,
} from 'react';
import type { IconComponentType } from '@sumup/icons';

Expand Down

0 comments on commit 5a5eccd

Please sign in to comment.