Giter Site home page Giter Site logo

react-alertdialog's Introduction

react-alertdialog

Made with create-react-library

NPM JavaScript Style Guide

Install

npm install --save @ferracinitec/react-alertdialog

Usage

import React, { useState } from 'react'

import { AlertDialog, AlertDialogProps } from '@ferracinitec/react-alertdialog'
import 'react-alertdialog/dist/index.css'

const App = () => {
	const [text, setText] = useState<string>('Wait response...')
	const [show, setShow] = useState<boolean>(false)
	const [alert, setAlert] = useState<AlertDialogProps>({
		type: "info",
		message: "",
		show: false,
	})

	const onYes = () => {
		setAlert({
			type: "info",
			title: "Confirmed",
			message: "Proceeding...",
			show: true,
		})
	}

	const onNo = () => {
		setAlert({
			type: "stop",
			title: "Canceled",
			message: "Aborting...",
			show: true,
		})
	}

	return (
		<div style={{padding: "2em"}}>
			<button onClick={() => {
				setShow(true)
				setText('Wait response...')
			}}>{text}</button>
			<AlertDialog
				type="question"
				title="Making a question"
				hideClose
				show={show}
				onHide={() => setShow(false)}
				buttons={[
					{text: 'Yes', onClick: onYes, background: 'green', color: 'white', width: '5em'},
					{text: 'No', onClick: onNo, background: 'red', color: 'white', width: '5em'}
				]}>
				<span style={{fontSize: 25}}>Do you proceed?</span>
			</AlertDialog>
			<AlertDialog
				type={alert.type!}
				title={alert.title!}
				hideClose
				show={alert.show!}
				message={alert.message}
				onHide={() => setAlert({...alert, show: false})} />
		</div>
	)
}

export default App

License

MIT © frddrt

react-alertdialog's People

Contributors

frddrt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.