refactor: Full token transfer (#35882)

* more

* refactor: full token

* refactor: full token
This commit is contained in:
二货机器人 2022-06-02 16:17:40 +08:00 committed by GitHub
parent 1356b52719
commit 4975cbff05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 105 additions and 125 deletions

View File

@ -34,6 +34,7 @@ import type { ComponentToken as SpaceComponentToken } from '../../space/style';
import type { ComponentToken as SpinComponentToken } from '../../spin/style'; import type { ComponentToken as SpinComponentToken } from '../../spin/style';
import type { ComponentToken as StepsComponentToken } from '../../steps/style'; import type { ComponentToken as StepsComponentToken } from '../../steps/style';
import type { ComponentToken as TimelineComponentToken } from '../../timeline/style'; import type { ComponentToken as TimelineComponentToken } from '../../timeline/style';
import type { ComponentToken as TransferComponentToken } from '../../transfer/style';
import type { ComponentToken as TypographyComponentToken } from '../../typography/style'; import type { ComponentToken as TypographyComponentToken } from '../../typography/style';
import type { ComponentToken as UploadComponentToken } from '../../upload/style'; import type { ComponentToken as UploadComponentToken } from '../../upload/style';
@ -112,6 +113,7 @@ export interface OverrideToken {
TreeSelect?: {}; TreeSelect?: {};
Typography?: TypographyComponentToken; Typography?: TypographyComponentToken;
Timeline?: TimelineComponentToken; Timeline?: TimelineComponentToken;
Transfer?: TransferComponentToken;
Tabs?: {}; Tabs?: {};
Calendar?: CalendarComponentToken; Calendar?: CalendarComponentToken;
Card?: {}; Card?: {};
@ -124,7 +126,6 @@ export interface OverrideToken {
Table?: {}; Table?: {};
Space?: SpaceComponentToken; Space?: SpaceComponentToken;
Progress?: ProgressComponentToken; Progress?: ProgressComponentToken;
Transfer?: {};
} }
/** Final token which contains the components level override */ /** Final token which contains the components level override */
@ -321,6 +322,7 @@ export interface AliasToken extends Omit<DerivativeToken, OmitDerivativeKey> {
controlOutlineWidth: number; controlOutlineWidth: number;
controlItemBgHover: string; // Note. It also is a color controlItemBgHover: string; // Note. It also is a color
controlItemBgActive: string; // Note. It also is a color controlItemBgActive: string; // Note. It also is a color
controlItemBgActiveHover: string; // Note. It also is a color
controlInteractiveSize: number; controlInteractiveSize: number;
// Color // Color

View File

@ -94,6 +94,7 @@ export default function formatToken(derivativeToken: RawMergedToken): AliasToken
colorBorder: new TinyColor({ h: 0, s: 0, v: 85 }).toHexString(), colorBorder: new TinyColor({ h: 0, s: 0, v: 85 }).toHexString(),
colorSplit: 'rgba(0, 0, 0, 0.06)', colorSplit: 'rgba(0, 0, 0, 0.06)',
controlItemBgActive: primaryColors[0], controlItemBgActive: primaryColors[0],
controlItemBgActiveHover: new TinyColor(primaryColors[0]).darken(2).toRgbString(),
fontWeightStrong: 600, fontWeightStrong: 600,
// 🔥🔥🔥🔥🔥🔥🔥🔥🔥 All TMP Token leaves here 🔥🔥🔥🔥🔥🔥🔥🔥🔥 // 🔥🔥🔥🔥🔥🔥🔥🔥🔥 All TMP Token leaves here 🔥🔥🔥🔥🔥🔥🔥🔥🔥

View File

@ -1,51 +1,32 @@
// import '../../style/index.less';
// import './index.less';
// style dependencies
// import '../../empty/style';
// import '../../checkbox/style';
// import '../../button/style';
// import '../../input/style';
// import '../../menu/style';
// import '../../dropdown/style';
// import '../../pagination/style';
// deps-lint-skip: form
// deps-lint-skip-all // deps-lint-skip-all
import type { CSSObject } from '@ant-design/cssinjs'; import type { CSSObject } from '@ant-design/cssinjs';
import { TinyColor } from '@ctrl/tinycolor';
import { import {
resetComponent, resetComponent,
genComponentStyleHook, genComponentStyleHook,
mergeToken, mergeToken,
operationUnit, operationUnit,
resetIcon,
} from '../../_util/theme'; } from '../../_util/theme';
import type { FullToken, GenerateStyle } from '../../_util/theme'; import type { FullToken, GenerateStyle } from '../../_util/theme';
import { genHoverStyle, genActiveStyle, initInputToken } from '../../input/style'; export interface ComponentToken {
import type { InputToken } from '../../input/style'; listWidth: number;
listWidthLG: number;
listHeight: number;
}
// FIXME: need full token check interface TransferToken extends FullToken<'Transfer'> {
type TransferToken = InputToken<FullToken<'Transfer'>> & { transferItemHeight: number;
borderColorBase: string;
borderColorSplit: string;
heightBase: number;
disabledColor: string;
backgroundColorLight: string;
transferListHeight: number;
transferHeaderHeight: number; transferHeaderHeight: number;
transferHeaderVerticalPadding: number; transferHeaderVerticalPadding: number;
transferItemPaddingVertical: number; transferItemPaddingVertical: number;
transferItemSelectedHoverBg: string; }
};
const genTransferCustomizeStyle: GenerateStyle<TransferToken> = ( const genTransferCustomizeStyle: GenerateStyle<TransferToken> = (
token: TransferToken, token: TransferToken,
): CSSObject => { ): CSSObject => {
const { antCls, componentCls, borderColorSplit, backgroundColorLight, transferListHeight } = const { antCls, componentCls, listHeight, controlHeightLG, marginXXS, margin } = token;
token;
const tableCls = `${antCls}-table`; const tableCls = `${antCls}-table`;
const inputCls = `${antCls}-input`; const inputCls = `${antCls}-input`;
@ -56,7 +37,7 @@ const genTransferCustomizeStyle: GenerateStyle<TransferToken> = (
flex: '1 1 50%', flex: '1 1 50%',
width: 'auto', width: 'auto',
height: 'auto', height: 'auto',
minHeight: transferListHeight, minHeight: listHeight,
}, },
// =================== Hook Components =================== // =================== Hook Components ===================
@ -66,28 +47,13 @@ const genTransferCustomizeStyle: GenerateStyle<TransferToken> = (
borderRadius: 0, borderRadius: 0,
[`${tableCls}-selection-column`]: { [`${tableCls}-selection-column`]: {
width: 40, // FIXME: hardcode in v4, width: controlHeightLG,
minWidth: 40, // FIXME: hardcode in v4, minWidth: controlHeightLG,
},
[`> ${tableCls}-content`]: {
// Header background color
[`> ${tableCls}-body > table > ${tableCls}-thead > tr > th`]: {
background: backgroundColorLight,
},
[`${tableCls}-row:last-child td`]: {
borderBottom: `${token.controlLineWidth}px ${token.controlLineType} ${borderColorSplit}`,
},
},
[`${tableCls}-body`]: {
margin: 0,
}, },
}, },
[`${tableCls}-pagination${tableCls}-pagination`]: { [`${tableCls}-pagination${tableCls}-pagination`]: {
margin: '16px 0 4px', // FIXME: hardcode in v4, margin: `${margin}px 0 ${marginXXS}px`,
}, },
}, },
@ -99,21 +65,13 @@ const genTransferCustomizeStyle: GenerateStyle<TransferToken> = (
}; };
const genTransferStatusColor = (token: TransferToken, color: string): CSSObject => { const genTransferStatusColor = (token: TransferToken, color: string): CSSObject => {
const { componentCls, borderColorBase } = token; const { componentCls, colorBorder } = token;
return { return {
[`${componentCls}-list`]: { [`${componentCls}-list`]: {
borderColor: color, borderColor: color,
'&-search:not([disabled])': { '&-search:not([disabled])': {
borderColor: borderColorBase, borderColor: colorBorder,
'&:hover': {
...genHoverStyle(token),
},
'&:focus': {
...genActiveStyle(token),
},
}, },
}, },
}; };
@ -134,33 +92,43 @@ const genTransferStatusStyle: GenerateStyle<TransferToken> = (token: TransferTok
const genTransferListStyle: GenerateStyle<TransferToken> = (token: TransferToken): CSSObject => { const genTransferListStyle: GenerateStyle<TransferToken> = (token: TransferToken): CSSObject => {
const { const {
componentCls, componentCls,
borderColorBase, colorBorder,
borderColorSplit, colorSplit,
heightBase, controlLineWidth,
transferListHeight, transferItemHeight,
transferHeaderHeight, transferHeaderHeight,
transferHeaderVerticalPadding, transferHeaderVerticalPadding,
transferItemPaddingVertical, transferItemPaddingVertical,
transferItemSelectedHoverBg, controlItemBgActive,
disabledColor, controlItemBgActiveHover,
colorTextDisabled,
listHeight,
listWidth,
listWidthLG,
marginXXS,
fontSizeIcon,
marginXS,
paddingSM,
controlLineType,
iconCls,
} = token; } = token;
return { return {
display: 'flex', display: 'flex',
flexDirection: 'column', flexDirection: 'column',
width: 180, // FIXME: hardcode in v4, width: listWidth,
height: transferListHeight, height: listHeight,
border: `${token.controlLineWidth}px ${token.controlLineType} ${borderColorBase}`, border: `${controlLineWidth}px ${controlLineType} ${colorBorder}`,
borderRadius: token.radiusBase, borderRadius: token.radiusBase,
'&-with-pagination': { '&-with-pagination': {
width: 250, // FIXME: hardcode in v4, width: listWidthLG,
height: 'auto', height: 'auto',
}, },
'&-search': { '&-search': {
'.anticon-search': { [`${iconCls}-search`]: {
color: disabledColor, color: colorTextDisabled,
}, },
}, },
@ -170,16 +138,16 @@ const genTransferListStyle: GenerateStyle<TransferToken> = (token: TransferToken
alignItems: 'center', alignItems: 'center',
height: transferHeaderHeight, height: transferHeaderHeight,
// border-top is on the transfer dom. We should minus 1px for this // border-top is on the transfer dom. We should minus 1px for this
padding: `${transferHeaderVerticalPadding - 1}px ${ padding: `${
token.paddingSM transferHeaderVerticalPadding - controlLineWidth
}px ${transferHeaderVerticalPadding}px`, }px ${paddingSM}px ${transferHeaderVerticalPadding}px`,
color: token.colorText, color: token.colorText,
background: token.colorBgComponent, background: token.colorBgComponent,
borderBottom: `${token.controlLineWidth}px ${token.controlLineType} ${borderColorSplit}`, borderBottom: `${controlLineWidth}px ${controlLineType} ${colorSplit}`,
borderRadius: `${token.radiusBase}px ${token.radiusBase}px 0 0`, borderRadius: `${token.radiusBase}px ${token.radiusBase}px 0 0`,
'> *:not(:last-child)': { '> *:not(:last-child)': {
marginInlineEnd: 4, // FIXME: hardcode in v4, marginInlineEnd: marginXXS,
}, },
'> *': { '> *': {
@ -195,7 +163,9 @@ const genTransferListStyle: GenerateStyle<TransferToken> = (token: TransferToken
}, },
'&-dropdown': { '&-dropdown': {
fontSize: 10, // FIXME: hardcode in v4, ...resetIcon(),
fontSize: fontSizeIcon,
transform: 'translateY(10%)', transform: 'translateY(10%)',
cursor: 'pointer', cursor: 'pointer',
@ -215,7 +185,7 @@ const genTransferListStyle: GenerateStyle<TransferToken> = (token: TransferToken
'&-search-wrapper': { '&-search-wrapper': {
position: 'relative', position: 'relative',
flex: 'none', flex: 'none',
padding: token.paddingSM, padding: paddingSM,
}, },
}, },
@ -229,13 +199,12 @@ const genTransferListStyle: GenerateStyle<TransferToken> = (token: TransferToken
'&-item': { '&-item': {
display: 'flex', display: 'flex',
alignItems: 'center', alignItems: 'center',
minHeight: heightBase, minHeight: transferItemHeight,
padding: `${transferItemPaddingVertical}px ${token.paddingSM}px`, padding: `${transferItemPaddingVertical}px ${paddingSM}px`,
lineHeight: `${heightBase - 2 * transferItemPaddingVertical}px`,
transition: `all ${token.motionDurationSlow}`, transition: `all ${token.motionDurationSlow}`,
'> *:not(:last-child)': { '> *:not(:last-child)': {
marginInlineEnd: 8, // FIXME: hardcode in v4, marginInlineEnd: marginXS,
}, },
'> *': { '> *': {
@ -252,7 +221,7 @@ const genTransferListStyle: GenerateStyle<TransferToken> = (token: TransferToken
'&-remove': { '&-remove': {
...operationUnit(token), ...operationUnit(token),
position: 'relative', position: 'relative',
color: token.borderColorBase, color: colorBorder,
'&::after': { '&::after': {
position: 'absolute', position: 'absolute',
@ -272,7 +241,7 @@ const genTransferListStyle: GenerateStyle<TransferToken> = (token: TransferToken
}, },
[`&${componentCls}-list-content-item-checked:hover`]: { [`&${componentCls}-list-content-item-checked:hover`]: {
backgroundColor: transferItemSelectedHoverBg, backgroundColor: controlItemBgActiveHover,
}, },
}, },
@ -283,11 +252,11 @@ const genTransferListStyle: GenerateStyle<TransferToken> = (token: TransferToken
}, },
'&-checked': { '&-checked': {
backgroundColor: token.controlItemBgActive, backgroundColor: controlItemBgActive,
}, },
'&-disabled': { '&-disabled': {
color: disabledColor, color: colorTextDisabled,
cursor: 'not-allowed', cursor: 'not-allowed',
}, },
}, },
@ -296,25 +265,35 @@ const genTransferListStyle: GenerateStyle<TransferToken> = (token: TransferToken
'&-pagination': { '&-pagination': {
padding: `${token.paddingXS}px 0`, padding: `${token.paddingXS}px 0`,
textAlign: 'end', textAlign: 'end',
borderTop: `${token.controlLineWidth}px ${token.controlLineType} ${borderColorSplit}`, borderTop: `${controlLineWidth}px ${controlLineType} ${colorSplit}`,
}, },
'&-body-not-found': { '&-body-not-found': {
flex: 'none', flex: 'none',
width: '100%', width: '100%',
margin: 'auto 0', margin: 'auto 0',
color: disabledColor, color: colorTextDisabled,
textAlign: 'center', textAlign: 'center',
}, },
'&-footer': { '&-footer': {
borderTop: `${token.controlLineWidth}px ${token.controlLineType} ${borderColorSplit}`, borderTop: `${controlLineWidth}px ${controlLineType} ${colorSplit}`,
}, },
}; };
}; };
const genTransferStyle: GenerateStyle<TransferToken> = (token: TransferToken): CSSObject => { const genTransferStyle: GenerateStyle<TransferToken> = (token: TransferToken): CSSObject => {
const { antCls, iconCls, componentCls, transferHeaderHeight } = token; const {
antCls,
iconCls,
componentCls,
transferHeaderHeight,
marginXS,
marginXXS,
fontSizeIcon,
fontSize,
lineHeight,
} = token;
return { return {
[componentCls]: { [componentCls]: {
@ -337,24 +316,24 @@ const genTransferStyle: GenerateStyle<TransferToken> = (token: TransferToken): C
flex: 'none', flex: 'none',
flexDirection: 'column', flexDirection: 'column',
alignSelf: 'center', alignSelf: 'center',
margin: '0 8px', // FIXME: hardcode in v4, margin: `0 ${marginXS}px`,
verticalAlign: 'middle', verticalAlign: 'middle',
[`${antCls}-btn`]: { [`${antCls}-btn`]: {
display: 'block', display: 'block',
'&:first-child': { '&:first-child': {
marginBottom: 4, // FIXME: hardcode in v4, marginBottom: marginXXS,
}, },
[iconCls]: { [iconCls]: {
fontSize: 12, // FIXME: hardcode in v4, fontSize: fontSizeIcon,
}, },
}, },
}, },
[`${antCls}-empty-image`]: { [`${antCls}-empty-image`]: {
maxHeight: transferHeaderHeight / 2 - 22, // FIXME: hardcode in v4, maxHeight: transferHeaderHeight / 2 - Math.round(fontSize * lineHeight),
}, },
}, },
}; };
@ -365,41 +344,39 @@ const genTransferRTLStyle: GenerateStyle<TransferToken> = (token: TransferToken)
return { return {
[`${componentCls}-rtl`]: { [`${componentCls}-rtl`]: {
direction: 'rtl', direction: 'rtl',
[`${componentCls}-list`]: {
'&-search': {
paddingInlineStart: token.paddingXS,
paddingInlineEnd: 24, // FIXME: hardcode in v4,
},
},
}, },
}; };
}; };
// ============================== Export ============================== // ============================== Export ==============================
export default genComponentStyleHook('Transfer', token => { export default genComponentStyleHook(
const transferHeaderHeight = 40; 'Transfer',
const lineHeightBase = 1.5715; token => {
const { fontSize, lineHeight, controlLineWidth, controlHeightLG, controlHeight } = token;
const transferToken = mergeToken<TransferToken>(initInputToken<FullToken<'Transfer'>>(token), { const fontHeight = Math.round(fontSize * lineHeight);
borderColorBase: new TinyColor({ h: 0, s: 0, v: 85 }).toHexString(), // FIXME: hardcode in v4 const transferHeaderHeight = controlHeightLG;
borderColorSplit: new TinyColor({ h: 0, s: 0, v: 94 }).toHexString(), // FIXME: hardcode in v4 const transferItemHeight = controlHeight;
backgroundColorLight: new TinyColor({ h: 0, s: 0, v: 98 }).toHexString(), // FIXME: hardcode in v4
disabledColor: new TinyColor('#000').setAlpha(0.25).toRgbString(), // FIXME: hardcode in v4
heightBase: 32, // FIXME: hardcode in v4,
transferListHeight: 200, // FIXME: hardcode in v4,
transferHeaderHeight, // FIXME: hardcode in v4,
transferHeaderVerticalPadding: Math.ceil(
(transferHeaderHeight - 1 - token.fontSizeBase * lineHeightBase) / 2, // FIXME: hardcode in v4,
),
transferItemPaddingVertical: 6, // FIXME: hardcode in v4,
transferItemSelectedHoverBg: new TinyColor(token.controlItemBgActive).darken(2).toHexString(), // FIXME: hardcode in v4,
});
return [ const transferToken = mergeToken<TransferToken>(token, {
genTransferStyle(transferToken), transferItemHeight,
genTransferCustomizeStyle(transferToken), transferHeaderHeight,
genTransferStatusStyle(transferToken), transferHeaderVerticalPadding: Math.ceil(
genTransferRTLStyle(transferToken), (transferHeaderHeight - controlLineWidth - fontHeight) / 2,
]; ),
}); transferItemPaddingVertical: (transferItemHeight - fontHeight) / 2,
});
return [
genTransferStyle(transferToken),
genTransferCustomizeStyle(transferToken),
genTransferStatusStyle(transferToken),
genTransferRTLStyle(transferToken),
];
},
{
listWidth: 180,
listHeight: 200,
listWidthLG: 250,
},
);