sweetalert-react

WebJar for sweetalert-react

License

License

MIT
Categories

Categories

Github Development Tools Version Controls React User Interface Web Frameworks
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

github-com-chentsulin-sweetalert-react
Last Version

Last Version

0.4.9
Release Date

Release Date

Type

Type

jar
Description

Description

sweetalert-react
WebJar for sweetalert-react
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/chentsulin/sweetalert-react

Download github-com-chentsulin-sweetalert-react

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/github-com-chentsulin-sweetalert-react/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>github-com-chentsulin-sweetalert-react</artifactId>
    <version>0.4.9</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/github-com-chentsulin-sweetalert-react/
implementation 'org.webjars.npm:github-com-chentsulin-sweetalert-react:0.4.9'
// https://jarcasting.com/artifacts/org.webjars.npm/github-com-chentsulin-sweetalert-react/
implementation ("org.webjars.npm:github-com-chentsulin-sweetalert-react:0.4.9")
'org.webjars.npm:github-com-chentsulin-sweetalert-react:jar:0.4.9'
<dependency org="org.webjars.npm" name="github-com-chentsulin-sweetalert-react" rev="0.4.9">
  <artifact name="github-com-chentsulin-sweetalert-react" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='github-com-chentsulin-sweetalert-react', version='0.4.9')
)
libraryDependencies += "org.webjars.npm" % "github-com-chentsulin-sweetalert-react" % "0.4.9"
[org.webjars.npm/github-com-chentsulin-sweetalert-react "0.4.9"]

Dependencies

compile (4)

Group / Artifact Type Version
org.webjars.npm : lodash.pick jar [4.4.0,5)
org.webjars.npm : mousetrap jar [1.6.0,2)
org.webjars.npm : sweetalert jar [1.1.3,2)
org.webjars.npm : warning jar [3.0.0,4)

Project Modules

There are no modules declared in this project.

sweetalert-react

NPM version Dependency Status

Declarative SweetAlert in React

Introduction

sweetalert-react is a wrapped sweetalert implementation with declarative React style component APIs. There is a show prop available for toggling alert component's visibility. And onConfirm, onCancel, onClose, onEscapeKey, onOutsideClick props allow you have a fine grained control over alert component events.

Install

$ npm install sweetalert-react

Usage

import React, { Component } from 'react';
import SweetAlert from 'sweetalert-react';

// ...

render() {
  return (
    <div>
      <button onClick={() => this.setState({ show: true })}>Alert</button>
      <SweetAlert
        show={this.state.show}
        title="Demo"
        text="SweetAlert in React"
        onConfirm={() => this.setState({ show: false })}
      />
    </div>
  );
}

You should import sweetalert.css from CDN, file, node_modules(sweetalert/dist/sweetalert.css) or wherever method to include this CSS file.

Checkout the full examples here.

Removed Options

  • timer: You should use setTimeout and pass show as false.
  • closeOnConfirm: You should pass show as false via onConfirm.
  • closeOnCancel: You should pass show as false via onCancel.
  • allowEscapeKey: You should pass show as false via onEscapeKey.
  • allowOutsideClick: You should pass show as false via onOutsideClick.

All other options can be passed as props, see them in Configuare Section in sweetalert document

FAQ

Q: My alert didn't close when 'go back' or 'go forward' in browser

You can listen to history changes and set show: false when it is mounted. See the full example here.

Q: Can I use react component to render HTML as the alert body?

Sure, you can achieve this with ReactDOMServer.renderToStaticMarkup:

import { renderToStaticMarkup } from 'react-dom/server';

<SweetAlert
  show={this.state.show}
  title="Demo"
  html
  text={renderToStaticMarkup(<HelloWorld />)}
  onConfirm={() => this.setState({ show: false })}
/>

See the full example here. Thanks @ArkadyB for discovering the approach in issue #53.

Relevant Projects

License

MIT © C.T. Lin

Versions

Version
0.4.9