react-asker

1.0.0 • Public • Published

react-asker

React replacement for window.prompt(), .confirm(), and .alert()

NPM JavaScript Style Guide

Install

npm install --save react-asker

Usage

import React, { Component } from 'react'
import { asker, AskerView } from 'react-asker'

export default class App extends Component {
  confirm = () => {
    asker.confirm({
      title: "Do you really want delete this element?",
      onAccept: () => console.log("Deleted!"),
      acceptCaption: "yes",
      cancelCaption: "no",
    });
  }

  prompt = () => {
    asker.prompt({
      title: "Type new name",
      defaultValue: "Henry",
      onAccept: name => console.log(`Changed name to ${name}!`),
      acceptCaption: "yes",
      cancelCaption: "no",
    });
  }

  componentDidMount() {
    asker.close();
  }

  componentWillUnmount() {
    asker.close();
  }

  render () {
    return (
      <div>
        <AskerView zIndex={1000} />
        <div onClick={this.confirm}>CONFIRM</div>
        <div onClick={this.prompt}>PROMPT</div>
      </div>
    )
  }
}

License

MIT © buuuudzik

Readme

Keywords

Package Sidebar

Install

npm i react-asker

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

51.5 kB

Total Files

6

Last publish

Collaborators

  • buuuudzik