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

@simpozio/popup

v0.0.1

Published

React popup component

Downloads

2

Readme

Popup Component

React component for Popup. Based on react-modal component

Installation

npm i @simpozio/popup

Usage

Basic

import React, {useState} from 'react';
import {Popup, PopupClose} from '@simpozio/popup';

const Component = () => {
  const [isOpen, setOpen] = useState();
  const handleOpen = () => setOpen(true);
  const handleClose = () => setOpen(false);

  return (
    <>
        <button
          type="button"
          onClick={handleOpen}>
          Open Popup
        </button>
        <Popup isOpen={isOpen} closePopup={handleClose}>
            Popup Content
            <PopupClose onClick={closePopup} />
        </Popup>
    </>
  );
};

With built-in state

import {Popup, PopupState PopupClose} from '@simpozio/popup';

const Component = () => {
  return (
    <PopupState>
        (({isOpen, openPopup, closePopup}) => (
            <>
                <button
                  type="button"
                  onClick={openPopup}>
                  Open Popup
                </button>
                <Popup isOpen={isOpen} closePopup={closePopup}>
                    Popup Content
                    <PopupClose onClick={closePopup} />
                </Popup>
            </>
        )}
    </>
  );
};

Styling

Styled Component

Default styling with styled components:

import styled from 'styled-components';
import {Popup, PopupClose} from '@simpozio/popup';

const StyledClose = styled(PopupClose)`
  font-size: 0.6rem;
`;

const StyledPopup = styled(Popup)`
  .popup__overlay {
    top: 0.5rem;
    right: 0.5rem;
    left: auto;
    bottom: auto;
    width: 180px;
    height: 60px;
    background: none;
  }

  .popup__content {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    color: #fff;
    background-color: #000;
  }

  ${StyledClose} {
    top: 0;
    right: 0;
    color: #fff;
  }
`;

const Component = () => {
  return (
    <PopupState>
      {({isOpen, openPopup, closePopup}) => (
        <>
          <Button
            type="button"
            variant="outlined"
            color="secondary"
            onClick={openPopup}>
            Open Popup
          </Button>
          <StyledPopup isOpen={isOpen} closePopup={closePopup}>
            <StyledClose onClick={closePopup} />
            <Wrapper>Popup Content</Wrapper>
          </StyledPopup>
        </>
      )}
    </PopupState>
  )
}

Custom Styles

You can style Popup component via styles attribute by passing styled-component's interpolated string:

import {css} from 'styled-components';
import {Popup, PopupClose} from '@simpozio/popup';

const customStyles = css(
  ({Overlay, Content, Close, theme}) => css`
    ${Overlay} {
      background: none;
    }

    ${Content} {
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
      color: ${theme.COLOR.INVERT};
      font-size: 2rem;
      background-color: ${theme.BACKGROUND.INVERT};
    }

    ${Close} {
      color: ${theme.COLOR.INVERT};
    }
  `
);

const Component = () => {
  return (
    <PopupState>
      {({isOpen, openPopup, closePopup}) => (
        <>
          <Button
            type="button"
            variant="outlined"
            color="secondary"
            onClick={openPopup}>
            Open Popup
          </Button>
          <Popup
            styles={customStyles}
            isOpen={isOpen}
            closePopup={closePopup}>
            <PopupClose onClick={closePopup} />
            <Wrapper>Popup Content</Wrapper>
          </Popup>
        </>
      )}
    </PopupState>
  )
}

Transition

You can change default popup transition for open/close by styling .ReactModal__Overlay--after-open and .ReactModal__Overlay--before-close classes, or OverlayAfterOpen and OverlayBeforeClose styled props on Popup component. Also you can change transition duration, by specifying closeDelay prop on Popup component. Don't forget to override default transition styles (opacity and visibility):

import {css} from 'styled-components';
import {Popup, PopupClose} from '@simpozio/popup';

const customStyles = css(
  ({Overlay, OverlayAfterOpen, OverlayBeforeClose}) => css`
    ${Overlay} {
        /*  overriding default transition styles */
        opacity: 1;
        visibility: visible;
        
        /* specifying new transition styles */
        transform: translateY(-1000px);
        transition: transform ease-in-out 1s;
    }

    ${OverlayAfterOpen} {
        /* specifying new transition styles */
        transform: translateY(0);
    }

    ${OverlayBeforeClose} {
        /*  overriding default transition styles */
        opacity: 1;
        visibility: visible;

        /* specifying new transition styles */
        transform: translateY(-1000px);
    }
  `
);

const Component = () => {
  return (
    <PopupState>
      {({isOpen, openPopup, closePopup}) => (
        <>
          <Button
            type="button"
            variant="outlined"
            color="secondary"
            onClick={openPopup}>
            Open Popup
          </Button>
          <Popup
            styles={customStyles}
            isOpen={isOpen}
            closeDelay={1000}
            closePopup={closePopup}>
            <PopupClose onClick={closePopup} />
            <Wrapper>Popup Content</Wrapper>
          </Popup>
        </>
      )}
    </PopupState>
  )
}

Props

Popup

  • isOpen: boolean - boolean controlling popup state
  • onOpen: function - onOpen callback called after popup is opened
  • onClose: function - onClose callback called after popup is closed
  • className: string - className string applied to portal element
  • label: string - aria-label prop
  • aria: object - object with ARIA attributes, such as: aria-label, aria-labelledby, aria-describedby etc. A complete list of ARIA attributes you can see in the ARIA specification
  • closePopup: function - closing handler function, for handling close with ESC button and overlay click.
  • appElement: string | HTMLElement - selector or HTML element of app root element. Prop for screenreaders, it needed for set aria-hidden for other page content, while modal is open.
  • shouldCloseOnOverlayClick: boolean - prop specify should popup close on overlay click or not
  • shouldCloseOnEsc: boolean - prop specify should popup close on ESC button pressed or not
  • closeDelay: number - popup closing delay for transition

Development

Look simpozio-frontend-common library