Repository: chentsulin/sweetalert-react
Branch: master
Commit: 8e214bce947f
Files: 87
Total size: 56.8 KB
Directory structure:
gitextract_ihku2qdz/
├── .babelrc
├── .editorconfig
├── .eslintignore
├── .eslintrc.json
├── .gitattributes
├── .gitignore
├── .travis.yml
├── CHANGELOG.md
├── LICENSE
├── README.md
├── __mocks__/
│ └── sweetalert.js
├── examples/
│ ├── cancel/
│ │ ├── .babelrc
│ │ ├── components/
│ │ │ └── App.js
│ │ ├── index.html
│ │ ├── index.js
│ │ ├── package.json
│ │ ├── server.js
│ │ └── webpack.config.js
│ ├── complex/
│ │ ├── .babelrc
│ │ ├── components/
│ │ │ └── App.js
│ │ ├── index.html
│ │ ├── index.js
│ │ ├── package.json
│ │ ├── server.js
│ │ └── webpack.config.js
│ ├── component-as-body/
│ │ ├── .babelrc
│ │ ├── components/
│ │ │ ├── App.js
│ │ │ └── HelloWorld.js
│ │ ├── index.html
│ │ ├── index.js
│ │ ├── package.json
│ │ ├── server.js
│ │ └── webpack.config.js
│ ├── esc/
│ │ ├── .babelrc
│ │ ├── components/
│ │ │ └── App.js
│ │ ├── index.html
│ │ ├── index.js
│ │ ├── package.json
│ │ ├── server.js
│ │ └── webpack.config.js
│ ├── history-change/
│ │ ├── .babelrc
│ │ ├── components/
│ │ │ └── App.js
│ │ ├── index.html
│ │ ├── index.js
│ │ ├── package.json
│ │ ├── server.js
│ │ └── webpack.config.js
│ ├── input/
│ │ ├── .babelrc
│ │ ├── components/
│ │ │ └── App.js
│ │ ├── index.html
│ │ ├── index.js
│ │ ├── package.json
│ │ ├── server.js
│ │ └── webpack.config.js
│ ├── outside-click/
│ │ ├── .babelrc
│ │ ├── components/
│ │ │ └── App.js
│ │ ├── index.html
│ │ ├── index.js
│ │ ├── package.json
│ │ ├── server.js
│ │ └── webpack.config.js
│ ├── show-input-error/
│ │ ├── .babelrc
│ │ ├── components/
│ │ │ └── App.js
│ │ ├── index.html
│ │ ├── index.js
│ │ ├── package.json
│ │ ├── server.js
│ │ └── webpack.config.js
│ └── simple/
│ ├── .babelrc
│ ├── components/
│ │ └── App.js
│ ├── index.html
│ ├── index.js
│ ├── package.json
│ ├── server.js
│ └── webpack.config.js
├── package.json
├── src/
│ ├── SweetAlert.js
│ ├── __tests__/
│ │ ├── SweetAlert-test.js
│ │ └── index-test.js
│ ├── index.js
│ └── utils/
│ ├── __mocks__/
│ │ └── isDOMEquals.js
│ ├── __tests__/
│ │ ├── isDOMEquals-test.js
│ │ └── outsideTargetHandlerFactory-test.js
│ ├── isDOMEquals.js
│ └── outsideTargetHandlerFactory.js
├── webpack.config.development.js
└── webpack.config.production.js
================================================
FILE CONTENTS
================================================
================================================
FILE: .babelrc
================================================
{
"presets": ["latest", "stage-2", "react"]
}
================================================
FILE: .editorconfig
================================================
root = true
[*]
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_size = 2
[*.md]
trim_trailing_whitespace = false
================================================
FILE: .eslintignore
================================================
node_modules
dist
lib
================================================
FILE: .eslintrc.json
================================================
{
"parser": "babel-eslint",
"extends": "airbnb",
"env": {
"browser": true,
"node": true,
"jest": true,
"jasmine": true
},
"rules": {
"arrow-parens": ["error", "as-needed"],
"class-methods-use-this": "off",
"comma-dangle": "off",
"consistent-return": "off",
"no-underscore-dangle": "off",
"import/no-extraneous-dependencies": ["error", {
"devDependencies": [
"**/__tests__/**.js",
"**/webpack.config.js",
"webpack.config.*.js"
],
"optionalDependencies": false
}],
"react/jsx-filename-extension": "off",
"react/require-default-props": "off"
}
}
================================================
FILE: .gitattributes
================================================
* text=auto
================================================
FILE: .gitignore
================================================
.DS_Store
npm-debug.log
node_modules
coverage
lib
dist
================================================
FILE: .travis.yml
================================================
sudo: false
language: node_js
node_js:
- '7'
- '6'
- '4'
script: "npm run test:cov"
after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
================================================
FILE: CHANGELOG.md
================================================
0.4.11 / 2017-12-12
===================
- [new] Support React v16
0.4.10 / 2017-04-24
==================
- [deps] Removes prototype reference which raises warnings in react 15.5 [#71](https://github.com/chentsulin/sweetalert-react/pull/71).
0.4.9 / 2017-02-13
==================
- [fix] clicked comfirm button with empty string should trigger onConfirm instead of onCancel. [#56](https://github.com/chentsulin/sweetalert-react/pull/56).
0.4.8 / 2017-02-05
==================
- [fix] `umd` build
0.4.7 / 2017-01-19
==================
- [fix] allow `animation` prop with `pop`, `slide-from-top`, `slide-from-bottom` value. [#50](https://github.com/chentsulin/sweetalert-react/pull/50).
0.4.6 / 2016-12-05
==================
- [fix] Don't break server rendering [#44](https://github.com/chentsulin/sweetalert-react/pull/44).
0.4.5 / 2016-11-09
==================
- [deps] update dependencies
- [fix] Added `inputValue` to `ALLOWS_KEYS` [#33](https://github.com/chentsulin/sweetalert-react/pull/33).
================================================
FILE: LICENSE
================================================
The MIT License (MIT)
Copyright (c) 2015-present C.T. Lin <chentsulin@gmail.com> (github.com/chentsulin/sweetalert-react)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
================================================
FILE: README.md
================================================
# sweetalert-react
[![NPM version][npm-image]][npm-url]
[![Dependency Status][david_img]][david_site]
> 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
```js
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](./examples).
## 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](http://t4t5.github.io/sweetalert/)
## 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](https://github.com/chentsulin/sweetalert-react/blob/master/examples/history-change/components/App.js).
### Q: Can I use react component to render HTML as the alert body?
Sure, you can achieve this with `ReactDOMServer.renderToStaticMarkup`:
```js
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](https://github.com/chentsulin/sweetalert-react/blob/master/examples/component-as-body/components/App.js). Thanks @ArkadyB for discovering the approach in [issue #53](https://github.com/chentsulin/sweetalert-react/issues/53).
## Relevant Projects
- [react-redux-sweetalert](https://github.com/chentsulin/react-redux-sweetalert)
## License
MIT © [C.T. Lin](https://github.com/chentsulin/sweetalert-react)
[npm-image]: https://badge.fury.io/js/sweetalert-react.svg
[npm-url]: https://npmjs.org/package/sweetalert-react
[travis-image]: https://travis-ci.org/chentsulin/sweetalert-react.svg
[travis-url]: https://travis-ci.org/chentsulin/sweetalert-react
[coveralls-image]: https://coveralls.io/repos/chentsulin/sweetalert-react/badge.svg?branch=master&service=github
[coveralls-url]: https://coveralls.io/r/chentsulin/sweetalert-react?branch=master
[david_img]: https://david-dm.org/chentsulin/sweetalert-react.svg
[david_site]: https://david-dm.org/chentsulin/sweetalert-react
================================================
FILE: __mocks__/sweetalert.js
================================================
const sweetalert = jest.genMockFromModule('sweetalert');
module.exports = sweetalert;
================================================
FILE: examples/cancel/.babelrc
================================================
{
"presets": ["latest", "stage-2", "react"]
}
================================================
FILE: examples/cancel/components/App.js
================================================
import React, { Component } from 'react';
import SweetAlert from 'sweetalert-react'; // eslint-disable-line import/no-extraneous-dependencies
import 'sweetalert/dist/sweetalert.css';
class App extends Component {
constructor(props, context) {
super(props, context);
this.state = {
show: false,
};
}
render() {
return (
<div>
<button onClick={() => this.setState({ show: true })}>Alert</button>
<SweetAlert
show={this.state.show}
title="Demo with Cancel"
text="SweetAlert in React"
showCancelButton
onConfirm={() => {
console.log('confirm'); // eslint-disable-line no-console
this.setState({ show: false });
}}
onCancel={() => {
console.log('cancel'); // eslint-disable-line no-console
this.setState({ show: false });
}}
onClose={() => console.log('close')} // eslint-disable-line no-console
/>
</div>
);
}
}
export default App;
================================================
FILE: examples/cancel/index.html
================================================
<html>
<head>
<title>sweetalert-react-example</title>
</head>
<body>
<div id="root"></div>
<script src="/static/bundle.js"></script>
</body>
</html>
================================================
FILE: examples/cancel/index.js
================================================
import React from 'react';
import { render } from 'react-dom';
import App from './components/App';
render(
<App />,
document.getElementById('root')
);
================================================
FILE: examples/cancel/package.json
================================================
{
"name": "sweetalert-react-example",
"version": "1.0.0",
"description": "sweetalert-react-example-description",
"private": true,
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"repository": {
"type": "git",
"url": "https://github.com/chentsulin/sweetalert-react.git"
},
"keywords": [
"sweetalert-react"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/chentsulin/sweetalert-react/issues"
},
"homepage": "https://github.com/chentsulin/sweetalert-react",
"dependencies": {
"react": "^15.0.1",
"react-dom": "^15.0.1",
"sweetalert": "^1.1.3"
},
"devDependencies": {
"babel-core": "^6.7.6",
"babel-loader": "^6.2.4",
"babel-preset-latest": "^6.22.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-2": "^6.22.0",
"css-loader": "^0.23.1",
"node-libs-browser": "^1.0.0",
"react-hot-loader": "^1.3.0",
"style-loader": "^0.13.1",
"webpack": "^1.12.15",
"webpack-dev-server": "^1.14.1"
}
}
================================================
FILE: examples/cancel/server.js
================================================
/* eslint-disable import/no-extraneous-dependencies */
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const config = require('./webpack.config');
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true,
stats: {
colors: true,
},
}).listen(3000, 'localhost', err => {
if (err) {
console.log(err); // eslint-disable-line no-console
}
console.log('Listening at localhost:3000'); // eslint-disable-line no-console
});
================================================
FILE: examples/cancel/webpack.config.js
================================================
const path = require('path');
const webpack = require('webpack');
module.exports = {
devtool: 'eval',
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./index',
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/',
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
],
resolve: {
alias: {
'sweetalert-react': path.join(__dirname, '..', '..', 'src', 'SweetAlert.js'),
},
extensions: ['', '.js'],
},
module: {
loaders: [{
test: /\.js$/,
loaders: ['react-hot', 'babel'],
exclude: /node_modules/,
include: __dirname,
}, {
test: /\.js$/,
loaders: ['babel'],
include: path.join(__dirname, '..', '..', 'src'),
}, {
test: /\.css$/,
loaders: ['style-loader', 'css-loader'],
}],
},
};
================================================
FILE: examples/complex/.babelrc
================================================
{
"presets": ["latest", "stage-2", "react"]
}
================================================
FILE: examples/complex/components/App.js
================================================
import React, { Component } from 'react';
import SweetAlert from 'sweetalert-react'; // eslint-disable-line import/no-extraneous-dependencies
import 'sweetalert/dist/sweetalert.css';
class App extends Component {
constructor(props, context) {
super(props, context);
this.state = {
show: false,
};
}
render() {
return (
<div>
<button onClick={() => this.setState({ show: true })}>Alert</button>
<SweetAlert
show={this.state.show}
title="Demo Complex"
type="success"
text="SweetAlert in React"
showCancelButton
onConfirm={() => {
console.log('confirm'); // eslint-disable-line no-console
this.setState({ show: false });
}}
onCancel={() => {
console.log('cancel'); // eslint-disable-line no-console
this.setState({ show: false });
}}
onEscapeKey={() => this.setState({ show: false })}
onOutsideClick={() => this.setState({ show: false })}
/>
</div>
);
}
}
export default App;
================================================
FILE: examples/complex/index.html
================================================
<html>
<head>
<title>sweetalert-react-example</title>
</head>
<body>
<div id="root"></div>
<script src="/static/bundle.js"></script>
</body>
</html>
================================================
FILE: examples/complex/index.js
================================================
import React from 'react';
import { render } from 'react-dom';
import App from './components/App';
render(
<App />,
document.getElementById('root')
);
================================================
FILE: examples/complex/package.json
================================================
{
"name": "sweetalert-react-example",
"version": "1.0.0",
"description": "sweetalert-react-example-description",
"private": true,
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"repository": {
"type": "git",
"url": "https://github.com/chentsulin/sweetalert-react.git"
},
"keywords": [
"sweetalert-react"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/chentsulin/sweetalert-react/issues"
},
"homepage": "https://github.com/chentsulin/sweetalert-react",
"dependencies": {
"react": "^15.0.1",
"react-dom": "^15.0.1",
"sweetalert": "^1.1.3"
},
"devDependencies": {
"babel-core": "^6.7.6",
"babel-loader": "^6.2.4",
"babel-preset-latest": "^6.22.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-2": "^6.22.0",
"css-loader": "^0.23.1",
"node-libs-browser": "^1.0.0",
"react-hot-loader": "^1.3.0",
"style-loader": "^0.13.1",
"webpack": "^1.12.15",
"webpack-dev-server": "^1.14.1"
}
}
================================================
FILE: examples/complex/server.js
================================================
/* eslint-disable import/no-extraneous-dependencies */
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const config = require('./webpack.config');
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true,
stats: {
colors: true,
},
}).listen(3000, 'localhost', err => {
if (err) {
console.log(err); // eslint-disable-line no-console
}
console.log('Listening at localhost:3000'); // eslint-disable-line no-console
});
================================================
FILE: examples/complex/webpack.config.js
================================================
const path = require('path');
const webpack = require('webpack');
module.exports = {
devtool: 'eval',
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./index',
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/',
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
],
resolve: {
alias: {
'sweetalert-react': path.join(__dirname, '..', '..', 'src', 'SweetAlert.js'),
},
extensions: ['', '.js'],
},
module: {
loaders: [{
test: /\.js$/,
loaders: ['react-hot', 'babel'],
exclude: /node_modules/,
include: __dirname,
}, {
test: /\.js$/,
loaders: ['babel'],
include: path.join(__dirname, '..', '..', 'src'),
}, {
test: /\.css$/,
loaders: ['style-loader', 'css-loader'],
}],
},
};
================================================
FILE: examples/component-as-body/.babelrc
================================================
{
"presets": ["latest", "stage-2", "react"]
}
================================================
FILE: examples/component-as-body/components/App.js
================================================
import React, { Component } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import SweetAlert from 'sweetalert-react'; // eslint-disable-line import/no-extraneous-dependencies
import 'sweetalert/dist/sweetalert.css';
import HelloWorld from './HelloWorld';
class App extends Component {
constructor(props, context) {
super(props, context);
this.state = {
show: false,
};
}
render() {
return (
<div>
<button onClick={() => this.setState({ show: true })}>Alert</button>
<SweetAlert
show={this.state.show}
title="Demo"
html
text={renderToStaticMarkup(<HelloWorld />)}
onConfirm={() => this.setState({ show: false })}
/>
</div>
);
}
}
export default App;
================================================
FILE: examples/component-as-body/components/HelloWorld.js
================================================
import React from 'react';
const HelloWorld = () => <h1>SweetAlert in React</h1>;
export default HelloWorld;
================================================
FILE: examples/component-as-body/index.html
================================================
<html>
<head>
<title>sweetalert-react-example</title>
</head>
<body>
<div id="root"></div>
<script src="/static/bundle.js"></script>
</body>
</html>
================================================
FILE: examples/component-as-body/index.js
================================================
import React from 'react';
import { render } from 'react-dom';
import App from './components/App';
render(
<App />,
document.getElementById('root')
);
================================================
FILE: examples/component-as-body/package.json
================================================
{
"name": "sweetalert-react-example",
"version": "1.0.0",
"description": "sweetalert-react-example-description",
"private": true,
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"repository": {
"type": "git",
"url": "https://github.com/chentsulin/sweetalert-react.git"
},
"keywords": [
"sweetalert-react"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/chentsulin/sweetalert-react/issues"
},
"homepage": "https://github.com/chentsulin/sweetalert-react",
"dependencies": {
"react": "^15.0.1",
"react-dom": "^15.0.1",
"sweetalert": "^1.1.3"
},
"devDependencies": {
"babel-core": "^6.7.6",
"babel-loader": "^6.2.4",
"babel-preset-latest": "^6.22.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-2": "^6.22.0",
"css-loader": "^0.23.1",
"node-libs-browser": "^1.0.0",
"react-hot-loader": "^1.3.0",
"style-loader": "^0.13.1",
"webpack": "^1.12.15",
"webpack-dev-server": "^1.14.1"
}
}
================================================
FILE: examples/component-as-body/server.js
================================================
/* eslint-disable import/no-extraneous-dependencies */
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const config = require('./webpack.config');
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true,
stats: {
colors: true,
},
}).listen(3000, 'localhost', err => {
if (err) {
console.log(err); // eslint-disable-line no-console
}
console.log('Listening at localhost:3000'); // eslint-disable-line no-console
});
================================================
FILE: examples/component-as-body/webpack.config.js
================================================
const path = require('path');
const webpack = require('webpack');
module.exports = {
devtool: 'eval',
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./index',
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/',
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
],
resolve: {
alias: {
'sweetalert-react': path.join(__dirname, '..', '..', 'src', 'SweetAlert.js'),
},
extensions: ['', '.js'],
},
module: {
loaders: [{
test: /\.js$/,
loaders: ['react-hot', 'babel'],
exclude: /node_modules/,
include: __dirname,
}, {
test: /\.js$/,
loaders: ['babel'],
include: path.join(__dirname, '..', '..', 'src'),
}, {
test: /\.css$/,
loaders: ['style-loader', 'css-loader'],
}],
},
};
================================================
FILE: examples/esc/.babelrc
================================================
{
"presets": ["latest", "stage-2", "react"]
}
================================================
FILE: examples/esc/components/App.js
================================================
import React, { Component } from 'react';
import SweetAlert from 'sweetalert-react'; // eslint-disable-line import/no-extraneous-dependencies
import 'sweetalert/dist/sweetalert.css';
class App extends Component {
constructor(props, context) {
super(props, context);
this.state = {
show: false,
};
}
render() {
return (
<div>
<button onClick={() => this.setState({ show: true })}>Alert</button>
<SweetAlert
show={this.state.show}
title="Demo Esc"
text="SweetAlert in React"
onConfirm={() => this.setState({ show: false })}
onEscapeKey={() => this.setState({ show: false })}
/>
</div>
);
}
}
export default App;
================================================
FILE: examples/esc/index.html
================================================
<html>
<head>
<title>sweetalert-react-example</title>
</head>
<body>
<div id="root"></div>
<script src="/static/bundle.js"></script>
</body>
</html>
================================================
FILE: examples/esc/index.js
================================================
import React from 'react';
import { render } from 'react-dom';
import App from './components/App';
render(
<App />,
document.getElementById('root')
);
================================================
FILE: examples/esc/package.json
================================================
{
"name": "sweetalert-react-example",
"version": "1.0.0",
"description": "sweetalert-react-example-description",
"private": true,
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"repository": {
"type": "git",
"url": "https://github.com/chentsulin/sweetalert-react.git"
},
"keywords": [
"sweetalert-react"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/chentsulin/sweetalert-react/issues"
},
"homepage": "https://github.com/chentsulin/sweetalert-react",
"dependencies": {
"react": "^15.0.1",
"react-dom": "^15.0.1",
"sweetalert": "^1.1.3"
},
"devDependencies": {
"babel-core": "^6.7.6",
"babel-loader": "^6.2.4",
"babel-preset-latest": "^6.22.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-2": "^6.22.0",
"css-loader": "^0.23.1",
"node-libs-browser": "^1.0.0",
"react-hot-loader": "^1.3.0",
"style-loader": "^0.13.1",
"webpack": "^1.12.15",
"webpack-dev-server": "^1.14.1"
}
}
================================================
FILE: examples/esc/server.js
================================================
/* eslint-disable import/no-extraneous-dependencies */
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const config = require('./webpack.config');
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true,
stats: {
colors: true,
},
}).listen(3000, 'localhost', err => {
if (err) {
console.log(err); // eslint-disable-line no-console
}
console.log('Listening at localhost:3000'); // eslint-disable-line no-console
});
================================================
FILE: examples/esc/webpack.config.js
================================================
const path = require('path');
const webpack = require('webpack');
module.exports = {
devtool: 'eval',
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./index',
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/',
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
],
resolve: {
alias: {
'sweetalert-react': path.join(__dirname, '..', '..', 'src', 'SweetAlert.js'),
},
extensions: ['', '.js'],
},
module: {
loaders: [{
test: /\.js$/,
loaders: ['react-hot', 'babel'],
exclude: /node_modules/,
include: __dirname,
}, {
test: /\.js$/,
loaders: ['babel'],
include: path.join(__dirname, '..', '..', 'src'),
}, {
test: /\.css$/,
loaders: ['style-loader', 'css-loader'],
}],
},
};
================================================
FILE: examples/history-change/.babelrc
================================================
{
"presets": ["latest", "stage-2", "react"]
}
================================================
FILE: examples/history-change/components/App.js
================================================
import React, { Component } from 'react';
import shortid from 'shortid';
import SweetAlert from 'sweetalert-react'; // eslint-disable-line import/no-extraneous-dependencies
import 'sweetalert/dist/sweetalert.css';
class App extends Component {
constructor(props, context) {
super(props, context);
this.state = {
show: false,
};
}
componentDidMount() {
window.addEventListener('popstate', this.hiddenAlert);
}
componentWillUnmount() {
window.removeEventListener('popstate', this.hiddenAlert);
}
hiddenAlert = () => {
this.setState({ show: false });
};
pushNextState = () => {
history.pushState(null, 'next', shortid.generate());
};
render() {
return (
<div>
<button onClick={this.pushNextState}>Next Page</button>
<button onClick={() => this.setState({ show: true })}>Alert</button>
<SweetAlert
show={this.state.show}
title="Demo"
text="SweetAlert in React"
onConfirm={this.hiddenAlert}
/>
</div>
);
}
}
export default App;
================================================
FILE: examples/history-change/index.html
================================================
<html>
<head>
<title>sweetalert-react-example</title>
</head>
<body>
<div id="root"></div>
<script src="/static/bundle.js"></script>
</body>
</html>
================================================
FILE: examples/history-change/index.js
================================================
import React from 'react';
import { render } from 'react-dom';
import App from './components/App';
render(
<App />,
document.getElementById('root')
);
================================================
FILE: examples/history-change/package.json
================================================
{
"name": "sweetalert-react-example",
"version": "1.0.0",
"description": "sweetalert-react-example-description",
"private": true,
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"repository": {
"type": "git",
"url": "https://github.com/chentsulin/sweetalert-react.git"
},
"keywords": [
"sweetalert-react"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/chentsulin/sweetalert-react/issues"
},
"homepage": "https://github.com/chentsulin/sweetalert-react",
"dependencies": {
"react": "^15.0.1",
"react-dom": "^15.0.1",
"shortid": "^2.2.6",
"sweetalert": "^1.1.3"
},
"devDependencies": {
"babel-core": "^6.7.6",
"babel-loader": "^6.2.4",
"babel-preset-latest": "^6.22.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-2": "^6.22.0",
"css-loader": "^0.23.1",
"node-libs-browser": "^1.0.0",
"react-hot-loader": "^1.3.0",
"style-loader": "^0.13.1",
"webpack": "^1.12.15",
"webpack-dev-server": "^1.14.1"
}
}
================================================
FILE: examples/history-change/server.js
================================================
/* eslint-disable import/no-extraneous-dependencies */
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const config = require('./webpack.config');
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true,
stats: {
colors: true,
},
}).listen(3000, 'localhost', err => {
if (err) {
console.log(err); // eslint-disable-line no-console
}
console.log('Listening at localhost:3000'); // eslint-disable-line no-console
});
================================================
FILE: examples/history-change/webpack.config.js
================================================
const path = require('path');
const webpack = require('webpack');
module.exports = {
devtool: 'eval',
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./index',
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/',
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
],
resolve: {
alias: {
'sweetalert-react': path.join(__dirname, '..', '..', 'src', 'SweetAlert.js'),
},
extensions: ['', '.js'],
},
module: {
loaders: [{
test: /\.js$/,
loaders: ['react-hot', 'babel'],
exclude: /node_modules/,
include: __dirname,
}, {
test: /\.js$/,
loaders: ['babel'],
include: path.join(__dirname, '..', '..', 'src'),
}, {
test: /\.css$/,
loaders: ['style-loader', 'css-loader'],
}],
},
};
================================================
FILE: examples/input/.babelrc
================================================
{
"presets": ["latest", "stage-2", "react"]
}
================================================
FILE: examples/input/components/App.js
================================================
import React, { Component } from 'react';
import SweetAlert from 'sweetalert-react'; // eslint-disable-line import/no-extraneous-dependencies
import 'sweetalert/dist/sweetalert.css';
class App extends Component {
constructor(props, context) {
super(props, context);
this.state = {
show: false,
};
}
render() {
return (
<div>
<button onClick={() => this.setState({ show: true })}>Alert</button>
<SweetAlert
show={this.state.show}
title="Demo Input"
text="SweetAlert in React"
type="input"
inputType="password"
inputPlaceholder="password"
onConfirm={inputValue => {
console.log(inputValue); // eslint-disable-line no-console
this.setState({ show: false });
}}
/>
</div>
);
}
}
export default App;
================================================
FILE: examples/input/index.html
================================================
<html>
<head>
<title>sweetalert-react-example</title>
</head>
<body>
<div id="root"></div>
<script src="/static/bundle.js"></script>
</body>
</html>
================================================
FILE: examples/input/index.js
================================================
import React from 'react';
import { render } from 'react-dom';
import App from './components/App';
render(
<App />,
document.getElementById('root')
);
================================================
FILE: examples/input/package.json
================================================
{
"name": "sweetalert-react-example",
"version": "1.0.0",
"description": "sweetalert-react-example-description",
"private": true,
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"repository": {
"type": "git",
"url": "https://github.com/chentsulin/sweetalert-react.git"
},
"keywords": [
"sweetalert-react"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/chentsulin/sweetalert-react/issues"
},
"homepage": "https://github.com/chentsulin/sweetalert-react",
"dependencies": {
"react": "^15.0.1",
"react-dom": "^15.0.1",
"sweetalert": "^1.1.3"
},
"devDependencies": {
"babel-core": "^6.7.6",
"babel-loader": "^6.2.4",
"babel-preset-latest": "^6.22.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-2": "^6.22.0",
"css-loader": "^0.23.1",
"node-libs-browser": "^1.0.0",
"react-hot-loader": "^1.3.0",
"style-loader": "^0.13.1",
"webpack": "^1.12.15",
"webpack-dev-server": "^1.14.1"
}
}
================================================
FILE: examples/input/server.js
================================================
/* eslint-disable import/no-extraneous-dependencies */
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const config = require('./webpack.config');
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true,
stats: {
colors: true,
},
}).listen(3000, 'localhost', err => {
if (err) {
console.log(err); // eslint-disable-line no-console
}
console.log('Listening at localhost:3000'); // eslint-disable-line no-console
});
================================================
FILE: examples/input/webpack.config.js
================================================
const path = require('path');
const webpack = require('webpack');
module.exports = {
devtool: 'eval',
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./index',
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/',
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
],
resolve: {
alias: {
'sweetalert-react': path.join(__dirname, '..', '..', 'src', 'SweetAlert.js'),
},
extensions: ['', '.js'],
},
module: {
loaders: [{
test: /\.js$/,
loaders: ['react-hot', 'babel'],
exclude: /node_modules/,
include: __dirname,
}, {
test: /\.js$/,
loaders: ['babel'],
include: path.join(__dirname, '..', '..', 'src'),
}, {
test: /\.css$/,
loaders: ['style-loader', 'css-loader'],
}],
},
};
================================================
FILE: examples/outside-click/.babelrc
================================================
{
"presets": ["latest", "stage-2", "react"]
}
================================================
FILE: examples/outside-click/components/App.js
================================================
import React, { Component } from 'react';
import SweetAlert from 'sweetalert-react'; // eslint-disable-line import/no-extraneous-dependencies
import 'sweetalert/dist/sweetalert.css';
class App extends Component {
constructor(props, context) {
super(props, context);
this.state = {
show: false,
};
}
render() {
return (
<div>
<button onClick={() => this.setState({ show: true })}>Alert</button>
<SweetAlert
show={this.state.show}
title="Demo OutsideClick"
text="SweetAlert in React"
onConfirm={() => this.setState({ show: false })}
onOutsideClick={() => this.setState({ show: false })}
/>
</div>
);
}
}
export default App;
================================================
FILE: examples/outside-click/index.html
================================================
<html>
<head>
<title>sweetalert-react-example</title>
</head>
<body>
<div id="root"></div>
<script src="/static/bundle.js"></script>
</body>
</html>
================================================
FILE: examples/outside-click/index.js
================================================
import React from 'react';
import { render } from 'react-dom';
import App from './components/App';
render(
<App />,
document.getElementById('root')
);
================================================
FILE: examples/outside-click/package.json
================================================
{
"name": "sweetalert-react-example",
"version": "1.0.0",
"description": "sweetalert-react-example-description",
"private": true,
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"repository": {
"type": "git",
"url": "https://github.com/chentsulin/sweetalert-react.git"
},
"keywords": [
"sweetalert-react"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/chentsulin/sweetalert-react/issues"
},
"homepage": "https://github.com/chentsulin/sweetalert-react",
"dependencies": {
"react": "^15.0.1",
"react-dom": "^15.0.1",
"sweetalert": "^1.1.3"
},
"devDependencies": {
"babel-core": "^6.7.6",
"babel-loader": "^6.2.4",
"babel-preset-latest": "^6.22.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-2": "^6.22.0",
"css-loader": "^0.23.1",
"node-libs-browser": "^1.0.0",
"react-hot-loader": "^1.3.0",
"style-loader": "^0.13.1",
"webpack": "^1.12.15",
"webpack-dev-server": "^1.14.1"
}
}
================================================
FILE: examples/outside-click/server.js
================================================
/* eslint-disable import/no-extraneous-dependencies */
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const config = require('./webpack.config');
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true,
stats: {
colors: true,
},
}).listen(3000, 'localhost', err => {
if (err) {
console.log(err); // eslint-disable-line no-console
}
console.log('Listening at localhost:3000'); // eslint-disable-line no-console
});
================================================
FILE: examples/outside-click/webpack.config.js
================================================
const path = require('path');
const webpack = require('webpack');
module.exports = {
devtool: 'eval',
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./index',
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/',
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
],
resolve: {
alias: {
'sweetalert-react': path.join(__dirname, '..', '..', 'src', 'SweetAlert.js'),
},
extensions: ['', '.js'],
},
module: {
loaders: [{
test: /\.js$/,
loaders: ['react-hot', 'babel'],
exclude: /node_modules/,
include: __dirname,
}, {
test: /\.js$/,
loaders: ['babel'],
include: path.join(__dirname, '..', '..', 'src'),
}, {
test: /\.css$/,
loaders: ['style-loader', 'css-loader'],
}],
},
};
================================================
FILE: examples/show-input-error/.babelrc
================================================
{
"presets": ["latest", "stage-2", "react"]
}
================================================
FILE: examples/show-input-error/components/App.js
================================================
import React, { Component } from 'react';
import swal from 'sweetalert';
import SweetAlert from 'sweetalert-react'; // eslint-disable-line import/no-extraneous-dependencies
import 'sweetalert/dist/sweetalert.css';
class App extends Component {
constructor(props, context) {
super(props, context);
this.state = {
show: false,
};
}
render() {
return (
<div>
<button onClick={() => this.setState({ show: true })}>Alert</button>
<SweetAlert
show={this.state.show}
title="An input!"
text="Write something interesting:"
type="input"
showCancelButton
closeOnConfirm={false}
animation="slide-from-top"
inputPlaceholder="Write something"
onConfirm={inputValue => {
if (inputValue === '') {
swal.showInputError('You need to write something!');
return;
}
this.setState({ show: false });
}}
/>
</div>
);
}
}
export default App;
================================================
FILE: examples/show-input-error/index.html
================================================
<html>
<head>
<title>sweetalert-react-example</title>
</head>
<body>
<div id="root"></div>
<script src="/static/bundle.js"></script>
</body>
</html>
================================================
FILE: examples/show-input-error/index.js
================================================
import React from 'react';
import { render } from 'react-dom';
import App from './components/App';
render(
<App />,
document.getElementById('root')
);
================================================
FILE: examples/show-input-error/package.json
================================================
{
"name": "sweetalert-react-example",
"version": "1.0.0",
"description": "sweetalert-react-example-description",
"private": true,
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"repository": {
"type": "git",
"url": "https://github.com/chentsulin/sweetalert-react.git"
},
"keywords": [
"sweetalert-react"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/chentsulin/sweetalert-react/issues"
},
"homepage": "https://github.com/chentsulin/sweetalert-react",
"dependencies": {
"react": "^15.0.1",
"react-dom": "^15.0.1",
"sweetalert": "^1.1.3"
},
"devDependencies": {
"babel-core": "^6.7.6",
"babel-loader": "^6.2.4",
"babel-preset-latest": "^6.22.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-2": "^6.22.0",
"css-loader": "^0.23.1",
"node-libs-browser": "^1.0.0",
"react-hot-loader": "^1.3.0",
"style-loader": "^0.13.1",
"webpack": "^1.12.15",
"webpack-dev-server": "^1.14.1"
}
}
================================================
FILE: examples/show-input-error/server.js
================================================
/* eslint-disable import/no-extraneous-dependencies */
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const config = require('./webpack.config');
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true,
stats: {
colors: true,
},
}).listen(3000, 'localhost', err => {
if (err) {
console.log(err); // eslint-disable-line no-console
}
console.log('Listening at localhost:3000'); // eslint-disable-line no-console
});
================================================
FILE: examples/show-input-error/webpack.config.js
================================================
const path = require('path');
const webpack = require('webpack');
module.exports = {
devtool: 'eval',
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./index',
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/',
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
],
resolve: {
alias: {
'sweetalert-react': path.join(__dirname, '..', '..', 'src', 'SweetAlert.js'),
},
extensions: ['', '.js'],
},
module: {
loaders: [{
test: /\.js$/,
loaders: ['react-hot', 'babel'],
exclude: /node_modules/,
include: __dirname,
}, {
test: /\.js$/,
loaders: ['babel'],
include: path.join(__dirname, '..', '..', 'src'),
}, {
test: /\.css$/,
loaders: ['style-loader', 'css-loader'],
}],
},
};
================================================
FILE: examples/simple/.babelrc
================================================
{
"presets": ["latest", "stage-2", "react"]
}
================================================
FILE: examples/simple/components/App.js
================================================
import React, { Component } from 'react';
import SweetAlert from 'sweetalert-react'; // eslint-disable-line import/no-extraneous-dependencies
import 'sweetalert/dist/sweetalert.css';
class App extends Component {
constructor(props, context) {
super(props, context);
this.state = {
show: false,
};
}
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>
);
}
}
export default App;
================================================
FILE: examples/simple/index.html
================================================
<html>
<head>
<title>sweetalert-react-example</title>
</head>
<body>
<div id="root"></div>
<script src="/static/bundle.js"></script>
</body>
</html>
================================================
FILE: examples/simple/index.js
================================================
import React from 'react';
import { render } from 'react-dom';
import App from './components/App';
render(
<App />,
document.getElementById('root')
);
================================================
FILE: examples/simple/package.json
================================================
{
"name": "sweetalert-react-example",
"version": "1.0.0",
"description": "sweetalert-react-example-description",
"private": true,
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"repository": {
"type": "git",
"url": "https://github.com/chentsulin/sweetalert-react.git"
},
"keywords": [
"sweetalert-react"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/chentsulin/sweetalert-react/issues"
},
"homepage": "https://github.com/chentsulin/sweetalert-react",
"dependencies": {
"react": "^15.0.1",
"react-dom": "^15.0.1",
"sweetalert": "^1.1.3"
},
"devDependencies": {
"babel-core": "^6.7.6",
"babel-loader": "^6.2.4",
"babel-preset-latest": "^6.22.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-2": "^6.22.0",
"css-loader": "^0.23.1",
"node-libs-browser": "^1.0.0",
"react-hot-loader": "^1.3.0",
"style-loader": "^0.13.1",
"webpack": "^1.12.15",
"webpack-dev-server": "^1.14.1"
}
}
================================================
FILE: examples/simple/server.js
================================================
/* eslint-disable import/no-extraneous-dependencies */
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const config = require('./webpack.config');
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true,
stats: {
colors: true,
},
}).listen(3000, 'localhost', err => {
if (err) {
console.log(err); // eslint-disable-line no-console
}
console.log('Listening at localhost:3000'); // eslint-disable-line no-console
});
================================================
FILE: examples/simple/webpack.config.js
================================================
const path = require('path');
const webpack = require('webpack');
module.exports = {
devtool: 'eval',
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./index',
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/',
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
],
resolve: {
alias: {
'sweetalert-react': path.join(__dirname, '..', '..', 'src', 'SweetAlert.js'),
},
extensions: ['', '.js'],
},
module: {
loaders: [{
test: /\.js$/,
loaders: ['react-hot', 'babel'],
exclude: /node_modules/,
include: __dirname,
}, {
test: /\.js$/,
loaders: ['babel'],
include: path.join(__dirname, '..', '..', 'src'),
}, {
test: /\.css$/,
loaders: ['style-loader', 'css-loader'],
}],
},
};
================================================
FILE: package.json
================================================
{
"name": "sweetalert-react",
"version": "0.4.11",
"description": "Declarative SweetAlert in React",
"main": "lib/index.js",
"license": "MIT",
"repository": "chentsulin/sweetalert-react",
"scripts": {
"clean": "rimraf lib dist coverage",
"lint": "eslint .",
"test": "jest",
"test:watch": "npm test -- --watch",
"test:cov": "npm test -- --coverage",
"check": "npm run lint && npm run test",
"build:lib": "babel src --out-dir lib --ignore __tests__",
"build:umd": "webpack src/index.js dist/sweetalert-react.js --config webpack.config.development.js",
"build:umd:min": "webpack src/index.js dist/sweetalert-react.min.js --config webpack.config.production.js",
"build": "npm run clean && npm run build:lib && npm run build:umd && npm run build:umd:min",
"preversion": "npm run clean && npm run check",
"version": "npm run build",
"postversion": "git push && git push --tags && npm run clean",
"prepublish": "npm run clean && npm run build"
},
"author": {
"name": "C.T. Lin",
"email": "chentsulin@gmail.com",
"url": "github.com/chentsulin/sweetalert-react"
},
"engines": {
"node": ">=0.10.0"
},
"files": [
"lib/"
],
"keywords": [
"alert",
"sweetalert",
"react",
"component",
"react-component"
],
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-eslint": "^7.1.1",
"babel-jest": "^19.0.0",
"babel-loader": "^6.2.10",
"babel-polyfill": "^6.20.0",
"babel-preset-latest": "^6.16.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-2": "^6.18.0",
"enzyme": "^2.7.0",
"eslint": "^3.13.1",
"eslint-config-airbnb": "^14.0.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^3.0.2",
"eslint-plugin-react": "^6.9.0",
"jest-cli": "^19.0.2",
"react": "^15.4.2",
"react-addons-test-utils": "^15.4.2",
"react-dom": "^15.4.2",
"rimraf": "^2.5.4",
"webpack": "^1.14.0"
},
"dependencies": {
"lodash.pick": "^4.4.0",
"mousetrap": "^1.6.0",
"prop-types": "^15.0.0",
"sweetalert": "^1.1.3",
"warning": "^3.0.0"
},
"peerDependencies": {
"react": "^0.14.0 || ^15.0.0-0 || ^16.0.0-0"
},
"jest": {
"verbose": true,
"collectCoverageFrom": [
"src/**/*.js"
],
"testPathIgnorePatterns": [
"<rootDir>/lib"
]
}
}
================================================
FILE: src/SweetAlert.js
================================================
import { Component } from 'react';
import PropTypes from 'prop-types';
import swal from 'sweetalert';
import pick from 'lodash.pick';
import mousetrap from 'mousetrap';
import warning from 'warning';
import outsideTargetHandlerFactory from './utils/outsideTargetHandlerFactory';
const ALLOWS_KEYS = [
'title',
'text',
'type',
'customClass',
'showCancelButton',
'showConfirmButton',
'confirmButtonText',
'confirmButtonColor',
'cancelButtonText',
'imageUrl',
'imageSize',
'html',
'animation',
'inputType',
'inputValue',
'inputPlaceholder',
'showLoaderOnConfirm',
];
const REMOVED_KEYS = [
'timer',
'closeOnConfirm',
'closeOnCancel',
'allowOutsideClick',
'allowEscapeKey',
];
const OVERWRITE_PROPS = {
closeOnConfirm: false,
closeOnCancel: false,
allowOutsideClick: false,
allowEscapeKey: false,
};
// reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input
const ALLOWS_INPUT_TYPES = [
'button',
'checkbox',
'color',
'date',
'datetime',
'datetime-local',
'email',
'file',
'hidden',
'image',
'month',
'number',
'password',
'radio',
'range',
'reset',
'search',
'submit',
'tel',
'text',
'time',
'url',
'week',
];
function warningRemoved(props) {
REMOVED_KEYS.forEach(key => {
warning(
props[key] === undefined,
'%s has been removed from sweetalert-react, pass `show` props and use event hook instead.',
`\`${key}\``
);
});
}
export default class SweetAlert extends Component {
/* eslint-disable react/no-unused-prop-types */
static propTypes = {
// sweetalert option
title: PropTypes.string.isRequired,
text: PropTypes.string,
type: PropTypes.oneOf(['warning', 'error', 'success', 'info', 'input']),
customClass: PropTypes.string,
showCancelButton: PropTypes.bool,
showConfirmButton: PropTypes.bool,
confirmButtonText: PropTypes.string,
confirmButtonColor: PropTypes.string,
cancelButtonText: PropTypes.string,
imageUrl: PropTypes.string,
imageSize(props, propName) {
if (!/^[1-9]\d*x[1-9]\d*/.test(props[propName])) {
return new Error('imageSize should have the format like this: "80x80"');
}
},
html: PropTypes.bool,
animation: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.oneOf(['pop', 'slide-from-top', 'slide-from-bottom']),
]),
inputType: PropTypes.oneOf(ALLOWS_INPUT_TYPES),
inputPlaceholder: PropTypes.string,
inputValue: PropTypes.string,
showLoaderOnConfirm: PropTypes.bool,
// custom option
show: PropTypes.bool,
onConfirm: PropTypes.func,
onCancel: PropTypes.func,
onClose: PropTypes.func,
onEscapeKey: PropTypes.func,
onOutsideClick: PropTypes.func,
};
/* eslint-enable react/no-unused-prop-types */
static defaultProps = {
// sweetalert option
text: null,
type: null,
customClass: null,
showCancelButton: false,
showConfirmButton: true,
confirmButtonText: 'OK',
confirmButtonColor: '#aedef4',
cancelButtonText: 'Cancel',
imageUrl: null,
imageSize: '80x80',
html: false,
animation: true,
inputType: 'text',
inputPlaceholder: null,
inputValue: null,
showLoaderOnConfirm: false,
// custom option
show: false,
};
constructor(props, context) {
super(props, context);
this._show = false;
}
componentDidMount() {
this.setupWithProps(this.props);
if (this.props.onOutsideClick) {
this.registerOutsideClickHandler(this.props.onOutsideClick);
}
}
componentWillReceiveProps(props) {
this.setupWithProps(props);
const oldOutsideClickHandler = this.props.onOutsideClick;
const newOutsideClickHandler = props.onOutsideClick;
if (oldOutsideClickHandler !== newOutsideClickHandler) {
if (oldOutsideClickHandler && newOutsideClickHandler) {
this.unregisterOutsideClickHandler();
this.registerOutsideClickHandler(newOutsideClickHandler);
} else if (oldOutsideClickHandler && !newOutsideClickHandler) {
this.unregisterOutsideClickHandler();
} else if ((!oldOutsideClickHandler) && newOutsideClickHandler) {
this.registerOutsideClickHandler(newOutsideClickHandler);
}
}
}
componentWillUnmount() {
this.unregisterOutsideClickHandler();
this.unbindEscapeKey();
}
setupWithProps(props) {
warningRemoved(props);
const { show, onConfirm, onCancel, onClose, onEscapeKey } = props;
if (show) {
swal({
...pick(props, ALLOWS_KEYS),
...OVERWRITE_PROPS,
}, isConfirm => this.handleClick(isConfirm, onConfirm, onCancel));
this._show = true;
if (onEscapeKey) this.bindEscapeKey(onEscapeKey);
} else {
this.handleClose(onClose);
}
}
registerOutsideClickHandler(handler) {
this._outsideClickHandler = outsideTargetHandlerFactory(
document.getElementsByClassName('sweet-alert')[0],
handler
);
this.enableOutsideClick();
}
unregisterOutsideClickHandler() {
this.disableOutsideClick();
this._outsideClickHandler = null;
}
enableOutsideClick() {
const fn = this._outsideClickHandler;
if (fn) {
document.addEventListener('mousedown', fn);
document.addEventListener('touchstart', fn);
}
}
disableOutsideClick() {
const fn = this._outsideClickHandler;
if (fn) {
document.removeEventListener('mousedown', fn);
document.removeEventListener('touchstart', fn);
}
}
bindEscapeKey(onEscapeKey) {
mousetrap.bind('esc', onEscapeKey);
}
unbindEscapeKey() {
mousetrap.unbind('esc');
}
handleClick(isConfirm, onConfirm, onCancel) {
if (isConfirm !== false) {
if (onConfirm) onConfirm(isConfirm);
} else {
if (onCancel) onCancel(); // eslint-disable-line no-lonely-if
}
}
handleClose(onClose) {
if (this._show) {
swal.close();
this.unbindEscapeKey();
if (onClose) onClose();
this._show = false;
}
}
render() {
return null;
}
}
================================================
FILE: src/__tests__/SweetAlert-test.js
================================================
/* eslint-disable no-console */
import React from 'react';
import { mount } from 'enzyme';
import swal from 'sweetalert';
import SweetAlert from '../SweetAlert';
jest.mock('sweetalert');
let _error;
beforeEach(() => {
_error = console.error;
console.error = jest.fn();
});
afterEach(() => {
console.error = _error;
_error = null;
swal.mockClear();
});
describe('propTypes', () => {
it('should return error when imageSize invalid', () => {
expect(SweetAlert.propTypes.imageSize({ imageSize: '8080' }, 'imageSize'))
.toBeInstanceOf(Error);
});
it('should not return error when imageSize valid', () => {
expect(SweetAlert.propTypes.imageSize({ imageSize: '80x80' }, 'imageSize'))
.not.toBeInstanceOf(Error);
});
it('should warning when title is not passed down to props', () => {
mount(<SweetAlert />);
const message = console.error.mock.calls[0][0];
expect(message).toMatch(
/Failed prop type: The prop `title` is marked as required in `SweetAlert`/
);
});
});
describe('allow ALLOWS_KEYS as props', () => {
it('should not log error when props pass down', () => {
mount(
<SweetAlert
title="t"
text="some text"
type="warning"
customClass="custom-class"
showCancelButton
showConfirmButton
confirmButtonText="confirm"
confirmButtonColor="green"
cancelButtonText="cannel"
imageUrl=""
imageSize="160x160"
html
animation
inputType="text"
inputValue="default"
inputPlaceholder="placeholder"
showLoaderOnConfirm
/>
);
expect(console.error).not.toBeCalled();
});
});
describe('warning REMOVED_KEYS', () => {
it('should warning when REMOVED_KEYS:timer is passed down to props', () => {
mount(<SweetAlert title="t" timer={60} />);
expect(console.error).toBeCalledWith(
'Warning: `timer` has been removed from sweetalert-react, ' +
'pass `show` props and use event hook instead.'
);
});
it('should warning when REMOVED_KEYS:timer is passed down to props', () => {
mount(<SweetAlert title="t" timer={60} />);
expect(console.error).toBeCalledWith(
'Warning: `timer` has been removed from sweetalert-react, ' +
'pass `show` props and use event hook instead.'
);
});
it('should warning when REMOVED_KEYS:closeOnConfirm is passed down to props', () => {
mount(<SweetAlert title="t" closeOnConfirm />);
expect(console.error).toBeCalledWith(
'Warning: `closeOnConfirm` has been removed from sweetalert-react, ' +
'pass `show` props and use event hook instead.'
);
});
it('should warning when REMOVED_KEYS:closeOnCancel is passed down to props', () => {
mount(<SweetAlert title="t" closeOnCancel />);
expect(console.error).toBeCalledWith(
'Warning: `closeOnCancel` has been removed from sweetalert-react, ' +
'pass `show` props and use event hook instead.'
);
});
it('should warning when REMOVED_KEYS:allowOutsideClick is passed down to props', () => {
mount(<SweetAlert title="t" allowOutsideClick />);
expect(console.error).toBeCalledWith(
'Warning: `allowOutsideClick` has been removed from sweetalert-react, ' +
'pass `show` props and use event hook instead.'
);
});
it('should warning when REMOVED_KEYS:allowEscapeKey is passed down to props', () => {
mount(<SweetAlert title="t" allowEscapeKey />);
expect(console.error).toBeCalledWith(
'Warning: `allowEscapeKey` has been removed from sweetalert-react, ' +
'pass `show` props and use event hook instead.'
);
});
});
describe('should show prop works', () => {
it('should call sweetalert when show is true', async () => {
mount(
<SweetAlert title="t" show />
);
expect(swal).toBeCalled();
});
it('should call sweetalert when show is false', async () => {
mount(
<SweetAlert title="t" />
);
expect(swal).not.toBeCalled();
});
});
describe('`onConfirm`', () => {
xit('should works', () => {
const callback = jest.fn();
mount(
<SweetAlert title="t" show onConfirm={callback} />
);
});
});
describe('Cancel', () => {
// body...
});
describe('Outside click', () => {
// body...
});
describe('ESC', () => {
// body...
});
================================================
FILE: src/__tests__/index-test.js
================================================
import React from 'react';
import { render } from 'react-dom';
import { renderToString } from 'react-dom/server';
import SweetAlert from '../';
it('should not break render', () => {
const node = document.createElement('div');
expect(() => {
render(
<SweetAlert title="client-rendering" />,
node
);
}).not.toThrow();
});
it('should not break renderToString', () => {
global.window = undefined;
expect(() => renderToString(
<SweetAlert title="server-rendering" />
)).not.toThrow();
});
================================================
FILE: src/index.js
================================================
if (typeof window === 'undefined') {
module.exports = () => null;
} else {
module.exports = require('./SweetAlert'); // eslint-disable-line global-require
}
================================================
FILE: src/utils/__mocks__/isDOMEquals.js
================================================
const isDOMEquals = jest.genMockFromModule('../isDOMEquals');
module.exports = isDOMEquals;
================================================
FILE: src/utils/__tests__/isDOMEquals-test.js
================================================
import isDOMEquals from '../isDOMEquals';
describe('isDOMEquals', () => {
it('should be true if dom equals', () => {
const div = document.createElement('div');
expect(isDOMEquals(div, div)).toEqual(true);
});
it('should be false if dom does not equal', () => {
const div1 = document.createElement('div');
const div2 = document.createElement('div');
expect(isDOMEquals(div1, div2)).toEqual(false);
});
});
================================================
FILE: src/utils/__tests__/outsideTargetHandlerFactory-test.js
================================================
import outsideTargetHandlerFactory from '../outsideTargetHandlerFactory';
jest.mock('../isDOMEquals');
const isDOMEquals = require('../isDOMEquals').default;
describe('outsideTargetHandlerFactory', () => {
let targetNode;
let eventHandler;
let handler;
beforeEach(() => {
targetNode = document.createElement('div');
eventHandler = jest.fn();
handler = outsideTargetHandlerFactory(targetNode, eventHandler);
});
it('handler should call stopPropagation', () => {
const event = {};
event.target = { parentNode: null };
event.stopPropagation = jest.fn();
handler(event);
expect(event.stopPropagation).toBeCalled();
});
it('eventHandler should be called when no parentNode', () => {
const event = {};
event.target = { parentNode: null };
event.stopPropagation = () => {};
handler(event);
expect(eventHandler).toBeCalled();
});
it('eventHandler should not be called when isDOMEquals return true', () => {
isDOMEquals.mockReturnValue(true);
const event = {};
event.target = { parentNode: document.createElement('div') };
event.stopPropagation = () => {};
handler(event);
expect(eventHandler.mock.calls.length).toEqual(0);
});
it('eventHandler should not be called when isDOMEquals return false', () => {
isDOMEquals.mockReturnValueOnce(false);
const event = {};
event.target = { parentNode: document.createElement('div') };
event.stopPropagation = () => {};
handler(event);
expect(eventHandler).toBeCalled();
});
});
================================================
FILE: src/utils/isDOMEquals.js
================================================
/**
* Determinate whether dom1 and dom2 is the same dom or not.
*
* @param {HTMLElement} dom1
* @param {HTMLElement} dom2
* @return {Boolean}
*/
export default function isDOMEquals(dom1, dom2) {
return dom1 === dom2;
}
================================================
FILE: src/utils/outsideTargetHandlerFactory.js
================================================
import isDOMEquals from './isDOMEquals';
/**
*
* @param {HTMLElement} targetNode
* @param {HTMLElement} eventHandler
* @return {Boolean}
*/
export default function outsideTargetHandlerFactory(targetNode, eventHandler) {
return evt => {
evt.stopPropagation();
let current = evt.target;
let found = false;
while (current.parentNode) {
found = isDOMEquals(current, targetNode);
if (found) return;
current = current.parentNode;
}
eventHandler(evt);
};
}
================================================
FILE: webpack.config.development.js
================================================
const webpack = require('webpack');
module.exports = {
module: {
loaders: [
{ test: /\.js$/, loaders: ['babel-loader'], exclude: /node_modules/ },
],
},
output: {
library: 'ReactSweetAlert',
libraryTarget: 'umd',
},
resolve: {
extensions: ['', '.js'],
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
}),
],
};
================================================
FILE: webpack.config.production.js
================================================
const webpack = require('webpack');
module.exports = {
module: {
loaders: [
{ test: /\.js$/, loaders: ['babel-loader'], exclude: /node_modules/ },
],
},
output: {
library: 'ReactSweetAlert',
libraryTarget: 'umd',
},
resolve: {
extensions: ['', '.js'],
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
new webpack.optimize.UglifyJsPlugin({
compressor: {
screw_ie8: true,
warnings: false,
},
}),
],
};
gitextract_ihku2qdz/ ├── .babelrc ├── .editorconfig ├── .eslintignore ├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── __mocks__/ │ └── sweetalert.js ├── examples/ │ ├── cancel/ │ │ ├── .babelrc │ │ ├── components/ │ │ │ └── App.js │ │ ├── index.html │ │ ├── index.js │ │ ├── package.json │ │ ├── server.js │ │ └── webpack.config.js │ ├── complex/ │ │ ├── .babelrc │ │ ├── components/ │ │ │ └── App.js │ │ ├── index.html │ │ ├── index.js │ │ ├── package.json │ │ ├── server.js │ │ └── webpack.config.js │ ├── component-as-body/ │ │ ├── .babelrc │ │ ├── components/ │ │ │ ├── App.js │ │ │ └── HelloWorld.js │ │ ├── index.html │ │ ├── index.js │ │ ├── package.json │ │ ├── server.js │ │ └── webpack.config.js │ ├── esc/ │ │ ├── .babelrc │ │ ├── components/ │ │ │ └── App.js │ │ ├── index.html │ │ ├── index.js │ │ ├── package.json │ │ ├── server.js │ │ └── webpack.config.js │ ├── history-change/ │ │ ├── .babelrc │ │ ├── components/ │ │ │ └── App.js │ │ ├── index.html │ │ ├── index.js │ │ ├── package.json │ │ ├── server.js │ │ └── webpack.config.js │ ├── input/ │ │ ├── .babelrc │ │ ├── components/ │ │ │ └── App.js │ │ ├── index.html │ │ ├── index.js │ │ ├── package.json │ │ ├── server.js │ │ └── webpack.config.js │ ├── outside-click/ │ │ ├── .babelrc │ │ ├── components/ │ │ │ └── App.js │ │ ├── index.html │ │ ├── index.js │ │ ├── package.json │ │ ├── server.js │ │ └── webpack.config.js │ ├── show-input-error/ │ │ ├── .babelrc │ │ ├── components/ │ │ │ └── App.js │ │ ├── index.html │ │ ├── index.js │ │ ├── package.json │ │ ├── server.js │ │ └── webpack.config.js │ └── simple/ │ ├── .babelrc │ ├── components/ │ │ └── App.js │ ├── index.html │ ├── index.js │ ├── package.json │ ├── server.js │ └── webpack.config.js ├── package.json ├── src/ │ ├── SweetAlert.js │ ├── __tests__/ │ │ ├── SweetAlert-test.js │ │ └── index-test.js │ ├── index.js │ └── utils/ │ ├── __mocks__/ │ │ └── isDOMEquals.js │ ├── __tests__/ │ │ ├── isDOMEquals-test.js │ │ └── outsideTargetHandlerFactory-test.js │ ├── isDOMEquals.js │ └── outsideTargetHandlerFactory.js ├── webpack.config.development.js └── webpack.config.production.js
SYMBOL INDEX (52 symbols across 12 files)
FILE: examples/cancel/components/App.js
class App (line 6) | class App extends Component {
method constructor (line 7) | constructor(props, context) {
method render (line 14) | render() {
FILE: examples/complex/components/App.js
class App (line 6) | class App extends Component {
method constructor (line 7) | constructor(props, context) {
method render (line 14) | render() {
FILE: examples/component-as-body/components/App.js
class App (line 8) | class App extends Component {
method constructor (line 9) | constructor(props, context) {
method render (line 16) | render() {
FILE: examples/esc/components/App.js
class App (line 6) | class App extends Component {
method constructor (line 7) | constructor(props, context) {
method render (line 14) | render() {
FILE: examples/history-change/components/App.js
class App (line 7) | class App extends Component {
method constructor (line 8) | constructor(props, context) {
method componentDidMount (line 15) | componentDidMount() {
method componentWillUnmount (line 19) | componentWillUnmount() {
method render (line 31) | render() {
FILE: examples/input/components/App.js
class App (line 6) | class App extends Component {
method constructor (line 7) | constructor(props, context) {
method render (line 14) | render() {
FILE: examples/outside-click/components/App.js
class App (line 6) | class App extends Component {
method constructor (line 7) | constructor(props, context) {
method render (line 14) | render() {
FILE: examples/show-input-error/components/App.js
class App (line 7) | class App extends Component {
method constructor (line 8) | constructor(props, context) {
method render (line 15) | render() {
FILE: examples/simple/components/App.js
class App (line 6) | class App extends Component {
method constructor (line 7) | constructor(props, context) {
method render (line 14) | render() {
FILE: src/SweetAlert.js
constant ALLOWS_KEYS (line 9) | const ALLOWS_KEYS = [
constant REMOVED_KEYS (line 29) | const REMOVED_KEYS = [
constant OVERWRITE_PROPS (line 37) | const OVERWRITE_PROPS = {
constant ALLOWS_INPUT_TYPES (line 45) | const ALLOWS_INPUT_TYPES = [
function warningRemoved (line 71) | function warningRemoved(props) {
class SweetAlert (line 81) | class SweetAlert extends Component {
method imageSize (line 95) | imageSize(props, propName) {
method constructor (line 143) | constructor(props, context) {
method componentDidMount (line 148) | componentDidMount() {
method componentWillReceiveProps (line 156) | componentWillReceiveProps(props) {
method componentWillUnmount (line 174) | componentWillUnmount() {
method setupWithProps (line 179) | setupWithProps(props) {
method registerOutsideClickHandler (line 194) | registerOutsideClickHandler(handler) {
method unregisterOutsideClickHandler (line 202) | unregisterOutsideClickHandler() {
method enableOutsideClick (line 207) | enableOutsideClick() {
method disableOutsideClick (line 215) | disableOutsideClick() {
method bindEscapeKey (line 223) | bindEscapeKey(onEscapeKey) {
method unbindEscapeKey (line 227) | unbindEscapeKey() {
method handleClick (line 231) | handleClick(isConfirm, onConfirm, onCancel) {
method handleClose (line 239) | handleClose(onClose) {
method render (line 248) | render() {
FILE: src/utils/isDOMEquals.js
function isDOMEquals (line 8) | function isDOMEquals(dom1, dom2) {
FILE: src/utils/outsideTargetHandlerFactory.js
function outsideTargetHandlerFactory (line 9) | function outsideTargetHandlerFactory(targetNode, eventHandler) {
Condensed preview — 87 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (67K chars).
[
{
"path": ".babelrc",
"chars": 48,
"preview": "{\n \"presets\": [\"latest\", \"stage-2\", \"react\"]\n}\n"
},
{
"path": ".editorconfig",
"chars": 188,
"preview": "root = true\n\n[*]\nindent_style = space\nend_of_line = lf\ncharset = utf-8\ntrim_trailing_whitespace = true\ninsert_final_newl"
},
{
"path": ".eslintignore",
"chars": 22,
"preview": "node_modules\ndist\nlib\n"
},
{
"path": ".eslintrc.json",
"chars": 649,
"preview": "{\n \"parser\": \"babel-eslint\",\n \"extends\": \"airbnb\",\n \"env\": {\n \"browser\": true,\n \"node\": true,\n \"jest\": true,"
},
{
"path": ".gitattributes",
"chars": 12,
"preview": "* text=auto\n"
},
{
"path": ".gitignore",
"chars": 55,
"preview": ".DS_Store\nnpm-debug.log\nnode_modules\ncoverage\nlib\ndist\n"
},
{
"path": ".travis.yml",
"chars": 170,
"preview": "sudo: false\nlanguage: node_js\nnode_js:\n - '7'\n - '6'\n - '4'\nscript: \"npm run test:cov\"\nafter_script: \"npm install cov"
},
{
"path": "CHANGELOG.md",
"chars": 1002,
"preview": "0.4.11 / 2017-12-12\n===================\n- [new] Support React v16\n\n0.4.10 / 2017-04-24\n==================\n- [deps] Remov"
},
{
"path": "LICENSE",
"chars": 1147,
"preview": "The MIT License (MIT)\n\nCopyright (c) 2015-present C.T. Lin <chentsulin@gmail.com> (github.com/chentsulin/sweetalert-reac"
},
{
"path": "README.md",
"chars": 3313,
"preview": "# sweetalert-react\n\n[![NPM version][npm-image]][npm-url]\n[![Dependency Status][david_img]][david_site]\n\n> Declarative Sw"
},
{
"path": "__mocks__/sweetalert.js",
"chars": 87,
"preview": "const sweetalert = jest.genMockFromModule('sweetalert');\n\nmodule.exports = sweetalert;\n"
},
{
"path": "examples/cancel/.babelrc",
"chars": 48,
"preview": "{\n \"presets\": [\"latest\", \"stage-2\", \"react\"]\n}\n"
},
{
"path": "examples/cancel/components/App.js",
"chars": 1041,
"preview": "import React, { Component } from 'react';\nimport SweetAlert from 'sweetalert-react'; // eslint-disable-line import/no-ex"
},
{
"path": "examples/cancel/index.html",
"chars": 166,
"preview": "<html>\n <head>\n <title>sweetalert-react-example</title>\n </head>\n <body>\n <div id=\"root\"></div>\n\t<script src=\"/"
},
{
"path": "examples/cancel/index.js",
"chars": 156,
"preview": "import React from 'react';\nimport { render } from 'react-dom';\nimport App from './components/App';\n\nrender(\n <App />,\n "
},
{
"path": "examples/cancel/package.json",
"chars": 1025,
"preview": "{\n \"name\": \"sweetalert-react-example\",\n \"version\": \"1.0.0\",\n \"description\": \"sweetalert-react-example-description\",\n "
},
{
"path": "examples/cancel/server.js",
"chars": 544,
"preview": "/* eslint-disable import/no-extraneous-dependencies */\n\nconst webpack = require('webpack');\nconst WebpackDevServer = req"
},
{
"path": "examples/cancel/webpack.config.js",
"chars": 938,
"preview": "const path = require('path');\nconst webpack = require('webpack');\n\nmodule.exports = {\n devtool: 'eval',\n entry: [\n "
},
{
"path": "examples/complex/.babelrc",
"chars": 48,
"preview": "{\n \"presets\": [\"latest\", \"stage-2\", \"react\"]\n}\n"
},
{
"path": "examples/complex/components/App.js",
"chars": 1106,
"preview": "import React, { Component } from 'react';\nimport SweetAlert from 'sweetalert-react'; // eslint-disable-line import/no-ex"
},
{
"path": "examples/complex/index.html",
"chars": 166,
"preview": "<html>\n <head>\n <title>sweetalert-react-example</title>\n </head>\n <body>\n <div id=\"root\"></div>\n\t<script src=\"/"
},
{
"path": "examples/complex/index.js",
"chars": 156,
"preview": "import React from 'react';\nimport { render } from 'react-dom';\nimport App from './components/App';\n\nrender(\n <App />,\n "
},
{
"path": "examples/complex/package.json",
"chars": 1025,
"preview": "{\n \"name\": \"sweetalert-react-example\",\n \"version\": \"1.0.0\",\n \"description\": \"sweetalert-react-example-description\",\n "
},
{
"path": "examples/complex/server.js",
"chars": 544,
"preview": "/* eslint-disable import/no-extraneous-dependencies */\n\nconst webpack = require('webpack');\nconst WebpackDevServer = req"
},
{
"path": "examples/complex/webpack.config.js",
"chars": 938,
"preview": "const path = require('path');\nconst webpack = require('webpack');\n\nmodule.exports = {\n devtool: 'eval',\n entry: [\n "
},
{
"path": "examples/component-as-body/.babelrc",
"chars": 48,
"preview": "{\n \"presets\": [\"latest\", \"stage-2\", \"react\"]\n}\n"
},
{
"path": "examples/component-as-body/components/App.js",
"chars": 798,
"preview": "import React, { Component } from 'react';\nimport { renderToStaticMarkup } from 'react-dom/server';\nimport SweetAlert fro"
},
{
"path": "examples/component-as-body/components/HelloWorld.js",
"chars": 111,
"preview": "import React from 'react';\n\nconst HelloWorld = () => <h1>SweetAlert in React</h1>;\n\nexport default HelloWorld;\n"
},
{
"path": "examples/component-as-body/index.html",
"chars": 166,
"preview": "<html>\n <head>\n <title>sweetalert-react-example</title>\n </head>\n <body>\n <div id=\"root\"></div>\n\t<script src=\"/"
},
{
"path": "examples/component-as-body/index.js",
"chars": 156,
"preview": "import React from 'react';\nimport { render } from 'react-dom';\nimport App from './components/App';\n\nrender(\n <App />,\n "
},
{
"path": "examples/component-as-body/package.json",
"chars": 1025,
"preview": "{\n \"name\": \"sweetalert-react-example\",\n \"version\": \"1.0.0\",\n \"description\": \"sweetalert-react-example-description\",\n "
},
{
"path": "examples/component-as-body/server.js",
"chars": 544,
"preview": "/* eslint-disable import/no-extraneous-dependencies */\n\nconst webpack = require('webpack');\nconst WebpackDevServer = req"
},
{
"path": "examples/component-as-body/webpack.config.js",
"chars": 938,
"preview": "const path = require('path');\nconst webpack = require('webpack');\n\nmodule.exports = {\n devtool: 'eval',\n entry: [\n "
},
{
"path": "examples/esc/.babelrc",
"chars": 48,
"preview": "{\n \"presets\": [\"latest\", \"stage-2\", \"react\"]\n}\n"
},
{
"path": "examples/esc/components/App.js",
"chars": 735,
"preview": "import React, { Component } from 'react';\nimport SweetAlert from 'sweetalert-react'; // eslint-disable-line import/no-ex"
},
{
"path": "examples/esc/index.html",
"chars": 166,
"preview": "<html>\n <head>\n <title>sweetalert-react-example</title>\n </head>\n <body>\n <div id=\"root\"></div>\n\t<script src=\"/"
},
{
"path": "examples/esc/index.js",
"chars": 156,
"preview": "import React from 'react';\nimport { render } from 'react-dom';\nimport App from './components/App';\n\nrender(\n <App />,\n "
},
{
"path": "examples/esc/package.json",
"chars": 1025,
"preview": "{\n \"name\": \"sweetalert-react-example\",\n \"version\": \"1.0.0\",\n \"description\": \"sweetalert-react-example-description\",\n "
},
{
"path": "examples/esc/server.js",
"chars": 544,
"preview": "/* eslint-disable import/no-extraneous-dependencies */\n\nconst webpack = require('webpack');\nconst WebpackDevServer = req"
},
{
"path": "examples/esc/webpack.config.js",
"chars": 938,
"preview": "const path = require('path');\nconst webpack = require('webpack');\n\nmodule.exports = {\n devtool: 'eval',\n entry: [\n "
},
{
"path": "examples/history-change/.babelrc",
"chars": 48,
"preview": "{\n \"presets\": [\"latest\", \"stage-2\", \"react\"]\n}\n"
},
{
"path": "examples/history-change/components/App.js",
"chars": 1082,
"preview": "import React, { Component } from 'react';\nimport shortid from 'shortid';\nimport SweetAlert from 'sweetalert-react'; // e"
},
{
"path": "examples/history-change/index.html",
"chars": 166,
"preview": "<html>\n <head>\n <title>sweetalert-react-example</title>\n </head>\n <body>\n <div id=\"root\"></div>\n\t<script src=\"/"
},
{
"path": "examples/history-change/index.js",
"chars": 156,
"preview": "import React from 'react';\nimport { render } from 'react-dom';\nimport App from './components/App';\n\nrender(\n <App />,\n "
},
{
"path": "examples/history-change/package.json",
"chars": 1050,
"preview": "{\n \"name\": \"sweetalert-react-example\",\n \"version\": \"1.0.0\",\n \"description\": \"sweetalert-react-example-description\",\n "
},
{
"path": "examples/history-change/server.js",
"chars": 544,
"preview": "/* eslint-disable import/no-extraneous-dependencies */\n\nconst webpack = require('webpack');\nconst WebpackDevServer = req"
},
{
"path": "examples/history-change/webpack.config.js",
"chars": 938,
"preview": "const path = require('path');\nconst webpack = require('webpack');\n\nmodule.exports = {\n devtool: 'eval',\n entry: [\n "
},
{
"path": "examples/input/.babelrc",
"chars": 48,
"preview": "{\n \"presets\": [\"latest\", \"stage-2\", \"react\"]\n}\n"
},
{
"path": "examples/input/components/App.js",
"chars": 874,
"preview": "import React, { Component } from 'react';\nimport SweetAlert from 'sweetalert-react'; // eslint-disable-line import/no-ex"
},
{
"path": "examples/input/index.html",
"chars": 166,
"preview": "<html>\n <head>\n <title>sweetalert-react-example</title>\n </head>\n <body>\n <div id=\"root\"></div>\n\t<script src=\"/"
},
{
"path": "examples/input/index.js",
"chars": 156,
"preview": "import React from 'react';\nimport { render } from 'react-dom';\nimport App from './components/App';\n\nrender(\n <App />,\n "
},
{
"path": "examples/input/package.json",
"chars": 1025,
"preview": "{\n \"name\": \"sweetalert-react-example\",\n \"version\": \"1.0.0\",\n \"description\": \"sweetalert-react-example-description\",\n "
},
{
"path": "examples/input/server.js",
"chars": 544,
"preview": "/* eslint-disable import/no-extraneous-dependencies */\n\nconst webpack = require('webpack');\nconst WebpackDevServer = req"
},
{
"path": "examples/input/webpack.config.js",
"chars": 938,
"preview": "const path = require('path');\nconst webpack = require('webpack');\n\nmodule.exports = {\n devtool: 'eval',\n entry: [\n "
},
{
"path": "examples/outside-click/.babelrc",
"chars": 48,
"preview": "{\n \"presets\": [\"latest\", \"stage-2\", \"react\"]\n}\n"
},
{
"path": "examples/outside-click/components/App.js",
"chars": 747,
"preview": "import React, { Component } from 'react';\nimport SweetAlert from 'sweetalert-react'; // eslint-disable-line import/no-ex"
},
{
"path": "examples/outside-click/index.html",
"chars": 166,
"preview": "<html>\n <head>\n <title>sweetalert-react-example</title>\n </head>\n <body>\n <div id=\"root\"></div>\n\t<script src=\"/"
},
{
"path": "examples/outside-click/index.js",
"chars": 156,
"preview": "import React from 'react';\nimport { render } from 'react-dom';\nimport App from './components/App';\n\nrender(\n <App />,\n "
},
{
"path": "examples/outside-click/package.json",
"chars": 1024,
"preview": "{\n \"name\": \"sweetalert-react-example\",\n \"version\": \"1.0.0\",\n \"description\": \"sweetalert-react-example-description\",\n "
},
{
"path": "examples/outside-click/server.js",
"chars": 544,
"preview": "/* eslint-disable import/no-extraneous-dependencies */\n\nconst webpack = require('webpack');\nconst WebpackDevServer = req"
},
{
"path": "examples/outside-click/webpack.config.js",
"chars": 938,
"preview": "const path = require('path');\nconst webpack = require('webpack');\n\nmodule.exports = {\n devtool: 'eval',\n entry: [\n "
},
{
"path": "examples/show-input-error/.babelrc",
"chars": 48,
"preview": "{\n \"presets\": [\"latest\", \"stage-2\", \"react\"]\n}\n"
},
{
"path": "examples/show-input-error/components/App.js",
"chars": 1055,
"preview": "import React, { Component } from 'react';\nimport swal from 'sweetalert';\nimport SweetAlert from 'sweetalert-react'; // e"
},
{
"path": "examples/show-input-error/index.html",
"chars": 166,
"preview": "<html>\n <head>\n <title>sweetalert-react-example</title>\n </head>\n <body>\n <div id=\"root\"></div>\n\t<script src=\"/"
},
{
"path": "examples/show-input-error/index.js",
"chars": 156,
"preview": "import React from 'react';\nimport { render } from 'react-dom';\nimport App from './components/App';\n\nrender(\n <App />,\n "
},
{
"path": "examples/show-input-error/package.json",
"chars": 1025,
"preview": "{\n \"name\": \"sweetalert-react-example\",\n \"version\": \"1.0.0\",\n \"description\": \"sweetalert-react-example-description\",\n "
},
{
"path": "examples/show-input-error/server.js",
"chars": 544,
"preview": "/* eslint-disable import/no-extraneous-dependencies */\n\nconst webpack = require('webpack');\nconst WebpackDevServer = req"
},
{
"path": "examples/show-input-error/webpack.config.js",
"chars": 938,
"preview": "const path = require('path');\nconst webpack = require('webpack');\n\nmodule.exports = {\n devtool: 'eval',\n entry: [\n "
},
{
"path": "examples/simple/.babelrc",
"chars": 48,
"preview": "{\n \"presets\": [\"latest\", \"stage-2\", \"react\"]\n}\n"
},
{
"path": "examples/simple/components/App.js",
"chars": 670,
"preview": "import React, { Component } from 'react';\nimport SweetAlert from 'sweetalert-react'; // eslint-disable-line import/no-ex"
},
{
"path": "examples/simple/index.html",
"chars": 166,
"preview": "<html>\n <head>\n <title>sweetalert-react-example</title>\n </head>\n <body>\n <div id=\"root\"></div>\n\t<script src=\"/"
},
{
"path": "examples/simple/index.js",
"chars": 156,
"preview": "import React from 'react';\nimport { render } from 'react-dom';\nimport App from './components/App';\n\nrender(\n <App />,\n "
},
{
"path": "examples/simple/package.json",
"chars": 1025,
"preview": "{\n \"name\": \"sweetalert-react-example\",\n \"version\": \"1.0.0\",\n \"description\": \"sweetalert-react-example-description\",\n "
},
{
"path": "examples/simple/server.js",
"chars": 544,
"preview": "/* eslint-disable import/no-extraneous-dependencies */\n\nconst webpack = require('webpack');\nconst WebpackDevServer = req"
},
{
"path": "examples/simple/webpack.config.js",
"chars": 938,
"preview": "const path = require('path');\nconst webpack = require('webpack');\n\nmodule.exports = {\n devtool: 'eval',\n entry: [\n "
},
{
"path": "package.json",
"chars": 2381,
"preview": "{\n \"name\": \"sweetalert-react\",\n \"version\": \"0.4.11\",\n \"description\": \"Declarative SweetAlert in React\",\n \"main\": \"li"
},
{
"path": "src/SweetAlert.js",
"chars": 6066,
"preview": "import { Component } from 'react';\nimport PropTypes from 'prop-types';\nimport swal from 'sweetalert';\nimport pick from '"
},
{
"path": "src/__tests__/SweetAlert-test.js",
"chars": 4340,
"preview": "/* eslint-disable no-console */\n\nimport React from 'react';\nimport { mount } from 'enzyme';\nimport swal from 'sweetalert"
},
{
"path": "src/__tests__/index-test.js",
"chars": 525,
"preview": "import React from 'react';\nimport { render } from 'react-dom';\nimport { renderToString } from 'react-dom/server';\n\nimpor"
},
{
"path": "src/index.js",
"chars": 161,
"preview": "if (typeof window === 'undefined') {\n module.exports = () => null;\n} else {\n module.exports = require('./SweetAlert');"
},
{
"path": "src/utils/__mocks__/isDOMEquals.js",
"chars": 93,
"preview": "const isDOMEquals = jest.genMockFromModule('../isDOMEquals');\n\nmodule.exports = isDOMEquals;\n"
},
{
"path": "src/utils/__tests__/isDOMEquals-test.js",
"chars": 435,
"preview": "import isDOMEquals from '../isDOMEquals';\n\ndescribe('isDOMEquals', () => {\n it('should be true if dom equals', () => {\n"
},
{
"path": "src/utils/__tests__/outsideTargetHandlerFactory-test.js",
"chars": 1544,
"preview": "import outsideTargetHandlerFactory from '../outsideTargetHandlerFactory';\n\njest.mock('../isDOMEquals');\n\nconst isDOMEqua"
},
{
"path": "src/utils/isDOMEquals.js",
"chars": 231,
"preview": "/**\n * Determinate whether dom1 and dom2 is the same dom or not.\n *\n * @param {HTMLElement} dom1\n * @param {HTMLEleme"
},
{
"path": "src/utils/outsideTargetHandlerFactory.js",
"chars": 506,
"preview": "import isDOMEquals from './isDOMEquals';\n\n/**\n *\n * @param {HTMLElement} targetNode\n * @param {HTMLElement} eventHan"
},
{
"path": "webpack.config.development.js",
"chars": 464,
"preview": "const webpack = require('webpack');\n\nmodule.exports = {\n module: {\n loaders: [\n { test: /\\.js$/, loaders: ['bab"
},
{
"path": "webpack.config.production.js",
"chars": 592,
"preview": "const webpack = require('webpack');\n\nmodule.exports = {\n module: {\n loaders: [\n { test: /\\.js$/, loaders: ['bab"
}
]
About this extraction
This page contains the full source code of the chentsulin/sweetalert-react GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 87 files (56.8 KB), approximately 17.9k tokens, and a symbol index with 52 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.