Skip to content

Commit ac71dee

Browse files
committed
feat(BCard): add img slot above or below header
test: for above bcard changes
1 parent 81b6275 commit ac71dee

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

packages/bootstrap-vue-3/src/components/BCard/BCard.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<template>
22
<component :is="tag" class="card" :class="classes">
3-
<b-card-img v-if="imgSrc && !imgBottomBoolean" v-bind="imgAttr" />
3+
<slot v-if="!imgBottomBoolean" name="img">
4+
<b-card-img v-if="imgSrc" v-bind="imgAttr" />
5+
</slot>
46
<b-card-header
57
v-if="header || $slots.header || headerHtml"
68
v-bind="headerAttrs"
@@ -27,7 +29,9 @@
2729
{{ footer }}
2830
</slot>
2931
</b-card-footer>
30-
<b-card-img v-if="imgSrc && imgBottomBoolean" v-bind="imgAttr" />
32+
<slot v-if="imgBottomBoolean" name="img">
33+
<b-card-img v-if="imgSrc" v-bind="imgAttr" />
34+
</slot>
3135
</component>
3236
</template>
3337

packages/bootstrap-vue-3/src/components/BCard/card.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,37 @@ describe('card', () => {
9898
expect(wrapper.classes()).not.toContain('flex-row-reverse')
9999
})
100100

101+
it('renders img slot', () => {
102+
const wrapper = mount(BCard, {
103+
slots: {img: 'foobar'},
104+
})
105+
expect(wrapper.text()).toBe('foobar')
106+
})
107+
108+
it('renders img in correct order when not prop imgBottom', () => {
109+
const wrapper = mount(BCard, {
110+
props: {header: 'header', bodyText: 'bodyText', footer: 'footer', imgBottom: false},
111+
slots: {img: 'img'},
112+
})
113+
expect(wrapper.text()).toBe('imgheaderbodyTextfooter')
114+
})
115+
116+
it('does not render b-card-img when slot img', () => {
117+
const wrapper = mount(BCard, {
118+
slots: {img: 'img'},
119+
})
120+
const $cardimg = wrapper.findComponent(BCardImg)
121+
expect($cardimg.exists()).toBe(false)
122+
})
123+
124+
it('renders img in correct order when prop imgBottom', () => {
125+
const wrapper = mount(BCard, {
126+
props: {header: 'header', bodyText: 'bodyText', footer: 'footer', imgBottom: true},
127+
slots: {img: 'img'},
128+
})
129+
expect(wrapper.text()).toBe('headerbodyTextfooterimg')
130+
})
131+
101132
it('does not have child BCardImg by default', () => {
102133
const wrapper = mount(BCard)
103134
const $img = wrapper.findComponent(BCardImg)

0 commit comments

Comments
 (0)