Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example for loading type + include loader on loading type #355

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,7 @@ const Toast = (props: ToastProps) => {
<>
{toastType || toast.icon || toast.promise ? (
<div data-icon="">
{toast.promise && toast.type === 'loading' && !toast.icon
? toast.icon || icons?.loading || getLoadingIcon()
: null}
{toast.type === 'loading' && !toast.icon ? toast.icon || icons?.loading || getLoadingIcon() : null}
{toast.type !== 'loading' ? toast.icon || icons?.[toastType] || getAsset(toastType) : null}
</div>
) : null}
Expand Down
20 changes: 20 additions & 0 deletions website/src/components/Types/Types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ const allTypes = [
},
}),
},
{
name: 'Loading',
snippet: `
const loadingId = toast.loading('Loading...');
...
toast.success('Done loading', {
id: loadingId
})
`,
action: () => {
const loadingId = toast.loading('Loading...');
new Promise((resolve) => {
setTimeout(() => {
toast.success('Done loading', {
id: loadingId,
});
}, 2000);
});
},
},
{
name: 'Promise',
snippet: `const promise = () => new Promise((resolve) => setTimeout(() => resolve({ name: 'Sonner' }), 2000));
Expand Down