Skip to content

feat(alert): Add fade prop #1785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 61 additions & 2 deletions src/components/alert/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ with the dismiss button.
<!-- alert-dismis-1.vue -->
```

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

Expand All @@ -178,7 +178,7 @@ the `show` prop to the number of seconds you would like the `<b-alert>` to remai
<b-alert :show="dismissCountDown"
dismissible
variant="warning"
@dismissed="dismissCountdown=0"
@dismissed="dismissCountDown=0"
@dismiss-count-down="countDownChanged">
This alert will dismiss after {{dismissCountDown}} seconds...
</b-alert>
Expand Down Expand Up @@ -210,4 +210,63 @@ export default {
<!-- alert-auto-dismiss-1.vue -->
```

## Fading alerts
Use the `fade` prop to enable animation. By default alerts are not animated.

```html
<template>
<div>
<b-alert show dismissible fade>
Dismissible Alert!
</b-alert>

<b-alert variant="danger"
dismissible
fade
:show="showDismissibleAlert"
@dismissed="showDismissibleAlert=false">
Dismissible Alert!
</b-alert>

<b-alert :show="dismissCountDown"
dismissible
fade
variant="warning"
@dismissed="dismissCountDown=0"
@dismiss-count-down="countDownChanged">
This alert will dismiss after {{dismissCountDown}} seconds...
</b-alert>

<b-btn @click="showAlert" variant="info" class="m-1">
Show alert with count-down timer
</b-btn>
<b-btn @click="showDismissibleAlert=true" variant="info" class="m-1">
Show dismissible alert ({{showDismissibleAlert?'visible':'hidden'}})
</b-btn>
</div>
</template>

<script>
export default {
data () {
return {
dismissSecs: 5,
dismissCountDown: 0,
showDismissibleAlert: false
}
},
methods: {
countDownChanged (dismissCountDown) {
this.dismissCountDown = dismissCountDown
},
showAlert () {
this.dismissCountDown = this.dismissSecs
}
}
}
</script>

<!-- alert-fade-1.vue -->
```

## Component Reference
6 changes: 6 additions & 0 deletions src/components/alert/alert.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.fade-enter-active, .fade-leave-active {
transition: opacity .15s linear;
}
.fade-enter, .fade-leave-to {
opacity: 0;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should target these classes to elements containing the class .alert, so that it doesn't interfere with users who may have their own fade transition with different settings?

Maybe:

.alert.fade-enter-active,
.alert.fade-leave-active {
     transition: opacity .15s linear;
 }
.alert.fade-enter,
.alert.fade-leave-to {
     opacity: 0;
 }

17 changes: 14 additions & 3 deletions src/components/alert/alert.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import bButtonClose from '../button/button-close'

import './alert.css'

export default {
components: {bButtonClose},
render (h) {
Expand All @@ -16,10 +18,15 @@ export default {
[ this.$slots.dismiss ]
)
}
return h(
const alert = h(
'div',
{ class: this.classObject, attrs: { role: 'alert', 'aria-live': 'polite', 'aria-atomic': true } },
[ dismissBtn, this.$slots.default ]
{class: this.classObject, attrs: {role: 'alert', 'aria-live': 'polite', 'aria-atomic': true}},
[dismissBtn, this.$slots.default]
)
return !this.fade ? alert : h(
'transition',
{ props: { name: 'fade', appear: true } },
[ alert ]
)
},
model: {
Expand Down Expand Up @@ -60,6 +67,10 @@ export default {
show: {
type: [Boolean, Number],
default: false
},
fade: {
type: Boolean,
default: false
}
},
watch: {
Expand Down