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';
|
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;
|
2017-11-21 20:48:22 +08:00
|
|
|
}
|
|
|
|
|
2018-12-05 19:12:18 +08:00
|
|
|
const Divider: React.SFC<DividerProps> = props => (
|
|
|
|
<ConfigConsumer>
|
|
|
|
{({ getPrefixCls }: ConfigConsumerProps) => {
|
|
|
|
const {
|
|
|
|
prefixCls: customizePrefixCls,
|
|
|
|
type = 'horizontal',
|
2019-06-06 00:39:45 +08:00
|
|
|
orientation = 'center',
|
2018-12-05 19:12:18 +08:00
|
|
|
className,
|
|
|
|
children,
|
|
|
|
dashed,
|
|
|
|
...restProps
|
|
|
|
} = props;
|
|
|
|
const prefixCls = getPrefixCls('divider', customizePrefixCls);
|
2019-08-05 18:38:10 +08:00
|
|
|
const orientationPrefix = orientation.length > 0 ? `-${orientation}` : orientation;
|
2018-12-07 20:02:01 +08:00
|
|
|
const classString = classNames(className, prefixCls, `${prefixCls}-${type}`, {
|
2018-12-05 19:12:18 +08:00
|
|
|
[`${prefixCls}-with-text${orientationPrefix}`]: children,
|
|
|
|
[`${prefixCls}-dashed`]: !!dashed,
|
|
|
|
});
|
|
|
|
return (
|
2019-08-08 12:32:39 +08:00
|
|
|
<div className={classString} {...restProps} role="separator">
|
2018-12-05 19:12:18 +08:00
|
|
|
{children && <span className={`${prefixCls}-inner-text`}>{children}</span>}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</ConfigConsumer>
|
|
|
|
);
|
|
|
|
|
|
|
|
export default Divider;
|