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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-alerts-lite

v0.3.0

Published

Minimal library for alerts built using react and react-transitions

Downloads

5

Readme

CircleCI Coverage Status

react-alerts-lite

Synopsis

A minimal library for rendering alert / toasts / popups / notifications in react apps.

Storybook

https://reactiness.github.io/react-alerts-lite/

Code Example

Importing AlertProvider

Import the AlertProvider and render before you need to use an Alert. You must only render the AlertProvider once.

import React, { Component } from "react";
import { AlertProvider } from "react-alerts-lite";

export class App extends Component {
  render() {
    return (
      <div>
        <AlertProvider/>
        <Root/>
      </div>
    );
  }
}

Importing Alerts

Import Alerts where you need to display an alert.

import React from "react";
import { Alerts } from "react-alerts-lite";

export class Demo extends React.Component {
  render() {
    return (
      <button onClick={() =>
        Alerts.push({
          type: "success",
          position: "bottom-full",
          transition: "fade"
        })
        }
      >
        Click me
      </button>
    )
  }
}

Importing CSS

import 'react-alerts-lite/dist/index.min.css';

Installation

react-alerts-lite requires react and react-dom to run. It has a single dependency on react-transition-group.

$ npm install react-alerts-lite

or

$ yarn add react-alerts-lite

API Reference

AlertProvider

Themes:

<AlertProvider
  theme="simple" | "rounded" | "shadowed" | "flat" | "bordered"
  transitions=""
/>

Custom transitions: Create your own

The transitions prop accepts an array of transitions with the :name and :transitions keys. Refer to react-transition-group documentation on creating transitions See bottom of page for simple template Note: maxHeight and duration are passed into transitions as props - use them where needed.

import ScaleSlideRight from "../path/to/my/react-transition-group-custom-transition";
import ScaleSlideRight from "../path/to/my/react-transition-group-custom-transition";

const customTransitions = [
  {
    name: "custom-transition_one",
    transition: ScaleSlideRight
  },
  {
    name: "custom-transition-two",
    transition: ScaleSlideUp
  }
];

pass your transitions array into AlertProvider

<AlertProvider
  transitions=[customTransitions]
/>

reference your transition with the :name you provided.

<button onClick={() =>
    Alerts.push({
      transition: "custom-transition_one"
    })
  }
>
  Click me
</button>

DefaultProps:

you can pass default props into the AlertProvider to apply to all alerts. Props passed directly to an Alert take precedence so you can overwrite these where necessary.

  <AlertProvider
    defaultProps={
      type: "error",
      position: "bottom",
      transition: "slide-up"
    }
  />

Now when you render an alert with no props defaultProps will take precedence over stock props.

<button onClick={
  () => Alerts.push()
  }
>
  Click me
</button>

Note: the alert created here would now have type "error", position: "bottom", and transition: "slide-up"

Alert

An alert accepts the following arguments

  Alerts.push({
    type: "basic" | "error" | "warning" | "info" | "error"
    timeout: <int>
    duration: <int>
    position: "top-full" | "top-left" | "top" | "top-right" | "bottom-left" | "bottom" | "bottom-right" | "bottom-full"
    content: <your content to render>
    closeButton: {true | false}
    onClose: () => {alert("my alert has unmounted")}
    maxHeight: <int>
    transition: "none" | "slide-up" | "slide-down" | "slide-up-through" | "fade" | "slide-right" | "slide-left" | "rotate-left" | "rotate-right" | "scale" | "scale-slide-down" | "scale-slide-left" | "scale-slide-right" | "scale-slide-up"
  })
  • timeout: How long before your alert unmounts
  • duration: How long the transition animation will take
  • closeButton: Whether to display the close button or not
  • onClose: callback for when the alert unmounts
  • maxHeight: Used in transitions to determine positioning of alerts in stack

Custom Transitions Example

Example of a simple fade transition.

import Transition from "react-transition-group/Transition";
import React from "react";

export function Fade({ children, maxHeight, duration, in: inProp }) {
  const defaultStyle = {
    transition: `${duration}ms ease-in`,
    transitionProperty: "opacity, max-height"
  };
  const transitionStyles = {
    entering: {
      opacity: 0,
      maxHeight: "0px"
    },
    entered: {
      opacity: 1,
      maxHeight
    },
    exiting: {
      opacity: 0,
      maxHeight: "0px"
    }
  };

  return (
    <Transition
      in={inProp}
      timeout={{
        enter: 0,
        exit: duration
      }}
    >
      {status => {
        if (status === "exited") {
          return null;
        }
        const currentStyles = transitionStyles[status];
        return React.cloneElement(children, {
          style: { ...defaultStyle, ...currentStyles }
        });
      }}
    </Transition>
  );
}

Contributors

I'll post issues and enhancements as i find them - feel free to contribute :)

License

MIT

Tech

peer-dependencies: react, react-dom dependencies: react-transition-group