1 | "use client";
|
2 |
|
3 | var __rest = this && this.__rest || function (s, e) {
|
4 | var t = {};
|
5 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
6 | if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
7 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
8 | }
|
9 | return t;
|
10 | };
|
11 | import * as React from 'react';
|
12 | import classNames from 'classnames';
|
13 | import { devUseWarning } from '../_util/warning';
|
14 | import { ConfigContext } from '../config-provider';
|
15 | import useStyle from './style';
|
16 | const Divider = props => {
|
17 | const {
|
18 | getPrefixCls,
|
19 | direction,
|
20 | divider
|
21 | } = React.useContext(ConfigContext);
|
22 | const {
|
23 | prefixCls: customizePrefixCls,
|
24 | type = 'horizontal',
|
25 | orientation = 'center',
|
26 | orientationMargin,
|
27 | className,
|
28 | rootClassName,
|
29 | children,
|
30 | dashed,
|
31 | variant = 'solid',
|
32 | plain,
|
33 | style
|
34 | } = props,
|
35 | restProps = __rest(props, ["prefixCls", "type", "orientation", "orientationMargin", "className", "rootClassName", "children", "dashed", "variant", "plain", "style"]);
|
36 | const prefixCls = getPrefixCls('divider', customizePrefixCls);
|
37 | const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);
|
38 | const hasChildren = !!children;
|
39 | const hasCustomMarginLeft = orientation === 'left' && orientationMargin != null;
|
40 | const hasCustomMarginRight = orientation === 'right' && orientationMargin != null;
|
41 | const classString = classNames(prefixCls, divider === null || divider === void 0 ? void 0 : divider.className, hashId, cssVarCls, `${prefixCls}-${type}`, {
|
42 | [`${prefixCls}-with-text`]: hasChildren,
|
43 | [`${prefixCls}-with-text-${orientation}`]: hasChildren,
|
44 | [`${prefixCls}-dashed`]: !!dashed,
|
45 | [`${prefixCls}-${variant}`]: variant !== 'solid',
|
46 | [`${prefixCls}-plain`]: !!plain,
|
47 | [`${prefixCls}-rtl`]: direction === 'rtl',
|
48 | [`${prefixCls}-no-default-orientation-margin-left`]: hasCustomMarginLeft,
|
49 | [`${prefixCls}-no-default-orientation-margin-right`]: hasCustomMarginRight
|
50 | }, className, rootClassName);
|
51 | const memoizedOrientationMargin = React.useMemo(() => {
|
52 | if (typeof orientationMargin === 'number') {
|
53 | return orientationMargin;
|
54 | }
|
55 | if (/^\d+$/.test(orientationMargin)) {
|
56 | return Number(orientationMargin);
|
57 | }
|
58 | return orientationMargin;
|
59 | }, [orientationMargin]);
|
60 | const innerStyle = Object.assign(Object.assign({}, hasCustomMarginLeft && {
|
61 | marginLeft: memoizedOrientationMargin
|
62 | }), hasCustomMarginRight && {
|
63 | marginRight: memoizedOrientationMargin
|
64 | });
|
65 |
|
66 | if (process.env.NODE_ENV !== 'production') {
|
67 | const warning = devUseWarning('Divider');
|
68 | process.env.NODE_ENV !== "production" ? warning(!children || type !== 'vertical', 'usage', '`children` not working in `vertical` mode.') : void 0;
|
69 | }
|
70 | return wrapCSSVar(React.createElement("div", Object.assign({
|
71 | className: classString,
|
72 | style: Object.assign(Object.assign({}, divider === null || divider === void 0 ? void 0 : divider.style), style)
|
73 | }, restProps, {
|
74 |
|
75 | role: "separator"
|
76 | }), children && type !== 'vertical' && (React.createElement("span", {
|
77 | className: `${prefixCls}-inner-text`,
|
78 | style: innerStyle
|
79 | }, children))));
|
80 | };
|
81 | if (process.env.NODE_ENV !== 'production') {
|
82 | Divider.displayName = 'Divider';
|
83 | }
|
84 | export default Divider; |
\ | No newline at end of file |