index.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import _mergeJSXProps from 'babel-helper-vue-jsx-merge-props';
  2. import _defineProperty from 'babel-runtime/helpers/defineProperty';
  3. import PropTypes from '../_util/vue-types';
  4. import { filterEmpty, initDefaultProps } from '../_util/props-util';
  5. import { ConfigConsumerProps } from '../config-provider/configConsumerProps';
  6. export var SpaceSizeType = PropTypes.oneOfType([PropTypes.number, PropTypes.oneOf(['small', 'middle', 'large'])]);
  7. var spaceSize = {
  8. small: 8,
  9. middle: 16,
  10. large: 24
  11. };
  12. export var SpaceProps = {
  13. prefixCls: PropTypes.string,
  14. size: SpaceSizeType,
  15. direction: PropTypes.oneOf(['horizontal', 'vertical']),
  16. align: PropTypes.oneOf(['start', 'end', 'center', 'baseline'])
  17. };
  18. var Space = {
  19. functional: true,
  20. name: 'ASpace',
  21. props: initDefaultProps(SpaceProps, {
  22. size: 'small',
  23. direction: 'horizontal'
  24. }),
  25. inject: {
  26. configProvider: { 'default': function _default() {
  27. return ConfigConsumerProps;
  28. } }
  29. },
  30. render: function render(h, content) {
  31. var _ref;
  32. var customizePrefixCls = content.prefixCls,
  33. configProvider = content.injections.configProvider,
  34. children = content.children;
  35. var _content$props = content.props,
  36. align = _content$props.align,
  37. size = _content$props.size,
  38. direction = _content$props.direction;
  39. var getPrefixCls = configProvider.getPrefixCls;
  40. var prefixCls = getPrefixCls('space', customizePrefixCls);
  41. var items = filterEmpty(children);
  42. var len = items.length;
  43. if (len === 0) {
  44. return null;
  45. }
  46. var mergedAlign = align === undefined && direction === 'horizontal' ? 'center' : align;
  47. var someSpaceClass = [(_ref = {}, _defineProperty(_ref, prefixCls, true), _defineProperty(_ref, prefixCls + '-' + direction, true), _defineProperty(_ref, prefixCls + '-align-' + mergedAlign, mergedAlign), _ref)];
  48. if (content.data['class']) {
  49. someSpaceClass.push(content.data['class']);
  50. }
  51. var itemClassName = prefixCls + '-item';
  52. var marginDirection = 'marginRight'; // directionConfig === 'rtl' ? 'marginLeft' : 'marginRight';
  53. return h(
  54. 'div',
  55. _mergeJSXProps([content.data, { 'class': someSpaceClass }]),
  56. [items.map(function (child, i) {
  57. return h(
  58. 'div',
  59. {
  60. 'class': itemClassName,
  61. key: itemClassName + '-' + i,
  62. style: i === len - 1 ? {} : _defineProperty({}, direction === 'vertical' ? 'marginBottom' : marginDirection, typeof size === 'string' ? spaceSize[size] + 'px' : size + 'px')
  63. },
  64. [child]
  65. );
  66. })]
  67. );
  68. }
  69. };
  70. /* istanbul ignore next */
  71. Space.install = function (Vue) {
  72. Vue.component(Space.name, Space);
  73. };
  74. export default Space;