Skip to content

Commit

Permalink
Merge pull request #10552 from marmelab/fix-button-icon-prop-type
Browse files Browse the repository at this point in the history
[TypeScript] Fix buttons `icon` prop type
  • Loading branch information
fzaninotto authored Feb 28, 2025
2 parents 2be72f4 + 2d76032 commit ba8d76d
Show file tree
Hide file tree
Showing 21 changed files with 34 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Fragment, ReactElement, useState } from 'react';
import { Fragment, useState } from 'react';
import ActionDelete from '@mui/icons-material/Delete';

import { alpha, styled } from '@mui/material/styles';
Expand Down Expand Up @@ -159,7 +159,7 @@ export interface BulkDeleteWithConfirmButtonProps<
confirmContent?: React.ReactNode;
confirmTitle?: React.ReactNode;
confirmColor?: 'primary' | 'warning';
icon?: ReactElement;
icon?: React.ReactNode;
mutationMode: MutationMode;
mutationOptions?: UseMutationOptions<
RecordType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { ReactElement } from 'react';
import ActionDelete from '@mui/icons-material/Delete';
import { alpha, styled } from '@mui/material/styles';
import {
Expand Down Expand Up @@ -110,7 +109,7 @@ export interface BulkDeleteWithUndoButtonProps<
RecordType extends RaRecord = any,
MutationOptionsError = unknown,
> extends ButtonProps {
icon?: ReactElement;
icon?: React.ReactNode;
mutationOptions?: UseMutationOptions<
RecordType,
MutationOptionsError,
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/button/BulkExportButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const sanitizeRestProps = ({

interface Props {
exporter?: Exporter;
icon?: JSX.Element;
icon?: React.ReactNode;
label?: string;
onClick?: (e: Event) => void;
resource?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Fragment, useState, ReactElement } from 'react';
import { Fragment, useState } from 'react';
import ActionUpdate from '@mui/icons-material/Update';

import { alpha, styled } from '@mui/material/styles';
Expand Down Expand Up @@ -156,7 +156,7 @@ export interface BulkUpdateWithConfirmButtonProps<
> extends ButtonProps {
confirmContent?: React.ReactNode;
confirmTitle?: React.ReactNode;
icon?: ReactElement;
icon?: React.ReactNode;
data: any;
onSuccess?: () => void;
onError?: (error: any) => void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { ReactElement } from 'react';
import ActionUpdate from '@mui/icons-material/Update';
import { alpha, styled } from '@mui/material/styles';
import {
Expand Down Expand Up @@ -117,7 +116,7 @@ export interface BulkUpdateWithUndoButtonProps<
RecordType extends RaRecord = any,
MutationOptionsError = unknown,
> extends ButtonProps {
icon?: ReactElement;
icon?: React.ReactNode;
data: any;
onSuccess?: () => void;
onError?: (error: any) => void;
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const Button = <RootComponent extends React.ElementType = 'button'>(

interface Props<RootComponent extends React.ElementType> {
alignIcon?: 'left' | 'right';
children?: React.ReactElement;
children?: React.ReactNode;
className?: string;
component?: RootComponent;
to?: LocationDescriptor | To;
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/button/CloneButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { memo, ReactElement } from 'react';
import { memo, ReactNode } from 'react';
import Queue from '@mui/icons-material/Queue';
import { Link } from 'react-router-dom';
import { stringify } from 'query-string';
Expand Down Expand Up @@ -56,7 +56,7 @@ const sanitizeRestProps = ({

interface Props {
record?: any;
icon?: ReactElement;
icon?: ReactNode;
scrollToTop?: boolean;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/button/CreateButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const defaultIcon = <ContentAdd />;

interface Props {
resource?: string;
icon?: React.ReactElement;
icon?: React.ReactNode;
scrollToTop?: boolean;
to?: LocationDescriptor | To;
}
Expand Down
3 changes: 1 addition & 2 deletions packages/ra-ui-materialui/src/button/DeleteButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { ReactElement } from 'react';
import { UseMutationOptions } from '@tanstack/react-query';
import {
RaRecord,
Expand Down Expand Up @@ -98,7 +97,7 @@ export interface DeleteButtonProps<
confirmTitle?: React.ReactNode;
confirmContent?: React.ReactNode;
confirmColor?: 'primary' | 'warning';
icon?: ReactElement;
icon?: React.ReactNode;
mutationMode?: MutationMode;
mutationOptions?: UseMutationOptions<
RecordType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Fragment, ReactEventHandler, ReactElement } from 'react';
import React, { Fragment, ReactEventHandler } from 'react';
import ActionDelete from '@mui/icons-material/Delete';
import clsx from 'clsx';

Expand Down Expand Up @@ -104,8 +104,8 @@ export interface DeleteWithConfirmButtonProps<
> extends ButtonProps {
confirmTitle?: React.ReactNode;
confirmContent?: React.ReactNode;
icon?: React.ReactNode;
confirmColor?: 'primary' | 'warning';
icon?: ReactElement;
mutationMode?: MutationMode;
onClick?: ReactEventHandler<any>;
// May be injected by Toolbar - sanitized in Button
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/button/DeleteWithUndoButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { ReactElement, ReactEventHandler } from 'react';
import { ReactNode, ReactEventHandler } from 'react';
import ActionDelete from '@mui/icons-material/Delete';
import clsx from 'clsx';
import { UseMutationOptions } from '@tanstack/react-query';
Expand Down Expand Up @@ -61,7 +61,7 @@ export interface DeleteWithUndoButtonProps<
RecordType extends RaRecord = any,
MutationOptionsError = unknown,
> extends ButtonProps {
icon?: ReactElement;
icon?: ReactNode;
onClick?: ReactEventHandler<any>;
mutationOptions?: UseMutationOptions<
RecordType,
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/button/EditButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { ReactElement } from 'react';
import { ReactNode } from 'react';
import clsx from 'clsx';
import { styled } from '@mui/material/styles';
import ContentCreate from '@mui/icons-material/Create';
Expand Down Expand Up @@ -77,7 +77,7 @@ const defaultIcon = <ContentCreate />;
const stopPropagation = e => e.stopPropagation();

interface Props<RecordType extends RaRecord = any> {
icon?: ReactElement;
icon?: ReactNode;
label?: string;
record?: RecordType;
resource?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/button/ExportButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const sanitizeRestProps = ({

interface Props {
exporter?: Exporter;
icon?: JSX.Element;
icon?: React.ReactNode;
label?: string;
maxResults?: number;
onClick?: (e: Event) => void;
Expand Down
3 changes: 1 addition & 2 deletions packages/ra-ui-materialui/src/button/ListButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { ReactElement } from 'react';
import ActionList from '@mui/icons-material/List';
import { Link } from 'react-router-dom';
import { useResourceContext, useCreatePath, useCanAccess } from 'ra-core';
Expand Down Expand Up @@ -78,7 +77,7 @@ const scrollStates = {
const defaultIcon = <ActionList />;

interface Props {
icon?: ReactElement;
icon?: React.ReactNode;
label?: string;
resource?: string;
scrollToTop?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/button/RefreshButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { ReactElement, MouseEvent, useCallback } from 'react';
import { MouseEvent, useCallback } from 'react';
import NavigationRefresh from '@mui/icons-material/Refresh';
import { useRefresh } from 'ra-core';

Expand Down Expand Up @@ -35,7 +35,7 @@ const defaultIcon = <NavigationRefresh />;

interface Props {
label?: string;
icon?: ReactElement;
icon?: React.ReactNode;
onClick?: (e: MouseEvent) => void;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/button/RefreshIconButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { useCallback, ReactElement } from 'react';
import { useCallback } from 'react';
import Tooltip from '@mui/material/Tooltip';
import IconButton, { IconButtonProps } from '@mui/material/IconButton';
import NavigationRefresh from '@mui/icons-material/Refresh';
Expand Down Expand Up @@ -45,7 +45,7 @@ const defaultIcon = <NavigationRefresh />;

interface Props {
className?: string;
icon?: ReactElement;
icon?: React.ReactNode;
label?: string;
onClick?: (e: MouseEvent) => void;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/ra-ui-materialui/src/button/SaveButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { MouseEventHandler, ReactElement, useCallback } from 'react';
import { MouseEventHandler, useCallback } from 'react';
import { UseMutationOptions } from '@tanstack/react-query';
import { styled } from '@mui/material/styles';
import { Button, ButtonProps, CircularProgress } from '@mui/material';
Expand All @@ -24,7 +24,7 @@ import {
* @prop {string} label Button label. Defaults to 'ra.action.save', translated.
* @prop {boolean} disabled Disable the button.
* @prop {string} variant Material UI variant for the button. Defaults to 'contained'.
* @prop {ReactElement} icon
* @prop {ReactNode} icon
* @prop {function} mutationOptions Object of options passed to react-query.
* @prop {function} transform Callback to execute before calling the dataProvider. Receives the data from the form, must return that transformed data. Can be asynchronous (and return a Promise)
* @prop {boolean} alwaysEnable Force enabling the <SaveButton>. If it's not defined, the `<SaveButton>` will be enabled using `react-hook-form`'s `isValidating` state props and form context's `saving` prop (disabled if isValidating or saving, enabled otherwise).
Expand Down Expand Up @@ -159,7 +159,7 @@ interface Props<
> {
className?: string;
disabled?: boolean;
icon?: ReactElement;
icon?: React.ReactNode;
invalid?: boolean;
label?: string;
mutationOptions?: UseMutationOptions<
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/button/ShowButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { memo, ReactElement } from 'react';
import { memo } from 'react';
import ImageEye from '@mui/icons-material/RemoveRedEye';
import { Link } from 'react-router-dom';
import {
Expand Down Expand Up @@ -76,7 +76,7 @@ const defaultIcon = <ImageEye />;
const stopPropagation = e => e.stopPropagation();

interface Props<RecordType extends RaRecord = any> {
icon?: ReactElement;
icon?: React.ReactNode;
label?: string;
record?: RecordType;
resource?: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/button/SortButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { ReactElement, memo } from 'react';
import { memo } from 'react';
import clsx from 'clsx';
import {
Button,
Expand Down Expand Up @@ -172,7 +172,7 @@ const arePropsEqual = (prevProps, nextProps) =>
export interface SortButtonProps {
className?: string;
fields: string[];
icon?: ReactElement;
icon?: React.ReactNode;
label?: string;
resource?: string;
sx?: SxProps;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Fragment, useState, ReactElement } from 'react';
import { Fragment, useState } from 'react';
import ActionUpdate from '@mui/icons-material/Update';

import { alpha, styled } from '@mui/material/styles';
Expand Down Expand Up @@ -157,7 +157,7 @@ export interface UpdateWithConfirmButtonProps<
> extends ButtonProps {
confirmContent?: React.ReactNode;
confirmTitle?: React.ReactNode;
icon?: ReactElement;
icon?: React.ReactNode;
data: any;
mutationMode?: MutationMode;
mutationOptions?: UseMutationOptions<
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from 'react';
import { alpha, styled } from '@mui/material/styles';
import { ReactElement } from 'react';
import ActionUpdate from '@mui/icons-material/Update';
import {
useRefresh,
Expand Down Expand Up @@ -113,7 +112,7 @@ export interface UpdateWithUndoButtonProps<
RecordType extends RaRecord = any,
MutationOptionsError = unknown,
> extends ButtonProps {
icon?: ReactElement;
icon?: React.ReactNode;
data: any;
mutationOptions?: UseMutationOptions<
RecordType,
Expand Down

0 comments on commit ba8d76d

Please sign in to comment.