Skip to content

Commit d6d354b

Browse files
committed
feat(BImg): add start and end props
refactor(BImg): move dimentions parser to function refactor(BImg): remove redundant || as it caused lower test coverage score, which could not be tested
1 parent 6aefa7f commit d6d354b

File tree

1 file changed

+20
-16
lines changed
  • packages/bootstrap-vue-3/src/components

1 file changed

+20
-16
lines changed

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ interface BImgProps {
1919
fluidGrow?: Booleanish
2020
height?: number | string
2121
left?: Booleanish
22+
start?: Booleanish
2223
right?: Booleanish
24+
end?: Booleanish
2325
rounded?: boolean | string
2426
sizes?: string | Array<string>
2527
src?: string
@@ -38,6 +40,8 @@ const props = withDefaults(defineProps<BImgProps>(), {
3840
fluidGrow: false,
3941
left: false,
4042
right: false,
43+
end: false,
44+
start: false,
4145
rounded: false,
4246
thumbnail: false,
4347
})
@@ -55,7 +59,9 @@ const centerBoolean = useBooleanish(toRef(props, 'center'))
5559
const fluidBoolean = useBooleanish(toRef(props, 'fluid'))
5660
const fluidGrowBoolean = useBooleanish(toRef(props, 'fluidGrow'))
5761
const leftBoolean = useBooleanish(toRef(props, 'left'))
62+
const startBoolean = useBooleanish(toRef(props, 'start'))
5863
const rightBoolean = useBooleanish(toRef(props, 'right'))
64+
const endBoolean = useBooleanish(toRef(props, 'end'))
5965
const thumbnailBoolean = useBooleanish(toRef(props, 'thumbnail'))
6066
6167
const BLANK_TEMPLATE =
@@ -99,20 +105,22 @@ const computedSizes = computed<string | undefined>(() =>
99105
)
100106
101107
const computedDimentions = computed<{height: number | undefined; width: number | undefined}>(() => {
102-
const width =
103-
typeof props.width === 'number' ? props.width : parseInt(props.width as string, 10) || undefined
104-
const height =
105-
typeof props.height === 'number'
106-
? props.height
107-
: parseInt(props.height as string, 10) || undefined
108+
const parser = (str: string | number | undefined): number | undefined =>
109+
str === undefined
110+
? undefined
111+
: typeof str === 'number'
112+
? str
113+
: Number.parseInt(str, 10) || undefined
114+
const width = parser(props.width)
115+
const height = parser(props.height)
108116
if (blankBoolean.value) {
109-
if (!!width && !height) {
117+
if (width !== undefined && height === undefined) {
110118
return {height: width, width}
111119
}
112-
if (!width && !!height) {
120+
if (width === undefined && height !== undefined) {
113121
return {height, width: height}
114122
}
115-
if (!width && !height) {
123+
if (width === undefined && height === undefined) {
116124
return {height: 1, width: 1}
117125
}
118126
}
@@ -123,11 +131,7 @@ const computedDimentions = computed<{height: number | undefined; width: number |
123131
})
124132
125133
const computedBlankImgSrc = computed(() =>
126-
makeBlankImgSrc(
127-
computedDimentions.value.width,
128-
computedDimentions.value.height,
129-
props.blankColor || 'transparent'
130-
)
134+
makeBlankImgSrc(computedDimentions.value.width, computedDimentions.value.height, props.blankColor)
131135
)
132136
133137
const attrs = computed(() => ({
@@ -141,9 +145,9 @@ const attrs = computed(() => ({
141145
}))
142146
143147
const alignment = computed<'float-start' | 'float-end' | 'mx-auto' | undefined>(() =>
144-
leftBoolean.value
148+
leftBoolean.value || startBoolean.value
145149
? 'float-start'
146-
: rightBoolean.value
150+
: rightBoolean.value || endBoolean.value
147151
? 'float-end'
148152
: centerBoolean.value
149153
? 'mx-auto'

0 commit comments

Comments
 (0)