ant-design/components/divider/index.tsx

43 lines
1.3 KiB
TypeScript
Raw Normal View History

import * as React from 'react';
import classNames from 'classnames';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
2017-11-21 20:48:22 +08:00
export interface DividerProps {
prefixCls?: string;
type?: 'horizontal' | 'vertical';
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
}
const Divider: React.SFC<DividerProps> = props => (
<ConfigConsumer>
{({ getPrefixCls }: ConfigConsumerProps) => {
const {
prefixCls: customizePrefixCls,
type = 'horizontal',
orientation = 'center',
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}`, {
[`${prefixCls}-with-text${orientationPrefix}`]: children,
[`${prefixCls}-dashed`]: !!dashed,
});
return (
<div className={classString} {...restProps} role="separator">
{children && <span className={`${prefixCls}-inner-text`}>{children}</span>}
</div>
);
}}
</ConfigConsumer>
);
export default Divider;