Skip to content
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

feat(b-sidebar): add prop backdrop-variant #5411

Merged
merged 10 commits into from
May 20, 2020
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
35 changes: 30 additions & 5 deletions src/components/sidebar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,27 +270,52 @@ Add a basic backdrop when the side bar is open via the `backdrop` prop. When set
sidebar will show an opaque backdrop. Clicking on the backdrop will close the sidebar, unless the
`no-close-on-backdrop` prop is set to `true`.

Optionally (as of BootstrapVue v2.15.0+) you can use the `backdrop-variant` prop to control the
theme color variant of the backdrop. The default backdrop variant is `dark`.

```html
<template>
<div>
<b-button v-b-toggle.sidebar-backdrop>Toggle Sidebar</b-button>

<b-sidebar
id="sidebar-backdrop"
title="Sidebar with backdrop"
:backdrop-variant="variant"
backdrop
shadow
>
<div class="px-3 py-2">
<p>
Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis
in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.
</p>
<b-img src="https://picsum.photos/500/500/?image=54" fluid thumbnail></b-img>
<b-form-group label="Backdrop variant" label-for="backdrop-variant">
<b-form-select id="backdrop-variant" v-model="variant" :options="variants"></b-form-select>
</b-form-group>
</div>
</b-sidebar>
</div>
</template>

<script>
export default {
data() {
return {
variant: 'dark',
variants: [
'transparent',
'white',
'light',
'dark',
'primary',
'secondary',
'success',
'danger',
'warning',
'info',
]
}
}
}
</script>

<!-- b-sidebar-backdrop.vue -->
```

Expand Down
3 changes: 1 addition & 2 deletions src/components/sidebar/_sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
z-index: -1;
width: 100vw;
height: 100vh;
background-color: #000;
opacity: 0.5;
opacity: 0.6;
}

.b-sidebar {
Expand Down
5 changes: 5 additions & 0 deletions src/components/sidebar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
"version": "2.12.0",
"description": "When `true`, shows a backdrop when the sidebar is open"
},
{
"prop": "backdropVariant",
"version": "2.15.0",
"description": "Theme variant color for the backdrop of the sidebar. Defaults to 'dark'"
},
{
"prop": "lazy",
"description": "When set to `true`, the content of the sidebar will only be rendered while the sidebar is open"
Expand Down
11 changes: 10 additions & 1 deletion src/components/sidebar/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,21 @@ const renderContent = (h, ctx) => {
if (ctx.lazy && !ctx.isOpen) {
return $header
}

return [$header, renderBody(h, ctx), renderFooter(h, ctx)]
}

const renderBackdrop = (h, ctx) => {
if (!ctx.backdrop) {
return h()
}

const { backdropVariant } = ctx

return h('div', {
directives: [{ name: 'show', value: ctx.localShow }],
staticClass: 'b-sidebar-backdrop',
class: { [`bg-${backdropVariant}`]: !!backdropVariant },
on: { click: ctx.onBackdropClick }
})
}
Expand Down Expand Up @@ -197,10 +202,14 @@ export const BSidebar = /*#__PURE__*/ Vue.extend({
// default: null
},
backdrop: {
// If true, shows a basic backdrop
// If `true`, shows a basic backdrop
type: Boolean,
default: false
},
backdropVariant: {
type: String,
default: () => getComponentConfig(NAME, 'backdropVariant')
},
noSlide: {
type: Boolean,
default: false
Expand Down
Loading