diff --git a/components/calendar/style/index.ts b/components/calendar/style/index.ts index bacf33270c..cf11ecb93d 100644 --- a/components/calendar/style/index.ts +++ b/components/calendar/style/index.ts @@ -1,8 +1,6 @@ import type { CSSObject } from '@ant-design/cssinjs'; import type { PickerPanelToken } 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 type { FullToken } from '../../theme/internal'; import { genComponentStyleHook, mergeToken } from '../../theme/internal'; @@ -40,7 +38,7 @@ export interface ComponentToken { itemActiveBg: string; } -interface CalendarToken extends InputToken>, PickerPanelToken { +interface CalendarToken extends FullToken<'Calendar'>, PickerPanelToken { calendarCls: string; dateValueHeight: number; weekHeight: number; @@ -215,18 +213,14 @@ export default genComponentStyleHook( 'Calendar', (token) => { const calendarCls = `${token.componentCls}-calendar`; - const calendarToken = mergeToken( - initInputToken>(token), - initPickerPanelToken(token), - { - calendarCls, - pickerCellInnerCls: `${token.componentCls}-cell-inner`, - dateValueHeight: token.controlHeightSM, - weekHeight: token.controlHeightSM * 0.75, - dateContentHeight: - (token.fontSizeSM * token.lineHeightSM + token.marginXS) * 3 + token.lineWidth * 2, - }, - ); + const calendarToken = mergeToken(token, initPickerPanelToken(token), { + calendarCls, + pickerCellInnerCls: `${token.componentCls}-cell-inner`, + dateValueHeight: token.controlHeightSM, + weekHeight: token.controlHeightSM * 0.75, + dateContentHeight: + (token.fontSizeSM * token.lineHeightSM + token.marginXS) * 3 + token.lineWidth * 2, + }); return [genCalendarStyles(calendarToken)]; }, diff --git a/components/date-picker/style/index.ts b/components/date-picker/style/index.ts index 62ef3f039d..8173b72f45 100644 --- a/components/date-picker/style/index.ts +++ b/components/date-picker/style/index.ts @@ -1,10 +1,11 @@ import type { CSSObject } from '@ant-design/cssinjs'; import { TinyColor } from '@ctrl/tinycolor'; -import type { InputToken } from '../../input/style'; +import type { SharedComponentToken, SharedInputToken } from '../../input/style'; import { genActiveStyle, genBasicInputStyle, genHoverStyle, + initComponentToken, initInputToken, } from '../../input/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 type { TokenWithCommonCls } from '../../theme/util/genComponentStyleHook'; -export interface ComponentToken { +export interface ComponentToken extends Exclude { /** * @desc 预设区域宽度 * @descEN Width of preset area @@ -61,9 +62,9 @@ export type PickerPanelToken = { pickerControlIconBorderWidth: number; }; -type PickerToken = InputToken> & PickerPanelToken; +type PickerToken = FullToken<'DatePicker'> & PickerPanelToken & SharedInputToken; -type SharedPickerToken = Omit; +type SharedPickerToken = TokenWithCommonCls & PickerPanelToken; const genPikerPadding = ( token: PickerToken, @@ -951,8 +952,8 @@ const genPickerStatusStyle: GenerateStyle = (token) => { [`&${componentCls}-focused, &:focus`]: { ...genActiveStyle( mergeToken(token, { - inputBorderActiveColor: colorError, - inputBorderHoverColor: colorError, + activeBorderColor: colorError, + hoverBorderColor: colorError, controlOutline: colorErrorOutline, }), ), @@ -972,8 +973,8 @@ const genPickerStatusStyle: GenerateStyle = (token) => { [`&${componentCls}-focused, &:focus`]: { ...genActiveStyle( mergeToken(token, { - inputBorderActiveColor: colorWarning, - inputBorderHoverColor: colorWarning, + activeBorderColor: colorWarning, + hoverBorderColor: colorWarning, controlOutline: colorWarningOutline, }), ), @@ -993,7 +994,7 @@ const genPickerStyle: GenerateStyle = (token) => { antCls, controlHeight, fontSize, - inputPaddingHorizontal, + paddingInline, colorBgContainer, lineWidth, lineType, @@ -1006,7 +1007,7 @@ const genPickerStyle: GenerateStyle = (token) => { controlHeightLG, fontSizeLG, controlHeightSM, - inputPaddingHorizontalSM, + paddingInlineSM, paddingXS, marginXS, colorTextDescription, @@ -1039,7 +1040,7 @@ const genPickerStyle: GenerateStyle = (token) => { { [componentCls]: { ...resetComponent(token), - ...genPikerPadding(token, controlHeight, fontSize, inputPaddingHorizontal), + ...genPikerPadding(token, controlHeight, fontSize, paddingInline), position: 'relative', display: 'inline-flex', alignItems: 'center', @@ -1117,7 +1118,7 @@ const genPickerStyle: GenerateStyle = (token) => { // Size '&-large': { - ...genPikerPadding(token, controlHeightLG, fontSizeLG, inputPaddingHorizontal), + ...genPikerPadding(token, controlHeightLG, fontSizeLG, paddingInline), [`${componentCls}-input > input`]: { fontSize: fontSizeLG, @@ -1125,7 +1126,7 @@ const genPickerStyle: GenerateStyle = (token) => { }, '&-small': { - ...genPikerPadding(token, controlHeightSM, fontSize, inputPaddingHorizontalSM), + ...genPikerPadding(token, controlHeightSM, fontSize, paddingInlineSM), }, [`${componentCls}-suffix`]: { @@ -1195,7 +1196,7 @@ const genPickerStyle: GenerateStyle = (token) => { // Clear [`${componentCls}-clear`]: { - insetInlineEnd: inputPaddingHorizontal, + insetInlineEnd: paddingInline, }, '&:hover': { @@ -1208,7 +1209,7 @@ const genPickerStyle: GenerateStyle = (token) => { [`${componentCls}-active-bar`]: { bottom: -lineWidth, height: lineWidthBold, - marginInlineStart: inputPaddingHorizontal, + marginInlineStart: paddingInline, background: colorPrimary, opacity: 0, transition: `all ${motionDurationSlow} ease-out`, @@ -1229,11 +1230,11 @@ const genPickerStyle: GenerateStyle = (token) => { [`&${componentCls}-small`]: { [`${componentCls}-clear`]: { - insetInlineEnd: inputPaddingHorizontalSM, + insetInlineEnd: paddingInlineSM, }, [`${componentCls}-active-bar`]: { - marginInlineStart: inputPaddingHorizontalSM, + marginInlineStart: paddingInlineSM, }, }, }, @@ -1342,7 +1343,7 @@ const genPickerStyle: GenerateStyle = (token) => { position: 'absolute', zIndex: 1, display: 'none', - marginInlineStart: inputPaddingHorizontal * 1.5, + marginInlineStart: paddingInline * 1.5, transition: `left ${motionDurationSlow} ease-out`, ...roundedArrow( sizePopupArrow, @@ -1501,10 +1502,7 @@ export const initPickerPanelToken = (token: TokenWithCommonCls): Pi export default genComponentStyleHook( 'DatePicker', (token) => { - const pickerToken = mergeToken( - initInputToken>(token), - initPickerPanelToken(token), - ); + const pickerToken = mergeToken(initInputToken(token), initPickerPanelToken(token)); return [ genPickerStyle(pickerToken), genPickerStatusStyle(pickerToken), @@ -1517,6 +1515,7 @@ export default genComponentStyleHook( ]; }, (token) => ({ + ...initComponentToken(token), presetsWidth: 120, presetsMaxWidth: 200, zIndexPopup: token.zIndexPopupBase + 50, diff --git a/components/input-number/style/index.ts b/components/input-number/style/index.ts index 07032b4a33..c9002a364d 100644 --- a/components/input-number/style/index.ts +++ b/components/input-number/style/index.ts @@ -1,5 +1,7 @@ -import type { InputToken } from '../../input/style'; +import type { SharedInputToken, SharedComponentToken } from '../../input/style'; import { + initComponentToken, + initInputToken, genActiveStyle, genBasicInputStyle, genDisabledStyle, @@ -7,14 +9,13 @@ import { genInputGroupStyle, genPlaceholderStyle, genStatusStyle, - initInputToken, } from '../../input/style'; import { resetComponent, resetIcon } from '../../style'; import { genCompactItemStyle } from '../../style/compact-item'; 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 输入框宽度 * @descEN Width of input @@ -36,9 +37,29 @@ export interface ComponentToken { * @descEN Handle visible */ 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>; +type InputNumberToken = FullToken<'InputNumber'> & SharedInputToken; export const genRadiusStyle = ( { componentCls, borderRadiusSM, borderRadiusLG }: InputNumberToken, @@ -72,18 +93,20 @@ const genInputNumberStyles: GenerateStyle = (token: InputNumbe controlHeightLG, controlHeightSM, colorError, - inputPaddingHorizontalSM, + paddingInlineSM, colorTextDescription, motionDurationMid, - colorPrimary, - inputPaddingHorizontal, - inputPaddingVertical, - colorBgContainer, + handleHoverColor, + paddingInline, + paddingBlock, + handleBg, + handleActiveBg, colorTextDisabled, borderRadiusSM, borderRadiusLG, controlWidth, handleVisible, + handleBorderColor, } = token; return [ @@ -124,7 +147,7 @@ const genInputNumberStyles: GenerateStyle = (token: InputNumbe [`input${componentCls}-input`]: { height: controlHeightSM - 2 * lineWidth, - padding: `0 ${inputPaddingHorizontalSM}px`, + padding: `0 ${paddingInlineSM}px`, }, }, @@ -186,7 +209,7 @@ const genInputNumberStyles: GenerateStyle = (token: InputNumbe '&-input': { ...resetComponent(token), width: '100%', - padding: `${inputPaddingVertical}px ${inputPaddingHorizontal}px`, + padding: `${paddingBlock}px ${paddingInline}px`, textAlign: 'start', backgroundColor: 'transparent', border: 0, @@ -222,7 +245,7 @@ const genInputNumberStyles: GenerateStyle = (token: InputNumbe insetInlineEnd: 0, width: token.handleWidth, height: '100%', - background: colorBgContainer, + background: handleBg, borderStartStartRadius: 0, borderStartEndRadius: borderRadius, borderEndEndRadius: borderRadius, @@ -261,10 +284,10 @@ const genInputNumberStyles: GenerateStyle = (token: InputNumbe lineHeight: 0, textAlign: 'center', cursor: 'pointer', - borderInlineStart: `${lineWidth}px ${lineType} ${colorBorder}`, + borderInlineStart: `${lineWidth}px ${lineType} ${handleBorderColor}`, transition: `all ${motionDurationMid} linear`, '&:active': { - background: token.colorFillAlter, + background: handleActiveBg, }, // Hover @@ -275,7 +298,7 @@ const genInputNumberStyles: GenerateStyle = (token: InputNumbe ${componentCls}-handler-up-inner, ${componentCls}-handler-down-inner `]: { - color: colorPrimary, + color: handleHoverColor, }, }, @@ -293,7 +316,7 @@ const genInputNumberStyles: GenerateStyle = (token: InputNumbe }, [`${componentCls}-handler-down`]: { - borderBlockStart: `${lineWidth}px ${lineType} ${colorBorder}`, + borderBlockStart: `${lineWidth}px ${lineType} ${handleBorderColor}`, borderEndEndRadius: borderRadius, }, @@ -344,8 +367,8 @@ const genInputNumberStyles: GenerateStyle = (token: InputNumbe const genAffixWrapperStyles: GenerateStyle = (token: InputNumberToken) => { const { componentCls, - inputPaddingVertical, - inputPaddingHorizontal, + paddingBlock, + paddingInline, inputAffixPadding, controlWidth, borderRadiusLG, @@ -361,7 +384,7 @@ const genAffixWrapperStyles: GenerateStyle = (token: InputNumb display: 'inline-flex', width: controlWidth, padding: 0, - paddingInlineStart: inputPaddingHorizontal, + paddingInlineStart: paddingInline, '&-lg': { borderRadius: borderRadiusLG, @@ -395,7 +418,7 @@ const genAffixWrapperStyles: GenerateStyle = (token: InputNumb }, [`input${componentCls}-input`]: { - padding: `${inputPaddingVertical}px 0`, + padding: `${paddingBlock}px 0`, }, '&::before': { @@ -427,7 +450,7 @@ const genAffixWrapperStyles: GenerateStyle = (token: InputNumb insetInlineEnd: 0, zIndex: 1, height: '100%', - marginInlineEnd: inputPaddingHorizontal, + marginInlineEnd: paddingInline, marginInlineStart: inputAffixPadding, }, }, @@ -439,7 +462,7 @@ const genAffixWrapperStyles: GenerateStyle = (token: InputNumb export default genComponentStyleHook( 'InputNumber', (token) => { - const inputNumberToken = initInputToken>(token); + const inputNumberToken = mergeToken(token, initInputToken(token)); return [ genInputNumberStyles(inputNumberToken), genAffixWrapperStyles(inputNumberToken), @@ -450,9 +473,14 @@ export default genComponentStyleHook( ]; }, (token) => ({ + ...initComponentToken(token), controlWidth: 90, handleWidth: token.controlHeightSM - token.lineWidth * 2, handleFontSize: token.fontSize / 2, handleVisible: 'auto', + handleActiveBg: token.colorFillAlter, + handleBg: token.colorBgContainer, + handleHoverColor: token.colorPrimary, + handleBorderColor: token.colorBorder, }), ); diff --git a/components/input/style/index.ts b/components/input/style/index.ts index 1c8d6a99d8..ade0de6474 100644 --- a/components/input/style/index.ts +++ b/components/input/style/index.ts @@ -5,17 +5,61 @@ import type { GlobalToken } from '../../theme/interface'; import type { FullToken, GenerateStyle } from '../../theme/internal'; import { genComponentStyleHook, mergeToken } from '../../theme/internal'; -export type InputToken> = 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; - inputPaddingVertical: number; - inputPaddingVerticalLG: number; - inputPaddingVerticalSM: number; - inputPaddingHorizontal: number; - inputPaddingHorizontalLG: number; - inputPaddingHorizontalSM: number; - inputBorderHoverColor: string; - inputBorderActiveColor: string; -}; +} + +interface InputToken extends FullToken<'Input'>, SharedInputToken {} export const genPlaceholderStyle = (color: string): CSSObject => ({ // Firefox @@ -32,12 +76,12 @@ export const genPlaceholderStyle = (color: string): CSSObject => ({ }); export const genHoverStyle = (token: InputToken): CSSObject => ({ - borderColor: token.inputBorderHoverColor, + borderColor: token.hoverBorderColor, borderInlineEndWidth: token.lineWidth, }); export const genActiveStyle = (token: InputToken) => ({ - borderColor: token.inputBorderHoverColor, + borderColor: token.activeBorderColor, boxShadow: `0 0 0 ${token.controlOutlineWidth}px ${token.controlOutline}`, borderInlineEndWidth: token.lineWidth, outline: 0, @@ -52,21 +96,15 @@ export const genDisabledStyle = (token: InputToken): CSSObject => ({ opacity: 1, '&:hover': { - ...genHoverStyle(mergeToken(token, { inputBorderHoverColor: token.colorBorder })), + ...genHoverStyle(mergeToken(token, { hoverBorderColor: token.colorBorder })), }, }); const genInputLargeStyle = (token: InputToken): CSSObject => { - const { - inputPaddingVerticalLG, - fontSizeLG, - lineHeightLG, - borderRadiusLG, - inputPaddingHorizontalLG, - } = token; + const { paddingBlockLG, fontSizeLG, lineHeightLG, borderRadiusLG, paddingInlineLG } = token; return { - padding: `${inputPaddingVerticalLG}px ${inputPaddingHorizontalLG}px`, + padding: `${paddingBlockLG}px ${paddingInlineLG}px`, fontSize: fontSizeLG, lineHeight: lineHeightLG, borderRadius: borderRadiusLG, @@ -74,7 +112,7 @@ const genInputLargeStyle = (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, }); @@ -100,8 +138,8 @@ export const genStatusStyle = (token: InputToken, parentCls: string): CSSObject '&:focus, &-focused': { ...genActiveStyle( mergeToken(token, { - inputBorderActiveColor: colorError, - inputBorderHoverColor: colorError, + activeBorderColor: colorError, + hoverBorderColor: colorError, controlOutline: colorErrorOutline, }), ), @@ -121,8 +159,8 @@ export const genStatusStyle = (token: InputToken, parentCls: string): CSSObject '&:focus, &-focused': { ...genActiveStyle( mergeToken(token, { - inputBorderActiveColor: colorWarning, - inputBorderHoverColor: colorWarning, + activeBorderColor: colorWarning, + hoverBorderColor: colorWarning, controlOutline: colorWarningOutline, }), ), @@ -140,7 +178,7 @@ export const genBasicInputStyle = (token: InputToken): CSSObject => ({ display: 'inline-block', width: '100%', minWidth: 0, - padding: `${token.inputPaddingVertical}px ${token.inputPaddingHorizontal}px`, + padding: `${token.paddingBlock}px ${token.paddingInline}px`, color: token.colorText, fontSize: token.fontSize, lineHeight: token.lineHeight, @@ -265,7 +303,7 @@ export const genInputGroupStyle = (token: InputToken): CSSObject => { '&-addon': { position: 'relative', - padding: `0 ${token.inputPaddingHorizontal}px`, + padding: `0 ${token.paddingInline}px`, color: token.colorText, fontWeight: 'normal', fontSize: token.fontSize, @@ -278,7 +316,7 @@ export const genInputGroupStyle = (token: InputToken): CSSObject => { // Reset Select's style in addon [`${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-selector`]: { @@ -297,7 +335,7 @@ export const genInputGroupStyle = (token: InputToken): CSSObject => { // https://github.com/ant-design/ant-design/issues/31333 [`${antCls}-cascader-picker`]: { - margin: `-9px -${token.inputPaddingHorizontal}px`, + margin: `-9px -${token.paddingInline}px`, backgroundColor: 'transparent', [`${antCls}-cascader-input`]: { textAlign: 'start', @@ -870,31 +908,6 @@ const genSearchInputStyle: GenerateStyle = (token: InputToken) => { }; }; -export function initInputToken(token: T): InputToken { - // @ts-ignore - return mergeToken>(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 = (token) => { const { componentCls, paddingLG } = token; const textareaPrefixCls = `${componentCls}-textarea`; @@ -962,7 +975,7 @@ const genTextAreaStyle: GenerateStyle = (token) => { [`${textareaPrefixCls}-suffix`]: { position: 'absolute', top: 0, - insetInlineEnd: token.inputPaddingHorizontal, + insetInlineEnd: token.paddingInline, bottom: 0, zIndex: 1, display: 'inline-flex', @@ -976,19 +989,66 @@ const genTextAreaStyle: GenerateStyle = (token) => { }; }; -// ============================== Export ============================== -export default genComponentStyleHook('Input', (token) => { - const inputToken = initInputToken>(token); +export function initInputToken(token: GlobalToken): SharedInputToken { + return mergeToken(token, { + inputAffixPadding: token.paddingXXS, + }); +} - return [ - genInputStyle(inputToken), - genTextAreaStyle(inputToken), - genAffixStyle(inputToken), - genGroupStyle(inputToken), - genSearchInputStyle(inputToken), - // ===================================================== - // == Space Compact == - // ===================================================== - genCompactItemStyle(inputToken), - ]; -}); +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 default genComponentStyleHook( + 'Input', + (token) => { + const inputToken = mergeToken(token, initInputToken(token)); + + return [ + genInputStyle(inputToken), + genTextAreaStyle(inputToken), + genAffixStyle(inputToken), + genGroupStyle(inputToken), + genSearchInputStyle(inputToken), + // ===================================================== + // == Space Compact == + // ===================================================== + genCompactItemStyle(inputToken), + ]; + }, + initComponentToken, +); diff --git a/components/mentions/style/index.ts b/components/mentions/style/index.ts index b7e8adfeb1..f8937451af 100644 --- a/components/mentions/style/index.ts +++ b/components/mentions/style/index.ts @@ -1,17 +1,18 @@ -import type { InputToken } from '../../input/style'; +import type { SharedComponentToken, SharedInputToken } from '../../input/style'; import { genActiveStyle, genBasicInputStyle, genDisabledStyle, genPlaceholderStyle, genStatusStyle, + initComponentToken, initInputToken, } from '../../input/style'; import { resetComponent, textEllipsis } from '../../style'; 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 * @descEN z-index of popup @@ -29,7 +30,7 @@ export interface ComponentToken { controlItemWidth: number; } -type MentionsToken = InputToken>; +type MentionsToken = FullToken<'Mentions'> & SharedInputToken; const genMentionsStyle: GenerateStyle = (token) => { const { @@ -41,8 +42,8 @@ const genMentionsStyle: GenerateStyle = (token) => { motionDurationSlow, lineHeight, controlHeight, - inputPaddingHorizontal, - inputPaddingVertical, + paddingInline, + paddingBlock, fontSize, colorBgElevated, paddingXXS, @@ -84,7 +85,7 @@ const genMentionsStyle: GenerateStyle = (token) => { [`&-affix-wrapper ${componentCls}-suffix`]: { position: 'absolute', top: 0, - insetInlineEnd: inputPaddingHorizontal, + insetInlineEnd: paddingInline, bottom: 0, zIndex: 1, display: 'inline-flex', @@ -98,7 +99,7 @@ const genMentionsStyle: GenerateStyle = (token) => { boxSizing: 'border-box', minHeight: controlHeight - 2, margin: 0, - padding: `${inputPaddingVertical}px ${inputPaddingHorizontal}px`, + padding: `${paddingBlock}px ${paddingInline}px`, overflow: 'inherit', overflowX: 'hidden', overflowY: 'auto', @@ -223,10 +224,11 @@ const genMentionsStyle: GenerateStyle = (token) => { export default genComponentStyleHook( 'Mentions', (token) => { - const mentionsToken = initInputToken>(token); + const mentionsToken = mergeToken(token, initInputToken(token)); return [genMentionsStyle(mentionsToken)]; }, (token) => ({ + ...initComponentToken(token), dropdownHeight: 250, controlItemWidth: 100, zIndexPopup: token.zIndexPopupBase + 50, diff --git a/components/pagination/style/index.ts b/components/pagination/style/index.ts index 31f4a79606..8ac5eda734 100644 --- a/components/pagination/style/index.ts +++ b/components/pagination/style/index.ts @@ -2,9 +2,10 @@ import type { CSSObject } from '@ant-design/cssinjs'; import { genBasicInputStyle, genInputSmallStyle, + initComponentToken, initInputToken, - type InputToken, } from '../../input/style'; +import type { SharedComponentToken, SharedInputToken } from '../../input/style'; import { genFocusOutline, genFocusStyle, resetComponent } from '../../style'; import type { FullToken, GenerateStyle } from '../../theme/internal'; import { genComponentStyleHook, mergeToken } from '../../theme/internal'; @@ -57,7 +58,7 @@ export interface ComponentToken { miniOptionsSizeChangerTop: number; } -interface PaginationToken extends InputToken> { +interface PaginationToken extends FullToken<'Pagination'>, SharedComponentToken, SharedInputToken { inputOutlineOffset: number; paginationMiniOptionsMarginInlineStart: number; paginationMiniQuickJumperInputWidth: number; @@ -751,6 +752,7 @@ export default genComponentStyleHook( paginationEllipsisTextIndent: '0.13em', // magic for ui experience }, initInputToken(token), + initComponentToken(token), ); return [ genPaginationStyle(paginationToken), diff --git a/components/theme/interface/components.ts b/components/theme/interface/components.ts index 9f8a34ac64..6664100cda 100644 --- a/components/theme/interface/components.ts +++ b/components/theme/interface/components.ts @@ -22,6 +22,7 @@ import type { ComponentToken as DropdownComponentToken } from '../../dropdown/st import type { ComponentToken as EmptyComponentToken } from '../../empty/style'; import type { ComponentToken as FloatButtonComponentToken } from '../../float-button/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 LayoutComponentToken } from '../../layout/style'; import type { ComponentToken as ListComponentToken } from '../../list/style'; @@ -84,7 +85,7 @@ export interface ComponentTokenMap { Form?: {}; Grid?: {}; Image?: ImageComponentToken; - Input?: {}; + Input?: InputComponentToken; InputNumber?: InputNumberComponentToken; Layout?: LayoutComponentToken; List?: ListComponentToken; diff --git a/components/typography/style/mixins.ts b/components/typography/style/mixins.ts index b905b08288..c11286227a 100644 --- a/components/typography/style/mixins.ts +++ b/components/typography/style/mixins.ts @@ -10,7 +10,6 @@ import { gold } from '@ant-design/colors'; import type { CSSObject } from '@ant-design/cssinjs'; import type { TypographyToken } from '.'; -import { initInputToken } from '../../input/style'; import { operationUnit } from '../../style'; import type { GenerateStyle } from '../../theme/internal'; @@ -187,10 +186,9 @@ export const getResetStyles: GenerateStyle = (token) }); export const getEditableStyles: GenerateStyle = (token) => { - const { componentCls } = token; + const { componentCls, paddingSM } = token; - const inputToken = initInputToken(token); - const inputShift = inputToken.inputPaddingVertical + 1; + const inputShift = paddingSM; return { '&-edit-content': { position: 'relative', diff --git a/docs/react/migrate-less-variables.en-US.md b/docs/react/migrate-less-variables.en-US.md index 2c2f5e6da5..363795fa3e 100644 --- a/docs/react/migrate-less-variables.en-US.md +++ b/docs/react/migrate-less-variables.en-US.md @@ -338,7 +338,43 @@ export default App; | `@image-preview-operation-color` | `previewOperationColor` | - | | `@image-preview-operation-disabled-color` | `previewOperationColorDisabled` | - | - +### Input + + +| 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 + + +| 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 diff --git a/docs/react/migrate-less-variables.zh-CN.md b/docs/react/migrate-less-variables.zh-CN.md index 77738aade6..6bb36f1ffd 100644 --- a/docs/react/migrate-less-variables.zh-CN.md +++ b/docs/react/migrate-less-variables.zh-CN.md @@ -335,7 +335,43 @@ export default App; | `@image-preview-operation-color` | `previewOperationColor` | - | | `@image-preview-operation-disabled-color` | `previewOperationColorDisabled` | - | - +### Input 输入框 + + +| 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 数字输入框 + + +| 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 布局