JSPM

react-simple-dialogs

1.2.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 103
  • Score
    100M100P100Q71586F
  • License MIT

A react library to create simple dialogs

Package Exports

  • react-simple-dialogs
  • react-simple-dialogs/dist/react-simple-dialogs.es.js
  • react-simple-dialogs/dist/react-simple-dialogs.umd.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-simple-dialogs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme



Build Test License MIT NPM Downloads NPM Version

React Simple Dialogs

Beautiful dialogs with a simple usage. No unnecessary settings, native-like usage, simple.
You can make it work in less than 10 seconds!

📖 Documentation

✨ Examples

🏗️ Instalation

# npm
npm install react-simple-dialogs
# yarn
yarn add react-simple-dialogs
# pnpm
pnpm add react-simple-dialogs

Container

In order to correctly render the dialogs, you must place the SimpleDialogContainer near to your root component.

Example

import React from 'react'

import { SimpleDialogContainer, simpleAlert } from 'react-simple-dialogs'

function App() {
  const alert = () => simpleAlert('Easy peasy lemon squeezy!')

  return (
    <div>
      <button onClick={alert}>Alert!</button>
      <SimpleDialogContainer />
    </div>
  )
}

💡 Simple Usage

Using the dialogs is almost like using the native dialogs function (alert, confirm and prompt).

All dialog function will return an Promise that only resolves when the user interacts with the dialog, so you can wait for the user interaction to continue your code execution.

Alert Dialog

import { simpleAlert } from 'react-simple-dialogs'

const showAlert = async () => {
  await simpleAlert("You can't do this right now.")

  console.log('Alert closed')
}

Confirm Dialog

import { simpleConfirm } from 'react-simple-dialogs'

const showConfirmation = async () => {
  if (await simpleConfirm('Please confirm something')) {
    console.log('Confirmed! 😄')
  } else {
    console.log('Not confirmed. 🥲')
  }
}

Prompt Dialog

import { simplePrompt } from 'react-simple-dialogs'

const showPrompt = async () => {
  const name = await simplePrompt('Please inform your name')

  console.log(`User name is ${name || 'a mistery'}`)
}
import { simpleModal } from 'react-simple-dialogs'

const showPrompt = async () => {
  await simpleModal(closeFn => (
    <div>
      <h1>My modal</h1>

      <p>My modal content, I can use this for anything I want!</p>

      <button onClick={closeFn}>Close</button>
    </div>
  ))

  console.log('Modal was closed')
}