|
3 | 3 | :class="classObject"
|
4 | 4 | role="alert"
|
5 | 5 | aria-live="polite"
|
6 |
| - aria-atomic="true" |
7 |
| - > |
8 |
| - <button type="button" |
| 6 | + aria-atomic="true"> |
| 7 | + <button v-if="dismissible" |
| 8 | + type="button" |
9 | 9 | class="close"
|
10 | 10 | data-dismiss="alert"
|
11 | 11 | :aria-label="dismissLabel"
|
12 |
| - @click.stop.prevent="dismiss" |
13 |
| - > |
| 12 | + @click.stop.prevent="dismiss"> |
14 | 13 | <span aria-hidden="true">×</span>
|
15 | 14 | </button>
|
16 | 15 | <slot></slot>
|
17 | 16 | </div>
|
18 | 17 | </template>
|
19 | 18 |
|
20 | 19 | <script>
|
21 |
| - import {warn} from '../utils'; |
| 20 | +import { warn } from '../utils'; |
22 | 21 |
|
23 |
| - export default { |
24 |
| - data() { |
25 |
| - return { |
26 |
| - countDownTimerId: null, |
27 |
| - dismissed: false |
28 |
| - }; |
| 22 | +export default { |
| 23 | + data() { |
| 24 | + return { |
| 25 | + countDownTimerId: null, |
| 26 | + dismissed: false |
| 27 | + }; |
| 28 | + }, |
| 29 | + created() { |
| 30 | + if (this.state) { |
| 31 | + warn('<b-alert> "state" property is deprecated, please use "variant" property instead.'); |
| 32 | + } |
| 33 | + }, |
| 34 | + computed: { |
| 35 | + classObject() { |
| 36 | + return ['alert', this.alertVariant, this.dismissible ? 'alert-dismissible' : '']; |
29 | 37 | },
|
30 |
| - created() { |
31 |
| - if (this.state) { |
32 |
| - warn('<b-alert> "state" property is deprecated, please use "variant" property instead.'); |
33 |
| - } |
| 38 | + alertVariant() { |
| 39 | + const variant = this.state || this.variant || 'info'; |
| 40 | + return `alert-${variant}`; |
34 | 41 | },
|
35 |
| - computed: { |
36 |
| - classObject() { |
37 |
| - return ['alert', this.alertVariant, this.dismissible ? 'alert-dismissible' : '']; |
38 |
| - }, |
39 |
| - alertVariant() { |
40 |
| - const variant = this.state || this.variant || 'info'; |
41 |
| - return `alert-${variant}`; |
42 |
| - }, |
43 |
| - localShow() { |
44 |
| - return !this.dismissed && (this.countDownTimerId || this.show); |
45 |
| - } |
| 42 | + localShow() { |
| 43 | + return !this.dismissed && (this.countDownTimerId || this.show); |
| 44 | + } |
| 45 | + }, |
| 46 | + props: { |
| 47 | + variant: { |
| 48 | + type: String, |
| 49 | + default: 'info' |
46 | 50 | },
|
47 |
| - props: { |
48 |
| - variant: { |
49 |
| - type: String, |
50 |
| - default: 'info' |
51 |
| - }, |
52 |
| - state: { |
53 |
| - type: String, |
54 |
| - default: null |
55 |
| - }, |
56 |
| - dismissible: { |
57 |
| - type: Boolean, |
58 |
| - default: false |
59 |
| - }, |
60 |
| - dismissLabel: { |
61 |
| - type: String, |
62 |
| - default: 'Close' |
63 |
| - }, |
64 |
| - show: { |
65 |
| - type: [Boolean, Number], |
66 |
| - default: false |
67 |
| - } |
| 51 | + state: { |
| 52 | + type: String, |
| 53 | + default: null |
68 | 54 | },
|
69 |
| - watch: { |
70 |
| - show() { |
71 |
| - this.showChanged(); |
72 |
| - } |
| 55 | + dismissible: { |
| 56 | + type: Boolean, |
| 57 | + default: false |
| 58 | + }, |
| 59 | + dismissLabel: { |
| 60 | + type: String, |
| 61 | + default: 'Close' |
73 | 62 | },
|
74 |
| - mounted() { |
| 63 | + show: { |
| 64 | + type: [Boolean, Number], |
| 65 | + default: false |
| 66 | + } |
| 67 | + }, |
| 68 | + watch: { |
| 69 | + show() { |
75 | 70 | this.showChanged();
|
| 71 | + } |
| 72 | + }, |
| 73 | + mounted() { |
| 74 | + this.showChanged(); |
| 75 | + }, |
| 76 | + methods: { |
| 77 | + dismiss() { |
| 78 | + this.clearCounter(); |
| 79 | + this.dismissed = true; |
| 80 | + if (typeof this.show === 'number') { |
| 81 | + this.$emit('dismiss-count-down', 0); |
| 82 | + } |
| 83 | + this.$emit('dismissed'); |
76 | 84 | },
|
77 |
| - methods: { |
78 |
| - dismiss() { |
79 |
| - this.clearCounter(); |
80 |
| - this.dismissed = true; |
81 |
| - if (typeof this.show === 'number') { |
82 |
| - this.$emit('dismiss-count-down', 0); |
83 |
| - } |
84 |
| - this.$emit('dismissed'); |
85 |
| - }, |
86 |
| - clearCounter() { |
87 |
| - if (this.countDownTimerId) { |
88 |
| - clearInterval(this.countDownTimerId); |
89 |
| - this.countDownTimerId = null; |
90 |
| - } |
91 |
| - }, |
92 |
| - showChanged() { |
93 |
| - // Reset dismiss status |
94 |
| - this.dismissed = false; |
95 |
| -
|
96 |
| - // No timer for boolean values |
97 |
| - if (this.show === true || this.show === false || this.show === null || this.show === 0) { |
98 |
| - return; |
99 |
| - } |
| 85 | + clearCounter() { |
| 86 | + if (this.countDownTimerId) { |
| 87 | + clearInterval(this.countDownTimerId); |
| 88 | + this.countDownTimerId = null; |
| 89 | + } |
| 90 | + }, |
| 91 | + showChanged() { |
| 92 | + // Reset dismiss status |
| 93 | + this.dismissed = false; |
100 | 94 |
|
101 |
| - let dismissCountDown = this.show; |
102 |
| - |
103 |
| - // Start counter |
104 |
| - this.clearCounter(); |
105 |
| - this.countDownTimerId = setInterval(() => { |
106 |
| - if (dismissCountDown < 2) { |
107 |
| - return this.dismiss(); |
108 |
| - } |
109 |
| - dismissCountDown--; |
110 |
| - this.$emit('dismiss-count-down', dismissCountDown); |
111 |
| - }, 1000); |
| 95 | + // No timer for boolean values |
| 96 | + if (this.show === true || this.show === false || this.show === null || this.show === 0) { |
| 97 | + return; |
112 | 98 | }
|
| 99 | +
|
| 100 | + let dismissCountDown = this.show; |
| 101 | +
|
| 102 | + // Start counter |
| 103 | + this.clearCounter(); |
| 104 | + this.countDownTimerId = setInterval(() => { |
| 105 | + if (dismissCountDown < 2) { |
| 106 | + return this.dismiss(); |
| 107 | + } |
| 108 | + dismissCountDown--; |
| 109 | + this.$emit('dismiss-count-down', dismissCountDown); |
| 110 | + }, 1000); |
113 | 111 | }
|
114 |
| - }; |
| 112 | + } |
| 113 | +}; |
115 | 114 | </script>
|
0 commit comments