-
-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Replace confirm dialog with Vuetify dialog fix #202
- Loading branch information
1 parent
f2e3084
commit a45900a
Showing
3 changed files
with
157 additions
and
39 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<template> | ||
<v-dialog | ||
v-model="show" | ||
:max-width="options.width" | ||
:style="{ zIndex: options.zIndex }" | ||
@keydown.esc="cancel" | ||
> | ||
<v-card> | ||
<v-toolbar :color="options.color" dark dense flat> | ||
<v-toolbar-title class="white--text">{{ title }}</v-toolbar-title> | ||
</v-toolbar> | ||
<v-card-text v-show="!!message" class="pa-4">{{ message }}</v-card-text> | ||
<v-card-actions class="pt-0"> | ||
<v-spacer></v-spacer> | ||
<v-btn @click.native="agree" flat :color="options.color">Yes</v-btn> | ||
<v-btn @click.native="cancel" flat>Cancel</v-btn> | ||
</v-card-actions> | ||
</v-card> | ||
</v-dialog> | ||
</template> | ||
|
||
<script> | ||
/** | ||
* Vuetify Confirm Dialog component | ||
* | ||
* Insert component where you want to use it: | ||
* <confirm ref="confirm"></confirm> | ||
* | ||
* Call it: | ||
* this.$refs.confirm.open('Delete', 'Are you sure?', { color: 'red' }).then((confirm) => {}) | ||
* Or use await: | ||
* if (await this.$refs.confirm.open('Delete', 'Are you sure?', { color: 'red' })) { | ||
* // yes | ||
* } | ||
* else { | ||
* // cancel | ||
* } | ||
* | ||
* Alternatively you can place it in main App component and access it globally via this.$root.$confirm | ||
* <template> | ||
* <v-app> | ||
* ... | ||
* <confirm ref="confirm"></confirm> | ||
* </v-app> | ||
* </template> | ||
* | ||
* mounted() { | ||
* this.$root.$confirm = this.$refs.confirm.open | ||
* } | ||
*/ | ||
export default { | ||
data: () => ({ | ||
dialog: false, | ||
resolve: null, | ||
reject: null, | ||
message: null, | ||
title: null, | ||
options: { | ||
color: 'primary', | ||
width: 290, | ||
zIndex: 200 | ||
} | ||
}), | ||
computed: { | ||
show: { | ||
get () { | ||
return this.dialog | ||
}, | ||
set (value) { | ||
this.dialog = value | ||
if (value === false) { | ||
this.cancel() | ||
} | ||
} | ||
} | ||
}, | ||
methods: { | ||
open (title, message, options) { | ||
this.dialog = true | ||
this.title = title | ||
this.message = message | ||
this.options = Object.assign(this.options, options) | ||
return new Promise((resolve, reject) => { | ||
this.resolve = resolve | ||
this.reject = reject | ||
}) | ||
}, | ||
agree () { | ||
this.resolve(true) | ||
this.dialog = false | ||
}, | ||
cancel () { | ||
this.resolve(false) | ||
this.dialog = false | ||
} | ||
} | ||
} | ||
</script> |
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