mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-12 23:35:38 +08:00
bf45c4c1b0
close #26594
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import * as React from 'react';
|
|
import classNames from 'classnames';
|
|
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
|
|
|
|
export interface DividerProps {
|
|
prefixCls?: string;
|
|
type?: 'horizontal' | 'vertical';
|
|
orientation?: 'left' | 'right' | 'center';
|
|
className?: string;
|
|
children?: React.ReactNode;
|
|
dashed?: boolean;
|
|
style?: React.CSSProperties;
|
|
plain?: boolean;
|
|
}
|
|
|
|
const Divider: React.FC<DividerProps> = props => (
|
|
<ConfigConsumer>
|
|
{({ getPrefixCls, direction }: ConfigConsumerProps) => {
|
|
const {
|
|
prefixCls: customizePrefixCls,
|
|
type = 'horizontal',
|
|
orientation = 'center',
|
|
className,
|
|
children,
|
|
dashed,
|
|
plain,
|
|
...restProps
|
|
} = props;
|
|
const prefixCls = getPrefixCls('divider', customizePrefixCls);
|
|
const orientationPrefix = orientation.length > 0 ? `-${orientation}` : orientation;
|
|
const hasChildren = !!children;
|
|
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',
|
|
},
|
|
className,
|
|
);
|
|
return (
|
|
<div className={classString} {...restProps} role="separator">
|
|
{children && <span className={`${prefixCls}-inner-text`}>{children}</span>}
|
|
</div>
|
|
);
|
|
}}
|
|
</ConfigConsumer>
|
|
);
|
|
|
|
export default Divider;
|