Skip to content
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
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ toast('This is a simple toast!', {
primary: '#fff',
secondary: '#000',
},
// Override icons for specific toast types
successIcon: '🎉',
errorIcon: '🔥',
loadingIcon: '⏳',
// Aria Props - Supports all ARIA props
aria: {
role: 'status',
Expand Down Expand Up @@ -124,6 +128,24 @@ toast.error('Something went wrong!');

Creates a notification with an animated error icon. Color accents can be themed with the `iconTheme` option.

##### Customizing Icons by Type

You can override the default icons for `success`, `error`, and `loading` toasts by providing the `successIcon`, `errorIcon`, and `loadingIcon` options respectively. These options accept a `Renderable` (JSX Element, string, or null).

```jsx
toast.success('This is a success toast with a custom icon!', {
successIcon: '✅',
});

toast.error('This is an error toast with a custom icon!', {
errorIcon: '❌',
});

toast.loading('This is a loading toast with a custom icon!', {
loadingIcon: '...',
});
```

##### Loading

```js
Expand Down
27 changes: 21 additions & 6 deletions src/components/ToastBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const ToastBar: Component<ToastBarProps> = (props) => {
{
duration: 350,
fill: 'forwards',
easing: 'cubic-bezier(.21,1.02,.73,1)'
easing: 'cubic-bezier(.21,1.02,.73,1)',
}
);
} else {
Expand All @@ -30,7 +30,7 @@ export const ToastBar: Component<ToastBarProps> = (props) => {
{
duration: 400,
fill: 'forwards',
easing: 'cubic-bezier(.06,.71,.55,1)'
easing: 'cubic-bezier(.06,.71,.55,1)',
}
);
}
Expand All @@ -46,21 +46,36 @@ export const ToastBar: Component<ToastBarProps> = (props) => {
}}
>
<Switch>
<Match when={props.toast.successIcon}>
<div class={props.toast.type} style={{ ...iconContainer, ...props.toast.iconContainerStyle }}>
{props.toast.successIcon}
</div>
</Match>
<Match when={props.toast.errorIcon}>
<div class={props.toast.type} style={{ ...iconContainer, ...props.toast.iconContainerStyle }}>
{props.toast.errorIcon}
</div>
</Match>
<Match when={props.toast.icon}>
<div style={iconContainer}>{props.toast.icon}</div>
<div style={{ ...iconContainer, ...props.toast.iconContainerStyle }}>{props.toast.icon}</div>
</Match>
<Match when={props.toast.loadingIcon}>
<div class={props.toast.type} style={{ ...iconContainer, ...props.toast.iconContainerStyle }}>
{props.toast.loadingIcon}
</div>
</Match>
<Match when={props.toast.type === 'loading'}>
<div style={iconContainer}>
<div class={props.toast.type} style={{ ...iconContainer, ...props.toast.iconContainerStyle }}>
<Loader {...props.toast.iconTheme} />
</div>
</Match>
<Match when={props.toast.type === 'success'}>
<div style={iconContainer}>
<div class={props.toast.type} style={{ ...iconContainer, ...props.toast.iconContainerStyle }}>
<Success {...props.toast.iconTheme} />
</div>
</Match>
<Match when={props.toast.type === 'error'}>
<div style={iconContainer}>
<div class={props.toast.type} style={{ ...iconContainer, ...props.toast.iconContainerStyle }}>
<Error {...props.toast.iconTheme} />
</div>
</Match>
Expand Down
4 changes: 4 additions & 0 deletions src/core/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export const defaultToastOptions: Required<ToastOptions> = {
style: {},
position: 'top-right',
iconTheme: {},
iconContainerStyle: {},
successIcon: '',
errorIcon: '',
loadingIcon: '',
};

export const defaultToasterOptions: ToasterProps = {
Expand Down
9 changes: 7 additions & 2 deletions src/types/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ export interface Toast {
type: ToastType;
id: string;
message: ValueOrFunction<Renderable, Toast>;
icon?: Renderable;
duration?: number;
pauseDuration: number;
paused: boolean;
position?: ToastPosition;

iconContainerStyle?: JSX.CSSProperties;
icon?: Renderable;
successIcon?: Renderable;
errorIcon?: Renderable;
loadingIcon?: Renderable;

ariaProps: {
role: 'status' | 'alert';
'aria-live': 'assertive' | 'off' | 'polite';
Expand All @@ -50,7 +55,7 @@ export interface Toast {
export type ToastOptions = Partial<
Pick<
Toast,
'id' | 'icon' | 'duration' | 'ariaProps' | 'className' | 'style' | 'position' | 'unmountDelay' | 'iconTheme'
'id' | 'icon' | 'duration' | 'ariaProps' | 'className' | 'style' | 'position' | 'unmountDelay' | 'iconTheme' | 'iconContainerStyle' | 'successIcon' | 'errorIcon' | 'loadingIcon'
>
>;

Expand Down