Skip to content

Commit

Permalink
add cancel button option to snackbar (buefy#3066)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgreenhall authored Nov 29, 2020
1 parent 2418bb7 commit f38adc2
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/pages/components/snackbar/api/snackbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ export default [
type: 'Function',
values: '—',
default: '—'
},
{
name: '<code>cancelText</code>',
description: `Snackbar's cancel button text. Default is no cancel button`,
type: 'String',
values: '—',
default: '—'
}
],
methods: [
Expand Down
11 changes: 11 additions & 0 deletions docs/pages/components/snackbar/examples/ExSimple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
type="is-danger"
size="is-medium"
@click="danger" />
<b-button
label="Launch snackbar (with cancel)"
size="is-medium"
@click="hasCancel" />
</div>
</section>
</template>
Expand Down Expand Up @@ -55,6 +59,13 @@
})
}
})
},
hasCancel() {
this.$buefy.snackbar.open({
indefinite: true,
message: 'Snackbar with a cancel button.',
cancelText: 'Cancel',
})
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/components/snackbar/Snackbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
<template v-else>
<div class="text" v-html="message" />
</template>
<div
v-if="cancelText"
class="action is-light is-cancel"
@click="close">
<button class="button">{{ cancelText }}</button>
</div>
<div
v-if="actionText"
class="action"
Expand Down Expand Up @@ -40,6 +46,10 @@ export default {
type: Function,
default: () => {}
},
cancelText: {
type: String | null,
default: null
},
indefinite: {
type: Boolean,
default: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`BSnackbar render correctly 1`] = `
<div role="alertdialog" class="snackbar is-dark is-top" style="" enter-active-class="fadeInDown" leave-active-class="fadeOut">
<div class="text"></div>
<!---->
<div class="action is-dark"><button class="button">OK</button></div>
</div>
`;
3 changes: 3 additions & 0 deletions src/scss/components/_notices.scss
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ $snackbar-box-shadow: $notices-box-shadow !default;
}
}
}
.action.is-cancel {
padding-right: 0;
}
@include mobile {
width: 100%;
margin: 0;
Expand Down
5 changes: 5 additions & 0 deletions types/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,11 @@ export declare type BSnackbarConfig = BNoticeConfig & {
*/
actionText?: string | null;

/**
* Snackbar's cancel button text
*/
cancelText?: string | null;

/**
* Show the Snackbar indefinitely until it is dismissed
*/
Expand Down

0 comments on commit f38adc2

Please sign in to comment.