-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
58 additions
and
37 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file was deleted.
Oops, something went wrong.