🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

react-simple-notify

Package Overview
Dependencies
Maintainers
0
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-simple-notify

# React Simple Notify

0.0.19
latest
Source
npm
Version published
Weekly downloads
540
-29.6%
Maintainers
0
Weekly downloads
 
Created
Source

Logo

DEMO

React Simple Notify

Installation

Install React Notify using npm or yarn:

npm install react-simple-notify
# or
yarn add react-simple-notify

Simple usage

import { notify, NotifyContainers } from 'react-simple-notify';

function App() {
  const showNotification = () => {
    notify.open({
      render: ({ onClose }) => (
        <div>
          This is a notify!
          <button onClick={onClose}>Close</button>
        </div>
      ),
    });
  };

  return (
    <>
      <button onClick={showNotification}>Show Notify</button>
      <NotifyContainers />
    </>
  );
}

export default App;

Notify API

notify.open(options)

Opens a notification with customizable options.

ParameterTypeDescriptionDefault Value
idstring (optional)A unique identifier for the notification. If not provided, a random ID will be generated.Random ID
durationnumber (optional)The time in milliseconds before the notification automatically closes. Set to 0 for persistent notifications.3500
alignmentNotifyAlignment (optional)The position on the screen where the notification will appear.NotifyAlignment.bottomLeft
variantstring (optional)Allows specifying a variant for custom styling or behavior.-
renderFunctionA render function that returns the content of the notification.-

notify.close(id)

Closes the notification with the specified ID.

ParameterTypeDescription
idstringThe unique identifier of the notification to close.

notify.closeAll()

Closes all currently open notifications. This function does not take any parameters.

Config API

config.set(props)

Sets the global configuration for notifications.

ParameterTypeDescriptionDefault Value
alignmentNotifyAlignment (optional)Global default alignment for notifications.NotifyAlignment.bottomLeft
animationConfigAnimationConfig (optional)Configuration for the enter and exit animations of notifications.-
notifyComponentReact.ComponentType / ReactNode (optional)A custom React component or element that will wrap the notification content, allowing for custom layouts.Fragment
reverseboolean (optional)Determines whether notifications stack in reverse order.false

config.reset()

Resets the global configuration for notifications to their default values. This function does not take any parameters.

Customizing Notification Container Styles

--rsn-container-padding: Sets the padding around the notification container. Defaults to 10px, allowing you to control the space between the screen's edge and the notifications.

--rsn-container-gap: Defines the gap between individual notifications. The default value is 10px, which you can adjust to manage the spacing between notifications for visual clarity.

example

:root {
    --rsn-container-padding: 15px;
    --rsn-container-gap: 15px;
}

Example of Custom AnimationConfig:

{
  enter: {
    duration: 300,
    easing: "ease-out",
    keyframes: ({ alignment }) => {
      return [
        { opacity: 0, transform: "translateY(-100%)" },
        { opacity: 1, transform: "translateY(0)" }
      ];
    }
  },
  exit: {
    duration: 200,
    easing: "ease-in",
    keyframes: ({ node }) => {
      return [
        { opacity: 1, transform: "scale(1)" },
        { opacity: 0, transform: "scale(0.5)" }
      ];
    }
  }
}

Keywords

react

FAQs

Package last updated on 21 Nov 2024

Did you know?

Socket

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.

Install

Related posts