Blame view

node_modules/bootstrap-vue/src/components/list-group/list-group-item.js 2.16 KB
4cd4fd28   郭伟龙   feat: 初始化项目
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { extend, mergeData } from '../../vue'
import { NAME_LIST_GROUP_ITEM } from '../../constants/components'
import { PROP_TYPE_BOOLEAN, PROP_TYPE_STRING } from '../../constants/props'
import { arrayIncludes } from '../../utils/array'
import { isTag } from '../../utils/dom'
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'

// --- Constants ---

const actionTags = ['a', 'router-link', 'button', 'b-link']

// --- Props ---

const linkProps = omit(BLinkProps, ['event', 'routerTag'])
delete linkProps.href.default
delete linkProps.to.default

export const props = makePropsConfigurable(
  sortKeys({
    ...linkProps,
    action: makeProp(PROP_TYPE_BOOLEAN, false),
    button: makeProp(PROP_TYPE_BOOLEAN, false),
    tag: makeProp(PROP_TYPE_STRING, 'div'),
    variant: makeProp(PROP_TYPE_STRING)
  }),
  NAME_LIST_GROUP_ITEM
)

// --- Main component ---

// @vue/component
export const BListGroupItem = /*#__PURE__*/ extend({
  name: NAME_LIST_GROUP_ITEM,
  functional: true,
  props,
  render(h, { props, data, children }) {
    const { button, variant, active, disabled } = props
    const link = isLink(props)
    const tag = button ? 'button' : !link ? props.tag : BLink
    const action = !!(props.action || link || button || arrayIncludes(actionTags, props.tag))

    const attrs = {}
    let itemProps = {}
    if (isTag(tag, 'button')) {
      if (!data.attrs || !data.attrs.type) {
        // Add a type for button is one not provided in passed attributes
        attrs.type = 'button'
      }
      if (props.disabled) {
        // Set disabled attribute if button and disabled
        attrs.disabled = true
      }
    } else {
      itemProps = pluckProps(linkProps, props)
    }

    return h(
      tag,
      mergeData(data, {
        attrs,
        props: itemProps,
        staticClass: 'list-group-item',
        class: {
          [`list-group-item-${variant}`]: variant,
          'list-group-item-action': action,
          active,
          disabled
        }
      }),
      children
    )
  }
})