├── .gitignore ├── LICENSE ├── README.md ├── index.js ├── package.json └── src └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Kyle J. Kemp 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DEPRECATED 2 | This library should not be used. Either import swal directly or use [this fork instead](https://github.com/toverux/ngsweetalert2). 3 | 4 | # ng2-sweetalert2 5 | A service wrapping sweetalert2 for angular 2. 6 | 7 | # Install 8 | `npm i -s ng2-sweetalert2` 9 | 10 | # Usage 11 | 12 | First, make sure you have a CSS loader set up for webpack, like so: 13 | ``` 14 | { 15 | test: /\.css/, 16 | loader: 'style!css' 17 | }, 18 | ``` 19 | 20 | Next, inject `SweetAlertService` into a component: 21 | ```js 22 | import { SweetAlertService } from 'ng2-sweetalert2'; 23 | 24 | @Component({ 25 | providers: [SweetAlertService] 26 | }) 27 | export class MyComponent { 28 | 29 | static get parameters() { 30 | return [[SweetAlertService]]; 31 | } 32 | 33 | constructor(swal) { 34 | this.swalService = swal; 35 | } 36 | ``` 37 | 38 | # API 39 | See [limonte/sweetalert2](https://github.com/limonte/sweetalert2) for examples. 40 | 41 | Function | Arguments | Description 42 | -------- | --------- | ----------- 43 | swal | any | Create a generic swal with any arguments. 44 | prompt | object | Create a swal that prompts user with a basic text entry field. 45 | confirm | object | Create a swal that confirms a user action. 46 | alert | object | Create a swal that alerts a user of something that happened. 47 | question | object | Wrapper for `alert` that sets type to `question`. 48 | success | object | Wrapper for `alert` that sets type to `success`. 49 | error | object | Wrapper for `alert` that sets type to `error`. 50 | warn | object | Wrapper for `alert` that sets type to `warn`. 51 | info | object | Wrapper for `alert` that sets type to `info`. 52 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.SweetAlertService = undefined; 7 | 8 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); 9 | 10 | var _sweetalert = require('sweetalert2'); 11 | 12 | var _sweetalert2 = _interopRequireDefault(_sweetalert); 13 | 14 | require('sweetalert2/dist/sweetalert2.min.css'); 15 | 16 | var _lodash = require('lodash.assign'); 17 | 18 | var _lodash2 = _interopRequireDefault(_lodash); 19 | 20 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 21 | 22 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 23 | 24 | var SweetAlertService = exports.SweetAlertService = function () { 25 | function SweetAlertService() { 26 | _classCallCheck(this, SweetAlertService); 27 | } 28 | 29 | _createClass(SweetAlertService, [{ 30 | key: 'swal', 31 | value: function swal() { 32 | return _sweetalert2.default.apply(undefined, arguments); 33 | } 34 | }, { 35 | key: 'prompt', 36 | value: function prompt(options) { 37 | var baseOptions = { 38 | showCancelButton: true, 39 | confirmButtonText: 'Submit', 40 | input: 'text' 41 | }; 42 | return (0, _sweetalert2.default)((0, _lodash2.default)(baseOptions, options)); 43 | } 44 | }, { 45 | key: 'confirm', 46 | value: function confirm(options) { 47 | var baseOptions = { 48 | showCancelButton: true, 49 | confirmButtonText: 'Confirm', 50 | type: 'warning' 51 | }; 52 | return (0, _sweetalert2.default)((0, _lodash2.default)(baseOptions, options)); 53 | } 54 | }, { 55 | key: 'alert', 56 | value: function alert(options) { 57 | var baseOptions = { 58 | confirmButtonText: 'OK', 59 | type: 'info' 60 | }; 61 | return (0, _sweetalert2.default)((0, _lodash2.default)(baseOptions, options)); 62 | } 63 | }, { 64 | key: 'question', 65 | value: function question(options) { 66 | return this.alert((0, _lodash2.default)({ type: 'question' }, options)); 67 | } 68 | }, { 69 | key: 'success', 70 | value: function success(options) { 71 | return this.alert((0, _lodash2.default)({ type: 'success' }, options)); 72 | } 73 | }, { 74 | key: 'error', 75 | value: function error(options) { 76 | return this.alert((0, _lodash2.default)({ type: 'error' }, options)); 77 | } 78 | }, { 79 | key: 'warn', 80 | value: function warn(options) { 81 | return this.alert((0, _lodash2.default)({ type: 'warn' }, options)); 82 | } 83 | }, { 84 | key: 'info', 85 | value: function info(options) { 86 | return this.alert((0, _lodash2.default)({ type: 'info' }, options)); 87 | } 88 | }]); 89 | 90 | return SweetAlertService; 91 | }(); 92 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ng2-sweetalert2", 3 | "version": "0.0.9", 4 | "description": "A service wrapping sweetalert2 for angular2.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/seiyria/ng2-sweetalert2.git" 12 | }, 13 | "keywords": [ 14 | "ng2", 15 | "angular2", 16 | "sweetalert2", 17 | "sweetalert", 18 | "swal", 19 | "ng2-sweetalert", 20 | "angular2-sweetalert", 21 | "ng2-sweetalert2", 22 | "angular2-sweetalert2" 23 | ], 24 | "author": "Kyle Kemp ", 25 | "license": "MIT", 26 | "bugs": { 27 | "url": "https://github.com/seiyria/ng2-sweetalert2/issues" 28 | }, 29 | "scripts": { 30 | "compile": "babel src/index.js -o index.js --presets es2015" 31 | }, 32 | "homepage": "https://github.com/seiyria/ng2-sweetalert2#readme", 33 | "dependencies": { 34 | "lodash.assign": "^4.0.8", 35 | "sweetalert2": "^5.2.0" 36 | }, 37 | "peerDependencies": { 38 | "@angular/platform-browser": "^4.2.5" 39 | }, 40 | "devDependencies": { 41 | "babel-preset-es2015": "^6.9.0" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | 2 | import sweetalert from 'sweetalert2'; 3 | import 'sweetalert2/dist/sweetalert2.min.css'; 4 | 5 | import assign from 'lodash.assign'; 6 | 7 | export class SweetAlertService { 8 | constructor() {} 9 | 10 | swal() { 11 | return sweetalert(...arguments); 12 | } 13 | 14 | prompt(options) { 15 | const baseOptions = { 16 | showCancelButton: true, 17 | confirmButtonText: 'Submit', 18 | input: 'text' 19 | }; 20 | return sweetalert(assign(baseOptions, options)); 21 | } 22 | 23 | confirm(options) { 24 | const baseOptions = { 25 | showCancelButton: true, 26 | confirmButtonText: 'Confirm', 27 | type: 'warning' 28 | }; 29 | return sweetalert(assign(baseOptions, options)); 30 | } 31 | 32 | alert(options) { 33 | const baseOptions = { 34 | confirmButtonText: 'OK', 35 | type: 'info' 36 | }; 37 | return sweetalert(assign(baseOptions, options)); 38 | } 39 | 40 | question(options) { 41 | return this.alert(assign({ type: 'question' }, options)); 42 | } 43 | 44 | success(options) { 45 | return this.alert(assign({ type: 'success' }, options)); 46 | } 47 | 48 | error(options) { 49 | return this.alert(assign({ type: 'error' }, options)); 50 | } 51 | 52 | warn(options) { 53 | return this.alert(assign({ type: 'warn' }, options)); 54 | } 55 | 56 | info(options) { 57 | return this.alert(assign({ type: 'info' }, options)); 58 | } 59 | } 60 | --------------------------------------------------------------------------------