Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@instabase.com/toast
Advanced tools
Readme
This is the Instabase library for showing toasts in the UI.
yarn add @instabase.com/toast
npm install -S @instabase.com/toast
If your webapp is not in an Instabase environment, you will have to add
ToastContainer
to the root of your app. Otherwise, it's already taken care of
for you.
Each toast call returns that toast's id.
import toast from '@instabase.com/toast';
// Create an info toast
toast.info('This is an info toast!');
// Create a loading toast
toast.loading('This is a loading toast!');
// Create a success toast
toast.success('This is a success toast!');
// Create an error toast
toast.error('This is an error toast!');
Toast configs are optional. If desired, you can provide an object with any of these fields as the second argument in your toast call:
id
: Used to identify your toast and update an existing toastpriority
: Can be either low
or high
. Low priority toasts are
automatically dismissed after 5 seconds. High priority toasts are shown until
the user closes them.
description
: String that provides further context. This cannot contain
any JSX. If the description is over 2 lines long, it will be truncated, and a
"View more" button will be shown to see the rest of the description.progressBar
: This is an object that describes the current progress of a
loading toast. Progress bars are not shown in any non-loading toast. Either
percentage
or fraction
must be provided.
percentage
: number, optionalfraction
: object, optional
value
: number, requiredmax
: number, requiredresourceName
: string, optional, used to show the units of the
progress barresourceNamePlural
: string, optional, used to show the units of the
progress barprimaryButton
: This is an object that describes the primary button that
the user can click to take an action. Either onClick
or href
must be
provided. This can be overridden by the "View more" button if the
description is too long.
label
: string, requiredonClick
: () => void
, optionalhref
: string, optionalsecondaryButton
: This is an object that describes the secondary button
that the user can click to take an action. Its type is the same as for
primaryButton
.// Create a loading toast
const toastId = toast.loading('Loading...');
// Update the loading toast into a success toast
toast.success('Success!', { id: toastId });
Dismissing a toast will trigger the exit animation, so the toast won't disappear immediately.
// Create a success toast
const toastId = toast.success('Success!');
// Dismiss the toast
toast.dismiss(toastId);
Removing a toast makes it go away immediately. It is the same as the user clicking the close button on a toast.
// Create a success toast
const toastId = toast.success('Success!');
// Remove the toast
toast.remove(toastId);
Clearing all toasts removes all toasts immediately.
toast.clear();
useStatusToast
is a hook that renders a toast according to a status that
can be loading, success, or error. The hook takes care of using a
consistent toast ID so that only a single toast is created, even when this
status changes. The hook takes in renderer functions for what toast
message and, optionally, what toast config to use for each status.
callPromiseWithToasts
is a util that renders a loading toast, calls a
promise, and renders a success toast or error toast according to the
promise's result. This util takes in only what toast message to show for each
loading/success/error status.
We wanted to keep all toasts consistent, so we don't allow custom timeouts or JSX in toast descriptions.
Restricting custom timeouts is necessary to avoid surprising the user when they don't expect toasts to disappear. For example, error toasts have high priority by default since most users want error toasts to remain on the page so that they can screenshot or copy the error message.
So far, we haven't seen any instances where JSX was absolutely necessary in toast content. By restricting toast content to just strings, we can provide a consistent user experience for toasts, and we can also encourage app developers to avoid using toasts to show overly complicated information. Toasts should mainly be used for simple status-like updates.
We decided to create our own toast library for two main reasons:
In the future, third-party apps can just import @instabase.com/toast
as a peer
dependency to create toasts on Instabase. This allows us to enforce our design
decisions on all apps, instead of requiring apps to use an open-source
library in a very specific way.
We need full control over toast state management because in the future, we need some way to handle notifications propagated from the backend. If we use an open-source toast library, we can immediately show these backend notifications whenever they're received on the frontend. However, it would be difficult to do anything more complicated if we don't have full control over toast state management.
FAQs
This is the Instabase library for showing toasts in the UI.
We found that @instabase.com/toast demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.