custom-bootstrap-vue
Version:
Custom version of bootstrap-vue created for providing specific theme to a particular project
87 lines (77 loc) • 2.15 kB
JavaScript
import { mergeData } from 'vue-functional-data-merge'
import Vue from '../../utils/vue'
import { arrayIncludes } from '../../utils/array'
import { getComponentConfig } from '../../utils/config'
import { isTag } from '../../utils/dom'
import { omit } from '../../utils/object'
import { pluckProps } from '../../utils/props'
import { isLink } from '../../utils/router'
import { BLink, props as BLinkProps } from '../link/link'
// --- Constants ---
const NAME = 'BListGroupItem'
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 = {
tag: {
type: String,
default: 'div'
},
action: {
type: Boolean,
default: null
},
button: {
type: Boolean,
default: null
},
variant: {
type: String,
default: () => getComponentConfig(NAME, 'variant')
},
...linkProps
}
// --- Main component ---
// @vue/component
export const BListGroupItem = /*#__PURE__*/ Vue.extend({
name: NAME,
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
)
}
})