Skip to content

Commit e86b6e0

Browse files
committed
feat!: standardize props in multiple comps
BREAKING-CHANGE: many of the components in the BCard space have props that prepend their name, for example, footerBgVariant, footerBorderVariant, footerHtml, etc. These have been replaced with each corresponding prop, without it's appended name to follow simplicity and single responsiblity. feat(BCardFooter)!: footerClass prop was removed instead use :class feat(BCardBody)!: bodyClass was removed instead use :class feat(BCardHeader)!: headerClass removed instead use :class feat: BCardImg includes lazy feat(BCardSubTitle)!: prop subtitle replaced with text feat(BCardSubTitle)!: prop subTitleTag replaced with tag feat(BCardSubTitle)!: prop subTitleTextVariant replace with textVariant feat(BCardBody): can also use prop text instead of default slot feat(BCardFooter)!: prop footer replaced with prop text feat(BCardFooter)!:prop footerBgVariant replaced with bgVariant feat(BCardFooter)!: prop footerBorderVariant replaced with borderVariant feat(BCardFooter)!: footerHtml replaced with html feat(BCardFooter)!: footerTag removed use tag feat(BCardFooter)!: footerTextVariant removed use textVariant refactor(BCardGroup): move cardType logic out of class object refactor(BCardGroup): classes is now object feat(BCardText): expand to include dynamic tag feat(BCardText): expand to include prop text feat(BCardTitle)!: prop title replaced with prop text feat(BCardTitle)!: prop titleTag replaced with prop tag test: card-body.spec.ts test: card-footer.spec.ts test: card-footer.spec.ts test: card-group.spec.ts test: card-header.spec.ts test: card-img.spec.ts test: card-sub-title.spec.ts test: card-text.spec.ts test: card-title.spec.ts test: card.spec.ts -- not done test: form-select-option converted to spec.ts
1 parent 2d53fbb commit e86b6e0

19 files changed

