linkmore-design
Version:
π πlmη»δ»ΆεΊγπ
51 lines (50 loc) β’ 3.1 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["prefixCls", "type", "orientation", "orientationMargin", "className", "children", "dashed", "plain"];
import classNames from 'classnames';
import * as React from 'react';
import { ConfigContext } from "../config-provider";
import warning from "../_util/warning";
var Divider = function Divider(props) {
var _classNames;
var _React$useContext = React.useContext(ConfigContext),
getPrefixCls = _React$useContext.getPrefixCls,
direction = _React$useContext.direction;
var customizePrefixCls = props.prefixCls,
_props$type = props.type,
type = _props$type === void 0 ? 'horizontal' : _props$type,
_props$orientation = props.orientation,
orientation = _props$orientation === void 0 ? 'center' : _props$orientation,
orientationMargin = props.orientationMargin,
className = props.className,
children = props.children,
dashed = props.dashed,
plain = props.plain,
restProps = _objectWithoutProperties(props, _excluded);
var prefixCls = getPrefixCls('divider', customizePrefixCls);
var orientationPrefix = orientation.length > 0 ? "-".concat(orientation) : orientation;
var hasChildren = !!children;
var hasCustomMarginLeft = orientation === 'left' && orientationMargin != null;
var hasCustomMarginRight = orientation === 'right' && orientationMargin != null;
var classString = classNames(prefixCls, "".concat(prefixCls, "-").concat(type), (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-with-text"), hasChildren), _defineProperty(_classNames, "".concat(prefixCls, "-with-text").concat(orientationPrefix), hasChildren), _defineProperty(_classNames, "".concat(prefixCls, "-dashed"), !!dashed), _defineProperty(_classNames, "".concat(prefixCls, "-plain"), !!plain), _defineProperty(_classNames, "".concat(prefixCls, "-rtl"), direction === 'rtl'), _defineProperty(_classNames, "".concat(prefixCls, "-no-default-orientation-margin-left"), hasCustomMarginLeft), _defineProperty(_classNames, "".concat(prefixCls, "-no-default-orientation-margin-right"), hasCustomMarginRight), _classNames), className);
var innerStyle = _objectSpread(_objectSpread({}, hasCustomMarginLeft && {
marginLeft: orientationMargin
}), hasCustomMarginRight && {
marginRight: orientationMargin
});
// Warning children not work in vertical mode
if (process.env.NODE_ENV !== 'production') {
warning(!children || type !== 'vertical', 'Divider', '`children` not working in `vertical` mode.');
}
return /*#__PURE__*/React.createElement("div", _extends({
className: classString
}, restProps, {
role: "separator"
}), children && type !== 'vertical' && /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-inner-text"),
style: innerStyle
}, children));
};
export default Divider;