2017-11-17 14:38:54 +08:00
|
|
|
import * as React from 'react';
|
2017-08-19 12:39:11 +08:00
|
|
|
import classNames from 'classnames';
|
2018-12-05 19:12:18 +08:00
|
|
|
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
|
2017-08-19 12:39:11 +08:00
|
|
|
|
2017-11-21 20:48:22 +08:00
|
|
|
export interface DividerProps {
|
|
|
|
prefixCls?: string;
|
|
|
|
type?: 'horizontal' | 'vertical';
|
2019-06-06 00:39:45 +08:00
|
|
|
orientation?: 'left' | 'right' | 'center';
|
2021-09-19 11:28:45 +08:00
|
|
|
orientationMargin?: string | number;
|
2017-11-21 20:48:22 +08:00
|
|
|
className?: string;
|
|
|
|
children?: React.ReactNode;
|
|
|
|
dashed?: boolean;
|
2017-12-07 23:16:25 +08:00
|
|
|
style?: React.CSSProperties;
|
2020-04-21 14:16:33 +08:00
|
|
|
plain?: boolean;
|
2017-11-21 20:48:22 +08:00
|
|
|
}
|
|
|
|
|
2020-03-28 11:56:57 +08:00
|
|
|
const Divider: React.FC<DividerProps> = props => (
|
2018-12-05 19:12:18 +08:00
|
|
|
<ConfigConsumer>
|
2020-04-29 10:17:37 +08:00
|
|
|
{({ getPrefixCls, direction }: ConfigConsumerProps) => {
|
2018-12-05 19:12:18 +08:00
|
|
|
const {
|
|
|
|
prefixCls: customizePrefixCls,
|
|
|
|
type = 'horizontal',
|
2019-06-06 00:39:45 +08:00
|
|
|
orientation = 'center',
|
2021-09-19 11:28:45 +08:00
|
|
|
orientationMargin,
|
2018-12-05 19:12:18 +08:00
|
|
|
className,
|
|
|
|
children,
|
|
|
|
dashed,
|
2020-04-21 14:16:33 +08:00
|
|
|
plain,
|
2018-12-05 19:12:18 +08:00
|
|
|
...restProps
|
|
|
|
} = props;
|
|
|
|
const prefixCls = getPrefixCls('divider', customizePrefixCls);
|
2019-08-05 18:38:10 +08:00
|
|
|
const orientationPrefix = orientation.length > 0 ? `-${orientation}` : orientation;
|
2020-04-21 14:16:33 +08:00
|
|
|
const hasChildren = !!children;
|
2021-09-19 11:28:45 +08:00
|
|
|
const hasCustomMarginLeft = orientation === 'left' && orientationMargin != null;
|
|
|
|
const hasCustomMarginRight = orientation === 'right' && orientationMargin != null;
|
2020-09-06 13:07:39 +08:00
|
|
|
const classString = classNames(
|
|
|
|
prefixCls,
|
|
|
|
`${prefixCls}-${type}`,
|
|
|
|
{
|
|
|
|
[`${prefixCls}-with-text`]: hasChildren,
|
|
|
|
[`${prefixCls}-with-text${orientationPrefix}`]: hasChildren,
|
|
|
|
[`${prefixCls}-dashed`]: !!dashed,
|
|
|
|
[`${prefixCls}-plain`]: !!plain,
|
|
|
|
[`${prefixCls}-rtl`]: direction === 'rtl',
|
2021-09-19 11:28:45 +08:00
|
|
|
[`${prefixCls}-no-default-orientation-margin-left`]: hasCustomMarginLeft,
|
|
|
|
[`${prefixCls}-no-default-orientation-margin-right`]: hasCustomMarginRight,
|
2020-09-06 13:07:39 +08:00
|
|
|
},
|
|
|
|
className,
|
|
|
|
);
|
2021-09-19 11:28:45 +08:00
|
|
|
|
|
|
|
const innerStyle = {
|
|
|
|
...(hasCustomMarginLeft && { marginLeft: orientationMargin }),
|
|
|
|
...(hasCustomMarginRight && { marginRight: orientationMargin }),
|
|
|
|
};
|
|
|
|
|
2018-12-05 19:12:18 +08:00
|
|
|
return (
|
2019-08-08 12:32:39 +08:00
|
|
|
<div className={classString} {...restProps} role="separator">
|
2021-09-19 11:28:45 +08:00
|
|
|
{children && (
|
|
|
|
<span className={`${prefixCls}-inner-text`} style={innerStyle}>
|
|
|
|
{children}
|
|
|
|
</span>
|
|
|
|
)}
|
2018-12-05 19:12:18 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</ConfigConsumer>
|
|
|
|
);
|
|
|
|
|
|
|
|
export default Divider;
|