Skip to content

Commit

Permalink
Fix types of toaster icons (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilkowalski authored Jan 14, 2024
1 parent 2282469 commit 7c19a8c
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 56 deletions.
15 changes: 2 additions & 13 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const Toast = (props: ToastProps) => {
loadingIcon: loadingIconProp,
expandByDefault,
classNames,
icons,
closeButtonAriaLabel = 'Close toast',
} = props;
const [mounted, setMounted] = React.useState(false);
Expand Down Expand Up @@ -194,13 +193,6 @@ const Toast = (props: ToastProps) => {
}, [deleteToast, toast.delete]);

function getLoadingIcon() {
if (icons.loading) {
return (
<div className="loader" data-visible={toastType === 'loading'}>
{icons.loading}
</div>
);
}
if (loadingIconProp) {
return (
<div className="loader" data-visible={toastType === 'loading'}>
Expand Down Expand Up @@ -340,9 +332,8 @@ const Toast = (props: ToastProps) => {
<>
{toastType || toast.icon || toast.promise ? (
<div data-icon="">
{toast.promise || toastType === 'loading'
? toast.icon || icons.loading || getLoadingIcon()
: toast.icon || icons?.[toastType] || getAsset(toastType)}
{(toast.promise || toast.type === 'loading') && !toast.icon ? getLoadingIcon() : null}
{toast.icon || getAsset(toastType)}
</div>
) : null}

Expand Down Expand Up @@ -432,7 +423,6 @@ const Toaster = (props: ToasterProps) => {
dir = getDocumentDirection(),
gap,
loadingIcon,
icons,
containerAriaLabel = 'Notifications',
} = props;
const [toasts, setToasts] = React.useState<ToastT[]>([]);
Expand Down Expand Up @@ -653,7 +643,6 @@ const Toaster = (props: ToasterProps) => {
expandByDefault={expand}
gap={gap}
loadingIcon={loadingIcon}
icons={icons}
expanded={expanded}
/>
))}
Expand Down
18 changes: 0 additions & 18 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ export interface ToastClassnames {
default?: string;
}

export interface ToastIcons {
success?: React.ReactNode;
info?: React.ReactNode;
warning?: React.ReactNode;
error?: React.ReactNode;
loading?: React.ReactNode;
}

export interface ToastT {
id: number | string;
title?: string | React.ReactNode;
Expand Down Expand Up @@ -103,17 +95,8 @@ export interface ToasterProps {
style?: React.CSSProperties;
offset?: string | number;
dir?: 'rtl' | 'ltr' | 'auto';
/**
* @deprecated Please use the `icons` prop instead:
* ```jsx
* <Toaster
* icons={{ loading: <LoadingIcon /> }}
* />
* ```
*/
loadingIcon?: React.ReactNode;
containerAriaLabel?: string;
icons?: ToastIcons;
}

export interface ToastProps {
Expand All @@ -140,7 +123,6 @@ export interface ToastProps {
descriptionClassName?: string;
loadingIcon?: React.ReactNode;
classNames?: ToastClassnames;
icons?: ToastIcons;
closeButtonAriaLabel?: string;
}

Expand Down
24 changes: 0 additions & 24 deletions website/src/pages/styling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,3 @@ Styling per toast type is also possible.
}}
/>
```

## Changing Icons

You can change the default icons using the `icons` prop:

```jsx
<Toaster
icons={{
success: <SuccessIcon />,
info: <InfoIcon />,
warning: <WarningIcon />,
error: <ErrorIcon />,
loading: <LoadingIcon />,
}}
/>
```

You can also set an icon for each toast:

```jsx
toast('Hello World', {
icon: <Icon />
});
```
2 changes: 1 addition & 1 deletion website/src/pages/toaster.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ Changes the directionality of the toast's text.
| invert | Dark toasts in light mode and vice versa. | `false` |
| toastOptions | These will act as default options for all toasts. See [toast()](/toast) for all available options. | `4000` |
| gap | Gap between toasts when expanded | `14` |
| icons | Changes the default icons | `-` |
| loadingIcon | Changes the default loading icon | `-` |

1 comment on commit 7c19a8c

@vercel
Copy link

@vercel vercel bot commented on 7c19a8c Jan 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.