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

sg-modal-lib

v1.1.8

Published

Library to simplify modal creation and management.

Downloads

9

Readme

SG Modal Library

Static Badge Static Badge

🖥 Tester la librairie sur CodeSandBox

🔎 Voir la librairie sur npm

sg-modal-lib is a simple and flexible React library for creating and managing modals in your web applications. It allows you to easily create custom modals with themes and configurations.

Features

  • Easy to use : Simple library for creating modals.
  • Customizable : Apply different themes (light/dark) and custom button text.
  • Lightweight : Built with minimal dependencies to keep your bundle size small.
  • Tested : Thoroughly tested with unit tests to ensure reliability and performance.
  • Accessible : Designed with accessibility in mind, following best practices to ensure usability for all users.
  • Responsive : Adapts seamlessly to various screen sizes and devices for a consistent user experience.
  • Flexible : Supports various modal types (confirmation, alert, etc.) to meet diverse use cases.
  • Easy integration : Works well with popular frameworks and libraries, making it simple to implement in existing projects.

Installation

Prerequisites

  • NodeJS (^20.11.1)
  • npm (^10.2.4)
  • IDE (VSCode recommended)

To install the sg-modal-lib library, you can use npm, pnpm or yarn :

npm install sg-modal-lib

or

pnpm install sg-modal-lib

or

yarn add sg-modal-lib

Usage

Here's a basic example of how to use the Modal component in your React application :

import { useState } from 'react';
import { Modal } from 'sg-modal-lib';
import 'sg-modal-lib/style.css'; // Import default styles function

const App = () => {
  const [isModalOpen, setIsModalOpen] = useState(false);

  const toggleModal = () => {
    setIsModalOpen((prevIsOpen) => !prevIsOpen);
  };

  return (
    <div>
      <button onClick={toggleModal}>Open Modal</button>
      <Modal
        isOpen={isModalOpen}
        toggleModal={toggleModal}
        title='Title' /* Optionnal, default to null */
        btnText='close' /* Optionnal, default to null */
        escapeClose={false} /* Optionnal, default to true */
        overlayClickClose={false} /* Optionnal, default to true */
        showClose={false} /* Optionnal, default to true */
        fadeDuration={300} /* Optionnal, default to 0 */
        styleTheme='dark' /* Optionnal, default to light */
      >
        <p>This is the content inside the modal!</p>
      </Modal>
    </div>
  );
};

export default App;

Props

Modal

The Modal component accepts the following props : | Name | Type | Required | Default value | Description | | --- | --- | --- | --- | --- | | isOpen | boolean | yes | / | Indicates whether the modal is open or closed | | toggleModal | function | yes | / | Function to toggle the modal's visibility | | children | React.ReactNode | yes | / | The content to be displayed inside the modal | | escapeClose | boolean | no | true | Allows the user to close the modal by pressing ESC | | overlayClickClose | boolean | no | true | Allows the user to close the modal by clicking the overlay | | showClose | boolean | no | true | Shows a (X) icon/link in the top-right corner | | title | string | no | null | The title of the modal, displayed on top if provided. If no provided, it's not displayed. | | btnText | string | no | null | The text for the additionnal bottom to close the modal, if provided. If no btnText provided, no button is displayed. | | styleTheme | string | no | light | Optional theme for the modal (e.g., 'light', 'dark'). | | fadeDuration | number | no | 0 | Number of milliseconds the fade transition takes |

Styling

The library includes default styles that can be imported using :

import 'sg-modal-lib/style.css';

You can also override these styles in your project by applying additional styles.

Css className :

  • sg-modal-lib
  • sg-modal-lib--open
  • sg-modal-lib--close
  • sg-modal-lib__dialog
  • sg-modal-lib__dialog--open
  • sg-modal-lib__dialog--close
  • sg-modal-lib__close
  • sg-modal-lib__title
  • sg-modal-lib__children
  • sg-modal-lib__btn

Remember to import the CSS file before your own so that you can override it.

Light theme :
Light theme screenshot
Dark theme :
Dark theme screenshot

Dependencies

Production Dependencies

Development Dependencies

Authors

  • Ségolène Ganzin - Initial work and main development (GitHub Profile)