Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit e0a223f

Browse files
committed
refactor: WIP script setup BLinkProps items
chore: update package refactor: standardize the flow of interface emits and props
1 parent 15eb308 commit e0a223f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+789
-651
lines changed

packages/bootstrap-vue-next/src/components/BAccordion/BAccordion.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ interface BAccordionProps {
1818
modelValue?: string
1919
}
2020
21+
interface BAccordionEmits {
22+
(e: 'update:modelValue', value: string): void
23+
}
24+
2125
const props = withDefaults(defineProps<BAccordionProps>(), {
2226
flush: false,
2327
free: false,
2428
id: undefined,
2529
modelValue: undefined,
2630
})
2731
28-
const emit = defineEmits<(e: 'update:modelValue', value: string) => void>()
32+
const emit = defineEmits<BAccordionEmits>()
2933
3034
defineSlots<{
3135
// eslint-disable-next-line @typescript-eslint/no-explicit-any

packages/bootstrap-vue-next/src/components/BAccordion/BAccordionItem.vue

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ interface BAccordionItemProps {
5858
isNav?: Booleanish
5959
}
6060
61+
interface BAccordionItemEmits {
62+
(e: 'show', value: BvTriggerableEvent): void
63+
(e: 'shown', value: BvTriggerableEvent): void
64+
(e: 'hide', value: BvTriggerableEvent): void
65+
(e: 'hidden', value: BvTriggerableEvent): void
66+
(e: 'hide-prevented'): void
67+
(e: 'show-prevented'): void
68+
(e: 'update:modelValue', value: boolean): void
69+
}
70+
6171
const props = withDefaults(defineProps<BAccordionItemProps>(), {
6272
headerTag: 'h2',
6373
id: undefined,
@@ -70,16 +80,6 @@ const props = withDefaults(defineProps<BAccordionItemProps>(), {
7080
visible: false,
7181
})
7282
73-
interface BAccordionItemEmits {
74-
(e: 'show', value: BvTriggerableEvent): void
75-
(e: 'shown', value: BvTriggerableEvent): void
76-
(e: 'hide', value: BvTriggerableEvent): void
77-
(e: 'hidden', value: BvTriggerableEvent): void
78-
(e: 'hide-prevented'): void
79-
(e: 'show-prevented'): void
80-
(e: 'update:modelValue', value: boolean): void
81-
}
82-
8383
const emit = defineEmits<BAccordionItemEmits>()
8484
8585
defineSlots<{

packages/bootstrap-vue-next/src/components/BAlert/BAlert.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ interface BAlertProps {
5353
showOnPause?: Booleanish
5454
}
5555
56+
interface BAlertEmits {
57+
(e: 'closed'): void
58+
(e: 'close-countdown', value: number): void
59+
(e: 'update:modelValue', value: boolean | number): void
60+
}
61+
5662
const props = withDefaults(defineProps<BAlertProps>(), {
5763
closeContent: undefined,
5864
closeVariant: 'secondary',
@@ -67,12 +73,6 @@ const props = withDefaults(defineProps<BAlertProps>(), {
6773
showOnPause: true,
6874
})
6975
70-
interface BAlertEmits {
71-
(e: 'closed'): void
72-
(e: 'close-countdown', value: number): void
73-
(e: 'update:modelValue', value: boolean | number): void
74-
}
75-
7676
const emit = defineEmits<BAlertEmits>()
7777
7878
defineSlots<{

packages/bootstrap-vue-next/src/components/BAvatar/BAvatar.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ interface BAvatarProps {
5050
variant?: ColorVariant | null
5151
}
5252
53+
interface BAvatarEmits {
54+
(e: 'click', value: MouseEvent): void
55+
(e: 'img-error', value: Event): void
56+
}
57+
5358
const props = withDefaults(defineProps<BAvatarProps>(), {
5459
ariaLabel: undefined,
5560
badgeOffset: undefined,
@@ -71,11 +76,6 @@ const props = withDefaults(defineProps<BAvatarProps>(), {
7176
variant: 'secondary',
7277
})
7378
74-
interface BAvatarEmits {
75-
(e: 'click', value: MouseEvent): void
76-
(e: 'img-error', value: Event): void
77-
}
78-
7979
const emit = defineEmits<BAvatarEmits>()
8080
8181
defineSlots<{

packages/bootstrap-vue-next/src/components/BBadge/BBadge.vue

Lines changed: 71 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,84 @@
44
</component>
55
</template>
66

7-
<script lang="ts">
8-
import {isLink, omit, pluckProps} from '../../utils'
7+
<script setup lang="ts">
8+
import {isLink, pluckProps} from '../../utils'
99
import {useBooleanish} from '../../composables'
10-
import {computed, defineComponent, type PropType, type SlotsType} from 'vue'
10+
import {computed} from 'vue'
1111
import type {Booleanish, ColorVariant} from '../../types'
12-
import BLink, {BLINK_PROPS} from '../BLink/BLink.vue'
12+
import BLink, {type BLinkProps} from '../BLink/BLink.vue'
1313
14-
const linkProps = omit(BLINK_PROPS, ['event', 'routerTag'] as const)
14+
defineSlots<{
15+
default?: Record<string, never>
16+
}>()
1517
16-
export default defineComponent({
17-
slots: Object as SlotsType<{
18-
default?: Record<string, never>
19-
}>,
20-
components: {BLink},
21-
props: {
22-
...linkProps,
23-
pill: {type: [Boolean, String] as PropType<Booleanish>, default: false},
24-
tag: {type: String, default: 'span'},
25-
textIndicator: {type: [Boolean, String] as PropType<Booleanish>, default: false},
26-
dotIndicator: {type: [Boolean, String] as PropType<Booleanish>, default: false},
27-
variant: {type: String as PropType<ColorVariant | null>, default: 'secondary'},
28-
},
29-
setup(props) {
30-
const pillBoolean = useBooleanish(() => props.pill)
31-
const textIndicatorBoolean = useBooleanish(() => props.textIndicator)
32-
const dotIndicatorBoolean = useBooleanish(() => props.dotIndicator)
33-
const activeBoolean = useBooleanish(() => props.active)
34-
const disabledBoolean = useBooleanish(() => props.disabled)
18+
interface BBadgeProps {
19+
pill?: Booleanish
20+
tag?: string
21+
textIndicator?: Booleanish
22+
dotIndicator?: Booleanish
23+
variant?: ColorVariant | null
24+
}
3525
36-
const computedLink = computed<boolean>(() => isLink(props))
26+
const props = withDefaults(defineProps<BBadgeProps & Omit<BLinkProps, 'event' | 'routerTag'>>(), {
27+
pill: false,
28+
tag: 'span',
29+
textIndicator: false,
30+
dotIndicator: false,
31+
variant: 'secondary',
32+
// Link props
33+
active: undefined,
34+
activeClass: 'router-link-active',
35+
append: false,
36+
disabled: false,
37+
href: undefined,
38+
// noPrefetch: {type: [Boolean, String] as PropType<Booleanish>, default: false},
39+
// prefetch: {type: [Boolean, String] as PropType<Booleanish>, default: null},
40+
rel: undefined,
41+
replace: false,
42+
routerComponentName: 'router-link',
43+
target: '_self',
44+
to: undefined,
45+
// End link props
46+
})
3747
38-
const computedTag = computed<string | typeof BLink>(() =>
39-
computedLink.value ? BLink : props.tag
40-
)
48+
const pillBoolean = useBooleanish(() => props.pill)
49+
const textIndicatorBoolean = useBooleanish(() => props.textIndicator)
50+
const dotIndicatorBoolean = useBooleanish(() => props.dotIndicator)
51+
const activeBoolean = useBooleanish(() => props.active)
52+
const disabledBoolean = useBooleanish(() => props.disabled)
4153
42-
const computedClasses = computed(() => ({
43-
[`bg-${props.variant}`]: props.variant !== null,
44-
'active': activeBoolean.value,
45-
'disabled': disabledBoolean.value,
46-
'text-dark': props.variant !== null && ['warning', 'info', 'light'].includes(props.variant),
47-
'rounded-pill': pillBoolean.value,
48-
'position-absolute top-0 start-100 translate-middle':
49-
textIndicatorBoolean.value || dotIndicatorBoolean.value,
50-
'p-2 border border-light rounded-circle': dotIndicatorBoolean.value,
51-
'text-decoration-none': computedLink.value,
52-
}))
54+
const computedLink = computed<boolean>(() => isLink(props))
5355
54-
const computedLinkProps = computed(() =>
55-
computedLink.value ? pluckProps(props, linkProps) : {}
56-
)
56+
const computedTag = computed<string | typeof BLink>(() => (computedLink.value ? BLink : props.tag))
5757
58-
return {
59-
computedClasses,
60-
computedLinkProps,
61-
computedTag,
62-
}
63-
},
64-
})
58+
const computedClasses = computed(() => ({
59+
[`bg-${props.variant}`]: props.variant !== null,
60+
'active': activeBoolean.value,
61+
'disabled': disabledBoolean.value,
62+
'text-dark': props.variant !== null && ['warning', 'info', 'light'].includes(props.variant),
63+
'rounded-pill': pillBoolean.value,
64+
'position-absolute top-0 start-100 translate-middle':
65+
textIndicatorBoolean.value || dotIndicatorBoolean.value,
66+
'p-2 border border-light rounded-circle': dotIndicatorBoolean.value,
67+
'text-decoration-none': computedLink.value,
68+
}))
69+
70+
const computedLinkProps = computed(() =>
71+
computedLink.value
72+
? pluckProps(props, {
73+
active: true,
74+
activeClass: true,
75+
append: true,
76+
disabled: true,
77+
href: true,
78+
rel: true,
79+
replace: true,
80+
routerComponentName: true,
81+
target: true,
82+
to: true,
83+
variant: true,
84+
} as Record<keyof Omit<BLinkProps, 'event' | 'routerTag'>, true>)
85+
: {}
86+
)
6587
</script>

packages/bootstrap-vue-next/src/components/BBreadcrumb/BBreadcrumbItem.vue

Lines changed: 76 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,64 +13,90 @@
1313
</li>
1414
</template>
1515

16-
<script lang="ts">
17-
import {omit, pluckProps} from '../../utils'
16+
<script setup lang="ts">
17+
import {pluckProps} from '../../utils'
1818
import {useBooleanish} from '../../composables'
19-
import {computed, defineComponent, type PropType, type SlotsType} from 'vue'
20-
import BLink, {BLINK_PROPS} from '../BLink/BLink.vue'
19+
import {computed} from 'vue'
20+
import BLink, {type BLinkProps} from '../BLink/BLink.vue'
2121
import type {Booleanish} from '../../types'
2222
23-
const linkProps = omit(BLINK_PROPS, ['event', 'routerTag'] as const)
23+
defineSlots<{
24+
default?: Record<string, never>
25+
}>()
2426
25-
export default defineComponent({
26-
slots: Object as SlotsType<{
27-
default?: Record<string, never>
28-
}>,
29-
components: {BLink},
30-
props: {
31-
...linkProps,
32-
active: {type: [Boolean, String] as PropType<Booleanish>, default: false},
33-
ariaCurrent: {type: String, default: 'location'},
34-
disabled: {type: [Boolean, String] as PropType<Booleanish>, default: false},
35-
text: {type: String, default: undefined},
36-
},
37-
emits: ['click'],
38-
setup(props, {emit}) {
39-
const activeBoolean = useBooleanish(() => props.active)
40-
const disabledBoolean = useBooleanish(() => props.disabled)
27+
interface BBreadcrumbItemProps {
28+
active?: Booleanish
29+
ariaCurrent?: string
30+
disabled?: Booleanish
31+
text?: string
32+
}
4133
42-
const computedClasses = computed(() => ({
43-
active: activeBoolean.value,
44-
}))
34+
interface BBreadcrumbItemEmits {
35+
(e: 'click', value: MouseEvent): void
36+
}
4537
46-
const computedTag = computed<'span' | typeof BLink>(() =>
47-
activeBoolean.value ? 'span' : BLink
48-
)
38+
const props = withDefaults(
39+
defineProps<BBreadcrumbItemProps & Omit<BLinkProps, 'event' | 'routerTag'>>(),
40+
{
41+
active: false,
42+
ariaCurrent: 'location',
43+
text: undefined,
44+
// Link props
45+
activeClass: 'router-link-active',
46+
append: false,
47+
disabled: false,
48+
event: 'click',
49+
href: undefined,
50+
// noPrefetch: {type: [Boolean, String] as PropType<Booleanish>, default: false},
51+
// prefetch: {type: [Boolean, String] as PropType<Booleanish>, default: null},
52+
rel: undefined,
53+
replace: false,
54+
routerComponentName: 'router-link',
55+
routerTag: 'a',
56+
target: '_self',
57+
to: undefined,
58+
variant: undefined,
59+
// End link props
60+
}
61+
)
4962
50-
const computedAriaCurrent = computed(() =>
51-
activeBoolean.value ? props.ariaCurrent : undefined
52-
)
63+
const emit = defineEmits<BBreadcrumbItemEmits>()
5364
54-
const computedLinkProps = computed(() =>
55-
computedTag.value !== 'span' ? pluckProps(props, linkProps) : {}
56-
)
65+
const activeBoolean = useBooleanish(() => props.active)
66+
const disabledBoolean = useBooleanish(() => props.disabled)
5767
58-
const clicked = (e: MouseEvent): void => {
59-
if (disabledBoolean.value || activeBoolean.value) {
60-
e.preventDefault()
61-
e.stopImmediatePropagation()
62-
return
63-
}
64-
if (!disabledBoolean.value) emit('click', e)
65-
}
68+
const computedClasses = computed(() => ({
69+
active: activeBoolean.value,
70+
}))
6671
67-
return {
68-
computedLinkProps,
69-
computedClasses,
70-
computedTag,
71-
computedAriaCurrent,
72-
clicked,
73-
}
74-
},
75-
})
72+
const computedTag = computed<'span' | typeof BLink>(() => (activeBoolean.value ? 'span' : BLink))
73+
74+
const computedAriaCurrent = computed(() => (activeBoolean.value ? props.ariaCurrent : undefined))
75+
76+
const computedLinkProps = computed(() =>
77+
computedTag.value !== 'span'
78+
? pluckProps(props, {
79+
active: true,
80+
activeClass: true,
81+
append: true,
82+
disabled: true,
83+
href: true,
84+
rel: true,
85+
replace: true,
86+
routerComponentName: true,
87+
target: true,
88+
to: true,
89+
variant: true,
90+
} as Record<keyof Omit<BLinkProps, 'event' | 'routerTag'>, true>)
91+
: {}
92+
)
93+
94+
const clicked = (e: MouseEvent): void => {
95+
if (disabledBoolean.value || activeBoolean.value) {
96+
e.preventDefault()
97+
e.stopImmediatePropagation()
98+
return
99+
}
100+
if (!disabledBoolean.value) emit('click', e)
101+
}
76102
</script>

0 commit comments

Comments
 (0)