index.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
  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 '../_util/hooks/useConfigInject';
  8. export var dividerProps = function dividerProps() {
  9. return {
  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. };
  30. var Divider = defineComponent({
  31. compatConfig: {
  32. MODE: 3
  33. },
  34. name: 'ADivider',
  35. props: dividerProps(),
  36. setup: function setup(props, _ref) {
  37. var slots = _ref.slots;
  38. var _useConfigInject = useConfigInject('divider', props),
  39. prefixClsRef = _useConfigInject.prefixCls,
  40. direction = _useConfigInject.direction;
  41. var hasCustomMarginLeft = computed(function () {
  42. return props.orientation === 'left' && props.orientationMargin != null;
  43. });
  44. var hasCustomMarginRight = computed(function () {
  45. return props.orientation === 'right' && props.orientationMargin != null;
  46. });
  47. var classString = computed(function () {
  48. var _ref2;
  49. var type = props.type,
  50. dashed = props.dashed,
  51. plain = props.plain;
  52. var prefixCls = prefixClsRef.value;
  53. return _ref2 = {}, _defineProperty(_ref2, prefixCls, true), _defineProperty(_ref2, "".concat(prefixCls, "-").concat(type), true), _defineProperty(_ref2, "".concat(prefixCls, "-dashed"), !!dashed), _defineProperty(_ref2, "".concat(prefixCls, "-plain"), !!plain), _defineProperty(_ref2, "".concat(prefixCls, "-rtl"), direction.value === 'rtl'), _defineProperty(_ref2, "".concat(prefixCls, "-no-default-orientation-margin-left"), hasCustomMarginLeft.value), _defineProperty(_ref2, "".concat(prefixCls, "-no-default-orientation-margin-right"), hasCustomMarginRight.value), _ref2;
  54. });
  55. var innerStyle = computed(function () {
  56. var marginValue = typeof props.orientationMargin === 'number' ? "".concat(props.orientationMargin, "px") : props.orientationMargin;
  57. return _objectSpread(_objectSpread({}, hasCustomMarginLeft.value && {
  58. marginLeft: marginValue
  59. }), hasCustomMarginRight.value && {
  60. marginRight: marginValue
  61. });
  62. });
  63. var orientationPrefix = computed(function () {
  64. return props.orientation.length > 0 ? '-' + props.orientation : props.orientation;
  65. });
  66. return function () {
  67. var _slots$default;
  68. var children = flattenChildren((_slots$default = slots.default) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots));
  69. return _createVNode("div", {
  70. "class": [classString.value, children.length ? "".concat(prefixClsRef.value, "-with-text ").concat(prefixClsRef.value, "-with-text").concat(orientationPrefix.value) : ''],
  71. "role": "separator"
  72. }, [children.length ? _createVNode("span", {
  73. "class": "".concat(prefixClsRef.value, "-inner-text"),
  74. "style": innerStyle.value
  75. }, [children]) : null]);
  76. };
  77. }
  78. });
  79. export default withInstall(Divider);