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

promise-dialog

v2.5.0

Published

Promise Based Dialog

Downloads

21

Readme

Promise Dialog

Promise Based Dialog(alert, confirm, toast, prompt, Loading) Utils

Demo

git clone [email protected]:hjxenjoy/promise-dialog.git
cd promise-dialog
pnpm i
npm start

Installation

Using npm:

npm install --save promise-dialog
pnpm add promise-dialog
yarn add promise-dialog

Usage

Basic Example

import * as pd from 'promise-dialog'

// only config in browser if using ssr like nextjs
if (process.browser) {
  // customize button text
  pd.setConfig({ okText: 'Sure', cancelText: 'Dismiss' })

  // customize className like tailwindcss (example with tailwindcss@^2.2)
  pd.setConfig({
    classes: {
      root: 'text-base text-gray-800',
      button:
        'relative flex-1 flex items-center justify-center h-12 bg-transparent focus:outline-none focus:ring focus:ring-inset focus:ring-green-400',
      okButton: 'text-green-600',
      cancelButton:
        'text-gray-500 before:absolute before:top-3 before:right-0 before:h-6 before:w-px before:border-l before:border-l-gray-200',
      title: 'text-center font-medium break-words leading-7',
      content: 'mt-2 text-gray-500 text-sm break-words text-center leading-6',
      html: 'mt-2 text-sm break-words',
      layer:
        'fixed inset-0 z-[1000] flex flex-col items-center justify-center p-4 bg-black bg-opacity-50',
      dialog: 'w-full max-w-xs bg-white overflow-hidden rounded-md shadow',
      body: 'p-5 text-center',
      actions: 'flex border-t border-1 border-gray-300',
      input:
        'w-full border border-gray-300 px-2 py-1 rounded placeholder-gray-400 focus:outline-none focus:ring-1 focus:ring-green-400 focus:border-green-400',
      textarea: 'resize-none',
      control: 'mt-2 min-w-[16rem]',
      loading:
        'fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-[1000] px-5 py-6 rounded-md bg-black/50 text-white flex flex-col items-center justify-center',
      loadingIcon: 'w-9 h-9 animate-spin',
      toast:
        'fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-[1000] p-5 flex flex-col items-center justify-center bg-black/50 rounded-md text-white',
      toastIcon: 'w-9 h-9',
    }
  })
}

const isDark = false

const html = `<div style="background-color: #eee;padding: 8px 0;">
  <h3>HTML Content is OK!</h3>
  <p>paragraph</p>
  <button class="mt-1 font-medium px-2 py-0.5 text-green-600 border border-green-500 rounded text-sm uppercase">click button</button>
  <script type="text/javascript">alert('script')</script>
</div>`

function testAlert(isAsync) {
  const props = {
    theme: isDark ? 'dark' : undefined,
    title: `Hello${isDark ? ' Dark Mode' : ''} Alert`,
    content: `This is a${isDark ? ' Dark Mode' : ''} alert content.`,
    html,
    buttonText: 'Sure!',
    onClose() {
      console.log('alert closed')
    },
  }
  if (isAsync) {
    pd.alert(props).then()
  } else {
    pd.syncAlert(props)
  }
}

function testConfirm(isAsync) {
  const props = {
    theme: isDark ? 'dark' : undefined,
    title: 'Hello Confirm',
    content: 'This is a confirm content.',
    html,
    onOk() {
      console.log('confirm ok')
    },
    onCancel() {
      console.log('confirm cancel')
    },
  }
  if (isAsync) {
    pd.confirm(props).then()
  } else {
    pd.syncConfirm(props)
  }
}

function testPrompt(isAsync, useInput = false) {
  const props = {
    theme: isDark ? 'dark' : undefined,
    title: 'Hello Prompt',
    placeholder: `Please Enter (in ${useInput ? 20 : 50} characters)`,
    defaultValue: useInput ? '' : 'Default Values...',
    maxLength: useInput ? 20 : 50,
    useInput,
    onBlur() {
      pd.scrollBack(0, 0)
    },
    onOk(value) {
      console.log(value)
    },
    onCancel() {
      console.log('prompt cancel')
    },
  }

  if (isAsync) {
    pd.prompt(props).then()
  } else {
    pd.syncPrompt(props)
  }
}

function testToast(isAsync, iconType = 'success') {
  const props = {
    theme: isDark ? 'dark' : undefined,
    title: 'Hello Toast',
    iconType,
    onClose() {
      console.log('toast disappear')
    },
  }
  if (isAsync) {
    pd.toast(props).then()
  } else {
    pd.syncToast(props)
  }
}

function testLoading() {
  pd.loading({ title: 'Loading...' })
}

function testLoaded() {
  pd.loaded()
}