Skip to content

Commit 0999b4c

Browse files
emanuelmutschlechnerpi0
authored andcommitted
feat(alert): Add fade prop (#1785)
* feat(alert): Add fade prop * docs(alert): Add example for fading alerts and fix some errors
1 parent 9911507 commit 0999b4c

File tree

3 files changed

+81
-5
lines changed

3 files changed

+81
-5
lines changed

src/components/alert/README.md

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ with the dismiss button.
168168
<!-- alert-dismis-1.vue -->
169169
```
170170

171-
### Auto dismissing alerts:
171+
### Auto dismissing alerts
172172
To create a `<b-alert>` that dismisses automatically after a period of time, set
173173
the `show` prop to the number of seconds you would like the `<b-alert>` to remain visible for.
174174

@@ -178,7 +178,7 @@ the `show` prop to the number of seconds you would like the `<b-alert>` to remai
178178
<b-alert :show="dismissCountDown"
179179
dismissible
180180
variant="warning"
181-
@dismissed="dismissCountdown=0"
181+
@dismissed="dismissCountDown=0"
182182
@dismiss-count-down="countDownChanged">
183183
This alert will dismiss after {{dismissCountDown}} seconds...
184184
</b-alert>
@@ -210,4 +210,63 @@ export default {
210210
<!-- alert-auto-dismiss-1.vue -->
211211
```
212212

213+
## Fading alerts
214+
Use the `fade` prop to enable animation. By default alerts are not animated.
215+
216+
```html
217+
<template>
218+
<div>
219+
<b-alert show dismissible fade>
220+
Dismissible Alert!
221+
</b-alert>
222+
223+
<b-alert variant="danger"
224+
dismissible
225+
fade
226+
:show="showDismissibleAlert"
227+
@dismissed="showDismissibleAlert=false">
228+
Dismissible Alert!
229+
</b-alert>
230+
231+
<b-alert :show="dismissCountDown"
232+
dismissible
233+
fade
234+
variant="warning"
235+
@dismissed="dismissCountDown=0"
236+
@dismiss-count-down="countDownChanged">
237+
This alert will dismiss after {{dismissCountDown}} seconds...
238+
</b-alert>
239+
240+
<b-btn @click="showAlert" variant="info" class="m-1">
241+
Show alert with count-down timer
242+
</b-btn>
243+
<b-btn @click="showDismissibleAlert=true" variant="info" class="m-1">
244+
Show dismissible alert ({{showDismissibleAlert?'visible':'hidden'}})
245+
</b-btn>
246+
</div>
247+
</template>
248+
249+
<script>
250+
export default {
251+
data () {
252+
return {
253+
dismissSecs: 5,
254+
dismissCountDown: 0,
255+
showDismissibleAlert: false
256+
}
257+
},
258+
methods: {
259+
countDownChanged (dismissCountDown) {
260+
this.dismissCountDown = dismissCountDown
261+
},
262+
showAlert () {
263+
this.dismissCountDown = this.dismissSecs
264+
}
265+
}
266+
}
267+
</script>
268+
269+
<!-- alert-fade-1.vue -->
270+
```
271+
213272
## Component Reference

src/components/alert/alert.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.fade-enter-active, .fade-leave-active {
2+
transition: opacity .15s linear;
3+
}
4+
.fade-enter, .fade-leave-to {
5+
opacity: 0;
6+
}

src/components/alert/alert.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import bButtonClose from '../button/button-close'
22

3+
import './alert.css'
4+
35
export default {
46
components: {bButtonClose},
57
render (h) {
@@ -16,10 +18,15 @@ export default {
1618
[ this.$slots.dismiss ]
1719
)
1820
}
19-
return h(
21+
const alert = h(
2022
'div',
21-
{ class: this.classObject, attrs: { role: 'alert', 'aria-live': 'polite', 'aria-atomic': true } },
22-
[ dismissBtn, this.$slots.default ]
23+
{class: this.classObject, attrs: {role: 'alert', 'aria-live': 'polite', 'aria-atomic': true}},
24+
[dismissBtn, this.$slots.default]
25+
)
26+
return !this.fade ? alert : h(
27+
'transition',
28+
{ props: { name: 'fade', appear: true } },
29+
[ alert ]
2330
)
2431
},
2532
model: {
@@ -60,6 +67,10 @@ export default {
6067
show: {
6168
type: [Boolean, Number],
6269
default: false
70+
},
71+
fade: {
72+
type: Boolean,
73+
default: false
6374
}
6475
},
6576
watch: {

0 commit comments

Comments
 (0)