vue-admin-core
Version:
A Component Library for Vue 3
78 lines (75 loc) • 2.43 kB
JavaScript
import { defineComponent, h } from 'vue';
import '../../__builtins__/index.mjs';
import '../../form-layout/index.mjs';
import { buildProps } from 'element-plus/es/utils/index';
import { useFormLayout } from '../../form-layout/src/index.mjs';
import { stylePrefix } from '../../__builtins__/configs/index.mjs';
const spaceProps = buildProps({
size: {
type: [String, Number]
},
direction: {
type: String
},
align: {
type: String
}
});
const spaceSize = {
small: 8,
middle: 16,
large: 24
};
const Space = defineComponent({
name: "FSpace",
props: spaceProps,
setup(props, { slots }) {
const layout = useFormLayout();
return () => {
var _a, _b, _c, _d, _e;
const { align, size = (_b = (_a = layout.value) == null ? void 0 : _a.spaceGap) != null ? _b : "small", direction = "horizontal" } = props;
const prefixCls = `${stylePrefix}-space`;
const children = (_c = slots.default) == null ? void 0 : _c.call(slots);
let items = [];
if (Array.isArray(children)) {
if (children.length === 1) {
if ((_d = children[0]["tag"]) == null ? void 0 : _d.endsWith("Fragment")) {
items = (_e = children[0]["componentOptions"]) == null ? void 0 : _e.children;
} else {
items = children;
}
} else {
items = children;
}
}
const len = items.length;
if (len === 0) {
return null;
}
const mergedAlign = align === void 0 && direction === "horizontal" ? "center" : align;
const marginDirection = "marginRight";
const someSpaceClass = {
[prefixCls]: true,
[`${prefixCls}-${direction}`]: true,
[`${prefixCls}-align-${mergedAlign}`]: mergedAlign
};
const itemClassName = `${prefixCls}-item`;
const renderItems = items.map(
(child, i) => h(
"div",
{
class: itemClassName,
key: `${itemClassName}-${i}`,
style: i === len - 1 ? {} : {
[direction === "vertical" ? "marginBottom" : marginDirection]: typeof size === "string" ? `${spaceSize[size]}px` : `${size}px`
}
},
{ default: () => [child] }
)
);
return h("div", { class: someSpaceClass }, { default: () => renderItems });
};
}
});
export { Space, Space as default, spaceProps };
//# sourceMappingURL=index.mjs.map