All Projects → chentsulin → Sweetalert React

chentsulin / Sweetalert React

Licence: mit
Declarative SweetAlert in React

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Sweetalert React

React Native Pdfview
📚 PDF viewer for React Native
Stars: ✭ 198 (-18.85%)
Mutual labels:  react-component
React Split Pane
React split-pane component
Stars: ✭ 2,665 (+992.21%)
Mutual labels:  react-component
React Sight
Visualization tool for React, with support for Fiber, Router (v4), and Redux
Stars: ✭ 2,716 (+1013.11%)
Mutual labels:  react-component
React Input Color
React color picker
Stars: ✭ 208 (-14.75%)
Mutual labels:  react-component
React Intl Tel Input
Rewrite International Telephone Input in React.js. (Looking for maintainers, and PRs & contributors are also welcomed!)
Stars: ✭ 212 (-13.11%)
Mutual labels:  react-component
React Native Htmlview
A React Native component which renders HTML content as native views
Stars: ✭ 2,546 (+943.44%)
Mutual labels:  react-component
React Voice Components
Set of React components that use the Web Speech API to bring voice experience to React applications
Stars: ✭ 195 (-20.08%)
Mutual labels:  react-component
React Css Grid
React layout component based on CSS Grid Layout and built with styled-components
Stars: ✭ 239 (-2.05%)
Mutual labels:  react-component
Yoshino
A themable React component library!Flexible Lightweight PC UI Components built on React! Anyone can generate easily all kinds of themes by it!
Stars: ✭ 216 (-11.48%)
Mutual labels:  react-component
React Image Gallery
React carousel image gallery component with thumbnail support 🖼
Stars: ✭ 2,946 (+1107.38%)
Mutual labels:  react-component
React Reorder
Drag & drop, touch enabled, reorderable / sortable list, React component
Stars: ✭ 209 (-14.34%)
Mutual labels:  react-component
React Adsense
📽 a simple React-component for Google AdSense / Baidu advertisement.
Stars: ✭ 210 (-13.93%)
Mutual labels:  react-component
React Kawaii
Cute SVG React Components
Stars: ✭ 2,709 (+1010.25%)
Mutual labels:  react-component
React Times
A time picker react component, no jquery-rely
Stars: ✭ 206 (-15.57%)
Mutual labels:  react-component
React Native demo
react-native实现网易新闻和美团,实现大部分页面。使用最新的react-navigation等组件,同时支持安卓和iOS设备。
Stars: ✭ 237 (-2.87%)
Mutual labels:  react-component
React Md Spinner
Material Design spinner components for React.js.
Stars: ✭ 195 (-20.08%)
Mutual labels:  react-component
React Photo View
一款精致的 React 图片预览组件
Stars: ✭ 218 (-10.66%)
Mutual labels:  react-component
Boundless
✨ accessible, battle-tested React components with infinite composability
Stars: ✭ 242 (-0.82%)
Mutual labels:  react-component
React Sweet Progress
A way to quickly add a progress bar to react app 🌈
Stars: ✭ 239 (-2.05%)
Mutual labels:  react-component
Virtual List
🧾 React Virtual List Component which worked with animation
Stars: ✭ 232 (-4.92%)
Mutual labels:  react-component

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].