2022-05-31 10:10:35 +08:00
|
|
|
import type { CSSObject } from '@ant-design/cssinjs';
|
|
|
|
import { TinyColor } from '@ctrl/tinycolor';
|
2022-06-27 14:25:59 +08:00
|
|
|
import type { FullToken, GenerateStyle } from '../../theme';
|
2022-07-11 15:35:58 +08:00
|
|
|
import { genComponentStyleHook, mergeToken } from '../../theme';
|
2022-05-31 10:10:35 +08:00
|
|
|
import genBorderedStyle from './bordered';
|
|
|
|
import genEllipsisStyle from './ellipsis';
|
|
|
|
import genEmptyStyle from './empty';
|
|
|
|
import genExpandStyle from './expand';
|
|
|
|
import genFilterStyle from './filter';
|
|
|
|
import genFixedStyle from './fixed';
|
2022-06-02 18:47:14 +08:00
|
|
|
import genPaginationStyle from './pagination';
|
2022-05-31 10:10:35 +08:00
|
|
|
import genRadiusStyle from './radius';
|
|
|
|
import genRtlStyle from './rtl';
|
|
|
|
import genSelectionStyle from './selection';
|
|
|
|
import genSizeStyle from './size';
|
|
|
|
import genSorterStyle from './sorter';
|
|
|
|
import genStickyStyle from './sticky';
|
|
|
|
import genSummaryStyle from './summary';
|
2022-07-11 15:35:58 +08:00
|
|
|
import { clearFix, resetComponent } from '../../style';
|
2022-05-31 10:10:35 +08:00
|
|
|
|
2022-06-24 11:11:42 +08:00
|
|
|
export interface ComponentToken {}
|
2022-06-17 18:47:47 +08:00
|
|
|
|
2022-05-31 10:10:35 +08:00
|
|
|
export interface TableToken extends FullToken<'Table'> {
|
|
|
|
tableFontSize: number;
|
|
|
|
tableBg: string;
|
|
|
|
tableRadius: number;
|
|
|
|
tablePaddingHorizontal: number;
|
|
|
|
tablePaddingVertical: number;
|
|
|
|
tablePaddingHorizontalMiddle: number;
|
|
|
|
tablePaddingVerticalMiddle: number;
|
|
|
|
tablePaddingHorizontalSmall: number;
|
|
|
|
tablePaddingVerticalSmall: number;
|
|
|
|
tableBorderColor: string;
|
|
|
|
tableHeaderTextColor: string;
|
|
|
|
tableHeaderBg: string;
|
|
|
|
tableFooterTextColor: string;
|
|
|
|
tableFooterBg: string;
|
|
|
|
tableHeaderCellSplitColor: string;
|
|
|
|
tableHeaderSortBg: string;
|
|
|
|
tableHeaderSortHoverBg: string;
|
|
|
|
tableHeaderIconColor: string;
|
2022-06-02 18:47:14 +08:00
|
|
|
tableHeaderIconColorHover: string;
|
2022-05-31 10:10:35 +08:00
|
|
|
tableBodySortBg: string;
|
|
|
|
tableFixedHeaderSortActiveBg: string;
|
|
|
|
tableHeaderFilterActiveBg: string;
|
|
|
|
tableFilterDropdownBg: string;
|
2022-06-02 18:47:14 +08:00
|
|
|
tableFilterDropdownHeight: number;
|
2022-05-31 10:10:35 +08:00
|
|
|
tableRowHoverBg: string;
|
|
|
|
tableSelectedRowBg: string;
|
|
|
|
tableSelectedRowHoverBg: string;
|
2022-06-02 18:47:14 +08:00
|
|
|
|
|
|
|
tableFontSizeMiddle: number;
|
|
|
|
tableFontSizeSmall: number;
|
2022-05-31 10:10:35 +08:00
|
|
|
tableSelectionColumnWidth: number;
|
|
|
|
tableExpandIconBg: string;
|
2022-06-24 11:32:42 +08:00
|
|
|
tableExpandColumnWidth: number;
|
2022-05-31 10:10:35 +08:00
|
|
|
tableExpandedRowBg: string;
|
2022-06-02 18:47:14 +08:00
|
|
|
tableFilterDropdownWidth: number;
|
|
|
|
tableFilterDropdownSearchWidth: number;
|
|
|
|
|
|
|
|
// Z-Index
|
|
|
|
zIndexTableFixed: number;
|
|
|
|
zIndexTableSticky: number;
|
|
|
|
|
|
|
|
// Virtual Scroll Bar
|
|
|
|
tableScrollThumbSize: number;
|
|
|
|
tableScrollThumbBg: string;
|
|
|
|
tableScrollThumbBgHover: string;
|
|
|
|
tableScrollBg: string;
|
2022-05-31 10:10:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const genTableStyle: GenerateStyle<TableToken, CSSObject> = token => {
|
2022-06-02 18:47:14 +08:00
|
|
|
const {
|
|
|
|
componentCls,
|
|
|
|
fontWeightStrong,
|
|
|
|
tablePaddingVertical,
|
|
|
|
tablePaddingHorizontal,
|
|
|
|
controlLineWidth,
|
|
|
|
controlLineType,
|
|
|
|
tableBorderColor,
|
|
|
|
tableFontSize,
|
|
|
|
tableBg,
|
|
|
|
tableRadius,
|
|
|
|
tableHeaderTextColor,
|
|
|
|
motionDurationSlow,
|
|
|
|
tableHeaderBg,
|
|
|
|
tableHeaderCellSplitColor,
|
|
|
|
tableRowHoverBg,
|
|
|
|
tableSelectedRowBg,
|
|
|
|
tableSelectedRowHoverBg,
|
|
|
|
tableFooterTextColor,
|
|
|
|
tableFooterBg,
|
2022-09-13 11:52:56 +08:00
|
|
|
wireframe,
|
2022-06-02 18:47:14 +08:00
|
|
|
} = token;
|
|
|
|
const tableBorder = `${controlLineWidth}px ${controlLineType} ${tableBorderColor}`;
|
2022-05-31 10:10:35 +08:00
|
|
|
return {
|
|
|
|
[`${componentCls}-wrapper`]: {
|
|
|
|
clear: 'both',
|
|
|
|
maxWidth: '100%',
|
|
|
|
...clearFix(),
|
|
|
|
|
|
|
|
[componentCls]: {
|
|
|
|
...resetComponent(token),
|
2022-06-02 18:47:14 +08:00
|
|
|
fontSize: tableFontSize,
|
|
|
|
background: tableBg,
|
|
|
|
borderRadius: tableRadius,
|
2022-05-31 10:10:35 +08:00
|
|
|
},
|
|
|
|
// https://github.com/ant-design/ant-design/issues/17611
|
|
|
|
table: {
|
|
|
|
width: '100%',
|
|
|
|
textAlign: 'start',
|
2022-06-02 18:47:14 +08:00
|
|
|
borderRadius: `${tableRadius}px ${tableRadius}px 0 0`,
|
2022-05-31 10:10:35 +08:00
|
|
|
borderCollapse: 'separate',
|
|
|
|
borderSpacing: 0,
|
|
|
|
},
|
|
|
|
|
|
|
|
// ============================= Cell =============================
|
|
|
|
[`
|
|
|
|
${componentCls}-thead > tr > th,
|
|
|
|
${componentCls}-tbody > tr > td,
|
|
|
|
tfoot > tr > th,
|
|
|
|
tfoot > tr > td
|
|
|
|
`]: {
|
|
|
|
position: 'relative',
|
2022-06-02 18:47:14 +08:00
|
|
|
padding: `${tablePaddingVertical}px ${tablePaddingHorizontal}px`,
|
2022-05-31 10:10:35 +08:00
|
|
|
overflowWrap: 'break-word',
|
|
|
|
},
|
|
|
|
|
|
|
|
// ============================ Title =============================
|
|
|
|
[`${componentCls}-title`]: {
|
2022-06-02 18:47:14 +08:00
|
|
|
padding: `${tablePaddingVertical}px ${tablePaddingHorizontal}px`,
|
2022-05-31 10:10:35 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
// ============================ Header ============================
|
|
|
|
[`${componentCls}-thead`]: {
|
|
|
|
'> tr > th': {
|
|
|
|
position: 'relative',
|
2022-06-02 18:47:14 +08:00
|
|
|
color: tableHeaderTextColor,
|
|
|
|
fontWeight: fontWeightStrong,
|
2022-05-31 10:10:35 +08:00
|
|
|
textAlign: 'start',
|
2022-06-02 18:47:14 +08:00
|
|
|
background: tableHeaderBg,
|
2022-05-31 10:10:35 +08:00
|
|
|
borderBottom: tableBorder,
|
2022-06-02 18:47:14 +08:00
|
|
|
transition: `background ${motionDurationSlow} ease`,
|
2022-05-31 10:10:35 +08:00
|
|
|
|
|
|
|
"&[colspan]:not([colspan='1'])": {
|
|
|
|
textAlign: 'center',
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&:not(:last-child):not(${componentCls}-selection-column):not(${componentCls}-row-expand-icon-cell):not([colspan])::before`]:
|
|
|
|
{
|
|
|
|
position: 'absolute',
|
|
|
|
top: '50%',
|
|
|
|
insetInlineEnd: 0,
|
|
|
|
width: 1,
|
|
|
|
height: '1.6em',
|
2022-06-02 18:47:14 +08:00
|
|
|
backgroundColor: tableHeaderCellSplitColor,
|
2022-05-31 10:10:35 +08:00
|
|
|
transform: 'translateY(-50%)',
|
2022-06-02 18:47:14 +08:00
|
|
|
transition: `background-color ${motionDurationSlow}`,
|
2022-05-31 10:10:35 +08:00
|
|
|
content: '""',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
'> tr:not(:last-child) > th[colspan]': {
|
|
|
|
borderBottom: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// ============================ Body ============================
|
|
|
|
[`${componentCls}-tbody`]: {
|
|
|
|
'> tr': {
|
|
|
|
'> td': {
|
2022-09-02 20:57:53 +08:00
|
|
|
borderTop: tableBorder,
|
2022-06-02 18:47:14 +08:00
|
|
|
transition: `background ${motionDurationSlow}`,
|
2022-05-31 10:10:35 +08:00
|
|
|
|
|
|
|
// ========================= Nest Table ===========================
|
|
|
|
[`
|
|
|
|
> ${componentCls}-wrapper:only-child,
|
|
|
|
> ${componentCls}-expanded-row-fixed > ${componentCls}-wrapper:only-child
|
|
|
|
`]: {
|
|
|
|
[componentCls]: {
|
2022-06-02 18:47:14 +08:00
|
|
|
marginBlock: `-${tablePaddingVertical}px`,
|
2022-06-24 11:32:42 +08:00
|
|
|
marginInline: `${
|
|
|
|
token.tableExpandColumnWidth - tablePaddingHorizontal
|
|
|
|
}px -${tablePaddingHorizontal}px`,
|
2022-05-31 10:10:35 +08:00
|
|
|
[`${componentCls}-tbody > tr:last-child > td`]: {
|
|
|
|
borderBottom: 0,
|
|
|
|
'&:first-child, &:last-child': {
|
|
|
|
borderRadius: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-09-02 20:57:53 +08:00
|
|
|
'&:last-child > td': {
|
|
|
|
borderBottom: tableBorder,
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&:first-child > td,
|
|
|
|
&${componentCls}-measure-row + tr > td`]: {
|
|
|
|
borderTop: 'none',
|
|
|
|
},
|
|
|
|
|
2022-05-31 10:10:35 +08:00
|
|
|
[`
|
|
|
|
&${componentCls}-row:hover > td,
|
|
|
|
> td${componentCls}-cell-row-hover
|
|
|
|
`]: {
|
2022-06-02 18:47:14 +08:00
|
|
|
background: tableRowHoverBg,
|
2022-05-31 10:10:35 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`&${componentCls}-row-selected`]: {
|
|
|
|
'> td': {
|
2022-06-02 18:47:14 +08:00
|
|
|
background: tableSelectedRowBg,
|
2022-05-31 10:10:35 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
'&:hover > td': {
|
2022-06-02 18:47:14 +08:00
|
|
|
background: tableSelectedRowHoverBg,
|
2022-05-31 10:10:35 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-09-13 11:52:56 +08:00
|
|
|
[`${componentCls}:not(${componentCls}-bordered) ${componentCls}-tbody > tr`]: wireframe
|
|
|
|
? undefined
|
|
|
|
: {
|
|
|
|
[`&${componentCls}-row:hover, &${componentCls}-row${componentCls}-row-selected`]: {
|
|
|
|
[`+ tr${componentCls}-row > td`]: {
|
|
|
|
borderTopColor: 'transparent',
|
|
|
|
},
|
|
|
|
},
|
2022-09-02 20:57:53 +08:00
|
|
|
|
2022-09-13 11:52:56 +08:00
|
|
|
[`&${componentCls}-row:last-child:hover > td,
|
2022-09-02 20:57:53 +08:00
|
|
|
&${componentCls}-row${componentCls}-row-selected:last-child > td`]: {
|
2022-09-13 11:52:56 +08:00
|
|
|
borderBottomColor: 'transparent',
|
|
|
|
},
|
2022-09-02 20:57:53 +08:00
|
|
|
|
2022-09-13 11:52:56 +08:00
|
|
|
[`
|
2022-09-02 20:57:53 +08:00
|
|
|
&${componentCls}-row:hover > td,
|
|
|
|
> td${componentCls}-cell-row-hover,
|
|
|
|
&${componentCls}-row${componentCls}-row-selected > td
|
|
|
|
`]: {
|
2022-09-13 11:52:56 +08:00
|
|
|
borderTopColor: 'transparent',
|
2022-09-02 20:57:53 +08:00
|
|
|
|
2022-09-13 11:52:56 +08:00
|
|
|
'&:first-child': {
|
|
|
|
borderStartStartRadius: tableRadius,
|
|
|
|
borderEndStartRadius: tableRadius,
|
|
|
|
},
|
2022-09-02 20:57:53 +08:00
|
|
|
|
2022-09-13 11:52:56 +08:00
|
|
|
'&:last-child': {
|
|
|
|
borderStartEndRadius: tableRadius,
|
|
|
|
borderEndEndRadius: tableRadius,
|
|
|
|
},
|
|
|
|
},
|
2022-09-02 20:57:53 +08:00
|
|
|
},
|
|
|
|
|
2022-05-31 10:10:35 +08:00
|
|
|
// ============================ Footer ============================
|
|
|
|
[`${componentCls}-footer`]: {
|
2022-06-02 18:47:14 +08:00
|
|
|
padding: `${tablePaddingVertical}px ${tablePaddingHorizontal}px`,
|
|
|
|
color: tableFooterTextColor,
|
|
|
|
background: tableFooterBg,
|
2022-05-31 10:10:35 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// ============================== Export ==============================
|
2022-06-24 11:11:42 +08:00
|
|
|
export default genComponentStyleHook('Table', token => {
|
|
|
|
const {
|
|
|
|
controlItemBgActive,
|
|
|
|
controlItemBgActiveHover,
|
|
|
|
colorTextPlaceholder,
|
|
|
|
colorTextHeading,
|
|
|
|
colorSplit,
|
|
|
|
fontSize,
|
|
|
|
padding,
|
|
|
|
paddingXS,
|
|
|
|
paddingSM,
|
|
|
|
controlHeight,
|
2022-07-21 17:00:42 +08:00
|
|
|
colorFillAlter,
|
|
|
|
colorIcon,
|
|
|
|
colorIconHover,
|
2022-06-24 11:11:42 +08:00
|
|
|
opacityLoading,
|
2022-06-28 20:33:01 +08:00
|
|
|
colorBgContainer,
|
2022-07-21 17:00:42 +08:00
|
|
|
colorFillSecondary,
|
2022-08-19 10:10:51 +08:00
|
|
|
radiusLG,
|
2022-07-21 17:00:42 +08:00
|
|
|
colorFillContent,
|
2022-06-24 11:35:54 +08:00
|
|
|
controlInteractiveSize: checkboxSize,
|
2022-06-24 11:11:42 +08:00
|
|
|
} = token;
|
2022-06-02 18:47:14 +08:00
|
|
|
|
2022-07-21 17:00:42 +08:00
|
|
|
const baseColorAction = new TinyColor(colorIcon);
|
|
|
|
const baseColorActionHover = new TinyColor(colorIconHover);
|
2022-06-02 18:47:14 +08:00
|
|
|
|
2022-06-24 11:11:42 +08:00
|
|
|
const tableSelectedRowBg = controlItemBgActive;
|
|
|
|
const zIndexTableFixed: number = 2;
|
2022-06-02 18:47:14 +08:00
|
|
|
|
2022-09-16 14:58:05 +08:00
|
|
|
const colorFillAlterSolid = new TinyColor(colorFillAlter)
|
|
|
|
.onBackground(colorBgContainer)
|
|
|
|
.toHexString();
|
|
|
|
|
2022-06-24 11:11:42 +08:00
|
|
|
const tableToken = mergeToken<TableToken>(token, {
|
|
|
|
tableFontSize: fontSize,
|
2022-06-28 20:33:01 +08:00
|
|
|
tableBg: colorBgContainer,
|
2022-08-19 10:10:51 +08:00
|
|
|
tableRadius: radiusLG,
|
2022-06-02 18:47:14 +08:00
|
|
|
|
2022-06-24 11:11:42 +08:00
|
|
|
tablePaddingVertical: padding,
|
|
|
|
tablePaddingHorizontal: padding,
|
|
|
|
tablePaddingVerticalMiddle: paddingSM,
|
|
|
|
tablePaddingHorizontalMiddle: paddingXS,
|
|
|
|
tablePaddingVerticalSmall: paddingXS,
|
|
|
|
tablePaddingHorizontalSmall: paddingXS,
|
|
|
|
tableBorderColor: colorSplit,
|
|
|
|
tableHeaderTextColor: colorTextHeading,
|
2022-09-16 14:58:05 +08:00
|
|
|
tableHeaderBg: colorFillAlterSolid,
|
2022-06-24 11:11:42 +08:00
|
|
|
tableFooterTextColor: colorTextHeading,
|
2022-09-16 14:58:05 +08:00
|
|
|
tableFooterBg: colorFillAlterSolid,
|
2022-06-24 11:11:42 +08:00
|
|
|
tableHeaderCellSplitColor: colorSplit,
|
2022-07-21 17:00:42 +08:00
|
|
|
tableHeaderSortBg: colorFillSecondary,
|
|
|
|
tableHeaderSortHoverBg: colorFillContent,
|
2022-06-24 11:11:42 +08:00
|
|
|
tableHeaderIconColor: baseColorAction
|
|
|
|
.clone()
|
|
|
|
.setAlpha(baseColorAction.getAlpha() * opacityLoading)
|
|
|
|
.toRgbString(),
|
|
|
|
tableHeaderIconColorHover: baseColorActionHover
|
|
|
|
.clone()
|
|
|
|
.setAlpha(baseColorActionHover.getAlpha() * opacityLoading)
|
|
|
|
.toRgbString(),
|
2022-07-21 17:00:42 +08:00
|
|
|
tableBodySortBg: colorFillAlter,
|
|
|
|
tableFixedHeaderSortActiveBg: colorFillSecondary,
|
|
|
|
tableHeaderFilterActiveBg: colorFillContent,
|
2022-06-28 20:33:01 +08:00
|
|
|
tableFilterDropdownBg: colorBgContainer,
|
2022-09-16 14:58:05 +08:00
|
|
|
tableRowHoverBg: colorFillAlterSolid,
|
2022-06-24 11:11:42 +08:00
|
|
|
tableSelectedRowBg,
|
|
|
|
tableSelectedRowHoverBg: controlItemBgActiveHover,
|
|
|
|
zIndexTableFixed,
|
|
|
|
zIndexTableSticky: zIndexTableFixed + 1,
|
|
|
|
tableFontSizeMiddle: fontSize,
|
|
|
|
tableFontSizeSmall: fontSize,
|
|
|
|
tableSelectionColumnWidth: controlHeight,
|
2022-06-28 20:33:01 +08:00
|
|
|
tableExpandIconBg: colorBgContainer,
|
2022-06-24 11:35:54 +08:00
|
|
|
tableExpandColumnWidth: checkboxSize + 2 * token.padding,
|
2022-07-21 17:00:42 +08:00
|
|
|
tableExpandedRowBg: colorFillAlter,
|
2022-06-02 18:47:14 +08:00
|
|
|
|
2022-06-24 11:11:42 +08:00
|
|
|
// Dropdown
|
|
|
|
tableFilterDropdownWidth: 120,
|
|
|
|
tableFilterDropdownHeight: 264,
|
|
|
|
tableFilterDropdownSearchWidth: 140,
|
2022-06-24 11:32:42 +08:00
|
|
|
|
2022-06-24 11:11:42 +08:00
|
|
|
// Virtual Scroll Bar
|
|
|
|
tableScrollThumbSize: 8, // Mac scroll bar size
|
|
|
|
tableScrollThumbBg: colorTextPlaceholder,
|
|
|
|
tableScrollThumbBgHover: colorTextHeading,
|
|
|
|
tableScrollBg: colorSplit,
|
|
|
|
});
|
2022-05-31 10:10:35 +08:00
|
|
|
|
2022-06-24 11:11:42 +08:00
|
|
|
return [
|
|
|
|
genTableStyle(tableToken),
|
|
|
|
genPaginationStyle(tableToken),
|
|
|
|
genSummaryStyle(tableToken),
|
|
|
|
genSorterStyle(tableToken),
|
|
|
|
genFilterStyle(tableToken),
|
|
|
|
genBorderedStyle(tableToken),
|
|
|
|
genRadiusStyle(tableToken),
|
|
|
|
genExpandStyle(tableToken),
|
|
|
|
genSummaryStyle(tableToken),
|
|
|
|
genEmptyStyle(tableToken),
|
|
|
|
genSelectionStyle(tableToken),
|
|
|
|
genFixedStyle(tableToken),
|
|
|
|
genStickyStyle(tableToken),
|
|
|
|
genEllipsisStyle(tableToken),
|
|
|
|
genSizeStyle(tableToken),
|
|
|
|
genRtlStyle(tableToken),
|
|
|
|
];
|
|
|
|
});
|