index.js 3.5 KB

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