UNPKG

ant-design-vue

Version:

An enterprise-class UI design language and Vue-based implementation

65 lines (58 loc) 2.77 kB
import { createVNode as _createVNode } from "vue"; 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 { inject, defineComponent } from 'vue'; import PropTypes from '../_util/vue-types'; import { filterEmpty } from '../_util/props-util'; import { defaultConfigProvider } from '../config-provider'; import { tuple, withInstall } from '../_util/type'; var spaceSize = { small: 8, middle: 16, large: 24 }; var Space = defineComponent({ name: 'ASpace', props: { prefixCls: PropTypes.string, size: { type: [String, Number] }, direction: PropTypes.oneOf(tuple('horizontal', 'vertical')), align: PropTypes.oneOf(tuple('start', 'end', 'center', 'baseline')) }, setup: function setup(props, _ref) { var slots = _ref.slots; var configProvider = inject('configProvider', defaultConfigProvider); return function () { var _someSpaceClass; var _a; var align = props.align, _props$size = props.size, size = _props$size === void 0 ? 'small' : _props$size, _props$direction = props.direction, direction = _props$direction === void 0 ? 'horizontal' : _props$direction, customizePrefixCls = props.prefixCls; var getPrefixCls = configProvider.getPrefixCls; var prefixCls = getPrefixCls('space', customizePrefixCls); var items = filterEmpty((_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)); var len = items.length; if (len === 0) { return null; } var mergedAlign = align === undefined && direction === 'horizontal' ? 'center' : align; var someSpaceClass = (_someSpaceClass = {}, _defineProperty(_someSpaceClass, prefixCls, true), _defineProperty(_someSpaceClass, "".concat(prefixCls, "-").concat(direction), true), _defineProperty(_someSpaceClass, "".concat(prefixCls, "-align-").concat(mergedAlign), mergedAlign), _someSpaceClass); var itemClassName = "".concat(prefixCls, "-item"); var marginDirection = 'marginRight'; // directionConfig === 'rtl' ? 'marginLeft' : 'marginRight'; return _createVNode("div", { "class": someSpaceClass }, [items.map(function (child, i) { return _createVNode("div", { "class": itemClassName, "key": "".concat(itemClassName, "-").concat(i), "style": i === len - 1 ? {} : _defineProperty({}, direction === 'vertical' ? 'marginBottom' : marginDirection, typeof size === 'string' ? "".concat(spaceSize[size], "px") : "".concat(size, "px")) }, [child]); })]); }; } }); export default withInstall(Space);