Skip to content

An opinionated toast component for React.

Fix types of toaster icons (#294)

Emil Kowalski7c19a8c9030d
diff --git a/src/index.tsx b/src/index.tsx
index d0ba5b4..d60f56b 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -56,7 +56,6 @@ const Toast = (props: ToastProps) => {
loadingIcon: loadingIconProp,
expandByDefault,
classNames,
- icons,
closeButtonAriaLabel = 'Close toast',
} = props;
const [mounted, setMounted] = React.useState(false);
@@ -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'}>
@@ -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}
@@ -432,7 +423,6 @@ const Toaster = (props: ToasterProps) => {
dir = getDocumentDirection(),
gap,
loadingIcon,
- icons,
containerAriaLabel = 'Notifications',
} = props;
const [toasts, setToasts] = React.useState<ToastT[]>([]);
@@ -653,7 +643,6 @@ const Toaster = (props: ToasterProps) => {
expandByDefault={expand}
gap={gap}
loadingIcon={loadingIcon}
- icons={icons}
expanded={expanded}
/>
))}
diff --git a/src/types.ts b/src/types.ts
index 9a6f87c..eab1a96 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -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;
@@ -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 {
@@ -140,7 +123,6 @@ export interface ToastProps {
descriptionClassName?: string;
loadingIcon?: React.ReactNode;
classNames?: ToastClassnames;
- icons?: ToastIcons;
closeButtonAriaLabel?: string;
}
diff --git a/website/src/pages/styling.mdx b/website/src/pages/styling.mdx
index 3482bb9..c5427d2 100644
--- a/website/src/pages/styling.mdx
+++ b/website/src/pages/styling.mdx
@@ -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 />
-});
-```
diff --git a/website/src/pages/toaster.mdx b/website/src/pages/toaster.mdx
index d9e6f53..7a7323f 100644
--- a/website/src/pages/toaster.mdx
+++ b/website/src/pages/toaster.mdx
@@ -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 | `-` |