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

fyndiq-component-modal

v2.6.0

Published

[Preview](http://developers.fyndiq.com/fyndiq-ui/?selectedKind=Modal&selectedStory=default)

Downloads

39

Readme

fyndiq-component-modal npm

Preview

A Modal component for Fyndiq

Installation

The package can be installed through NPM:

npm i -S fyndiq-component-modal

It exports two main components: a Modal component which is fully customizable, as well as a confirm utility to quickly create beautiful confirm dialogs.

Modal

Usage

The easiest way to use the Modal component is to open it using ModalButton component:

import React from 'react'
import { ModalButton } from 'fyndiq-component-modal'

// Normal usage
<ModalButton button="Open Modal">
  Modal content
</ModalButton>

This setup will take care of opening the modal when pressing on the button, as well as closing the modal when clicking outside or pressing escape.

To customize the modal itself, you can pass it as a children:

import React from 'react'
import Modal, { ModalButton } from 'fyndiq-component-modal'

// Advanced styling
<ModalButton>
  <Modal overlayClassName="overlay" wrapperClassName="wrapper">
    Content
  </Modal>
</ModalButton>

// Access the onClose method from the children by using a function
<ModalButton>
  <Modal>
    {({ onClose }) => (
      <div>
        Content
        <button onClick={onClose}>Close popup</button>
      </div>
    )}
  </Modal>
</ModalButton>

For advanced use, you can use directly the Modal component and control its open prop, as well as binding the onClose callback prop.

API

The component Modal has the following customizable props:

| Name | Type | Description | Default value | |---|---|---|---| | open | Boolean | Shows or hide the modal | false | | children | React Node or Function | Content of the modal. If a function is passed, a onClose prop will be passed to it, to allow for programatical closing | null | | overlayClassName | String | ClassName of the background overlay |  | | **wrapperClassName** | String | ClassName of the content wrapper |  | | closeClassName | String | ClassName of the close button | `` | | forced | Boolean | Force the modal to be shown. Clicking outside or pressing ESC won't close it, instead you will have to use the children prop in function mode to programatically close it | false | | onClose | Function | Handler method called when the modal is closed | () => {} |

The component ModalButton has the following customizable props

| Name | Type | Description | Default value | |---|---|---|---| | button | Button or String | Content of the button that will open the modal. If a string is passed, it will be converted to a Button Component | Open Modal | | children | React Element | Content of the modal. If the element is not a Modal Component, it will be wrapped into one. Pass a Modal component as children to allow customisation of the Modal. | null |

Confirm

Usage

The easiest way to create a confirm flow is to use the confirm creation utility, as well as the Confirm React Component to customize its appearance.

import React from 'react'
import { Confirm, ConfirmWrapper, confirm } from 'fyndiq-component-modal'

// First you need to render the <ConfirmWrapper /> somewhere on your app.
// It is recommended that you put it somewhere in the root of your app:
const MyApp = () => (
  <React.Fragment>
    <ConfirmWrapper />
    <Layout /> {/* Rest of your app*/}
  </React.Fragment>
)

// This example shows how to display a warning confirm dialog,
// that pops up when the user clicks on a Delete button.
import { Warning } from 'fyndiq-icons'
import Button from 'fyndiq-component-button'

<Button onClick={confirmDelete}>
  ⚠️ Delete something
</Button>

// Here is where the magic happens ✨
async confirmDelete() => {
  const isValidated = await confirm(
    <Confirm
      type="warning"
      icon={<Warning />}
      title="Do you really want to delete that thing?"
      message="If you delete it, there is no way back"
      validateButton="Delete"
    />
  )

  if (isValidated) {
    // do something
  }
}

API

The component Confirm has the following customizable props

| Name | Type | Description | Default value | |---|---|---|---| | type | String | Color scheme of the dialog. One of info, warning, success | info | | title | Node | Title of the notification | Are you sure? | | message | Node | Additional message for the popup | '' | | icon | Icon | Icon shown on top of the confirm dialog | null | | validateButton | String or Button | Validate button (or text) | OK | | cancelButton | String or Button | Cancel button (or text) | Cancel | | open | Boolean | Shows or hide the confirm dialog. Used internally by the confirm utility | true | | onValidate | Function | Handler called when the user clicked on validate. Used internally by the confirm utility function | () => {} | | onCancel | Function | Handler called when the user clicked on cancel. Used internally by the confirm utility function | () => {} |