+1065
-86
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<template>
22
<component :is="tag" class="card" :class="classes">
3+
<!-- replace with BCardImg -->
34
<img v-if="imgSrc && !imgBottomBoolean" v-bind="imgAttr" :class="imgClasses" />
45
<component
56
:is="headerTag"
@@ -57,22 +58,22 @@ interface BCardProps {
5758
bodyBgVariant?: ColorVariant
5859
bodyClass?: Array<string> | Record<string, boolean | undefined | null> | string
5960
bodyTag?: string
60-
bodyTextVariant?: ColorVariant
61+
bodyTextVariant?: TextColorVariant
6162
borderVariant?: ColorVariant
6263
footer?: string
6364
footerBgVariant?: ColorVariant
6465
footerBorderVariant?: ColorVariant
6566
footerClass?: Array<string> | Record<string, boolean | undefined | null> | string
6667
footerHtml?: string
6768
footerTag?: string
68-
footerTextVariant?: ColorVariant
69+
footerTextVariant?: TextColorVariant
6970
header?: string
7071
headerBgVariant?: ColorVariant
7172
headerBorderVariant?: ColorVariant
7273
headerClass?: Array<string> | Record<string, boolean | undefined | null> | string
7374
headerHtml?: string
7475
headerTag?: string
75-
headerTextVariant?: ColorVariant
76+
headerTextVariant?: TextColorVariant
7677
imgAlt?: string
7778
imgBottom?: Booleanish
7879
imgEnd?: Booleanish
@@ -168,8 +169,14 @@ const imgClasses = computed(() => ({
168169
const imgAttr = computed(() => ({
169170
src: props.imgSrc,
170171
alt: props.imgAlt,
171-
height: props.imgHeight,
172-
width: props.imgWidth,
172+
height:
173+
(typeof props.imgHeight === 'number'
174+
? props.imgHeight
175+
: parseInt(props.imgHeight as string, 10)) || undefined,
176+
width:
177+
(typeof props.imgWidth === 'number'
178+
? props.imgWidth
179+
: parseInt(props.imgWidth as string, 10)) || undefined,
173180
}))
174181
175182
const subTitleClasses = computed(() => ({

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
<template>
22
<component :is="bodyTag" class="card-body" :class="classes">
3-
<b-card-title v-if="title" :title-tag="titleTag" :title="title" />
3+
<b-card-title v-if="!!title || $slots.title" :tag="titleTag">
4+
<slot name="title">
5+
{{ title }}
6+
</slot>
7+
</b-card-title>
8+
49
<b-card-sub-title
5-
v-if="subTitle"
6-
:sub-title-tag="subTitleTag"
7-
:sub-title="subTitle"
8-
:sub-title-text-variant="subTitleTextVariant"
9-
/>
10-
<slot />
10+
v-if="!!subTitle || !!$slots.subTitle"
11+
:tag="subTitleTag"
12+
:text-variant="subTitleTextVariant"
13+
>
14+
<slot name="subTitle">
15+
{{ subTitle }}
16+
</slot>
17+
</b-card-sub-title>
18+
19+
<slot>
20+
{{ text }}
21+
</slot>
1122
</component>
1223
</template>
1324

@@ -21,7 +32,6 @@ import {useBooleanish} from '../../composables'
2132
2233
interface BCardBodyProps {
2334
bodyBgVariant?: ColorVariant
24-
bodyClass?: Array<string> | Record<string, boolean | undefined | null> | string
2535
bodyTag?: string
2636
bodyTextVariant?: TextColorVariant
2737
overlay?: Booleanish
@@ -30,6 +40,7 @@ interface BCardBodyProps {
3040
subTitleTextVariant?: TextColorVariant
3141
title?: string
3242
titleTag?: string
43+
text?: string
3344
}
3445
3546
const props = withDefaults(defineProps<BCardBodyProps>(), {
Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
<template>
2-
<component :is="footerTag" class="card-footer" :class="[footerClass, classes]">
2+
<component :is="tag" class="card-footer" :class="classes">
33
<!-- eslint-disable-next-line vue/no-v-html -->
4-
<div v-if="!!footerHtml" v-html="footerHtml" />
4+
<div v-if="!!html" v-html="html" />
55
<slot v-else>
6-
{{ footer }}
6+
{{ text }}
77
</slot>
88
</component>
99
</template>
1010

1111
<script setup lang="ts">
12-
// import type {BCardFooterProps} from '../../types/components'
13-
import type {ColorVariant, TextColorVariant} from '../../types'
12+
// import type {BCardHeaderProps} from '../../types/components'
1413
import {computed} from 'vue'
14+
import type {ColorVariant, TextColorVariant} from '../../types'
1515
16-
interface BCardFooterProps {
17-
footer?: string
18-
footerBgVariant?: ColorVariant
19-
footerBorderVariant?: ColorVariant
20-
footerClass?: Array<string> | Record<string, boolean | undefined | null> | string
21-
footerHtml?: string
22-
footerTag?: string
23-
footerTextVariant?: TextColorVariant
16+
interface BCardHeaderProps {
17+
text?: string
18+
bgVariant?: ColorVariant
19+
borderVariant?: ColorVariant
20+
html?: string
21+
tag?: string
22+
textVariant?: TextColorVariant
2423
}
2524
26-
const props = withDefaults(defineProps<BCardFooterProps>(), {
27-
footerTag: 'div',
25+
const props = withDefaults(defineProps<BCardHeaderProps>(), {
26+
tag: 'div',
2827
})
2928
3029
const classes = computed(() => ({
31-
[`text-${props.footerTextVariant}`]: props.footerTextVariant !== undefined,
32-
[`bg-${props.footerBgVariant}`]: props.footerBgVariant !== undefined,
33-
[`border-${props.footerBorderVariant}`]: props.footerBorderVariant !== undefined,
30+
[`text-${props.textVariant}`]: props.textVariant !== undefined,
31+
[`bg-${props.bgVariant}`]: props.bgVariant !== undefined,
32+
[`border-${props.borderVariant}`]: props.borderVariant !== undefined,
3433
}))
3534
</script>

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ const props = withDefaults(defineProps<BCardGroupProps>(), {
2525
const columnsBoolean = useBooleanish(toRef(props, 'columns'))
2626
const deckBoolean = useBooleanish(toRef(props, 'deck'))
2727
28-
const classes = computed(() =>
28+
const cardTypeClass = computed(() =>
2929
deckBoolean.value ? 'card-deck' : columnsBoolean.value ? 'card-columns' : 'card-group'
3030
)
31+
32+
const classes = computed(() => ({
33+
[cardTypeClass.value]: !!cardTypeClass.value,
34+
}))
3135
</script>
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
<template>
2-
<component :is="headerTag" class="card-header" :class="[headerClass, classes]">
2+
<component :is="tag" class="card-header" :class="classes">
33
<!-- eslint-disable-next-line vue/no-v-html -->
4-
<div v-if="!!headerHtml" v-html="headerHtml" />
4+
<div v-if="!!html" v-html="html" />
55
<slot v-else>
6-
{{ header }}
6+
{{ text }}
77
</slot>
88
</component>
99
</template>
1010

1111
<script setup lang="ts">
1212
// import type {BCardHeaderProps} from '../../types/components'
1313
import {computed} from 'vue'
14-
import type {ColorVariant} from '../../types'
14+
import type {ColorVariant, TextColorVariant} from '../../types'
1515
1616
interface BCardHeaderProps {
17-
header?: string
18-
headerBgVariant?: ColorVariant
19-
headerBorderVariant?: ColorVariant
20-
headerClass?: Array<string> | Record<string, boolean | undefined | null> | string
21-
headerHtml?: string
22-
headerTag?: string
23-
headerTextVariant?: ColorVariant
17+
text?: string
18+
bgVariant?: ColorVariant
19+
borderVariant?: ColorVariant
20+
html?: string
21+
tag?: string
22+
textVariant?: TextColorVariant
2423
}
2524
2625
const props = withDefaults(defineProps<BCardHeaderProps>(), {
27-
headerTag: 'div',
26+
tag: 'div',
2827
})
2928
3029
const classes = computed(() => ({
31-
[`text-${props.headerTextVariant}`]: props.headerTextVariant !== undefined,
32-
[`bg-${props.headerBgVariant}`]: props.headerBgVariant !== undefined,
33-
[`border-${props.headerBorderVariant}`]: props.headerBorderVariant !== undefined,
30+
[`text-${props.textVariant}`]: props.textVariant !== undefined,
31+
[`bg-${props.bgVariant}`]: props.bgVariant !== undefined,
32+
[`border-${props.borderVariant}`]: props.borderVariant !== undefined,
3433
}))
3534
</script>

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface BCardImgProps {
1616
left?: Booleanish
1717
right?: Booleanish
1818
src?: string
19+
lazy?: Booleanish
1920
start?: Booleanish
2021
top?: Booleanish
2122
width?: number | string
@@ -27,6 +28,7 @@ const props = withDefaults(defineProps<BCardImgProps>(), {
2728
left: false,
2829
right: false,
2930
alt: undefined,
31+
lazy: false,
3032
start: false,
3133
top: false,
3234
})
@@ -37,8 +39,10 @@ const leftBoolean = useBooleanish(toRef(props, 'left'))
3739
const rightBoolean = useBooleanish(toRef(props, 'right'))
3840
const startBoolean = useBooleanish(toRef(props, 'start'))
3941
const topBoolean = useBooleanish(toRef(props, 'top'))
42+
const lazyBoolean = useBooleanish(toRef(props, 'lazy'))
4043
4144
const attrs = computed(() => ({
45+
loading: lazyBoolean.value ? 'lazy' : 'eager',
4246
src: props.src,
4347
alt: props.alt,
4448
width:
@@ -49,24 +53,24 @@ const attrs = computed(() => ({
4953
undefined,
5054
}))
5155
52-
const classes = computed(() => {
53-
const align = leftBoolean.value ? 'float-left' : rightBoolean.value ? 'float-right' : ''
56+
const alignment = computed(() =>
57+
leftBoolean.value ? 'float-left' : rightBoolean.value ? 'float-right' : ''
58+
)
5459
55-
let baseClass = 'card-img'
60+
const baseClass = computed(() =>
61+
topBoolean.value
62+
? 'card-img-top'
63+
: rightBoolean.value || endBoolean.value
64+
? 'card-img-right'
65+
: bottomBoolean.value
66+
? 'card-img-bottom'
67+
: leftBoolean.value || startBoolean.value
68+
? 'card-img-left'
69+
: 'card-img'
70+
)
5671
57-
if (topBoolean.value) {
58-
baseClass += '-top'
59-
} else if (rightBoolean.value || endBoolean.value) {
60-
baseClass += '-right'
61-
} else if (bottomBoolean.value) {
62-
baseClass += '-bottom'
63-
} else if (leftBoolean.value || startBoolean.value) {
64-
baseClass += '-left'
65-
}
66-
67-
return {
68-
[align]: !!align,
69-
[baseClass]: true,
70-
}
71-
})
72+
const classes = computed(() => ({
73+
[alignment.value]: !!alignment.value,
74+
[baseClass.value]: !!baseClass.value,
75+
}))
7276
</script>
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
2-
<component :is="subTitleTag" class="card-subtitle mb-2" :class="classes">
2+
<component :is="tag" class="card-subtitle mb-2" :class="classes">
33
<slot>
4-
{{ subTitle }}
4+
{{ text }}
55
</slot>
66
</component>
77
</template>
@@ -12,17 +12,17 @@ import type {TextColorVariant} from '../../types'
1212
import {computed} from 'vue'
1313
1414
interface BCardSubtitleProps {
15-
subTitle?: string
16-
subTitleTag?: string
17-
subTitleTextVariant?: TextColorVariant
15+
text?: string
16+
tag?: string
17+
textVariant?: TextColorVariant
1818
}
1919
2020
const props = withDefaults(defineProps<BCardSubtitleProps>(), {
21-
subTitleTag: 'h6',
22-
subTitleTextVariant: 'muted',
21+
tag: 'h6',
22+
textVariant: 'muted',
2323
})
2424
2525
const classes = computed(() => ({
26-
[`text-${props.subTitleTextVariant}`]: !!props.subTitleTextVariant,
26+
[`text-${props.textVariant}`]: !!props.textVariant,
2727
}))
2828
</script>
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
<template>
2-
<p class="card-text">
3-
<slot />
4-
</p>
2+
<component :is="tag" class="card-text">
3+
<slot>
4+
{{ text }}
5+
</slot>
6+
</component>
57
</template>
8+
9+
<script setup lang="ts">
10+
interface BCardTextProps {
11+
text?: string
12+
tag?: string
13+
}
14+
15+
withDefaults(defineProps<BCardTextProps>(), {
16+
tag: 'p',
17+
})
18+
</script>
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
2-
<component :is="titleTag" class="card-title">
2+
<component :is="tag" class="card-title">
33
<slot>
4-
{{ title }}
4+
{{ text }}
55
</slot>
66
</component>
77
</template>
@@ -10,11 +10,11 @@
1010
// import type {BCardTitleProps} from '../../types/components'
1111
1212
interface BCardTitleProps {
13-
title?: string
14-
titleTag?: string
13+
text?: string
14+
tag?: string
1515
}
1616
1717
withDefaults(defineProps<BCardTitleProps>(), {
18-
titleTag: 'h4',
18+
tag: 'h4',
1919
})
2020
</script>

0 commit comments

Comments
 (0)