2022-05-09 22:20:07 +08:00
|
|
|
import type { CSSObject } from '@ant-design/cssinjs';
|
2022-11-23 20:22:38 +08:00
|
|
|
import type { FullToken, GenerateStyle } from '../../theme/internal';
|
|
|
|
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
|
2022-07-11 15:35:58 +08:00
|
|
|
import { resetComponent } from '../../style';
|
2022-03-10 13:59:49 +08:00
|
|
|
|
2022-03-25 17:54:57 +08:00
|
|
|
/** Component only token. Which will handle additional calculation of alias token */
|
|
|
|
export interface ComponentToken {
|
|
|
|
sizePaddingEdgeHorizontal: number;
|
|
|
|
}
|
2022-03-10 13:59:49 +08:00
|
|
|
|
2022-04-07 14:53:33 +08:00
|
|
|
interface DividerToken extends FullToken<'Divider'> {
|
2022-03-10 13:59:49 +08:00
|
|
|
dividerVerticalGutterMargin: number;
|
|
|
|
dividerHorizontalWithTextGutterMargin: number;
|
|
|
|
dividerHorizontalGutterMargin: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============================== Shared ==============================
|
2022-03-11 14:29:29 +08:00
|
|
|
const genSharedDividerStyle: GenerateStyle<DividerToken> = (token): CSSObject => {
|
2022-11-01 15:06:38 +08:00
|
|
|
const { componentCls, sizePaddingEdgeHorizontal, colorSplit, lineWidth } = token;
|
2022-03-10 13:59:49 +08:00
|
|
|
|
2022-03-11 14:29:29 +08:00
|
|
|
return {
|
2022-04-07 14:53:33 +08:00
|
|
|
[componentCls]: {
|
2022-03-11 14:29:29 +08:00
|
|
|
...resetComponent(token),
|
2022-11-01 15:06:38 +08:00
|
|
|
borderBlockStart: `${lineWidth}px solid ${colorSplit}`,
|
2022-03-10 13:59:49 +08:00
|
|
|
|
2022-03-11 14:29:29 +08:00
|
|
|
// vertical
|
|
|
|
'&-vertical': {
|
2022-03-10 13:59:49 +08:00
|
|
|
position: 'relative',
|
2022-03-11 14:29:29 +08:00
|
|
|
top: '-0.06em',
|
|
|
|
display: 'inline-block',
|
|
|
|
height: '0.9em',
|
|
|
|
margin: `0 ${token.dividerVerticalGutterMargin}px`,
|
|
|
|
verticalAlign: 'middle',
|
|
|
|
borderTop: 0,
|
2022-11-01 15:06:38 +08:00
|
|
|
borderInlineStart: `${lineWidth}px solid ${colorSplit}`,
|
2022-03-10 13:59:49 +08:00
|
|
|
},
|
|
|
|
|
2022-03-11 14:29:29 +08:00
|
|
|
'&-horizontal': {
|
|
|
|
display: 'flex',
|
|
|
|
clear: 'both',
|
|
|
|
width: '100%',
|
|
|
|
minWidth: '100%', // Fix https://github.com/ant-design/ant-design/issues/10914
|
|
|
|
margin: `${token.dividerHorizontalGutterMargin}px 0`,
|
2022-03-10 13:59:49 +08:00
|
|
|
},
|
|
|
|
|
2022-03-11 14:29:29 +08:00
|
|
|
'&-horizontal&-with-text': {
|
|
|
|
display: 'flex',
|
|
|
|
margin: `${token.dividerHorizontalWithTextGutterMargin}px 0`,
|
2022-03-22 20:02:04 +08:00
|
|
|
color: token.colorTextHeading,
|
2022-03-11 14:29:29 +08:00
|
|
|
fontWeight: 500,
|
|
|
|
fontSize: token.fontSizeLG,
|
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
textAlign: 'center',
|
2022-03-25 17:54:57 +08:00
|
|
|
borderBlockStart: `0 ${colorSplit}`,
|
2022-03-11 14:29:29 +08:00
|
|
|
|
|
|
|
'&::before, &::after': {
|
|
|
|
position: 'relative',
|
|
|
|
top: '50%',
|
|
|
|
width: '50%',
|
2022-11-01 15:06:38 +08:00
|
|
|
borderBlockStart: `${lineWidth}px solid transparent`,
|
2022-03-11 14:29:29 +08:00
|
|
|
// Chrome not accept `inherit` in `border-top`
|
|
|
|
borderBlockStartColor: 'inherit',
|
|
|
|
borderBlockEnd: 0,
|
|
|
|
transform: 'translateY(50%)',
|
|
|
|
content: "''",
|
|
|
|
},
|
2022-03-10 13:59:49 +08:00
|
|
|
},
|
|
|
|
|
2022-03-17 16:57:20 +08:00
|
|
|
'&-horizontal&-with-text-left': {
|
|
|
|
'&::before': {
|
|
|
|
top: '50%',
|
|
|
|
width: '5%',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&::after': {
|
|
|
|
top: '50%',
|
|
|
|
width: '95%',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-03-11 14:29:29 +08:00
|
|
|
'&-horizontal&-with-text-right': {
|
|
|
|
'&::before': {
|
|
|
|
top: '50%',
|
|
|
|
width: '95%',
|
|
|
|
},
|
2022-03-10 13:59:49 +08:00
|
|
|
|
2022-03-11 14:29:29 +08:00
|
|
|
'&::after': {
|
|
|
|
top: '50%',
|
|
|
|
width: '5%',
|
|
|
|
},
|
2022-03-10 13:59:49 +08:00
|
|
|
},
|
|
|
|
|
2022-04-07 14:53:33 +08:00
|
|
|
[`${componentCls}-inner-text`]: {
|
2022-03-11 14:29:29 +08:00
|
|
|
display: 'inline-block',
|
|
|
|
padding: '0 1em',
|
|
|
|
},
|
2022-03-10 13:59:49 +08:00
|
|
|
|
2022-03-11 14:29:29 +08:00
|
|
|
'&-dashed': {
|
|
|
|
background: 'none',
|
2022-03-25 17:54:57 +08:00
|
|
|
borderColor: colorSplit,
|
2022-03-11 14:29:29 +08:00
|
|
|
borderStyle: 'dashed',
|
2022-11-01 15:06:38 +08:00
|
|
|
borderWidth: `${lineWidth}px 0 0`,
|
2022-03-10 13:59:49 +08:00
|
|
|
},
|
|
|
|
|
2022-03-11 14:29:29 +08:00
|
|
|
'&-horizontal&-with-text&-dashed': {
|
|
|
|
'&::before, &::after': {
|
|
|
|
borderStyle: 'dashed none none',
|
|
|
|
},
|
2022-03-10 13:59:49 +08:00
|
|
|
},
|
|
|
|
|
2022-03-11 14:29:29 +08:00
|
|
|
'&-vertical&-dashed': {
|
2022-11-01 15:06:38 +08:00
|
|
|
borderInlineStart: lineWidth,
|
2022-04-19 11:27:09 +08:00
|
|
|
borderInlineEnd: 0,
|
|
|
|
borderBlockStart: 0,
|
|
|
|
borderBlockEnd: 0,
|
2022-03-10 13:59:49 +08:00
|
|
|
},
|
|
|
|
|
2022-03-11 14:29:29 +08:00
|
|
|
'&-plain&-with-text': {
|
2022-03-22 09:37:37 +08:00
|
|
|
color: token.colorText,
|
2022-03-11 14:29:29 +08:00
|
|
|
fontWeight: 'normal',
|
|
|
|
fontSize: token.fontSize,
|
2022-03-10 13:59:49 +08:00
|
|
|
},
|
|
|
|
|
2022-03-11 14:29:29 +08:00
|
|
|
'&-horizontal&-with-text-left&-no-default-orientation-margin-left': {
|
|
|
|
'&::before': {
|
|
|
|
width: 0,
|
|
|
|
},
|
|
|
|
|
|
|
|
'&::after': {
|
|
|
|
width: '100%',
|
|
|
|
},
|
|
|
|
|
2022-04-07 14:53:33 +08:00
|
|
|
[`${componentCls}-inner-text`]: {
|
2022-03-25 17:54:57 +08:00
|
|
|
paddingInlineStart: sizePaddingEdgeHorizontal,
|
2022-03-11 14:29:29 +08:00
|
|
|
},
|
2022-03-10 13:59:49 +08:00
|
|
|
},
|
|
|
|
|
2022-03-11 14:29:29 +08:00
|
|
|
'&-horizontal&-with-text-right&-no-default-orientation-margin-right': {
|
|
|
|
'&::before': {
|
|
|
|
width: '100%',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&::after': {
|
|
|
|
width: 0,
|
|
|
|
},
|
|
|
|
|
2022-04-07 14:53:33 +08:00
|
|
|
[`${componentCls}-inner-text`]: {
|
2022-03-25 17:54:57 +08:00
|
|
|
paddingInlineEnd: sizePaddingEdgeHorizontal,
|
2022-03-11 14:29:29 +08:00
|
|
|
},
|
2022-03-10 13:59:49 +08:00
|
|
|
},
|
|
|
|
},
|
2022-03-11 14:29:29 +08:00
|
|
|
};
|
|
|
|
};
|
2022-03-10 13:59:49 +08:00
|
|
|
|
|
|
|
// ============================== Export ==============================
|
2022-04-07 14:53:33 +08:00
|
|
|
export default genComponentStyleHook(
|
|
|
|
'Divider',
|
2022-11-19 13:47:33 +08:00
|
|
|
(token) => {
|
2022-04-11 16:04:00 +08:00
|
|
|
const dividerToken = mergeToken<DividerToken>(token, {
|
2022-05-04 20:52:44 +08:00
|
|
|
dividerVerticalGutterMargin: token.marginXS,
|
2022-04-07 14:53:33 +08:00
|
|
|
dividerHorizontalWithTextGutterMargin: token.margin,
|
|
|
|
dividerHorizontalGutterMargin: token.marginLG,
|
2022-04-11 16:04:00 +08:00
|
|
|
});
|
2022-04-07 14:53:33 +08:00
|
|
|
return [genSharedDividerStyle(dividerToken)];
|
|
|
|
},
|
|
|
|
{
|
|
|
|
sizePaddingEdgeHorizontal: 0,
|
|
|
|
},
|
|
|
|
);
|