🌐 AI搜索 & 代理 主页
Skip to content

Commit 4b0c163

Browse files
Hiwsjacobmllr95tmorehouse
authored
feat(b-sidebar): add prop backdrop-variant (#5411)
* initial take * Update sidebar.js * Update package.json * Update sidebar.spec.js * Update sidebar.spec.js * Migrate to `backdrop-variant` prop * Update _sidebar.scss * Update README.md * Update README.md Co-authored-by: Rasmus Nielsen <rni@nova-c.dk> Co-authored-by: Jacob Müller <jacob.mueller.elz@gmail.com> Co-authored-by: Troy Morehouse <troymore@nbnet.nb.ca>
1 parent 9172665 commit 4b0c163

File tree

6 files changed

+105
-78
lines changed

6 files changed

+105
-78
lines changed

src/components/sidebar/README.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,27 +270,52 @@ Add a basic backdrop when the side bar is open via the `backdrop` prop. When set
270270
sidebar will show an opaque backdrop. Clicking on the backdrop will close the sidebar, unless the
271271
`no-close-on-backdrop` prop is set to `true`.
272272

273+
Optionally (as of BootstrapVue v2.15.0+) you can use the `backdrop-variant` prop to control the
274+
theme color variant of the backdrop. The default backdrop variant is `dark`.
275+
273276
```html
274277
<template>
275278
<div>
276279
<b-button v-b-toggle.sidebar-backdrop>Toggle Sidebar</b-button>
280+
277281
<b-sidebar
278282
id="sidebar-backdrop"
279283
title="Sidebar with backdrop"
284+
:backdrop-variant="variant"
280285
backdrop
281286
shadow
282287
>
283288
<div class="px-3 py-2">
284-
<p>
285-
Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis
286-
in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.
287-
</p>
288-
<b-img src="https://picsum.photos/500/500/?image=54" fluid thumbnail></b-img>
289+
<b-form-group label="Backdrop variant" label-for="backdrop-variant">
290+
<b-form-select id="backdrop-variant" v-model="variant" :options="variants"></b-form-select>
291+
</b-form-group>
289292
</div>
290293
</b-sidebar>
291294
</div>
292295
</template>
293296

297+
<script>
298+
export default {
299+
data() {
300+
return {
301+
variant: 'dark',
302+
variants: [
303+
'transparent',
304+
'white',
305+
'light',
306+
'dark',
307+
'primary',
308+
'secondary',
309+
'success',
310+
'danger',
311+
'warning',
312+
'info',
313+
]
314+
}
315+
}
316+
}
317+
</script>
318+
294319
<!-- b-sidebar-backdrop.vue -->
295320
```
296321

src/components/sidebar/_sidebar.scss

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
z-index: -1;
1616
width: 100vw;
1717
height: 100vh;
18-
background-color: #000;
19-
opacity: 0.5;
18+
opacity: 0.6;
2019
}
2120

2221
.b-sidebar {

src/components/sidebar/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@
7676
"version": "2.12.0",
7777
"description": "When `true`, shows a backdrop when the sidebar is open"
7878
},
79+
{
80+
"prop": "backdropVariant",
81+
"version": "2.15.0",
82+
"description": "Theme variant color for the backdrop of the sidebar. Defaults to 'dark'"
83+
},
7984
{
8085
"prop": "lazy",
8186
"description": "When set to `true`, the content of the sidebar will only be rendered while the sidebar is open"

src/components/sidebar/sidebar.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,21 @@ const renderContent = (h, ctx) => {
108108
if (ctx.lazy && !ctx.isOpen) {
109109
return $header
110110
}
111+
111112
return [$header, renderBody(h, ctx), renderFooter(h, ctx)]
112113
}
113114

114115
const renderBackdrop = (h, ctx) => {
115116
if (!ctx.backdrop) {
116117
return h()
117118
}
119+
120+
const { backdropVariant } = ctx
121+
118122
return h('div', {
119123
directives: [{ name: 'show', value: ctx.localShow }],
120124
staticClass: 'b-sidebar-backdrop',
125+
class: { [`bg-${backdropVariant}`]: !!backdropVariant },
121126
on: { click: ctx.onBackdropClick }
122127
})
123128
}
@@ -197,10 +202,14 @@ export const BSidebar = /*#__PURE__*/ Vue.extend({
197202
// default: null
198203
},
199204
backdrop: {
200-
// If true, shows a basic backdrop
205+
// If `true`, shows a basic backdrop
201206
type: Boolean,
202207
default: false
203208
},
209+
backdropVariant: {
210+
type: String,
211+
default: () => getComponentConfig(NAME, 'backdropVariant')
212+
},
204213
noSlide: {
205214
type: Boolean,
206215
default: false

0 commit comments

Comments
 (0)