2023-08-11 13:43:44 +08:00
|
|
|
|
import type { CSSProperties } from 'react';
|
2023-11-15 14:11:12 +08:00
|
|
|
|
import type { CSSObject } from '@ant-design/cssinjs';
|
|
|
|
|
import { unit } from '@ant-design/cssinjs';
|
|
|
|
|
|
2023-05-14 11:43:21 +08:00
|
|
|
|
import { resetComponent } from '../../style';
|
2023-11-15 14:11:12 +08:00
|
|
|
|
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
|
2023-11-29 17:23:45 +08:00
|
|
|
|
import { genStyleHooks, mergeToken } from '../../theme/internal';
|
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 {
|
2023-08-11 13:43:44 +08:00
|
|
|
|
/**
|
|
|
|
|
* @desc 文本横向内间距
|
|
|
|
|
* @descEN Horizontal padding of text
|
|
|
|
|
*/
|
|
|
|
|
textPaddingInline: CSSProperties['paddingInline'];
|
|
|
|
|
/**
|
|
|
|
|
* @desc 文本与边缘距离,取值 0 ~ 1
|
|
|
|
|
* @descEN Distance between text and edge, which should be a number between 0 and 1.
|
|
|
|
|
*/
|
|
|
|
|
orientationMargin: number;
|
|
|
|
|
/**
|
|
|
|
|
* @desc 纵向分割线的横向外间距
|
|
|
|
|
* @descEN Horizontal margin of vertical Divider
|
|
|
|
|
*/
|
|
|
|
|
verticalMarginInline: CSSProperties['marginInline'];
|
2022-03-25 17:54:57 +08:00
|
|
|
|
}
|
2022-03-10 13:59:49 +08:00
|
|
|
|
|
2022-04-07 14:53:33 +08:00
|
|
|
|
interface DividerToken extends FullToken<'Divider'> {
|
2023-11-15 14:11:12 +08:00
|
|
|
|
sizePaddingEdgeHorizontal: number | string;
|
|
|
|
|
dividerHorizontalWithTextGutterMargin: number | string;
|
|
|
|
|
dividerHorizontalGutterMargin: number | string;
|
2022-03-10 13:59:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ============================== Shared ==============================
|
2022-03-11 14:29:29 +08:00
|
|
|
|
const genSharedDividerStyle: GenerateStyle<DividerToken> = (token): CSSObject => {
|
2023-08-11 13:43:44 +08:00
|
|
|
|
const {
|
|
|
|
|
componentCls,
|
|
|
|
|
sizePaddingEdgeHorizontal,
|
|
|
|
|
colorSplit,
|
|
|
|
|
lineWidth,
|
|
|
|
|
textPaddingInline,
|
|
|
|
|
orientationMargin,
|
|
|
|
|
verticalMarginInline,
|
|
|
|
|
} = 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),
|
2023-11-15 14:11:12 +08:00
|
|
|
|
borderBlockStart: `${unit(lineWidth)} 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',
|
2023-08-11 13:43:44 +08:00
|
|
|
|
marginInline: verticalMarginInline,
|
|
|
|
|
marginBlock: 0,
|
2022-03-11 14:29:29 +08:00
|
|
|
|
verticalAlign: 'middle',
|
|
|
|
|
borderTop: 0,
|
2023-11-15 14:11:12 +08:00
|
|
|
|
borderInlineStart: `${unit(lineWidth)} 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
|
2023-11-15 14:11:12 +08:00
|
|
|
|
margin: `${unit(token.dividerHorizontalGutterMargin)} 0`,
|
2022-03-10 13:59:49 +08:00
|
|
|
|
},
|
|
|
|
|
|
2023-01-20 10:31:27 +08:00
|
|
|
|
[`&-horizontal${componentCls}-with-text`]: {
|
2022-03-11 14:29:29 +08:00
|
|
|
|
display: 'flex',
|
2022-12-07 14:25:26 +08:00
|
|
|
|
alignItems: 'center',
|
2023-11-15 14:11:12 +08:00
|
|
|
|
margin: `${unit(token.dividerHorizontalWithTextGutterMargin)} 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',
|
|
|
|
|
width: '50%',
|
2023-11-15 14:11:12 +08:00
|
|
|
|
borderBlockStart: `${unit(lineWidth)} 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
|
|
|
|
},
|
|
|
|
|
|
2023-01-20 10:31:27 +08:00
|
|
|
|
[`&-horizontal${componentCls}-with-text-left`]: {
|
2022-03-17 16:57:20 +08:00
|
|
|
|
'&::before': {
|
2023-11-15 14:11:12 +08:00
|
|
|
|
width: `calc(${orientationMargin} * 100%)`,
|
2022-03-17 16:57:20 +08:00
|
|
|
|
},
|
|
|
|
|
'&::after': {
|
2023-11-15 14:11:12 +08:00
|
|
|
|
width: `calc(100% - ${orientationMargin} * 100%)`,
|
2022-03-17 16:57:20 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
2023-01-20 10:31:27 +08:00
|
|
|
|
[`&-horizontal${componentCls}-with-text-right`]: {
|
2022-03-11 14:29:29 +08:00
|
|
|
|
'&::before': {
|
2023-11-15 14:11:12 +08:00
|
|
|
|
width: `calc(100% - ${orientationMargin} * 100%)`,
|
2022-03-11 14:29:29 +08:00
|
|
|
|
},
|
|
|
|
|
'&::after': {
|
2023-11-15 14:11:12 +08:00
|
|
|
|
width: `calc(${orientationMargin} * 100%)`,
|
2022-03-11 14:29:29 +08:00
|
|
|
|
},
|
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',
|
2023-08-11 13:43:44 +08:00
|
|
|
|
paddingBlock: 0,
|
|
|
|
|
paddingInline: textPaddingInline,
|
2022-03-11 14:29:29 +08:00
|
|
|
|
},
|
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',
|
2023-11-15 14:11:12 +08:00
|
|
|
|
borderWidth: `${unit(lineWidth)} 0 0`,
|
2022-03-10 13:59:49 +08:00
|
|
|
|
},
|
|
|
|
|
|
2023-01-20 10:31:27 +08:00
|
|
|
|
[`&-horizontal${componentCls}-with-text${componentCls}-dashed`]: {
|
2022-03-11 14:29:29 +08:00
|
|
|
|
'&::before, &::after': {
|
|
|
|
|
borderStyle: 'dashed none none',
|
|
|
|
|
},
|
2022-03-10 13:59:49 +08:00
|
|
|
|
},
|
|
|
|
|
|
2023-01-20 10:31:27 +08:00
|
|
|
|
[`&-vertical${componentCls}-dashed`]: {
|
2023-05-14 11:43:21 +08:00
|
|
|
|
borderInlineStartWidth: lineWidth,
|
2022-04-19 11:27:09 +08:00
|
|
|
|
borderInlineEnd: 0,
|
|
|
|
|
borderBlockStart: 0,
|
|
|
|
|
borderBlockEnd: 0,
|
2022-03-10 13:59:49 +08:00
|
|
|
|
},
|
|
|
|
|
|
2024-07-01 23:17:48 +08:00
|
|
|
|
'&-dotted': {
|
|
|
|
|
background: 'none',
|
|
|
|
|
borderColor: colorSplit,
|
|
|
|
|
borderStyle: 'dotted',
|
|
|
|
|
borderWidth: `${unit(lineWidth)} 0 0`,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
[`&-horizontal${componentCls}-with-text${componentCls}-dotted`]: {
|
|
|
|
|
'&::before, &::after': {
|
|
|
|
|
borderStyle: 'dotted none none',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
[`&-vertical${componentCls}-dotted`]: {
|
|
|
|
|
borderInlineStartWidth: lineWidth,
|
|
|
|
|
borderInlineEnd: 0,
|
|
|
|
|
borderBlockStart: 0,
|
|
|
|
|
borderBlockEnd: 0,
|
|
|
|
|
},
|
|
|
|
|
|
2023-01-20 10:31:27 +08:00
|
|
|
|
[`&-plain${componentCls}-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
|
|
|
|
},
|
|
|
|
|
|
2023-01-20 10:31:27 +08:00
|
|
|
|
[`&-horizontal${componentCls}-with-text-left${componentCls}-no-default-orientation-margin-left`]:
|
|
|
|
|
{
|
|
|
|
|
'&::before': {
|
|
|
|
|
width: 0,
|
|
|
|
|
},
|
2022-03-11 14:29:29 +08:00
|
|
|
|
|
2023-01-20 10:31:27 +08:00
|
|
|
|
'&::after': {
|
|
|
|
|
width: '100%',
|
|
|
|
|
},
|
2022-03-11 14:29:29 +08:00
|
|
|
|
|
2023-01-20 10:31:27 +08:00
|
|
|
|
[`${componentCls}-inner-text`]: {
|
|
|
|
|
paddingInlineStart: sizePaddingEdgeHorizontal,
|
|
|
|
|
},
|
2022-03-11 14:29:29 +08:00
|
|
|
|
},
|
2022-03-10 13:59:49 +08:00
|
|
|
|
|
2023-01-20 10:31:27 +08:00
|
|
|
|
[`&-horizontal${componentCls}-with-text-right${componentCls}-no-default-orientation-margin-right`]:
|
|
|
|
|
{
|
|
|
|
|
'&::before': {
|
|
|
|
|
width: '100%',
|
|
|
|
|
},
|
2022-03-11 14:29:29 +08:00
|
|
|
|
|
2023-01-20 10:31:27 +08:00
|
|
|
|
'&::after': {
|
|
|
|
|
width: 0,
|
|
|
|
|
},
|
2022-03-11 14:29:29 +08:00
|
|
|
|
|
2023-01-20 10:31:27 +08:00
|
|
|
|
[`${componentCls}-inner-text`]: {
|
|
|
|
|
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
|
|
|
|
|
2023-11-15 14:11:12 +08:00
|
|
|
|
export const prepareComponentToken: GetDefaultToken<'Divider'> = (token) => ({
|
|
|
|
|
textPaddingInline: '1em',
|
|
|
|
|
orientationMargin: 0.05,
|
|
|
|
|
verticalMarginInline: token.marginXS,
|
|
|
|
|
});
|
|
|
|
|
|
2022-03-10 13:59:49 +08:00
|
|
|
|
// ============================== Export ==============================
|
2023-11-29 17:23:45 +08:00
|
|
|
|
export default genStyleHooks(
|
2022-04-07 14:53:33 +08:00
|
|
|
|
'Divider',
|
2022-11-19 13:47:33 +08:00
|
|
|
|
(token) => {
|
2022-04-11 16:04:00 +08:00
|
|
|
|
const dividerToken = mergeToken<DividerToken>(token, {
|
2022-04-07 14:53:33 +08:00
|
|
|
|
dividerHorizontalWithTextGutterMargin: token.margin,
|
|
|
|
|
dividerHorizontalGutterMargin: token.marginLG,
|
2023-08-11 13:43:44 +08:00
|
|
|
|
sizePaddingEdgeHorizontal: 0,
|
2022-04-11 16:04:00 +08:00
|
|
|
|
});
|
2022-04-07 14:53:33 +08:00
|
|
|
|
return [genSharedDividerStyle(dividerToken)];
|
|
|
|
|
},
|
2023-11-15 14:11:12 +08:00
|
|
|
|
prepareComponentToken,
|
2023-11-29 17:23:45 +08:00
|
|
|
|
{
|
|
|
|
|
unitless: {
|
|
|
|
|
orientationMargin: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-04-07 14:53:33 +08:00
|
|
|
|
);
|