bootstrap-vue
Version:
BootstrapVue, with over 40 plugins and more than 75 custom components, provides one of the most comprehensive implementations of Bootstrap v4 components and grid system for Vue.js. With extensive and automated WAI-ARIA accessibility markup.
162 lines (141 loc) • 4.29 kB
JavaScript
;
exports.__esModule = true;
exports.default = exports.BImg = exports.props = void 0;
var _vue = _interopRequireDefault(require("../../utils/vue"));
var _vueFunctionalDataMerge = require("vue-functional-data-merge");
var _config = require("../../utils/config");
var _inspect = require("../../utils/inspect");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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; }
// --- Constants --
var NAME = 'BImg'; // Blank image with fill template
var BLANK_TEMPLATE = '<svg width="%{w}" height="%{h}" ' + 'xmlns="http://www.w3.org/2000/svg" ' + 'viewBox="0 0 %{w} %{h}" preserveAspectRatio="none">' + '<rect width="100%" height="100%" style="fill:%{f};"></rect>' + '</svg>';
var props = {
src: {
type: String,
default: null
},
alt: {
type: String,
default: null
},
width: {
type: [Number, String],
default: null
},
height: {
type: [Number, String],
default: null
},
block: {
type: Boolean,
default: false
},
fluid: {
type: Boolean,
default: false
},
fluidGrow: {
// Gives fluid images class `w-100` to make them grow to fit container
type: Boolean,
default: false
},
rounded: {
// rounded can be:
// false: no rounding of corners
// true: slightly rounded corners
// 'top': top corners rounded
// 'right': right corners rounded
// 'bottom': bottom corners rounded
// 'left': left corners rounded
// 'circle': circle/oval
// '0': force rounding off
type: [Boolean, String],
default: false
},
thumbnail: {
type: Boolean,
default: false
},
left: {
type: Boolean,
default: false
},
right: {
type: Boolean,
default: false
},
center: {
type: Boolean,
default: false
},
blank: {
type: Boolean,
default: false
},
blankColor: {
type: String,
default: function _default() {
return (0, _config.getComponentConfig)(NAME, 'blankColor');
}
} // --- Helper methods ---
};
exports.props = props;
function makeBlankImgSrc(width, height, color) {
var src = encodeURIComponent(BLANK_TEMPLATE.replace('%{w}', String(width)).replace('%{h}', String(height)).replace('%{f}', color));
return "data:image/svg+xml;charset=UTF-8,".concat(src);
} // @vue/component
var BImg =
/*#__PURE__*/
_vue.default.extend({
name: NAME,
functional: true,
props: props,
render: function render(h, _ref) {
var _class;
var props = _ref.props,
data = _ref.data;
var src = props.src;
var width = parseInt(props.width, 10) ? parseInt(props.width, 10) : null;
var height = parseInt(props.height, 10) ? parseInt(props.height, 10) : null;
var align = null;
var block = props.block;
if (props.blank) {
if (!height && Boolean(width)) {
height = width;
} else if (!width && Boolean(height)) {
width = height;
}
if (!width && !height) {
width = 1;
height = 1;
} // Make a blank SVG image
src = makeBlankImgSrc(width, height, props.blankColor || 'transparent');
}
if (props.left) {
align = 'float-left';
} else if (props.right) {
align = 'float-right';
} else if (props.center) {
align = 'mx-auto';
block = true;
}
return h('img', (0, _vueFunctionalDataMerge.mergeData)(data, {
attrs: {
src: src,
alt: props.alt,
width: width ? String(width) : null,
height: height ? String(height) : null
},
class: (_class = {
'img-thumbnail': props.thumbnail,
'img-fluid': props.fluid || props.fluidGrow,
'w-100': props.fluidGrow,
rounded: props.rounded === '' || props.rounded === true
}, _defineProperty(_class, "rounded-".concat(props.rounded), (0, _inspect.isString)(props.rounded) && props.rounded !== ''), _defineProperty(_class, align, Boolean(align)), _defineProperty(_class, 'd-block', block), _class)
}));
}
});
exports.BImg = BImg;
var _default2 = BImg;
exports.default = _default2;