Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
solid-toast
Advanced tools
yarn add solid-toast
npm install solid-toast
Add a Toaster to your component tree. This component will render all toasts. Now you can trigger toast()
from anywhere!
import toast, { Toaster } from 'solid-toast';
const notify = () => toast('Here is your toast.');
const App = () => {
return (
<div>
<button onClick={notify}>Make me a toast</button>
<Toaster />
</div>
);
};
toast()
FunctionCall this function from anywhere to create a toast.
You can provide ToastOptions
as the second argument. They will overwrite all options received from the <Toaster/>
component.
toast('This is a simple toast!', {
duration: 5000,
position: 'top-right',
// Add a delay before the toast is removed
// This can be used to time the toast exit animation
unmountDelay: 500,
// Styling - Supports CSS Objects, classes, and inline styles
// Will be applied to the toast container
style: {
'background-color': '#f00',
},
className: 'my-custom-class',
// Custom Icon - Supports text as well as JSX Elements
icon: '🍩',
// Set accent colors for default icons that ship with Solid Toast
iconTheme: {
primary: '#fff',
secondary: '#000',
},
// Aria Props - Supports all ARIA props
aria: {
role: 'status',
'aria-live': 'polite',
},
})
There are several ways of generating toasts
toast('This is a blank toast!')
Blank toasts do not come with a default icon. However, you can set a custom JSX Element/Text (Emoji) icon by placing it in the icon
option.
toast.success('Successfully saved!');
Creates a notification with an animated checkmark. Color accents can be themed with the iconTheme
option.
toast.error('Something went wrong!');
Creates a notification with an animated error icon. Color accents can be themed with the iconTheme
option.
toast.loading('Loading Photos...');
Shows a toast with a loading indicator icon. The content can later be updated with an error or success icon. See how to update the toast content here.
The promise()
function can be used to create a toast from a promise. This will automatically show a loading icon and update the toast with the result of the promise.
const myPromise = fetchData();
toast.promise(myPromise, {
loading: 'Loading',
success: <b>Got the data</b>,
error: 'An error occurred 😔',
});
You also have the ability to completely customize the appearance of your toast. A custom JSX Element can be passed like so:
toast.custom(() => (
<div>
<h1>Custom Toast</h1>
<p>This is a custom toast!</p>
</div>
));
You can also hook into the toast life-cycle by adding a parameter to the JSX Function call like so:
toast.custom((t) => {
<div>
<h1>Custom Toast</h1>
<p>This is a custom toast!</p>
<p>{t.visible ? 'Showing' : 'I will close in 1 second'}</p>
<button
onClick={() => toast.dismiss(t.id)}
>
Close Toast
</button>
</div>
}, {
unmoutDelay: 1000,
})
You can manually dismiss a notification with toast.dismiss. Be aware that it triggers the exit animation and does not remove the Toast instantly. Toasts will auto-remove after 1 second by default. You can adjust the dismiss duration with the unmountDelay
option.
const toastId = toast.loading('Loading...');
// ...
toast.dismiss(toastId);
Dismiss all toasts by omitting all arguments.
toast.dismiss();
Toasts can be removed instantly with toast.remove. This will not trigger the exit animation and remove the toast instantly.
toast.remove(toastId);
// or
toast.remove();
Each toast call returns a unique id. Use this id
in the toast options to update an existing toast.
const toastId = toast.loading('Loading...');
// ...
toast.success('This worked', {
id: toastId,
});
Toaster
ComponentThis component will render all toasts.
<Toaster
position="top-center"
// Spacing between each toast in pixels
gutter={8}
containerClassName=""
containerStyle={{}}
toastOptions={{
// Define default options that each toast will inherit. Will be overwritten by individual toast options
className: '',
duration: 5000,
style: {
background: '#363636',
color: '#fff',
},
}}
/>
This project is inspired by
FAQs
Customizable Toast Notifications for SolidJS
The npm package solid-toast receives a total of 12,365 weekly downloads. As such, solid-toast popularity was classified as popular.
We found that solid-toast demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.