feat: input token (#44325)

* feat: input token

* feat: input number token

* feat: input token

* fix: date-picker & calendar

* fix: calendar style

* fix: token use
This commit is contained in:
MadCcc 2023-08-22 09:38:11 +08:00 committed by GitHub
parent f34ff52cec
commit d1d3b57dcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 305 additions and 149 deletions

View File

@ -1,8 +1,6 @@
import type { CSSObject } from '@ant-design/cssinjs'; import type { CSSObject } from '@ant-design/cssinjs';
import type { PickerPanelToken } from '../../date-picker/style'; import type { PickerPanelToken } from '../../date-picker/style';
import { genPanelStyle, initPickerPanelToken } from '../../date-picker/style'; import { genPanelStyle, initPickerPanelToken } from '../../date-picker/style';
import type { InputToken } from '../../input/style';
import { initInputToken } from '../../input/style';
import { resetComponent } from '../../style'; import { resetComponent } from '../../style';
import type { FullToken } from '../../theme/internal'; import type { FullToken } from '../../theme/internal';
import { genComponentStyleHook, mergeToken } from '../../theme/internal'; import { genComponentStyleHook, mergeToken } from '../../theme/internal';
@ -40,7 +38,7 @@ export interface ComponentToken {
itemActiveBg: string; itemActiveBg: string;
} }
interface CalendarToken extends InputToken<FullToken<'Calendar'>>, PickerPanelToken { interface CalendarToken extends FullToken<'Calendar'>, PickerPanelToken {
calendarCls: string; calendarCls: string;
dateValueHeight: number; dateValueHeight: number;
weekHeight: number; weekHeight: number;
@ -215,18 +213,14 @@ export default genComponentStyleHook(
'Calendar', 'Calendar',
(token) => { (token) => {
const calendarCls = `${token.componentCls}-calendar`; const calendarCls = `${token.componentCls}-calendar`;
const calendarToken = mergeToken<CalendarToken>( const calendarToken = mergeToken<CalendarToken>(token, initPickerPanelToken(token), {
initInputToken<FullToken<'Calendar'>>(token),
initPickerPanelToken(token),
{
calendarCls, calendarCls,
pickerCellInnerCls: `${token.componentCls}-cell-inner`, pickerCellInnerCls: `${token.componentCls}-cell-inner`,
dateValueHeight: token.controlHeightSM, dateValueHeight: token.controlHeightSM,
weekHeight: token.controlHeightSM * 0.75, weekHeight: token.controlHeightSM * 0.75,
dateContentHeight: dateContentHeight:
(token.fontSizeSM * token.lineHeightSM + token.marginXS) * 3 + token.lineWidth * 2, (token.fontSizeSM * token.lineHeightSM + token.marginXS) * 3 + token.lineWidth * 2,
}, });
);
return [genCalendarStyles(calendarToken)]; return [genCalendarStyles(calendarToken)];
}, },

View File

@ -1,10 +1,11 @@
import type { CSSObject } from '@ant-design/cssinjs'; import type { CSSObject } from '@ant-design/cssinjs';
import { TinyColor } from '@ctrl/tinycolor'; import { TinyColor } from '@ctrl/tinycolor';
import type { InputToken } from '../../input/style'; import type { SharedComponentToken, SharedInputToken } from '../../input/style';
import { import {
genActiveStyle, genActiveStyle,
genBasicInputStyle, genBasicInputStyle,
genHoverStyle, genHoverStyle,
initComponentToken,
initInputToken, initInputToken,
} from '../../input/style'; } from '../../input/style';
import { resetComponent, roundedArrow, textEllipsis } from '../../style'; import { resetComponent, roundedArrow, textEllipsis } from '../../style';
@ -22,7 +23,7 @@ import type { FullToken, GenerateStyle } from '../../theme/internal';
import { genComponentStyleHook, mergeToken } from '../../theme/internal'; import { genComponentStyleHook, mergeToken } from '../../theme/internal';
import type { TokenWithCommonCls } from '../../theme/util/genComponentStyleHook'; import type { TokenWithCommonCls } from '../../theme/util/genComponentStyleHook';
export interface ComponentToken { export interface ComponentToken extends Exclude<SharedComponentToken, 'addonBg'> {
/** /**
* @desc * @desc
* @descEN Width of preset area * @descEN Width of preset area
@ -61,9 +62,9 @@ export type PickerPanelToken = {
pickerControlIconBorderWidth: number; pickerControlIconBorderWidth: number;
}; };
type PickerToken = InputToken<FullToken<'DatePicker'>> & PickerPanelToken; type PickerToken = FullToken<'DatePicker'> & PickerPanelToken & SharedInputToken;
type SharedPickerToken = Omit<PickerToken, 'zIndexPopup' | 'presetsWidth' | 'presetsMaxWidth'>; type SharedPickerToken = TokenWithCommonCls<GlobalToken> & PickerPanelToken;
const genPikerPadding = ( const genPikerPadding = (
token: PickerToken, token: PickerToken,
@ -951,8 +952,8 @@ const genPickerStatusStyle: GenerateStyle<PickerToken> = (token) => {
[`&${componentCls}-focused, &:focus`]: { [`&${componentCls}-focused, &:focus`]: {
...genActiveStyle( ...genActiveStyle(
mergeToken<PickerToken>(token, { mergeToken<PickerToken>(token, {
inputBorderActiveColor: colorError, activeBorderColor: colorError,
inputBorderHoverColor: colorError, hoverBorderColor: colorError,
controlOutline: colorErrorOutline, controlOutline: colorErrorOutline,
}), }),
), ),
@ -972,8 +973,8 @@ const genPickerStatusStyle: GenerateStyle<PickerToken> = (token) => {
[`&${componentCls}-focused, &:focus`]: { [`&${componentCls}-focused, &:focus`]: {
...genActiveStyle( ...genActiveStyle(
mergeToken<PickerToken>(token, { mergeToken<PickerToken>(token, {
inputBorderActiveColor: colorWarning, activeBorderColor: colorWarning,
inputBorderHoverColor: colorWarning, hoverBorderColor: colorWarning,
controlOutline: colorWarningOutline, controlOutline: colorWarningOutline,
}), }),
), ),
@ -993,7 +994,7 @@ const genPickerStyle: GenerateStyle<PickerToken> = (token) => {
antCls, antCls,
controlHeight, controlHeight,
fontSize, fontSize,
inputPaddingHorizontal, paddingInline,
colorBgContainer, colorBgContainer,
lineWidth, lineWidth,
lineType, lineType,
@ -1006,7 +1007,7 @@ const genPickerStyle: GenerateStyle<PickerToken> = (token) => {
controlHeightLG, controlHeightLG,
fontSizeLG, fontSizeLG,
controlHeightSM, controlHeightSM,
inputPaddingHorizontalSM, paddingInlineSM,
paddingXS, paddingXS,
marginXS, marginXS,
colorTextDescription, colorTextDescription,
@ -1039,7 +1040,7 @@ const genPickerStyle: GenerateStyle<PickerToken> = (token) => {
{ {
[componentCls]: { [componentCls]: {
...resetComponent(token), ...resetComponent(token),
...genPikerPadding(token, controlHeight, fontSize, inputPaddingHorizontal), ...genPikerPadding(token, controlHeight, fontSize, paddingInline),
position: 'relative', position: 'relative',
display: 'inline-flex', display: 'inline-flex',
alignItems: 'center', alignItems: 'center',
@ -1117,7 +1118,7 @@ const genPickerStyle: GenerateStyle<PickerToken> = (token) => {
// Size // Size
'&-large': { '&-large': {
...genPikerPadding(token, controlHeightLG, fontSizeLG, inputPaddingHorizontal), ...genPikerPadding(token, controlHeightLG, fontSizeLG, paddingInline),
[`${componentCls}-input > input`]: { [`${componentCls}-input > input`]: {
fontSize: fontSizeLG, fontSize: fontSizeLG,
@ -1125,7 +1126,7 @@ const genPickerStyle: GenerateStyle<PickerToken> = (token) => {
}, },
'&-small': { '&-small': {
...genPikerPadding(token, controlHeightSM, fontSize, inputPaddingHorizontalSM), ...genPikerPadding(token, controlHeightSM, fontSize, paddingInlineSM),
}, },
[`${componentCls}-suffix`]: { [`${componentCls}-suffix`]: {
@ -1195,7 +1196,7 @@ const genPickerStyle: GenerateStyle<PickerToken> = (token) => {
// Clear // Clear
[`${componentCls}-clear`]: { [`${componentCls}-clear`]: {
insetInlineEnd: inputPaddingHorizontal, insetInlineEnd: paddingInline,
}, },
'&:hover': { '&:hover': {
@ -1208,7 +1209,7 @@ const genPickerStyle: GenerateStyle<PickerToken> = (token) => {
[`${componentCls}-active-bar`]: { [`${componentCls}-active-bar`]: {
bottom: -lineWidth, bottom: -lineWidth,
height: lineWidthBold, height: lineWidthBold,
marginInlineStart: inputPaddingHorizontal, marginInlineStart: paddingInline,
background: colorPrimary, background: colorPrimary,
opacity: 0, opacity: 0,
transition: `all ${motionDurationSlow} ease-out`, transition: `all ${motionDurationSlow} ease-out`,
@ -1229,11 +1230,11 @@ const genPickerStyle: GenerateStyle<PickerToken> = (token) => {
[`&${componentCls}-small`]: { [`&${componentCls}-small`]: {
[`${componentCls}-clear`]: { [`${componentCls}-clear`]: {
insetInlineEnd: inputPaddingHorizontalSM, insetInlineEnd: paddingInlineSM,
}, },
[`${componentCls}-active-bar`]: { [`${componentCls}-active-bar`]: {
marginInlineStart: inputPaddingHorizontalSM, marginInlineStart: paddingInlineSM,
}, },
}, },
}, },
@ -1342,7 +1343,7 @@ const genPickerStyle: GenerateStyle<PickerToken> = (token) => {
position: 'absolute', position: 'absolute',
zIndex: 1, zIndex: 1,
display: 'none', display: 'none',
marginInlineStart: inputPaddingHorizontal * 1.5, marginInlineStart: paddingInline * 1.5,
transition: `left ${motionDurationSlow} ease-out`, transition: `left ${motionDurationSlow} ease-out`,
...roundedArrow( ...roundedArrow(
sizePopupArrow, sizePopupArrow,
@ -1501,10 +1502,7 @@ export const initPickerPanelToken = (token: TokenWithCommonCls<GlobalToken>): Pi
export default genComponentStyleHook( export default genComponentStyleHook(
'DatePicker', 'DatePicker',
(token) => { (token) => {
const pickerToken = mergeToken<PickerToken>( const pickerToken = mergeToken<PickerToken>(initInputToken(token), initPickerPanelToken(token));
initInputToken<FullToken<'DatePicker'>>(token),
initPickerPanelToken(token),
);
return [ return [
genPickerStyle(pickerToken), genPickerStyle(pickerToken),
genPickerStatusStyle(pickerToken), genPickerStatusStyle(pickerToken),
@ -1517,6 +1515,7 @@ export default genComponentStyleHook(
]; ];
}, },
(token) => ({ (token) => ({
...initComponentToken(token),
presetsWidth: 120, presetsWidth: 120,
presetsMaxWidth: 200, presetsMaxWidth: 200,
zIndexPopup: token.zIndexPopupBase + 50, zIndexPopup: token.zIndexPopupBase + 50,

View File

@ -1,5 +1,7 @@
import type { InputToken } from '../../input/style'; import type { SharedInputToken, SharedComponentToken } from '../../input/style';
import { import {
initComponentToken,
initInputToken,
genActiveStyle, genActiveStyle,
genBasicInputStyle, genBasicInputStyle,
genDisabledStyle, genDisabledStyle,
@ -7,14 +9,13 @@ import {
genInputGroupStyle, genInputGroupStyle,
genPlaceholderStyle, genPlaceholderStyle,
genStatusStyle, genStatusStyle,
initInputToken,
} from '../../input/style'; } from '../../input/style';
import { resetComponent, resetIcon } from '../../style'; import { resetComponent, resetIcon } from '../../style';
import { genCompactItemStyle } from '../../style/compact-item'; import { genCompactItemStyle } from '../../style/compact-item';
import type { FullToken, GenerateStyle } from '../../theme/internal'; import type { FullToken, GenerateStyle } from '../../theme/internal';
import { genComponentStyleHook } from '../../theme/internal'; import { genComponentStyleHook, mergeToken } from '../../theme/internal';
export interface ComponentToken { export interface ComponentToken extends SharedComponentToken {
/** /**
* @desc * @desc
* @descEN Width of input * @descEN Width of input
@ -36,9 +37,29 @@ export interface ComponentToken {
* @descEN Handle visible * @descEN Handle visible
*/ */
handleVisible: 'auto' | true; handleVisible: 'auto' | true;
/**
* @desc
* @descEN Background color of handle
*/
handleBg: string;
/**
* @desc
* @descEN Active background color of handle
*/
handleActiveBg: string;
/**
* @desc
* @descEN Hover color of handle
*/
handleHoverColor: string;
/**
* @desc
* @descEN Border color of handle
*/
handleBorderColor: string;
} }
type InputNumberToken = InputToken<FullToken<'InputNumber'>>; type InputNumberToken = FullToken<'InputNumber'> & SharedInputToken;
export const genRadiusStyle = ( export const genRadiusStyle = (
{ componentCls, borderRadiusSM, borderRadiusLG }: InputNumberToken, { componentCls, borderRadiusSM, borderRadiusLG }: InputNumberToken,
@ -72,18 +93,20 @@ const genInputNumberStyles: GenerateStyle<InputNumberToken> = (token: InputNumbe
controlHeightLG, controlHeightLG,
controlHeightSM, controlHeightSM,
colorError, colorError,
inputPaddingHorizontalSM, paddingInlineSM,
colorTextDescription, colorTextDescription,
motionDurationMid, motionDurationMid,
colorPrimary, handleHoverColor,
inputPaddingHorizontal, paddingInline,
inputPaddingVertical, paddingBlock,
colorBgContainer, handleBg,
handleActiveBg,
colorTextDisabled, colorTextDisabled,
borderRadiusSM, borderRadiusSM,
borderRadiusLG, borderRadiusLG,
controlWidth, controlWidth,
handleVisible, handleVisible,
handleBorderColor,
} = token; } = token;
return [ return [
@ -124,7 +147,7 @@ const genInputNumberStyles: GenerateStyle<InputNumberToken> = (token: InputNumbe
[`input${componentCls}-input`]: { [`input${componentCls}-input`]: {
height: controlHeightSM - 2 * lineWidth, height: controlHeightSM - 2 * lineWidth,
padding: `0 ${inputPaddingHorizontalSM}px`, padding: `0 ${paddingInlineSM}px`,
}, },
}, },
@ -186,7 +209,7 @@ const genInputNumberStyles: GenerateStyle<InputNumberToken> = (token: InputNumbe
'&-input': { '&-input': {
...resetComponent(token), ...resetComponent(token),
width: '100%', width: '100%',
padding: `${inputPaddingVertical}px ${inputPaddingHorizontal}px`, padding: `${paddingBlock}px ${paddingInline}px`,
textAlign: 'start', textAlign: 'start',
backgroundColor: 'transparent', backgroundColor: 'transparent',
border: 0, border: 0,
@ -222,7 +245,7 @@ const genInputNumberStyles: GenerateStyle<InputNumberToken> = (token: InputNumbe
insetInlineEnd: 0, insetInlineEnd: 0,
width: token.handleWidth, width: token.handleWidth,
height: '100%', height: '100%',
background: colorBgContainer, background: handleBg,
borderStartStartRadius: 0, borderStartStartRadius: 0,
borderStartEndRadius: borderRadius, borderStartEndRadius: borderRadius,
borderEndEndRadius: borderRadius, borderEndEndRadius: borderRadius,
@ -261,10 +284,10 @@ const genInputNumberStyles: GenerateStyle<InputNumberToken> = (token: InputNumbe
lineHeight: 0, lineHeight: 0,
textAlign: 'center', textAlign: 'center',
cursor: 'pointer', cursor: 'pointer',
borderInlineStart: `${lineWidth}px ${lineType} ${colorBorder}`, borderInlineStart: `${lineWidth}px ${lineType} ${handleBorderColor}`,
transition: `all ${motionDurationMid} linear`, transition: `all ${motionDurationMid} linear`,
'&:active': { '&:active': {
background: token.colorFillAlter, background: handleActiveBg,
}, },
// Hover // Hover
@ -275,7 +298,7 @@ const genInputNumberStyles: GenerateStyle<InputNumberToken> = (token: InputNumbe
${componentCls}-handler-up-inner, ${componentCls}-handler-up-inner,
${componentCls}-handler-down-inner ${componentCls}-handler-down-inner
`]: { `]: {
color: colorPrimary, color: handleHoverColor,
}, },
}, },
@ -293,7 +316,7 @@ const genInputNumberStyles: GenerateStyle<InputNumberToken> = (token: InputNumbe
}, },
[`${componentCls}-handler-down`]: { [`${componentCls}-handler-down`]: {
borderBlockStart: `${lineWidth}px ${lineType} ${colorBorder}`, borderBlockStart: `${lineWidth}px ${lineType} ${handleBorderColor}`,
borderEndEndRadius: borderRadius, borderEndEndRadius: borderRadius,
}, },
@ -344,8 +367,8 @@ const genInputNumberStyles: GenerateStyle<InputNumberToken> = (token: InputNumbe
const genAffixWrapperStyles: GenerateStyle<InputNumberToken> = (token: InputNumberToken) => { const genAffixWrapperStyles: GenerateStyle<InputNumberToken> = (token: InputNumberToken) => {
const { const {
componentCls, componentCls,
inputPaddingVertical, paddingBlock,
inputPaddingHorizontal, paddingInline,
inputAffixPadding, inputAffixPadding,
controlWidth, controlWidth,
borderRadiusLG, borderRadiusLG,
@ -361,7 +384,7 @@ const genAffixWrapperStyles: GenerateStyle<InputNumberToken> = (token: InputNumb
display: 'inline-flex', display: 'inline-flex',
width: controlWidth, width: controlWidth,
padding: 0, padding: 0,
paddingInlineStart: inputPaddingHorizontal, paddingInlineStart: paddingInline,
'&-lg': { '&-lg': {
borderRadius: borderRadiusLG, borderRadius: borderRadiusLG,
@ -395,7 +418,7 @@ const genAffixWrapperStyles: GenerateStyle<InputNumberToken> = (token: InputNumb
}, },
[`input${componentCls}-input`]: { [`input${componentCls}-input`]: {
padding: `${inputPaddingVertical}px 0`, padding: `${paddingBlock}px 0`,
}, },
'&::before': { '&::before': {
@ -427,7 +450,7 @@ const genAffixWrapperStyles: GenerateStyle<InputNumberToken> = (token: InputNumb
insetInlineEnd: 0, insetInlineEnd: 0,
zIndex: 1, zIndex: 1,
height: '100%', height: '100%',
marginInlineEnd: inputPaddingHorizontal, marginInlineEnd: paddingInline,
marginInlineStart: inputAffixPadding, marginInlineStart: inputAffixPadding,
}, },
}, },
@ -439,7 +462,7 @@ const genAffixWrapperStyles: GenerateStyle<InputNumberToken> = (token: InputNumb
export default genComponentStyleHook( export default genComponentStyleHook(
'InputNumber', 'InputNumber',
(token) => { (token) => {
const inputNumberToken = initInputToken<FullToken<'InputNumber'>>(token); const inputNumberToken = mergeToken<InputNumberToken>(token, initInputToken(token));
return [ return [
genInputNumberStyles(inputNumberToken), genInputNumberStyles(inputNumberToken),
genAffixWrapperStyles(inputNumberToken), genAffixWrapperStyles(inputNumberToken),
@ -450,9 +473,14 @@ export default genComponentStyleHook(
]; ];
}, },
(token) => ({ (token) => ({
...initComponentToken(token),
controlWidth: 90, controlWidth: 90,
handleWidth: token.controlHeightSM - token.lineWidth * 2, handleWidth: token.controlHeightSM - token.lineWidth * 2,
handleFontSize: token.fontSize / 2, handleFontSize: token.fontSize / 2,
handleVisible: 'auto', handleVisible: 'auto',
handleActiveBg: token.colorFillAlter,
handleBg: token.colorBgContainer,
handleHoverColor: token.colorPrimary,
handleBorderColor: token.colorBorder,
}), }),
); );

View File

@ -5,17 +5,61 @@ import type { GlobalToken } from '../../theme/interface';
import type { FullToken, GenerateStyle } from '../../theme/internal'; import type { FullToken, GenerateStyle } from '../../theme/internal';
import { genComponentStyleHook, mergeToken } from '../../theme/internal'; import { genComponentStyleHook, mergeToken } from '../../theme/internal';
export type InputToken<T extends GlobalToken = FullToken<'Input'>> = T & { export interface SharedComponentToken {
/**
* @desc
* @descEN Horizontal padding of input
*/
paddingInline: number;
/**
* @desc
* @descEN Horizontal padding of small input
*/
paddingInlineSM: number;
/**
* @desc
* @descEN Horizontal padding of large input
*/
paddingInlineLG: number;
/**
* @desc
* @descEN Vertical padding of input
*/
paddingBlock: number;
/**
* @desc
* @descEN Vertical padding of small input
*/
paddingBlockSM: number;
/**
* @desc
* @descEN Vertical padding of large input
*/
paddingBlockLG: number;
/**
* @desc /
* @descEN Background color of addon
*/
addonBg: string;
/**
* @desc
* @descEN Hover border color
*/
hoverBorderColor: string;
/**
* @desc
* @descEN Active border color
*/
activeBorderColor: string;
}
export interface ComponentToken extends SharedComponentToken {}
export interface SharedInputToken {
inputAffixPadding: number; inputAffixPadding: number;
inputPaddingVertical: number; }
inputPaddingVerticalLG: number;
inputPaddingVerticalSM: number; interface InputToken extends FullToken<'Input'>, SharedInputToken {}
inputPaddingHorizontal: number;
inputPaddingHorizontalLG: number;
inputPaddingHorizontalSM: number;
inputBorderHoverColor: string;
inputBorderActiveColor: string;
};
export const genPlaceholderStyle = (color: string): CSSObject => ({ export const genPlaceholderStyle = (color: string): CSSObject => ({
// Firefox // Firefox
@ -32,12 +76,12 @@ export const genPlaceholderStyle = (color: string): CSSObject => ({
}); });
export const genHoverStyle = (token: InputToken): CSSObject => ({ export const genHoverStyle = (token: InputToken): CSSObject => ({
borderColor: token.inputBorderHoverColor, borderColor: token.hoverBorderColor,
borderInlineEndWidth: token.lineWidth, borderInlineEndWidth: token.lineWidth,
}); });
export const genActiveStyle = (token: InputToken) => ({ export const genActiveStyle = (token: InputToken) => ({
borderColor: token.inputBorderHoverColor, borderColor: token.activeBorderColor,
boxShadow: `0 0 0 ${token.controlOutlineWidth}px ${token.controlOutline}`, boxShadow: `0 0 0 ${token.controlOutlineWidth}px ${token.controlOutline}`,
borderInlineEndWidth: token.lineWidth, borderInlineEndWidth: token.lineWidth,
outline: 0, outline: 0,
@ -52,21 +96,15 @@ export const genDisabledStyle = (token: InputToken): CSSObject => ({
opacity: 1, opacity: 1,
'&:hover': { '&:hover': {
...genHoverStyle(mergeToken<InputToken>(token, { inputBorderHoverColor: token.colorBorder })), ...genHoverStyle(mergeToken<InputToken>(token, { hoverBorderColor: token.colorBorder })),
}, },
}); });
const genInputLargeStyle = (token: InputToken): CSSObject => { const genInputLargeStyle = (token: InputToken): CSSObject => {
const { const { paddingBlockLG, fontSizeLG, lineHeightLG, borderRadiusLG, paddingInlineLG } = token;
inputPaddingVerticalLG,
fontSizeLG,
lineHeightLG,
borderRadiusLG,
inputPaddingHorizontalLG,
} = token;
return { return {
padding: `${inputPaddingVerticalLG}px ${inputPaddingHorizontalLG}px`, padding: `${paddingBlockLG}px ${paddingInlineLG}px`,
fontSize: fontSizeLG, fontSize: fontSizeLG,
lineHeight: lineHeightLG, lineHeight: lineHeightLG,
borderRadius: borderRadiusLG, borderRadius: borderRadiusLG,
@ -74,7 +112,7 @@ const genInputLargeStyle = (token: InputToken): CSSObject => {
}; };
export const genInputSmallStyle = (token: InputToken): CSSObject => ({ export const genInputSmallStyle = (token: InputToken): CSSObject => ({
padding: `${token.inputPaddingVerticalSM}px ${token.controlPaddingHorizontalSM - 1}px`, padding: `${token.paddingBlockSM}px ${token.paddingInlineSM}px`,
borderRadius: token.borderRadiusSM, borderRadius: token.borderRadiusSM,
}); });
@ -100,8 +138,8 @@ export const genStatusStyle = (token: InputToken, parentCls: string): CSSObject
'&:focus, &-focused': { '&:focus, &-focused': {
...genActiveStyle( ...genActiveStyle(
mergeToken<InputToken>(token, { mergeToken<InputToken>(token, {
inputBorderActiveColor: colorError, activeBorderColor: colorError,
inputBorderHoverColor: colorError, hoverBorderColor: colorError,
controlOutline: colorErrorOutline, controlOutline: colorErrorOutline,
}), }),
), ),
@ -121,8 +159,8 @@ export const genStatusStyle = (token: InputToken, parentCls: string): CSSObject
'&:focus, &-focused': { '&:focus, &-focused': {
...genActiveStyle( ...genActiveStyle(
mergeToken<InputToken>(token, { mergeToken<InputToken>(token, {
inputBorderActiveColor: colorWarning, activeBorderColor: colorWarning,
inputBorderHoverColor: colorWarning, hoverBorderColor: colorWarning,
controlOutline: colorWarningOutline, controlOutline: colorWarningOutline,
}), }),
), ),
@ -140,7 +178,7 @@ export const genBasicInputStyle = (token: InputToken): CSSObject => ({
display: 'inline-block', display: 'inline-block',
width: '100%', width: '100%',
minWidth: 0, minWidth: 0,
padding: `${token.inputPaddingVertical}px ${token.inputPaddingHorizontal}px`, padding: `${token.paddingBlock}px ${token.paddingInline}px`,
color: token.colorText, color: token.colorText,
fontSize: token.fontSize, fontSize: token.fontSize,
lineHeight: token.lineHeight, lineHeight: token.lineHeight,
@ -265,7 +303,7 @@ export const genInputGroupStyle = (token: InputToken): CSSObject => {
'&-addon': { '&-addon': {
position: 'relative', position: 'relative',
padding: `0 ${token.inputPaddingHorizontal}px`, padding: `0 ${token.paddingInline}px`,
color: token.colorText, color: token.colorText,
fontWeight: 'normal', fontWeight: 'normal',
fontSize: token.fontSize, fontSize: token.fontSize,
@ -278,7 +316,7 @@ export const genInputGroupStyle = (token: InputToken): CSSObject => {
// Reset Select's style in addon // Reset Select's style in addon
[`${antCls}-select`]: { [`${antCls}-select`]: {
margin: `-${token.inputPaddingVertical + 1}px -${token.inputPaddingHorizontal}px`, margin: `-${token.paddingBlock + 1}px -${token.paddingInline}px`,
[`&${antCls}-select-single:not(${antCls}-select-customize-input)`]: { [`&${antCls}-select-single:not(${antCls}-select-customize-input)`]: {
[`${antCls}-select-selector`]: { [`${antCls}-select-selector`]: {
@ -297,7 +335,7 @@ export const genInputGroupStyle = (token: InputToken): CSSObject => {
// https://github.com/ant-design/ant-design/issues/31333 // https://github.com/ant-design/ant-design/issues/31333
[`${antCls}-cascader-picker`]: { [`${antCls}-cascader-picker`]: {
margin: `-9px -${token.inputPaddingHorizontal}px`, margin: `-9px -${token.paddingInline}px`,
backgroundColor: 'transparent', backgroundColor: 'transparent',
[`${antCls}-cascader-input`]: { [`${antCls}-cascader-input`]: {
textAlign: 'start', textAlign: 'start',
@ -870,31 +908,6 @@ const genSearchInputStyle: GenerateStyle<InputToken> = (token: InputToken) => {
}; };
}; };
export function initInputToken<T extends GlobalToken = GlobalToken>(token: T): InputToken<T> {
// @ts-ignore
return mergeToken<InputToken<T>>(token, {
inputAffixPadding: token.paddingXXS,
inputPaddingVertical: Math.max(
Math.round(((token.controlHeight - token.fontSize * token.lineHeight) / 2) * 10) / 10 -
token.lineWidth,
3,
),
inputPaddingVerticalLG:
Math.ceil(((token.controlHeightLG - token.fontSizeLG * token.lineHeightLG) / 2) * 10) / 10 -
token.lineWidth,
inputPaddingVerticalSM: Math.max(
Math.round(((token.controlHeightSM - token.fontSize * token.lineHeight) / 2) * 10) / 10 -
token.lineWidth,
0,
),
inputPaddingHorizontal: token.paddingSM - token.lineWidth,
inputPaddingHorizontalSM: token.paddingXS - token.lineWidth,
inputPaddingHorizontalLG: token.controlPaddingHorizontal - token.lineWidth,
inputBorderHoverColor: token.colorPrimaryHover,
inputBorderActiveColor: token.colorPrimaryHover,
});
}
const genTextAreaStyle: GenerateStyle<InputToken> = (token) => { const genTextAreaStyle: GenerateStyle<InputToken> = (token) => {
const { componentCls, paddingLG } = token; const { componentCls, paddingLG } = token;
const textareaPrefixCls = `${componentCls}-textarea`; const textareaPrefixCls = `${componentCls}-textarea`;
@ -962,7 +975,7 @@ const genTextAreaStyle: GenerateStyle<InputToken> = (token) => {
[`${textareaPrefixCls}-suffix`]: { [`${textareaPrefixCls}-suffix`]: {
position: 'absolute', position: 'absolute',
top: 0, top: 0,
insetInlineEnd: token.inputPaddingHorizontal, insetInlineEnd: token.paddingInline,
bottom: 0, bottom: 0,
zIndex: 1, zIndex: 1,
display: 'inline-flex', display: 'inline-flex',
@ -976,9 +989,54 @@ const genTextAreaStyle: GenerateStyle<InputToken> = (token) => {
}; };
}; };
export function initInputToken(token: GlobalToken): SharedInputToken {
return mergeToken<InputToken>(token, {
inputAffixPadding: token.paddingXXS,
});
}
export const initComponentToken = (token: GlobalToken): SharedComponentToken => {
const {
controlHeight,
fontSize,
lineHeight,
lineWidth,
controlHeightSM,
controlHeightLG,
fontSizeLG,
lineHeightLG,
paddingSM,
controlPaddingHorizontalSM,
controlPaddingHorizontal,
colorFillAlter,
colorPrimaryHover,
} = token;
return {
paddingBlock: Math.max(
Math.round(((controlHeight - fontSize * lineHeight) / 2) * 10) / 10 - lineWidth,
3,
),
paddingBlockSM: Math.max(
Math.round(((controlHeightSM - fontSize * lineHeight) / 2) * 10) / 10 - lineWidth,
0,
),
paddingBlockLG:
Math.ceil(((controlHeightLG - fontSizeLG * lineHeightLG) / 2) * 10) / 10 - lineWidth,
paddingInline: paddingSM - lineWidth,
paddingInlineSM: controlPaddingHorizontalSM - lineWidth,
paddingInlineLG: controlPaddingHorizontal - lineWidth,
addonBg: colorFillAlter,
activeBorderColor: colorPrimaryHover,
hoverBorderColor: colorPrimaryHover,
};
};
// ============================== Export ============================== // ============================== Export ==============================
export default genComponentStyleHook('Input', (token) => { export default genComponentStyleHook(
const inputToken = initInputToken<FullToken<'Input'>>(token); 'Input',
(token) => {
const inputToken = mergeToken<InputToken>(token, initInputToken(token));
return [ return [
genInputStyle(inputToken), genInputStyle(inputToken),
@ -991,4 +1049,6 @@ export default genComponentStyleHook('Input', (token) => {
// ===================================================== // =====================================================
genCompactItemStyle(inputToken), genCompactItemStyle(inputToken),
]; ];
}); },
initComponentToken,
);

View File

@ -1,17 +1,18 @@
import type { InputToken } from '../../input/style'; import type { SharedComponentToken, SharedInputToken } from '../../input/style';
import { import {
genActiveStyle, genActiveStyle,
genBasicInputStyle, genBasicInputStyle,
genDisabledStyle, genDisabledStyle,
genPlaceholderStyle, genPlaceholderStyle,
genStatusStyle, genStatusStyle,
initComponentToken,
initInputToken, initInputToken,
} from '../../input/style'; } from '../../input/style';
import { resetComponent, textEllipsis } from '../../style'; import { resetComponent, textEllipsis } from '../../style';
import type { FullToken, GenerateStyle } from '../../theme/internal'; import type { FullToken, GenerateStyle } from '../../theme/internal';
import { genComponentStyleHook } from '../../theme/internal'; import { genComponentStyleHook, mergeToken } from '../../theme/internal';
export interface ComponentToken { export interface ComponentToken extends SharedComponentToken {
/** /**
* @desc z-index * @desc z-index
* @descEN z-index of popup * @descEN z-index of popup
@ -29,7 +30,7 @@ export interface ComponentToken {
controlItemWidth: number; controlItemWidth: number;
} }
type MentionsToken = InputToken<FullToken<'Mentions'>>; type MentionsToken = FullToken<'Mentions'> & SharedInputToken;
const genMentionsStyle: GenerateStyle<MentionsToken> = (token) => { const genMentionsStyle: GenerateStyle<MentionsToken> = (token) => {
const { const {
@ -41,8 +42,8 @@ const genMentionsStyle: GenerateStyle<MentionsToken> = (token) => {
motionDurationSlow, motionDurationSlow,
lineHeight, lineHeight,
controlHeight, controlHeight,
inputPaddingHorizontal, paddingInline,
inputPaddingVertical, paddingBlock,
fontSize, fontSize,
colorBgElevated, colorBgElevated,
paddingXXS, paddingXXS,
@ -84,7 +85,7 @@ const genMentionsStyle: GenerateStyle<MentionsToken> = (token) => {
[`&-affix-wrapper ${componentCls}-suffix`]: { [`&-affix-wrapper ${componentCls}-suffix`]: {
position: 'absolute', position: 'absolute',
top: 0, top: 0,
insetInlineEnd: inputPaddingHorizontal, insetInlineEnd: paddingInline,
bottom: 0, bottom: 0,
zIndex: 1, zIndex: 1,
display: 'inline-flex', display: 'inline-flex',
@ -98,7 +99,7 @@ const genMentionsStyle: GenerateStyle<MentionsToken> = (token) => {
boxSizing: 'border-box', boxSizing: 'border-box',
minHeight: controlHeight - 2, minHeight: controlHeight - 2,
margin: 0, margin: 0,
padding: `${inputPaddingVertical}px ${inputPaddingHorizontal}px`, padding: `${paddingBlock}px ${paddingInline}px`,
overflow: 'inherit', overflow: 'inherit',
overflowX: 'hidden', overflowX: 'hidden',
overflowY: 'auto', overflowY: 'auto',
@ -223,10 +224,11 @@ const genMentionsStyle: GenerateStyle<MentionsToken> = (token) => {
export default genComponentStyleHook( export default genComponentStyleHook(
'Mentions', 'Mentions',
(token) => { (token) => {
const mentionsToken = initInputToken<FullToken<'Mentions'>>(token); const mentionsToken = mergeToken<MentionsToken>(token, initInputToken(token));
return [genMentionsStyle(mentionsToken)]; return [genMentionsStyle(mentionsToken)];
}, },
(token) => ({ (token) => ({
...initComponentToken(token),
dropdownHeight: 250, dropdownHeight: 250,
controlItemWidth: 100, controlItemWidth: 100,
zIndexPopup: token.zIndexPopupBase + 50, zIndexPopup: token.zIndexPopupBase + 50,

View File

@ -2,9 +2,10 @@ import type { CSSObject } from '@ant-design/cssinjs';
import { import {
genBasicInputStyle, genBasicInputStyle,
genInputSmallStyle, genInputSmallStyle,
initComponentToken,
initInputToken, initInputToken,
type InputToken,
} from '../../input/style'; } from '../../input/style';
import type { SharedComponentToken, SharedInputToken } from '../../input/style';
import { genFocusOutline, genFocusStyle, resetComponent } from '../../style'; import { genFocusOutline, genFocusStyle, resetComponent } from '../../style';
import type { FullToken, GenerateStyle } from '../../theme/internal'; import type { FullToken, GenerateStyle } from '../../theme/internal';
import { genComponentStyleHook, mergeToken } from '../../theme/internal'; import { genComponentStyleHook, mergeToken } from '../../theme/internal';
@ -57,7 +58,7 @@ export interface ComponentToken {
miniOptionsSizeChangerTop: number; miniOptionsSizeChangerTop: number;
} }
interface PaginationToken extends InputToken<FullToken<'Pagination'>> { interface PaginationToken extends FullToken<'Pagination'>, SharedComponentToken, SharedInputToken {
inputOutlineOffset: number; inputOutlineOffset: number;
paginationMiniOptionsMarginInlineStart: number; paginationMiniOptionsMarginInlineStart: number;
paginationMiniQuickJumperInputWidth: number; paginationMiniQuickJumperInputWidth: number;
@ -751,6 +752,7 @@ export default genComponentStyleHook(
paginationEllipsisTextIndent: '0.13em', // magic for ui experience paginationEllipsisTextIndent: '0.13em', // magic for ui experience
}, },
initInputToken(token), initInputToken(token),
initComponentToken(token),
); );
return [ return [
genPaginationStyle(paginationToken), genPaginationStyle(paginationToken),

View File

@ -22,6 +22,7 @@ import type { ComponentToken as DropdownComponentToken } from '../../dropdown/st
import type { ComponentToken as EmptyComponentToken } from '../../empty/style'; import type { ComponentToken as EmptyComponentToken } from '../../empty/style';
import type { ComponentToken as FloatButtonComponentToken } from '../../float-button/style'; import type { ComponentToken as FloatButtonComponentToken } from '../../float-button/style';
import type { ComponentToken as ImageComponentToken } from '../../image/style'; import type { ComponentToken as ImageComponentToken } from '../../image/style';
import type { ComponentToken as InputComponentToken } from '../../input/style';
import type { ComponentToken as InputNumberComponentToken } from '../../input-number/style'; import type { ComponentToken as InputNumberComponentToken } from '../../input-number/style';
import type { ComponentToken as LayoutComponentToken } from '../../layout/style'; import type { ComponentToken as LayoutComponentToken } from '../../layout/style';
import type { ComponentToken as ListComponentToken } from '../../list/style'; import type { ComponentToken as ListComponentToken } from '../../list/style';
@ -84,7 +85,7 @@ export interface ComponentTokenMap {
Form?: {}; Form?: {};
Grid?: {}; Grid?: {};
Image?: ImageComponentToken; Image?: ImageComponentToken;
Input?: {}; Input?: InputComponentToken;
InputNumber?: InputNumberComponentToken; InputNumber?: InputNumberComponentToken;
Layout?: LayoutComponentToken; Layout?: LayoutComponentToken;
List?: ListComponentToken; List?: ListComponentToken;

View File

@ -10,7 +10,6 @@
import { gold } from '@ant-design/colors'; import { gold } from '@ant-design/colors';
import type { CSSObject } from '@ant-design/cssinjs'; import type { CSSObject } from '@ant-design/cssinjs';
import type { TypographyToken } from '.'; import type { TypographyToken } from '.';
import { initInputToken } from '../../input/style';
import { operationUnit } from '../../style'; import { operationUnit } from '../../style';
import type { GenerateStyle } from '../../theme/internal'; import type { GenerateStyle } from '../../theme/internal';
@ -187,10 +186,9 @@ export const getResetStyles: GenerateStyle<TypographyToken, CSSObject> = (token)
}); });
export const getEditableStyles: GenerateStyle<TypographyToken, CSSObject> = (token) => { export const getEditableStyles: GenerateStyle<TypographyToken, CSSObject> = (token) => {
const { componentCls } = token; const { componentCls, paddingSM } = token;
const inputToken = initInputToken(token); const inputShift = paddingSM;
const inputShift = inputToken.inputPaddingVertical + 1;
return { return {
'&-edit-content': { '&-edit-content': {
position: 'relative', position: 'relative',

View File

@ -338,7 +338,43 @@ export default App;
| `@image-preview-operation-color` | `previewOperationColor` | - | | `@image-preview-operation-color` | `previewOperationColor` | - |
| `@image-preview-operation-disabled-color` | `previewOperationColorDisabled` | - | | `@image-preview-operation-disabled-color` | `previewOperationColorDisabled` | - |
<!-- ### Input --> ### Input
<!-- prettier-ignore -->
| Less variables | Component Token | Note |
| --- | --- | --- |
| `@input-height-base` | `controlHeight` | Global Token |
| `@input-height-lg` | `controlHeightLG` | Global Token |
| `@input-height-sm` | `controlHeightSM` | Global Token |
| `@input-padding-horizontal` | `paddingInline` | - |
| `@input-padding-horizontal-base` | `paddingInline` | - |
| `@input-padding-horizontal-sm` | `paddingInlineSM` | - |
| `@input-padding-horizontal-lg` | `paddingInlineLG` | - |
| `@input-padding-vertical-base` | `paddinBlock` | - |
| `@input-padding-vertical-sm` | `paddingBlockSM` | - |
| `@input-padding-vertical-lg` | `paddingBlockLG` | - |
| `@input-placeholder-color` | `colorTextPlaceholder` | Global Token |
| `@input-color` | `colorText` | Global Token |
| `@input-icon-color` | - | 已废弃 |
| `@input-border-color` | `colorBorder` | Global Token |
| `@input-bg` | `colorBgContainer` | Global Token |
| `@input-addon-bg` | `addonBg` | - |
| `@input-hover-border-color` | `hoverBorderColor` | - |
| `@input-disabled-bg` | `colorBgContainerDisabled` | Global Token |
| `@input-outline-offset` | `activeShadow` | Control box-shadow when active |
| `@input-icon-hover-color` | `colorIconHover` | Global Token |
| `@input-disabled-color` | `colorTextDisabled` | Global Token |
### InputNumber
<!-- prettier-ignore -->
| Less variables | Component Token | Note |
| --- | --- | --- |
| `@input-number-hover-border-color` | `hoverBorderColor` | - |
| `@input-number-handler-active-bg` | `handleActiveBg` | - |
| `@input-number-handler-hover-bg` | `handleHoverColor` | Wrong usage in 4.x, which is actually text color |
| `@input-number-handler-bg` | `handleBg` | - |
| `@input-number-handler-border-color` | `handleBorderColor` | - |
### Layout ### Layout

View File

@ -335,7 +335,43 @@ export default App;
| `@image-preview-operation-color` | `previewOperationColor` | - | | `@image-preview-operation-color` | `previewOperationColor` | - |
| `@image-preview-operation-disabled-color` | `previewOperationColorDisabled` | - | | `@image-preview-operation-disabled-color` | `previewOperationColorDisabled` | - |
<!-- ### Input 输入框 --> ### Input 输入框
<!-- prettier-ignore -->
| less 变量 | Component Token | 备注 |
| --- | --- | --- |
| `@input-height-base` | `controlHeight` | 全局 Token |
| `@input-height-lg` | `controlHeightLG` | 全局 Token |
| `@input-height-sm` | `controlHeightSM` | 全局 Token |
| `@input-padding-horizontal` | `paddingInline` | - |
| `@input-padding-horizontal-base` | `paddingInline` | - |
| `@input-padding-horizontal-sm` | `paddingInlineSM` | - |
| `@input-padding-horizontal-lg` | `paddingInlineLG` | - |
| `@input-padding-vertical-base` | `paddinBlock` | - |
| `@input-padding-vertical-sm` | `paddingBlockSM` | - |
| `@input-padding-vertical-lg` | `paddingBlockLG` | - |
| `@input-placeholder-color` | `colorTextPlaceholder` | 全局 Token |
| `@input-color` | `colorText` | 全局 Token |
| `@input-icon-color` | - | 已废弃 |
| `@input-border-color` | `colorBorder` | 全局 Token |
| `@input-bg` | `colorBgContainer` | 全局 Token |
| `@input-addon-bg` | `addonBg` | - |
| `@input-hover-border-color` | `hoverBorderColor` | - |
| `@input-disabled-bg` | `colorBgContainerDisabled` | 全局 Token |
| `@input-outline-offset` | `activeShadow` | 控制激活态阴影 |
| `@input-icon-hover-color` | `colorIconHover` | 全局 Token |
| `@input-disabled-color` | `colorTextDisabled` | 全局 Token |
### InputNumber 数字输入框
<!-- prettier-ignore -->
| less 变量 | Component Token | 备注 |
| --- | --- | --- |
| `@input-number-hover-border-color` | `hoverBorderColor` | - |
| `@input-number-handler-active-bg` | `handleActiveBg` | - |
| `@input-number-handler-hover-bg` | `handleHoverColor` | 4.x 中命名有误,实际上是 color |
| `@input-number-handler-bg` | `handleBg` | - |
| `@input-number-handler-border-color` | `handleBorderColor` | - |
### Layout 布局 ### Layout 布局