index.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import _extends from "@babel/runtime/helpers/esm/extends";
  3. import { createVNode as _createVNode } from "vue";
  4. import { flattenChildren } from '../_util/props-util';
  5. import { computed, defineComponent } from 'vue';
  6. import { withInstall } from '../_util/type';
  7. import useConfigInject from '../config-provider/hooks/useConfigInject';
  8. import useStyle from './style';
  9. export const dividerProps = () => ({
  10. prefixCls: String,
  11. type: {
  12. type: String,
  13. default: 'horizontal'
  14. },
  15. dashed: {
  16. type: Boolean,
  17. default: false
  18. },
  19. orientation: {
  20. type: String,
  21. default: 'center'
  22. },
  23. plain: {
  24. type: Boolean,
  25. default: false
  26. },
  27. orientationMargin: [String, Number]
  28. });
  29. const Divider = defineComponent({
  30. name: 'ADivider',
  31. inheritAttrs: false,
  32. compatConfig: {
  33. MODE: 3
  34. },
  35. props: dividerProps(),
  36. setup(props, _ref) {
  37. let {
  38. slots,
  39. attrs
  40. } = _ref;
  41. const {
  42. prefixCls: prefixClsRef,
  43. direction
  44. } = useConfigInject('divider', props);
  45. const [wrapSSR, hashId] = useStyle(prefixClsRef);
  46. const hasCustomMarginLeft = computed(() => props.orientation === 'left' && props.orientationMargin != null);
  47. const hasCustomMarginRight = computed(() => props.orientation === 'right' && props.orientationMargin != null);
  48. const classString = computed(() => {
  49. const {
  50. type,
  51. dashed,
  52. plain
  53. } = props;
  54. const prefixCls = prefixClsRef.value;
  55. return {
  56. [prefixCls]: true,
  57. [hashId.value]: !!hashId.value,
  58. [`${prefixCls}-${type}`]: true,
  59. [`${prefixCls}-dashed`]: !!dashed,
  60. [`${prefixCls}-plain`]: !!plain,
  61. [`${prefixCls}-rtl`]: direction.value === 'rtl',
  62. [`${prefixCls}-no-default-orientation-margin-left`]: hasCustomMarginLeft.value,
  63. [`${prefixCls}-no-default-orientation-margin-right`]: hasCustomMarginRight.value
  64. };
  65. });
  66. const innerStyle = computed(() => {
  67. const marginValue = typeof props.orientationMargin === 'number' ? `${props.orientationMargin}px` : props.orientationMargin;
  68. return _extends(_extends({}, hasCustomMarginLeft.value && {
  69. marginLeft: marginValue
  70. }), hasCustomMarginRight.value && {
  71. marginRight: marginValue
  72. });
  73. });
  74. const orientationPrefix = computed(() => props.orientation.length > 0 ? '-' + props.orientation : props.orientation);
  75. return () => {
  76. var _a;
  77. const children = flattenChildren((_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots));
  78. return wrapSSR(_createVNode("div", _objectSpread(_objectSpread({}, attrs), {}, {
  79. "class": [classString.value, children.length ? `${prefixClsRef.value}-with-text ${prefixClsRef.value}-with-text${orientationPrefix.value}` : '', attrs.class],
  80. "role": "separator"
  81. }), [children.length ? _createVNode("span", {
  82. "class": `${prefixClsRef.value}-inner-text`,
  83. "style": innerStyle.value
  84. }, [children]) : null]));
  85. };
  86. }
  87. });
  88. export default withInstall(Divider);