-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mdc-dialog): Support v-model for open/close dialog
- Loading branch information
Showing
3 changed files
with
139 additions
and
102 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 |
---|---|---|
@@ -1,88 +1,90 @@ | ||
## Usage | ||
|
||
```html | ||
<mdc-dialog ref="dialog" | ||
title="Title" accept="Accept" cancel="Decline" | ||
@accept="onAccept" @cancel="onDecline" | ||
>{{ dialogText }}</mdc-dialog> | ||
``` | ||
|
||
```javascript | ||
var vm = new Vue({ | ||
data: { | ||
dialogText: 'Lorem ipsum dolor sit amet, ...', | ||
}, | ||
methods: { | ||
showDialog () { | ||
this.$refs.dialog.show() | ||
}, | ||
onAccept () { | ||
console.log('accepted') | ||
}, | ||
onDecline () { | ||
console.log('declined') | ||
}, | ||
} | ||
}) | ||
``` | ||
|
||
### props | ||
|
||
| props | Type | Default | Description | | ||
|-------|------|---------|-------------| | ||
|`title`|String| required | the dialog title | | ||
|`accept`|String|`'Ok'`| the dialog accept button text | | ||
|`accept-disabled`|String|`'Ok'`| the dialog accept button text | | ||
|`cancel`| String| `'cancel'`| the dialog cancel button text | | ||
|`scrollable`| Boolean| false | whether the dialog is scrollable | | ||
|`accent`| Boolean| false | set accented style to the footer buttons | | ||
|
||
### events | ||
|
||
| props | args | Description | | ||
|---------|------|--------------| | ||
|`@accept`| none | emitted when dialog is accepted | | ||
|`@cancel`| none | emitted when dialog is cancelled | | ||
|`@validate`| accept | emmited before the dialog is accepted _(*)_ | | ||
|
||
> Note that if you listen to the @validate event, then You must call | ||
the accept argument to finally close the box. Use `accept(false)` to | ||
prevent emitting the `accept` event and just close. | ||
|
||
### Custom validation logic | ||
|
||
You can use the `accept-disabled` property to prevent the dialog to close | ||
when the accept button is clicked. | ||
|
||
```html | ||
<mdc-dialog ref="dialog" title="Dialog" accept="Accept" cancel="Decline" | ||
:accept-disabled="isThisNotAcceptable" | ||
>Lorem ipsum dolor sit amet</mdc-dialog> | ||
``` | ||
|
||
Or use the `@validate` event to trigger your own validation logic as follow: | ||
|
||
```html | ||
<mdc-dialog ref="dialog" title="Dialog" accept="Accept" cancel="Decline" | ||
@validate="onValidate" | ||
>Lorem ipsum dolor sit amet</mdc-dialog> | ||
``` | ||
|
||
```javascript | ||
export default { | ||
methods:{ | ||
onValidate ({accept}) { | ||
let isValid = false | ||
// custom validation logic here | ||
// .. | ||
if (isValid) { | ||
accept() | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### Reference | ||
|
||
<https://material.io/components/web/catalog/dialogs> | ||
## Usage | ||
|
||
```html | ||
<mdc-button raised @click="open=!open">Show dialog</mdc-button> | ||
<mdc-dialog v-model="open" | ||
title="Title" accept="Accept" cancel="Decline" | ||
@accept="onAccept" @cancel="onDecline"> | ||
{{ dialogText }} | ||
</mdc-dialog> | ||
``` | ||
|
||
```javascript | ||
var vm = new Vue({ | ||
data: { | ||
dialogText: 'Lorem ipsum dolor sit amet, ...', | ||
open: false, | ||
}, | ||
methods: { | ||
onAccept() { | ||
console.log('accepted'); | ||
}, | ||
onDecline() { | ||
console.log('declined'); | ||
}, | ||
}, | ||
}); | ||
``` | ||
|
||
### props | ||
|
||
| props | Type | Default | Description | | ||
| ----------------- | ------- | ---------- | ---------------------------------------- | | ||
| `open` | Boolean | false | optional v-model when true opens dialog | | ||
| `title` | String | required | the dialog title | | ||
| `accept` | String | `'Ok'` | the dialog accept button text | | ||
| `accept-disabled` | String | `'Ok'` | the dialog accept button text | | ||
| `cancel` | String | `'cancel'` | the dialog cancel button text | | ||
| `scrollable` | Boolean | false | whether the dialog is scrollable | | ||
| `accent` | Boolean | false | set accented style to the footer buttons | | ||
|
||
### events | ||
|
||
| props | args | Description | | ||
| ----------- | ------- | ------------------------------------------------------- | | ||
| `@change` | Boolean | notify v-model/listeners that drawer state has changed. | | ||
| `@accept` | none | emitted when dialog is accepted | | ||
| `@cancel` | none | emitted when dialog is cancelled | | ||
| `@validate` | accept | emmited before the dialog is accepted _(\*)_ | | ||
|
||
> Note that if you listen to the @validate event, then You must call | ||
> the accept argument to finally close the box. Use `accept(false)` to | ||
> prevent emitting the `accept` event and just close. | ||
### Custom validation logic | ||
|
||
You can use the `accept-disabled` property to prevent the dialog to close | ||
when the accept button is clicked. | ||
|
||
```html | ||
<mdc-dialog ref="dialog" title="Dialog" accept="Accept" cancel="Decline" | ||
:accept-disabled="isThisNotAcceptable" | ||
>Lorem ipsum dolor sit amet</mdc-dialog> | ||
``` | ||
|
||
Or use the `@validate` event to trigger your own validation logic as follow: | ||
|
||
```html | ||
<mdc-dialog ref="dialog" title="Dialog" accept="Accept" cancel="Decline" | ||
@validate="onValidate" | ||
>Lorem ipsum dolor sit amet</mdc-dialog> | ||
``` | ||
|
||
```javascript | ||
export default { | ||
methods: { | ||
onValidate({ accept }) { | ||
let isValid = false; | ||
// custom validation logic here | ||
// .. | ||
if (isValid) { | ||
accept(); | ||
} | ||
}, | ||
}, | ||
}; | ||
``` | ||
|
||
### Reference | ||
|
||
<https://material.io/components/web/catalog/dialogs> |
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,16 +1,23 @@ | ||
<template> | ||
<div class="mdc-demo mdc-demo--container"> | ||
<div class="mdc-demo mdc-demo--container"> | ||
|
||
<mdc-dialog ref="dialog" title="Dialog" accept="Accept" cancel="Decline" | ||
@validate="$event.accept()" | ||
> | ||
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod | ||
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim | ||
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea | ||
commodo consequat. | ||
</mdc-dialog> | ||
<mdc-dialog v-model="open" title="Dialog" accept="Accept" cancel="Decline" @validate="$event.accept(false)"> | ||
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et | ||
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex | ||
ea commodo consequat. | ||
</mdc-dialog> | ||
|
||
<mdc-button raised @click="$refs.dialog.show()">Show Dialog</mdc-button> | ||
<mdc-button raised @click="open=!open">Show Dialog</mdc-button> | ||
|
||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
data() { | ||
return { | ||
open: 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