Skip to content

Commit 2c3756d

Browse files
committed
Define correct types for horizontal alignment when we want to justify the content.
Define text horizontal alignment possible. Avoid problems with definition of namespace and the common alignments. Unified code to calculate possible css classes of justify content
1 parent 0e1a12c commit 2c3756d

File tree

12 files changed

+62
-46
lines changed

12 files changed

+62
-46
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import BCardFooter from './BCardFooter.vue'
4747
import {isEmptySlot} from '../../utils'
4848
4949
interface BCardProps {
50-
align?: Alignment
50+
align?: Alignment.TextHorizontal
5151
bgVariant?: ColorVariant
5252
bodyBgVariant?: ColorVariant
5353
bodyClass?: ClassValue

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
<script setup lang="ts">
88
// import type {BNavProps} from '../types/components'
99
import type {Alignment, Booleanish} from '../../types'
10-
import {useBooleanish} from '../../composables'
10+
import {useAlignment, useBooleanish} from '../../composables'
1111
import {computed, toRef} from 'vue'
1212
1313
interface BNavProps {
14-
align?: Alignment
14+
align?: Alignment.JustifyContent
1515
cardHeader?: Booleanish
1616
fill?: Booleanish
1717
justified?: Booleanish
@@ -40,6 +40,7 @@ const pillsBoolean = useBooleanish(toRef(props, 'pills'))
4040
const smallBoolean = useBooleanish(toRef(props, 'small'))
4141
const tabsBoolean = useBooleanish(toRef(props, 'tabs'))
4242
const verticalBoolean = useBooleanish(toRef(props, 'vertical'))
43+
const alignment = useAlignment(toRef(props, 'align'))
4344
4445
const computedClasses = computed(() => ({
4546
'nav-tabs': tabsBoolean.value,
@@ -50,7 +51,7 @@ const computedClasses = computed(() => ({
5051
'flex-column': verticalBoolean.value,
5152
'nav-fill': !verticalBoolean.value && fillBoolean.value,
5253
'nav-justified': !verticalBoolean.value && justifiedBoolean.value,
53-
[`justify-content-${props.align}`]: !verticalBoolean.value && props.align !== undefined,
54+
[alignment.value]: !verticalBoolean.value && props.align !== undefined,
5455
'small': smallBoolean.value,
5556
}))
5657
</script>

packages/bootstrap-vue-3/src/components/BNavbar/BNavbarNav.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
<script setup lang="ts">
88
import type {Alignment, Booleanish} from '../../types'
99
import {computed, toRef} from 'vue'
10-
import {useBooleanish} from '../../composables'
10+
import {useAlignment, useBooleanish} from '../../composables'
1111
1212
interface Props {
13-
align?: Alignment
13+
align?: Alignment.JustifyContent
1414
fill?: Booleanish
1515
justified?: Booleanish
1616
small?: Booleanish
@@ -27,11 +27,12 @@ const props = withDefaults(defineProps<Props>(), {
2727
const fillBoolean = useBooleanish(toRef(props, 'fill'))
2828
const justifiedBoolean = useBooleanish(toRef(props, 'justified'))
2929
const smallBoolean = useBooleanish(toRef(props, 'small'))
30+
const alignment = useAlignment(toRef(props, 'align'))
3031
3132
const computedClasses = computed(() => ({
3233
'nav-fill': fillBoolean.value,
3334
'nav-justified': justifiedBoolean.value,
34-
[`justify-content-${props.align}`]: props.align !== undefined,
35+
[alignment.value]: props.align !== undefined,
3536
'small': smallBoolean.value,
3637
}))
3738
</script>

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const sanitizeCurrentPage = (value: number, numberOfPages: number) => {
3131
export default defineComponent({
3232
name: 'BPagination',
3333
props: {
34-
align: {type: String as PropType<Alignment>, default: 'start'},
34+
align: {type: String as PropType<Alignment.JustifyContent | 'fill'>, default: 'start'},
3535
ariaControls: {type: String, required: false},
3636
ariaLabel: {type: String, default: 'Pagination'},
3737
disabled: {type: [Boolean, String] as PropType<Booleanish>, default: false},
@@ -71,7 +71,10 @@ export default defineComponent({
7171
const lastNumberBoolean = useBooleanish(toRef(props, 'lastNumber'))
7272
const pillsBoolean = useBooleanish(toRef(props, 'pills'))
7373
74-
const alignment = useAlignment(toRef(props, 'align'))
74+
const justifyAlign = computed((): Alignment.JustifyContent => {
75+
return props.align == 'fill' ? 'start' : props.align
76+
});
77+
const alignment = useAlignment(toRef(justifyAlign, 'value'))
7578
7679
// Use Active to on page-item to denote active tab
7780
const numberOfPages = computed(() =>
@@ -261,7 +264,7 @@ export default defineComponent({
261264
262265
return () => {
263266
const buttons = []
264-
const pageNumbers = pages.value.map((p) => p.number) // array of numbers.. Used in first and last number comparisons
267+
const pageNumbers = pages.value.map((p) => p.number) // array of numbers... Used in first and last number comparisons
265268
const isActivePage = (pageNumber: number) => pageNumber === props.modelValue
266269
const noCurrentPage: boolean = props.modelValue < 1
267270
const fill = props.align === 'fill'

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import {computed, defineComponent, PropType, toRef} from 'vue'
99
import {getBreakpointProps, getClasses} from '../utils'
1010
import type {Alignment, Booleanish} from '../types'
11-
import {useBooleanish} from '../composables'
11+
import {useAlignment, useBooleanish} from '../composables'
1212
1313
const rowColsProps = getBreakpointProps('cols', [''], {type: [String, Number], default: null})
1414
@@ -20,12 +20,13 @@ export default defineComponent({
2020
gutterY: {type: String, default: null},
2121
noGutters: {type: [Boolean, String] as PropType<Booleanish>, default: false},
2222
alignV: {type: String as PropType<Alignment.Vertical>, default: null},
23-
alignH: {type: String as PropType<Alignment.Horizontal>, default: null},
23+
alignH: {type: String as PropType<Alignment.JustifyContent>, default: null},
2424
alignContent: {type: String as PropType<Alignment.Content>, default: null},
2525
...rowColsProps,
2626
},
2727
setup(props) {
2828
const noGuttersBoolean = useBooleanish(toRef(props, 'noGutters'))
29+
const alignment = useAlignment(toRef(props, 'alignH'))
2930
3031
const rowColsClasses = computed(() => getClasses(props, rowColsProps, 'cols', 'row-cols'))
3132
@@ -36,7 +37,7 @@ export default defineComponent({
3637
[`gy-${props.gutterY}`]: props.gutterY !== null,
3738
'g-0': noGuttersBoolean.value,
3839
[`align-items-${props.alignV}`]: props.alignV !== null,
39-
[`justify-content-${props.alignH}`]: props.alignH !== null,
40+
[alignment.value]: props.alignH !== null,
4041
[`align-content-${props.alignContent}`]: props.alignContent !== null,
4142
},
4243
])

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@
7676
import type {BTabsParentData} from '../../types/components'
7777
import {computed, InjectionKey, onMounted, provide, ref, toRef, useSlots, watch} from 'vue'
7878
import {BvEvent, getId} from '../../utils'
79-
import {useBooleanish} from '../../composables'
79+
import {useAlignment, useBooleanish} from '../../composables'
8080
import type {Alignment, Booleanish, ClassValue} from '../../types'
8181
8282
interface BTabsProps {
8383
activeNavItemClass?: ClassValue
8484
activeTabClass?: ClassValue
85-
align?: Alignment
85+
align?: Alignment.JustifyContent
8686
card?: Booleanish
8787
contentClass?: ClassValue
8888
end?: Booleanish
@@ -205,10 +205,12 @@ const computedClasses = computed(() => ({
205205
'align-items-start': verticalBoolean.value,
206206
}))
207207
208+
const alignment = useAlignment(toRef(props, 'align'))
209+
208210
const navTabsClasses = computed(() => ({
209211
'nav-pills': pillsBoolean.value,
210212
'flex-column me-3': verticalBoolean.value,
211-
[`justify-content-${props.align}`]: props.align !== undefined,
213+
[alignment.value]: props.align !== undefined,
212214
'nav-fill': fillBoolean.value,
213215
'card-header-tabs': cardBoolean.value,
214216
'nav-justified': justifiedBoolean.value,

packages/bootstrap-vue-3/src/composables/useAlignment.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@ import type {Alignment} from '../types'
33

44
/**
55
*
6-
* @param props
6+
* @param align
77
* @returns
88
*/
99
export default (
10-
align: Ref<Alignment>
11-
): ComputedRef<'justify-content-center' | 'justify-content-end' | 'justify-content-start'> =>
12-
computed(() =>
13-
align.value === 'center'
14-
? 'justify-content-center'
15-
: align.value === 'end'
16-
? 'justify-content-end'
17-
: 'justify-content-start'
18-
)
10+
align: Ref<Alignment.JustifyContent | undefined>
11+
): ComputedRef<string> => computed(() => {
12+
if (!align.value) return ''
13+
return `justify-content-${align.value}`
14+
})
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/**
22
* @external
33
*/
4-
declare type Alignment = 'start' | 'end' | 'center' | 'fill'
4+
declare type CommonAlignment = 'start' | 'end' | 'center' | 'fill'
55

66
declare namespace Alignment {
7-
type Vertical = Alignment | 'baseline' | 'stretch'
8-
type Horizontal = Alignment | 'between' | 'around'
9-
type Content = Alignment | 'between' | 'around' | 'stretch'
7+
type Vertical = CommonAlignment | 'baseline' | 'stretch'
8+
type Horizontal = CommonAlignment | 'between' | 'around'
9+
type Content = CommonAlignment | 'between' | 'around' | 'stretch'
10+
type JustifyContent = 'start' | 'end' | 'center' | 'between' | 'around' | 'evenly'
11+
type TextHorizontal = 'start' | 'end' | 'center'
1012
}
1113

1214
export default Alignment

packages/bootstrap-vue-3/src/types/components/BCard/BCard.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {Alignment, ColorVariant, TextColorVariant} from '../..'
22
// Props
33
export interface Props {
4-
align?: Alignment
4+
align?: Alignment.TextHorizontal
55
bgVariant?: ColorVariant
66
bodyBgVariant?: ColorVariant
77
bodyClass?: Array<unknown> | Record<string, unknown> | string

packages/bootstrap-vue-3/src/types/components/BPagination/BPagination.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {Alignment, InputSize} from '../..'
22
// Props
33
export interface Props {
4-
align?: Alignment
4+
align?: Alignment.Horizontal
55
ariaControls?: string
66
ariaLabel?: string
77
disabled?: boolean

0 commit comments

Comments
 (0)