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-10-28 16:44:19 +08:00
|
|
|
import { resetComponent, textEllipsis } from '../../style';
|
2022-03-31 17:11:44 +08:00
|
|
|
|
2022-04-08 15:28:34 +08:00
|
|
|
interface DescriptionsToken extends FullToken<'Descriptions'> {
|
2022-03-31 17:11:44 +08:00
|
|
|
descriptionsTitleMarginBottom: number;
|
|
|
|
descriptionsExtraColor: string;
|
|
|
|
descriptionItemPaddingBottom: number;
|
|
|
|
descriptionsDefaultPadding: string;
|
|
|
|
descriptionsBg: string;
|
|
|
|
descriptionsMiddlePadding: string;
|
|
|
|
descriptionsSmallPadding: string;
|
|
|
|
descriptionsItemLabelColonMarginRight: number;
|
|
|
|
descriptionsItemLabelColonMarginLeft: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
const genBorderedStyle = (token: DescriptionsToken): CSSObject => {
|
|
|
|
const {
|
2022-04-08 15:28:34 +08:00
|
|
|
componentCls,
|
2022-03-31 17:11:44 +08:00
|
|
|
descriptionsSmallPadding,
|
|
|
|
descriptionsDefaultPadding,
|
|
|
|
descriptionsMiddlePadding,
|
|
|
|
descriptionsBg,
|
|
|
|
} = token;
|
|
|
|
return {
|
2022-04-08 15:28:34 +08:00
|
|
|
[`&${componentCls}-bordered`]: {
|
|
|
|
[`${componentCls}-view`]: {
|
2022-05-25 10:36:05 +08:00
|
|
|
border: `${token.lineWidth}px ${token.lineType} ${token.colorSplit}`,
|
2022-03-31 17:11:44 +08:00
|
|
|
'> table': {
|
|
|
|
tableLayout: 'auto',
|
|
|
|
borderCollapse: 'collapse',
|
|
|
|
},
|
|
|
|
},
|
2022-04-08 15:28:34 +08:00
|
|
|
[`${componentCls}-item-label, ${componentCls}-item-content`]: {
|
2022-03-31 17:11:44 +08:00
|
|
|
padding: descriptionsDefaultPadding,
|
2022-05-25 10:36:05 +08:00
|
|
|
borderInlineEnd: `${token.lineWidth}px ${token.lineType} ${token.colorSplit}`,
|
2022-03-31 17:11:44 +08:00
|
|
|
'&:last-child': {
|
|
|
|
borderInlineEnd: 'none',
|
|
|
|
},
|
|
|
|
},
|
2022-04-08 15:28:34 +08:00
|
|
|
[`${componentCls}-item-label`]: {
|
2022-03-31 17:11:44 +08:00
|
|
|
backgroundColor: descriptionsBg,
|
|
|
|
'&::after': {
|
|
|
|
display: 'none',
|
|
|
|
},
|
|
|
|
},
|
2022-04-08 15:28:34 +08:00
|
|
|
[`${componentCls}-row`]: {
|
2022-05-25 10:36:05 +08:00
|
|
|
borderBottom: `${token.lineWidth}px ${token.lineType} ${token.colorSplit}`,
|
2022-03-31 17:11:44 +08:00
|
|
|
'&:last-child': {
|
|
|
|
borderBottom: 'none',
|
|
|
|
},
|
|
|
|
},
|
2022-04-08 15:28:34 +08:00
|
|
|
[`&${componentCls}-middle`]: {
|
|
|
|
[`${componentCls}-item-label, ${componentCls}-item-content`]: {
|
2022-03-31 17:11:44 +08:00
|
|
|
padding: descriptionsMiddlePadding,
|
|
|
|
},
|
|
|
|
},
|
2022-04-08 15:28:34 +08:00
|
|
|
[`&${componentCls}-small`]: {
|
|
|
|
[`${componentCls}-item-label, ${componentCls}-item-content`]: {
|
2022-03-31 17:11:44 +08:00
|
|
|
padding: descriptionsSmallPadding,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const genDescriptionStyles: GenerateStyle<DescriptionsToken> = (token: DescriptionsToken) => {
|
|
|
|
const {
|
2022-04-08 15:28:34 +08:00
|
|
|
componentCls,
|
2022-03-31 17:11:44 +08:00
|
|
|
descriptionsExtraColor,
|
|
|
|
descriptionItemPaddingBottom,
|
|
|
|
descriptionsItemLabelColonMarginRight,
|
|
|
|
descriptionsItemLabelColonMarginLeft,
|
|
|
|
descriptionsTitleMarginBottom,
|
|
|
|
} = token;
|
|
|
|
return {
|
2022-04-08 15:28:34 +08:00
|
|
|
[componentCls]: {
|
2022-03-31 17:11:44 +08:00
|
|
|
...resetComponent(token),
|
|
|
|
...genBorderedStyle(token),
|
|
|
|
[`&-rtl`]: {
|
|
|
|
direction: 'rtl',
|
|
|
|
},
|
2022-04-08 15:28:34 +08:00
|
|
|
[`${componentCls}-header`]: {
|
2022-03-31 17:11:44 +08:00
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
marginBottom: descriptionsTitleMarginBottom,
|
|
|
|
},
|
2022-04-08 15:28:34 +08:00
|
|
|
[`${componentCls}-title`]: {
|
2022-10-28 16:44:19 +08:00
|
|
|
...textEllipsis,
|
2022-03-31 17:11:44 +08:00
|
|
|
flex: 'auto',
|
|
|
|
color: token.colorText,
|
2022-05-25 10:36:05 +08:00
|
|
|
fontWeight: token.fontWeightStrong,
|
2022-03-31 17:11:44 +08:00
|
|
|
fontSize: token.fontSizeLG,
|
2022-05-25 10:36:05 +08:00
|
|
|
lineHeight: token.lineHeightLG,
|
2022-03-31 17:11:44 +08:00
|
|
|
},
|
2022-04-08 15:28:34 +08:00
|
|
|
[`${componentCls}-extra`]: {
|
2022-04-19 11:27:09 +08:00
|
|
|
marginInlineStart: 'auto',
|
2022-03-31 17:11:44 +08:00
|
|
|
color: descriptionsExtraColor,
|
|
|
|
fontSize: token.fontSize,
|
|
|
|
},
|
2022-04-08 15:28:34 +08:00
|
|
|
[`${componentCls}-view`]: {
|
2022-03-31 17:11:44 +08:00
|
|
|
width: '100%',
|
2022-11-01 15:06:38 +08:00
|
|
|
borderRadius: token.borderRadiusLG,
|
2022-03-31 17:11:44 +08:00
|
|
|
table: {
|
|
|
|
width: '100%',
|
|
|
|
tableLayout: 'fixed',
|
|
|
|
},
|
|
|
|
},
|
2022-04-08 15:28:34 +08:00
|
|
|
[`${componentCls}-row`]: {
|
2022-03-31 17:11:44 +08:00
|
|
|
'> th, > td': {
|
|
|
|
paddingBottom: descriptionItemPaddingBottom,
|
|
|
|
},
|
|
|
|
'&:last-child': {
|
|
|
|
borderBottom: 'none',
|
|
|
|
},
|
|
|
|
},
|
2022-04-08 15:28:34 +08:00
|
|
|
[`${componentCls}-item-label`]: {
|
2022-03-31 17:11:44 +08:00
|
|
|
color: token.colorText,
|
|
|
|
fontWeight: 'normal',
|
|
|
|
fontSize: token.fontSize,
|
|
|
|
lineHeight: token.lineHeight,
|
|
|
|
textAlign: `start`,
|
|
|
|
|
|
|
|
'&::after': {
|
2022-05-25 10:36:05 +08:00
|
|
|
content: '":"',
|
2022-03-31 17:11:44 +08:00
|
|
|
position: 'relative',
|
2022-05-25 10:36:05 +08:00
|
|
|
top: -0.5, // magic for position
|
2022-03-31 17:11:44 +08:00
|
|
|
marginInline: `${descriptionsItemLabelColonMarginLeft}px ${descriptionsItemLabelColonMarginRight}px`,
|
|
|
|
},
|
|
|
|
|
2022-04-08 15:28:34 +08:00
|
|
|
[`&${componentCls}-item-no-colon::after`]: {
|
2022-03-31 17:11:44 +08:00
|
|
|
content: '""',
|
|
|
|
},
|
|
|
|
},
|
2022-04-08 15:28:34 +08:00
|
|
|
[`${componentCls}-item-no-label`]: {
|
2022-03-31 17:11:44 +08:00
|
|
|
'&::after': {
|
|
|
|
margin: 0,
|
|
|
|
content: '""',
|
|
|
|
},
|
|
|
|
},
|
2022-04-08 15:28:34 +08:00
|
|
|
[`${componentCls}-item-content`]: {
|
2022-03-31 17:11:44 +08:00
|
|
|
display: 'table-cell',
|
|
|
|
flex: 1,
|
|
|
|
color: token.colorText,
|
|
|
|
fontSize: token.fontSize,
|
|
|
|
lineHeight: token.lineHeight,
|
|
|
|
wordBreak: 'break-word',
|
|
|
|
overflowWrap: 'break-word',
|
|
|
|
},
|
2022-04-08 15:28:34 +08:00
|
|
|
[`${componentCls}-item`]: {
|
2022-03-31 17:11:44 +08:00
|
|
|
paddingBottom: 0,
|
|
|
|
verticalAlign: 'top',
|
|
|
|
'&-container': {
|
|
|
|
display: 'flex',
|
2022-04-08 15:28:34 +08:00
|
|
|
[`${componentCls}-item-label`]: {
|
2022-03-31 17:11:44 +08:00
|
|
|
display: 'inline-flex',
|
|
|
|
alignItems: 'baseline',
|
|
|
|
},
|
2022-04-08 15:28:34 +08:00
|
|
|
[`${componentCls}-item-content`]: {
|
2022-03-31 17:11:44 +08:00
|
|
|
display: 'inline-flex',
|
|
|
|
alignItems: 'baseline',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-04-26 10:21:50 +08:00
|
|
|
'&-middle': {
|
2022-04-08 15:28:34 +08:00
|
|
|
[`${componentCls}-row`]: {
|
2022-03-31 17:11:44 +08:00
|
|
|
'> th, > td': {
|
|
|
|
paddingBottom: token.paddingSM,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-04-26 10:21:50 +08:00
|
|
|
'&-small': {
|
2022-04-08 15:28:34 +08:00
|
|
|
[`${componentCls}-row`]: {
|
2022-03-31 17:11:44 +08:00
|
|
|
'> th, > td': {
|
|
|
|
paddingBottom: token.paddingXS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
// ============================== Export ==============================
|
2022-11-19 13:47:33 +08:00
|
|
|
export default genComponentStyleHook('Descriptions', (token) => {
|
2022-07-21 17:00:42 +08:00
|
|
|
const descriptionsBg = token.colorFillAlter;
|
2022-05-25 10:36:05 +08:00
|
|
|
const descriptionsTitleMarginBottom = token.fontSizeSM * token.lineHeightSM;
|
2022-03-31 17:11:44 +08:00
|
|
|
const descriptionsExtraColor = token.colorText;
|
|
|
|
const descriptionsSmallPadding = `${token.paddingXS}px ${token.padding}px`;
|
|
|
|
const descriptionsDefaultPadding = `${token.padding}px ${token.paddingLG}px`;
|
|
|
|
const descriptionsMiddlePadding = `${token.paddingSM}px ${token.paddingLG}px`;
|
|
|
|
const descriptionItemPaddingBottom = token.padding;
|
2022-05-25 10:36:05 +08:00
|
|
|
const descriptionsItemLabelColonMarginRight = token.marginXS;
|
|
|
|
const descriptionsItemLabelColonMarginLeft = token.marginXXS / 2;
|
2022-03-31 17:11:44 +08:00
|
|
|
|
2022-04-11 16:04:00 +08:00
|
|
|
const descriptionToken = mergeToken<DescriptionsToken>(token, {
|
2022-03-31 17:11:44 +08:00
|
|
|
descriptionsBg,
|
|
|
|
descriptionsTitleMarginBottom,
|
|
|
|
descriptionsExtraColor,
|
|
|
|
descriptionItemPaddingBottom,
|
|
|
|
descriptionsSmallPadding,
|
|
|
|
descriptionsDefaultPadding,
|
|
|
|
descriptionsMiddlePadding,
|
|
|
|
descriptionsItemLabelColonMarginRight,
|
|
|
|
descriptionsItemLabelColonMarginLeft,
|
2022-04-11 16:04:00 +08:00
|
|
|
});
|
2022-03-31 17:11:44 +08:00
|
|
|
|
2022-04-08 15:28:34 +08:00
|
|
|
return [genDescriptionStyles(descriptionToken)];
|
|
|
|
});
|