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-popup-advanced

v0.2.0

Published

An advanced React Popup helper/container

Downloads

1

Readme

An advanced React Popup Component

Key features

  • Provides standard popup for EditName, Date, Number and String filters.
  • Allows custom content in the popup content section
  • Provides a standardised header and footer
  • Any number of customisable action buttons hosted in the footer
  • Is activated programmatically (i.e. can be attached to onClick on any element)
  • TypeScript support

Demo

Have a look at the demo-page to see the react popup in action!

Load the CSS!

Do not forget to load the rpopup.css into your project (using a 'require' or other means)

require('react-popup-advanced/styles/rpopup.css')

Using the React Popup Control

The control provides a PopupContainer which contains a fixed header and footer. A PopupContent derived control is nestled in between these. There are four standard implementations of the PopupContent but you can easily write your own.

Footer hosts PopupActionItem

The footer items are PopupActionItem that can be given through the settings. If only an array of 'strings' are given then PopupActionItems are auto-generated based upon these.

The 'edit-name' content type

FixedItems.png

...
// handle a footer button click
var newName = (btn: PopupActionItem) => {
    if (btn.code == "OK")
        btnDL.innerHTML = btn.data.name;
}

// find the element you wish to attach the popup to
var btnDL: any = document.getElementsByClassName('test-dl')[0];

// on click make the popup come up towards the left/bottom and with the following settings...
btnDL.addEventListener("click", () => {
    var props: any = {
        element: btnDL,
        direction: PopupDirection.DownLeft,
        tintBackDrop: true,
        header: "Please enter a user name",
        actions: ['OK', 'Cancel'],
        content: new PopupEditName(newName, btnDL.innerHTML)
    }
    PopupContainer.show(props);
});

content property

The content property should provide an implementation of a PopupContentBase (representing the middle part of the popup).
In this case the PopupEditName is given which takes as first parameter a handler that is called when a footer item is clicked and the second parameter is the text the user wishes to edit. The implementation above shows the button text being used as default and updated once the 'OK' button is selected.

The 'number-range' content type

filternumbers.png

...
const filterTemp: any = {
    operator1: ">=",
    operator2: "<",
    operand1: "100",
    operand2: "350"
}

var filterData = (btn: PopupActionItem) => {
    if (btn.code == "Filter") {
        var msg = btn.data.operator1 + " " + btn.data.operand1 + "   ";
        msg += btn.data.operator2 + " " + btn.data.operand2;
        btnDR.innerHTML = msg;
        btnDR.data = btn.data;
    }
    if (btn.code == "Remove") {
        btnDR.innerHTML = "- no filter -";
        btnDR.data = undefined;
    }
}

// find the element you wish to attach the popup to
var btnDR: any = document.getElementsByClassName('test-dr')[0];

// on click make the popup come up towards the left/bottom and with the following settings...
btnDR.addEventListener("click", () => {

    var initialState = btnDR.data || filterTemp;

    var props: any = {
        element: btnDR,
        direction: PopupDirection.DownRight,
        tintBackDrop: true,
        header: "Filter between two numbers",
        actions: ['Filter', 'Remove'],
        content: new PopupFilterNumberRange(filterData, initialState)
    }

    PopupContainer.show(props);
});

content property

Again, the content property should provide an implementation of a PopupContentBase (representing the middle part of the popup).
In this case the PopupFilterNumberRange is given which takes as first parameter a handler that is called when a footer item is clicked and the second parameter is the state of the filter when it first shows. The implementation above shows an initial state of the 'filterTemp' being used unless the element has been given some settings to hold. This clearly fully depends on your implementation...

The 'date-range' content type

filternumbers.png

...
var filteredDates = (btn: PopupActionItem) => {
    if (btn.code == "Filter") {
        btnUR.innerHTML = btn.data.operator1 + " " + btn.data.operand1;
        btnUR.data = btn.data;
    }
    if (btn.code == "Remove") {
        btnUR.innerHTML = "- no filter -";
        btnUR.data = undefined;
    }
}

var btnUR: any = document.getElementsByClassName('test-ur')[0];
btnUR.addEventListener("click", () => {
    var props: any = {
        element: btnUR,
        direction: PopupDirection.UpRight,
        tintBackDrop: true,
        header: "Select date range",
        actions: ['Filter', 'Remove'],
        content: new PopupFilterDates(filteredDates, btnUR.data)
    }

    PopupContainer.show(props);
});

The 'string-filter' content type

filternumbers.png

...
var doFilterString = (btn: PopupActionItem) => {
    if (btn.code == "Filter") {
        btnCenter.innerHTML = btn.data.operator + " " + btn.data.operand
        btnCenter.data = btn.data;
    }
    if (btn.code == "Remove") {
        btnCenter.innerHTML = "- no filter -";
        btnCenter.data = undefined;
    }
}

var btnCenter: any = document.getElementsByClassName('test-center')[0];
btnCenter.addEventListener("click", () => {
    var props: any = {
        direction: PopupDirection.Center,
        tintBackDrop: true,
        header: "This is my CENTERED string filter",
        actions: ['Filter', 'Remove'],
        content: new PopupFilterStrings(doFilterString, btnCenter.data)
    }
    PopupContainer.show(props);
});

Creating custom content

ToDo...

Further Comments

ToDo...

History

|version | Notes | | ---- | ------ | v 0.2.0 | TypeScript support v 0.1.0 | Initial release.