/
badge.js
55 lines (49 loc) · 1.45 KB
/
badge.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { defineComponent, mergeData } from '../../vue'
import { NAME_BADGE } from '../../constants/components'
import { PROP_TYPE_BOOLEAN, PROP_TYPE_STRING } from '../../constants/props'
import { omit, sortKeys } from '../../utils/object'
import { makeProp, makePropsConfigurable, pluckProps } from '../../utils/props'
import { isLink } from '../../utils/router'
import { BLink, props as BLinkProps } from '../link/link'
// --- Props ---
const linkProps = omit(BLinkProps, ['event', 'routerTag'])
delete linkProps.href.default
delete linkProps.to.default
export const props = makePropsConfigurable(
sortKeys({
...linkProps,
pill: makeProp(PROP_TYPE_BOOLEAN, false),
tag: makeProp(PROP_TYPE_STRING, 'span'),
variant: makeProp(PROP_TYPE_STRING, 'secondary')
}),
NAME_BADGE
)
// --- Main component ---
// @vue/component
export const BBadge = /*#__PURE__*/ defineComponent({
name: NAME_BADGE,
functional: true,
props,
render(h, { props, data, children }) {
const { active, disabled } = props
const link = isLink(props)
const tag = link ? BLink : props.tag
const variant = props.variant || 'secondary'
return h(
tag,
mergeData(data, {
staticClass: 'badge',
class: [
`badge-${variant}`,
{
'badge-pill': props.pill,
active,
disabled
}
],
props: link ? pluckProps(linkProps, props) : {}
}),
children
)
}
})