This repository was archived by the owner on Nov 30, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +60
-25
lines changed Expand file tree Collapse file tree 3 files changed +60
-25
lines changed Original file line number Diff line number Diff line change 3
3
### Markup
4
4
5
5
``` html
6
- <m-snackbar ref =" snackbar" />
6
+ <m-button
7
+ raised
8
+ interactive
9
+ @click =" isSnackbarOpen=true" >open</m-button >
10
+ <m-snackbar
11
+ :options =" options"
12
+ v-model =" isSnackbarOpen" />
7
13
```
8
14
9
15
### Script
10
16
11
17
``` javascript
12
- let options = {
13
- message: ' snackbar message'
18
+ data () {
19
+ return {
20
+ isSnackbarOpen: false ,
21
+ options: {
22
+ message: ' I am a snackbar!' ,
23
+ timeout: 3000 ,
24
+ actionHandler : () => console .log (' snackbar action' ),
25
+ actionText: ' ok' ,
26
+ multiline: false ,
27
+ actionOnBottom: false
28
+ }
29
+ }
14
30
}
15
-
16
- this .$refs .snackbar .show (options)
17
31
```
18
32
19
- ### Props & methods
33
+ ### Props
20
34
21
35
| Prop | Type | Default | Required | Description |
22
36
| ------| ------| ---------| ----------| -------------|
23
- | alignStart | Boolean | - | false | start-aligned snackbar |
24
- | dismissesOnAction | Boolean | true | false | keep snackbar when action button is pressed |
25
-
26
- | Method | Description |
27
- | --------| -------------|
28
- | show | show the snackbar with given options |
29
-
30
- The show() function takes a object as parameter to configure the snackbar. The benefit is that you don't have to add more than one snackbar in your template to show different snackbars. Have a look at the [ reference] ( https://github.com/material-components/material-components-web/blob/master/packages/mdc-snackbar/README.md#showing-a-message-and-action ) for details of the options object.
37
+ | alignStart | Boolean | false | - | start-aligned snackbar |
38
+ | dismissesOnAction | Boolean | true | - | keep snackbar when action button is pressed |
39
+ | options | Object | - | true | snackbar options (see script section)|
31
40
32
41
### Reference
33
42
Original file line number Diff line number Diff line change 1
1
<template >
2
2
<div
3
3
class =" mdc-snackbar"
4
- :class =" classes" >
4
+ :class =" classes"
5
+ aria-live =" assertive"
6
+ aria-atomic =" true"
7
+ aria-hidden =" true"
8
+ @MDCSnackbar:hide =" model = false" >
5
9
<div class =" mdc-snackbar__text" />
6
10
<div class =" mdc-snackbar__action-wrapper" >
7
11
<button
8
12
type =" button"
9
- class =" mdc-button mdc- snackbar__action-button" />
13
+ class =" mdc-snackbar__action-button" />
10
14
</div >
11
15
</div >
12
16
</template >
@@ -18,14 +22,26 @@ import themeClassMixin from '../base/themeClassMixin.js'
18
22
19
23
export default {
20
24
mixins: [themeClassMixin],
25
+ model: {
26
+ prop: ' open' ,
27
+ event : ' change'
28
+ },
21
29
props: {
22
30
alignStart: {
23
31
type: Boolean ,
24
- required : false
32
+ default : false
25
33
},
26
34
dismissesOnAction: {
27
35
type: Boolean ,
28
36
default: true
37
+ },
38
+ open : {
39
+ type: Boolean ,
40
+ default: false
41
+ },
42
+ options: {
43
+ type: Object ,
44
+ required: true
29
45
}
30
46
},
31
47
data () {
@@ -38,18 +54,28 @@ export default {
38
54
return {
39
55
' mdc-snackbar--align-start' : this .alignStart
40
56
}
57
+ },
58
+ model: {
59
+ get () {
60
+ return this .open
61
+ },
62
+ set (value) {
63
+ this .$emit (' change' , value)
64
+ }
41
65
}
42
66
},
43
67
mounted () {
44
68
this .mdcSnackbar = MDCSnackbar .attachTo (this .$el )
45
- this .mdcSnackbar .dismissesOnAction = this .dismissesOnAction
46
69
},
47
70
beforeDestroy () {
48
71
this .mdcSnackbar .destroy ()
49
72
},
50
- methods: {
51
- show (options ) {
52
- this .mdcSnackbar .show (options)
73
+ watch: {
74
+ dismissesOnAction () {
75
+ this .mdcSnackbar .dismissesOnAction = this .dismissesOnAction
76
+ },
77
+ open () {
78
+ if (this .open ) this .mdcSnackbar .show (this .options )
53
79
}
54
80
}
55
81
}
Original file line number Diff line number Diff line change 1
- @import " @material/snackbar/mdc-snackbar" ;
2
- @import " @material/button/mdc-button" ;
3
-
4
1
.mdc-snackbar {
5
2
transform : translateY (100% );
6
- }
3
+ }
4
+
5
+ @import " @material/snackbar/mdc-snackbar" ;
6
+
You can’t perform that action at this time.
0 commit comments