bootstrap-view
Version:
With more than 85 components, over 45 available plugins, several directives, and 1000+ icons, BootstrapVue provides one of the most comprehensive implementations of the Bootstrap v4 component and grid system available for Vue.js v2.6, complete with extens
114 lines (108 loc) • 6.17 kB
JavaScript
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { extend, mergeData } from '../../vue';
import { NAME_CARD } from '../../constants/components';
import { PROP_TYPE_BOOLEAN, PROP_TYPE_STRING } from '../../constants/props';
import { SLOT_NAME_DEFAULT, SLOT_NAME_FOOTER, SLOT_NAME_HEADER } from '../../constants/slots';
import { htmlOrText } from '../../utils/html';
import { hasNormalizedSlot, normalizeSlot } from '../../utils/normalize-slot';
import { sortKeys } from '../../utils/object';
import { copyProps, makeProp, makePropsConfigurable, pluckProps, prefixPropName, unprefixPropName } from '../../utils/props';
import { props as cardProps } from '../../mixins/card';
import { BCardBody, props as BCardBodyProps } from './card-body';
import { BCardHeader, props as BCardHeaderProps } from './card-header';
import { BCardFooter, props as BCardFooterProps } from './card-footer';
import { BCardImg, props as BCardImgProps } from './card-img';
// --- Props ---
var cardImgProps = copyProps(BCardImgProps, prefixPropName.bind(null, 'img'));
cardImgProps.imgSrc.required = false;
export var props = makePropsConfigurable(sortKeys(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, BCardBodyProps), BCardHeaderProps), BCardFooterProps), cardImgProps), cardProps), {}, {
align: makeProp(PROP_TYPE_STRING),
noBody: makeProp(PROP_TYPE_BOOLEAN, false)
})), NAME_CARD);
// --- Main component ---
// @vue/component
export var BCard = /*#__PURE__*/extend({
name: NAME_CARD,
functional: true,
props: props,
render: function render(h, _ref) {
var props = _ref.props,
data = _ref.data,
slots = _ref.slots,
scopedSlots = _ref.scopedSlots;
var imgSrc = props.imgSrc,
imgLeft = props.imgLeft,
imgRight = props.imgRight,
imgStart = props.imgStart,
imgEnd = props.imgEnd,
imgBottom = props.imgBottom,
header = props.header,
headerHtml = props.headerHtml,
footer = props.footer,
footerHtml = props.footerHtml,
align = props.align,
textVariant = props.textVariant,
bgVariant = props.bgVariant,
borderVariant = props.borderVariant;
var $scopedSlots = scopedSlots || {};
var $slots = slots();
var slotScope = {};
var $imgFirst = h();
var $imgLast = h();
if (imgSrc) {
var $img = h(BCardImg, {
props: pluckProps(cardImgProps, props, unprefixPropName.bind(null, 'img'))
});
if (imgBottom) {
$imgLast = $img;
} else {
$imgFirst = $img;
}
}
var $header = h();
var hasHeaderSlot = hasNormalizedSlot(SLOT_NAME_HEADER, $scopedSlots, $slots);
if (hasHeaderSlot || header || headerHtml) {
$header = h(BCardHeader, {
props: pluckProps(BCardHeaderProps, props),
domProps: hasHeaderSlot ? {} : htmlOrText(headerHtml, header)
}, normalizeSlot(SLOT_NAME_HEADER, slotScope, $scopedSlots, $slots));
}
var $content = normalizeSlot(SLOT_NAME_DEFAULT, slotScope, $scopedSlots, $slots);
// Wrap content in `<card-body>` when `noBody` prop set
if (!props.noBody) {
$content = h(BCardBody, {
props: pluckProps(BCardBodyProps, props)
}, $content);
// When the `overlap` prop is set we need to wrap the `<b-card-img>` and `<b-card-body>`
// into a relative positioned wrapper to don't distract a potential header or footer
if (props.overlay && imgSrc) {
$content = h('div', {
staticClass: 'position-relative'
}, [$imgFirst, $content, $imgLast]);
// Reset image variables since they are already in the wrapper
$imgFirst = h();
$imgLast = h();
}
}
var $footer = h();
var hasFooterSlot = hasNormalizedSlot(SLOT_NAME_FOOTER, $scopedSlots, $slots);
if (hasFooterSlot || footer || footerHtml) {
$footer = h(BCardFooter, {
props: pluckProps(BCardFooterProps, props),
domProps: hasHeaderSlot ? {} : htmlOrText(footerHtml, footer)
}, normalizeSlot(SLOT_NAME_FOOTER, slotScope, $scopedSlots, $slots));
}
return h(props.tag, mergeData(data, {
staticClass: 'card',
class: _defineProperty(_defineProperty(_defineProperty(_defineProperty({
'flex-row': imgLeft || imgStart,
'flex-row-reverse': (imgRight || imgEnd) && !(imgLeft || imgStart)
}, "text-".concat(align), align), "bg-".concat(bgVariant), bgVariant), "border-".concat(borderVariant), borderVariant), "text-".concat(textVariant), textVariant)
}), [$imgFirst, $header, $content, $footer, $imgLast]);
}
});