Skip to content

Commit

Permalink
wip link fix
Browse files Browse the repository at this point in the history
  • Loading branch information
avil13 committed May 14, 2019
1 parent 2e946a9 commit ecf942c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 37 deletions.
47 changes: 33 additions & 14 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"dependencies": {
"vue": "^2.5.22",
"sweetalert2": "7.x"
"sweetalert2": "8.x"
},
"devDependencies": {
"@babel/core": "^7.2.2",
Expand Down
45 changes: 24 additions & 21 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,51 @@
// @ts-check
import Vue from 'vue';

/** @type swal {import("sweetalert2")} */
import Swal, { SweetAlertOptions } from 'sweetalert2';

require('sweetalert2/dist/sweetalert2.min.css');

type VueSwalInstance = typeof Swal.fire;

declare module 'vue/types/vue' {
interface Vue {
$swal: typeof Swal.fire;
$swal: VueSwalInstance;
}

interface VueConstructor<V extends Vue = Vue> {
swal: typeof Swal.fire;
swal: VueSwalInstance;
}
}



function isBrowser() {
return typeof window !== 'undefined';
interface VueSweetalert2Options extends SweetAlertOptions {
includeCss?: boolean;
}

class VueSweetalert2 {
static install(Vue: Vue | any, options?: SweetAlertOptions): void {
// adding a global method or property
let _swal;

if (isBrowser()) {
_swal = (options ? Swal.mixin(options).fire.bind(Swal) : Swal.fire.bind(Swal));
} else {
_swal = function () {
return Promise.resolve();
};
static install(Vue: Vue | any, options?: VueSweetalert2Options): void {
options = {
...{
includeCss: true
},
...options
};

if (options.includeCss === false) {
require('sweetalert2/dist/sweetalert2.min.css');
}

// adding a global method or property
let _swal: VueSwalInstance;

_swal = options ? Swal.mixin(options).fire.bind(Swal) : Swal.fire.bind(Swal);

// Object.assign(_swal, Swal);

Vue['swal'] = _swal;

// add the instance method
if (!Vue.prototype.hasOwnProperty('$swal')) {
Vue.prototype.$swal = _swal;
}
}
};

}

export default VueSweetalert2;
1 change: 0 additions & 1 deletion src/vue-sweetaler2

This file was deleted.

0 comments on commit ecf942c

Please sign in to comment.