list-group-item.js
3.46 KB
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
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
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 ---
var actionTags = ['a', 'router-link', 'button', 'b-link']; // --- Props ---
var linkProps = omit(BLinkProps, ['event', 'routerTag']);
delete linkProps.href.default;
delete linkProps.to.default;
export var props = makePropsConfigurable(sortKeys(_objectSpread(_objectSpread({}, 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 var BListGroupItem = /*#__PURE__*/extend({
name: NAME_LIST_GROUP_ITEM,
functional: true,
props: props,
render: function render(h, _ref) {
var _class;
var props = _ref.props,
data = _ref.data,
children = _ref.children;
var button = props.button,
variant = props.variant,
active = props.active,
disabled = props.disabled;
var link = isLink(props);
var tag = button ? 'button' : !link ? props.tag : BLink;
var action = !!(props.action || link || button || arrayIncludes(actionTags, props.tag));
var attrs = {};
var 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: attrs,
props: itemProps,
staticClass: 'list-group-item',
class: (_class = {}, _defineProperty(_class, "list-group-item-".concat(variant), variant), _defineProperty(_class, 'list-group-item-action', action), _defineProperty(_class, "active", active), _defineProperty(_class, "disabled", disabled), _class)
}), children);
}
});