npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@dt-dds/react-toast

v1.0.0-beta.111

Published

Toast is a pop-up message used to display relevant information to our users.

Readme

Toast Package

Toast is a pop-up message used to display relevant information to our users.

Usage

import { Toaster, ToastType, emitToast } from '@dt-dds/react';

const notify = () =>
  emitToast({
    title: 'success',
    message: 'myMEssage' + count,
    type: ToastType.Success,
    children: (
      <Tooltip>
        <Button onClick={() => console.log('clicked')}>Action 2</Button>
        <Tooltip.Content>Some tooltip</Tooltip.Content>
      </Tooltip>
    ),
  });

const App = () => {
  return (
    <div>
      <button onClick={notify}>Click me</button>
      <Toaster />
    </div>
  );
};

Customizable

It's a very customizable component. We are using react-hot-toast for control our provider. You can check the react-hot-toast documentation for more knowledge on this. However, you can create your provider if you wish. For example, let's say you want to create a new prop called autoHide. If this prop isn't true, you want to have the toast indefinitely on the screen.

interface CallToastArgs {
  title: string;
  message: string;
  type: ToastType;
  autoHide: boolean;
}

export const ToasterContext = createContext({
  callToast: (args: CallToastArgs) => null,
});

const Toaster = ({ children }: { children: React.ReactNode }) => {
  const [toast, setToast] = useState<
    Partial<ToastProps> & { autoHide: boolean }
  >(null);

  const callToast = ({ title, message, type, autoHide }: CallToastArgs) =>
    setToast({
      id: Date.now().toString(),
      title,
      message,
      type,
      autoHide,
    });

  const close = () =>
    setToast((prevState) => ({ ...prevState, isVisible: false }));

  useEffect(() => {
    if (toast && toast.autoHide) {
      const timer = setTimeout(() => close(), 1000);
      return () => clearTimeout(timer);
    }
  }, [toast]);

  return (
    <ToasterContext.Provider value={{ callToast }}>
      {children}
      <div style={{ position: 'fixed', bottom: 10, left: 10 }}>
        {toast && (
          <Toast
            key={toast.id}
            id={toast.id}
            type={toast.type}
            title={toast.title}
            message={toast.message}
            isVisible={toast.isVisible}
            onClose={close}
          />
        )}
      </div>
    </ToasterContext.Provider>
  );
};

const App = () => {
  return (
    <Toaster>
      <MyComponent />
    </Toaster>
  );
};

const MyComponent = () => {
  const { callToast } = useContext(ToasterContext);

  return (
    <Button
      onClick={() =>
        callToast({
          message: 'myMEssage' + count,
          type: ToastType.Success,
          title: 'success',
          autoHide: false,
        })
      }
    >
      Clicked Me
    </Button>
  );
};

API

Toaster

| Property | Type | Default | Description | | -------------------- | :------------------------------ | :-------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | toastOptions | DefaultToastOptions | - | These will act as default options for all toasts. See the documentation here. | | reverseOrder | boolean | - | Toasts spawn at top by default. Set to true if you want new toasts at the end. | | gutter | number | 8 | Changes the gap between each toast. | | containerStyle | React.CSSProperties | - | Customize the style of toaster div. This can be used to change the offset of all toasts | | containerClassName | string | undefined | Add a custom CSS class name to toaster div. | | children | (toast: Toast) => JSX.Element | - | You can customize how each toast is displayed by passing your own render function to the Toaster as its children. This function will be called for every toast, allowing you to render any component based on the toast’s state. Note: If the rendered component is a button, its styles will be overridden by the default styles. |

emitToast

| Property | Type | Default | Description | | ------------- | :---------------- | :------ | :------------------------------------------------------------------------ | | type | enum<ToastType> | - | Sets the variant toast ("success", ..., "N") | | title | string | - | The title to be displayed | | message | string | - | The message to be displayed | | dismissable | boolean | true | Sets the visibility of a close button that will fire the onClose callback | | children | ReactNode | - | A child that will be rendered at the end of the content section |

The emitToast extends from ToastOptions. They will overwrite all options received from <Toaster />. For example:

| Property | Type | Default | Description | | ---------- | :-------------- | :--------------------------------- | :---------------------------------- | | duration | number | For success: 4000, error: Infinity | Show the toast for a duration in ms | | style | CSSProperties | - | Add css directly to the toast. |

You can check all ToastOptions here. The Toast position is fixed, on small screens it will be on the bottom center and on large screens it will be on the bottom right. The default duration for any type of toast is 4000ms. For the error type, the duration is infinite.

dismissToast

| Property | Type | Default | Description | | --------- | :------- | :------ | :------------------------- | | toastId | string | - | ID of the toast to dismiss |

Toast

| Property | Type | Default | Description | | ------------- | :---------------- | :------ | :------------------------------------------------------------------------------------------------------------ | | id | string | - | Toast identifier | | dataTest | string | - | Defines a value for the data test | | title | string | - | The title to be displayed | | message | string | - | The message to be displayed | | onClose | string | - | The callback when the close button is fired. | | type | enum<ToastType> | - | Sets the variant toast ("success", ..., "N") | | isVisible | boolean | true | Sets the visibility of the toast and triggers the fade out effect | | dismissable | boolean | true | Sets the visibility of a close button that will fire the onClose callback | | children | ReactNode | - | Child components to be rendered at the end of the content section, this can be used to receive action buttons |

Stack

  • TypeScript for static type checking
  • React — JavaScript library for user interfaces
  • Emotion — for writing css styles with JavaScript
  • Storybook — UI component environment powered by Vite
  • Jest - JavaScript Testing Framework
  • React Testing Library - to test UI components in a user-centric way
  • ESLint for code linting
  • Prettier for code formatting
  • Tsup — TypeScript bundler powered by esbuild
  • Yarn from managing packages

Commands

  • yarn build - Build the package
  • yarn dev - Run the package locally
  • yarn lint - Lint all files within this package
  • yarn test - Run all unit tests
  • yarn test:report - Open the test coverage report
  • yarn test:update:snapshot - Run all unit tests and update the snapshot

Compilation

Running yarn build from the root of the package will use tsup to compile the raw TypeScript and React code to plain JavaScript.

The /dist folder contains the compiled output.

toast
└── dist
    ├── index.d.ts  <-- Types
    ├── index.js    <-- CommonJS version
    └── index.mjs   <-- ES Modules version
    ...

Versioning

Follows semantic versioning

© License

Licensed under MIT License