MCPcopy Index your code
hub / github.com/chentsulin/sweetalert-react

github.com/chentsulin/sweetalert-react @v0.4.11

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.4.11 ↗ · + Follow
57 symbols 135 edges 49 files 0 documented · 0% updated 4y agov0.4.11 · 2017-12-12★ 23919 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

sweetalert-react

NPM version Dependency Status

Declarative SweetAlert in React

Introduction

sweetalert-react is a wrapped sweetalert implement with declarative React style component api. There is a show prop on it to determinate that alert should be displayed or not, and onConfirm, onCancel, onClose, onEscapeKey and onOutsideClick props to have more controls on alert element event.

Install

$ npm install sweetalert-react

Usage

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

// ...

render() {
  return (



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



  );
}

You should import sweetalert.css from cdn, file, node_modules(sweetalert/dist/sweetalert.css) or wherever can find the css code.

Checkout 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 of 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 history change and set show: false when it mounted. See full example here.

Q: Can I use react component to render html for popup body?

Sure, you can achieve it 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 full example here. Thanks @ArkadyB for discovering the approach in issue #53.

Relevant Projects

License

MIT © C.T. Lin

Core symbols most depended-on inside this repo

registerOutsideClickHandler
called by 3
src/SweetAlert.js
unregisterOutsideClickHandler
called by 3
src/SweetAlert.js
isDOMEquals
called by 3
src/utils/isDOMEquals.js
imageSize
called by 2
src/SweetAlert.js
setupWithProps
called by 2
src/SweetAlert.js
unbindEscapeKey
called by 2
src/SweetAlert.js
outsideTargetHandlerFactory
called by 2
src/utils/outsideTargetHandlerFactory.js
warningRemoved
called by 1
src/SweetAlert.js

Shape

Method 33
Class 19
Function 5

Languages

TypeScript100%

Modules by API surface

src/SweetAlert.js18 symbols
examples/history-change/components/App.js6 symbols
examples/simple/components/App.js4 symbols
examples/show-input-error/components/App.js4 symbols
examples/outside-click/components/App.js4 symbols
examples/input/components/App.js4 symbols
examples/esc/components/App.js4 symbols
examples/complex/components/App.js4 symbols
examples/cancel/components/App.js4 symbols
examples/component-as-body/components/App.js2 symbols
src/utils/outsideTargetHandlerFactory.js1 symbols
src/utils/isDOMEquals.js1 symbols

For agents

$ claude mcp add sweetalert-react \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page