mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-06 05:58:46 +08:00
4db1fc1a20
* refactor: change divider into cssinjs * fix: token and logical css * fix: token to margin * fix: token add marginLG 24px margin * 1.5 = 16 * 1.5 * fix: comment the _style less * fix: move file * fix: add px for marginNumber * fix: borderwidth * fix: delete test css * fix: add comment fixme * fix: add dividerNotDefaultTextPadding token to divider * fix: add prefixCls to fix the inner classname * fix: delete useless code * fix: delete withPrefix * fix: delete import * fix: wrapper with prefixCls Co-authored-by: zengguhao.zgh <zengguhao.zgh@alibaba-inc.com>
73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
import * as React from 'react';
|
|
import classNames from 'classnames';
|
|
import { ConfigContext } from '../config-provider';
|
|
|
|
import useStyle from './style';
|
|
|
|
export interface DividerProps {
|
|
prefixCls?: string;
|
|
type?: 'horizontal' | 'vertical';
|
|
orientation?: 'left' | 'right' | 'center';
|
|
orientationMargin?: string | number;
|
|
className?: string;
|
|
children?: React.ReactNode;
|
|
dashed?: boolean;
|
|
style?: React.CSSProperties;
|
|
plain?: boolean;
|
|
}
|
|
|
|
const Divider: React.FC<DividerProps> = props => {
|
|
const { getPrefixCls, direction } = React.useContext(ConfigContext);
|
|
|
|
const {
|
|
prefixCls: customizePrefixCls,
|
|
type = 'horizontal',
|
|
orientation = 'center',
|
|
orientationMargin,
|
|
className,
|
|
children,
|
|
dashed,
|
|
plain,
|
|
...restProps
|
|
} = props;
|
|
const prefixCls = getPrefixCls('divider', customizePrefixCls);
|
|
const [wrapSSR, hashId] = useStyle(prefixCls);
|
|
|
|
const orientationPrefix = orientation.length > 0 ? `-${orientation}` : orientation;
|
|
const hasChildren = !!children;
|
|
const hasCustomMarginLeft = orientation === 'left' && orientationMargin != null;
|
|
const hasCustomMarginRight = orientation === 'right' && orientationMargin != null;
|
|
const classString = classNames(
|
|
prefixCls,
|
|
hashId,
|
|
`${prefixCls}-${type}`,
|
|
{
|
|
[`${prefixCls}-with-text`]: hasChildren,
|
|
[`${prefixCls}-with-text${orientationPrefix}`]: hasChildren,
|
|
[`${prefixCls}-dashed`]: !!dashed,
|
|
[`${prefixCls}-plain`]: !!plain,
|
|
[`${prefixCls}-rtl`]: direction === 'rtl',
|
|
[`${prefixCls}-no-default-orientation-margin-left`]: hasCustomMarginLeft,
|
|
[`${prefixCls}-no-default-orientation-margin-right`]: hasCustomMarginRight,
|
|
},
|
|
className,
|
|
);
|
|
|
|
const innerStyle = {
|
|
...(hasCustomMarginLeft && { marginLeft: orientationMargin }),
|
|
...(hasCustomMarginRight && { marginRight: orientationMargin }),
|
|
};
|
|
|
|
return wrapSSR(
|
|
<div className={classString} {...restProps} role="separator">
|
|
{children && (
|
|
<span className={`${prefixCls}-inner-text`} style={innerStyle}>
|
|
{children}
|
|
</span>
|
|
)}
|
|
</div>,
|
|
);
|
|
};
|
|
|
|
export default Divider;
|