1
1
<template >
2
2
<li role =" presentation" >
3
3
<component
4
- :is =" tag "
4
+ :is =" computedTag "
5
5
class =" dropdown-item"
6
6
:class =" computedClasses"
7
7
:disabled =" disabledBoolean"
8
8
:aria-disabled =" disabledBoolean ? true : null"
9
9
:aria-current =" activeBoolean ? true : null"
10
- :href =" tag === 'a' ? href : null"
10
+ :href =" computedTag === 'a' ? href : null"
11
11
:rel =" rel"
12
- :type =" tag === 'button' ? 'button' : null"
12
+ :type =" computedTag === 'button' ? 'button' : null"
13
13
:target =" target"
14
- v-bind =" componentAttrs "
14
+ v-bind =" computedLinkProps "
15
15
@click =" clicked"
16
16
>
17
17
<slot />
21
21
22
22
<script setup lang="ts">
23
23
import BLink from ' ../BLink/BLink.vue'
24
- import {computed , inject , useAttrs } from ' vue'
25
- import type {Booleanish , ClassValue , ColorVariant , LinkTarget } from ' ../../types'
24
+ import {computed , inject } from ' vue'
25
+ import type {BLinkProps , ClassValue } from ' ../../types'
26
26
import {useBooleanish } from ' ../../composables'
27
- import {collapseInjectionKey , dropdownInjectionKey , navbarInjectionKey } from ' ../../utils'
27
+ import {
28
+ collapseInjectionKey ,
29
+ dropdownInjectionKey ,
30
+ isLink ,
31
+ navbarInjectionKey ,
32
+ pick ,
33
+ } from ' ../../utils'
28
34
29
35
defineOptions ({
30
36
inheritAttrs: false ,
31
37
})
32
38
33
39
const props = withDefaults (
34
- defineProps <{
35
- href? : string
36
- linkClass? : ClassValue
37
- active? : Booleanish
38
- disabled? : Booleanish
39
- rel? : string
40
- target? : LinkTarget
41
- variant? : ColorVariant | null
42
- }>(),
40
+ defineProps <
41
+ {
42
+ linkClass?: ClassValue
43
+ } & Omit < BLinkProps , ' event' | ' routerTag' >
44
+ > (),
43
45
{
44
- active: false ,
45
- disabled: false ,
46
- rel: undefined ,
47
- target: ' _self' ,
48
- variant: null ,
49
46
linkClass: undefined ,
47
+ // Link props
48
+ active: undefined ,
49
+ activeClass: undefined ,
50
+ append: false ,
50
51
href: undefined ,
52
+ // noPrefetch: {type: [Boolean, String] as PropType<Booleanish>, default: false},
53
+ // prefetch: {type: [Boolean, String] as PropType<Booleanish>, default: null},
54
+ rel: undefined ,
55
+ replace: false ,
56
+ routerComponentName: ' router-link' ,
57
+ target: ' _self' ,
58
+ to: undefined ,
59
+ opacity: undefined ,
60
+ opacityHover: undefined ,
61
+ underlineVariant: null ,
62
+ underlineOffset: undefined ,
63
+ underlineOffsetHover: undefined ,
64
+ underlineOpacity: undefined ,
65
+ underlineOpacityHover: undefined ,
51
66
}
52
67
)
53
68
@@ -63,8 +78,6 @@ defineSlots<{
63
78
default? : (props : Record <string , never >) => any
64
79
}>()
65
80
66
- const attrs = useAttrs ()
67
-
68
81
const computedClasses = computed (() => [
69
82
props .linkClass ,
70
83
{
@@ -74,19 +87,41 @@ const computedClasses = computed(() => [
74
87
},
75
88
])
76
89
77
- const tag = computed <' button' | ' a' | typeof BLink >(() =>
78
- props .href ? ' a' : attrs .to ? BLink : ' button'
90
+ const computedLink = computed <boolean >(() => isLink (props ))
91
+
92
+ const computedTag = computed <typeof BLink | ' button' | ' a' >(() =>
93
+ computedLink .value ? BLink : props .href ? ' a' : ' button'
79
94
)
80
95
81
- const componentAttrs = computed (() => ({
82
- ... (attrs .to ? {activeClass: ' active' , ... attrs } : attrs ),
83
- }))
96
+ const computedLinkProps = computed (() =>
97
+ computedLink .value
98
+ ? pick (props , [
99
+ ' active' ,
100
+ ' activeClass' ,
101
+ ' append' ,
102
+ ' href' ,
103
+ ' rel' ,
104
+ ' replace' ,
105
+ ' routerComponentName' ,
106
+ ' target' ,
107
+ ' to' ,
108
+ ' variant' ,
109
+ ' opacity' ,
110
+ ' opacityHover' ,
111
+ ' underlineVariant' ,
112
+ ' underlineOffset' ,
113
+ ' underlineOffsetHover' ,
114
+ ' underlineOpacity' ,
115
+ ' underlineOpacityHover' ,
116
+ ])
117
+ : {}
118
+ )
84
119
85
120
const collapseData = inject (collapseInjectionKey , null )
86
121
const dropdownData = inject (dropdownInjectionKey , null )
87
122
const navbarData = inject (navbarInjectionKey , null )
88
123
89
- // Pretty sure this emits if tag is not button and is disabled
124
+ // Pretty sure this emits if computedTag is not button and is disabled
90
125
const clicked = (e : MouseEvent ): void => {
91
126
emit (' click' , e )
92
127
if (navbarData !== null ) {
0 commit comments