birdpaper-ui
Version:
一个通用的 vue3 UI组件库。A common vue3 UI component library.
63 lines (62 loc) • 1.88 kB
JavaScript
;
const vue = require("vue");
const dom = require("../../utils/dom.js");
const util = require("../../utils/util.js");
const _space = /* @__PURE__ */ vue.defineComponent({
name: "Space",
props: {
/** 间距大小 */
size: {
type: [Number, String],
default: "normal"
},
/** 布局类型 */
type: {
type: String,
default: "horizontal"
},
/** 水平对齐方式 */
justify: {
type: String,
default: "flex-start"
},
/** 垂直对齐方式 */
align: {
type: String,
default: "flex-start"
}
},
setup(props, {
slots
}) {
const typeMap = {
mini: 4,
small: 8,
normal: 10,
large: 24
};
const size = util.isString(props.size) ? typeMap[props.size] : props.size;
const render = () => {
var _a;
const children = dom.getAllElements((_a = slots.default) == null ? void 0 : _a.call(slots), true).filter((item) => item.type !== vue.Comment);
return vue.createVNode("div", {
"class": ["bp-space", `bp-space-${props.type}`],
"style": `justify-content:${props.justify};align-items:${props.align}`
}, [children.map((child, index) => {
var _a2;
const hasSplit = slots.split && index > 0;
return vue.createVNode(vue.Fragment, {
"key": child.key ?? `item-${index}`
}, [hasSplit && vue.createVNode("div", {
"class": "bp-space-item",
"style": props.type === "horizontal" ? `margin: 0 ${size}px` : `margin: ${size}px 0`
}, [(_a2 = slots.split) == null ? void 0 : _a2.call(slots)]), vue.createVNode("div", {
"class": "bp-space-item",
"style": props.type === "horizontal" ? `margin: 0 ${size}px` : `margin: ${size}px 0`
}, [child])]);
})]);
};
return render;
}
});
module.exports = _space;