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';
2018-08-01 15:43:47 +08:00
orientation?: 'left' | 'right' | '';
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 = '',
className,
children,
dashed,
...restProps
} = props;
const prefixCls = getPrefixCls('divider', customizePrefixCls);
2018-12-07 20:02:01 +08:00
const orientationPrefix = orientation.length > 0 ? '-' + orientation : orientation;
const classString = classNames(className, prefixCls, `${prefixCls}-${type}`, {
[`${prefixCls}-with-text${orientationPrefix}`]: children,
[`${prefixCls}-dashed`]: !!dashed,
});
return (
<div className={classString} {...restProps}>
{children && <span className={`${prefixCls}-inner-text`}>{children}</span>}
</div>
);
}}
</ConfigConsumer>
);
export default Divider;