ant-design/components/input/style/token.ts

156 lines
4.0 KiB
TypeScript
Raw Normal View History

import { mergeToken } from '../../theme/internal';
import type { AliasToken, FullToken } from '../../theme/internal';
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;
/**
* @desc
* @descEN Box-shadow when active
*/
activeShadow: string;
/**
* @desc
* @descEN Box-shadow when active in error status
*/
errorActiveShadow: string;
/**
* @desc
* @descEN Box-shadow when active in warning status
*/
warningActiveShadow: string;
/**
* @desc hover状态时背景颜色
* @descEN Background color when the input box hovers
*/
hoverBg: string;
/**
* @desc
* @descEN Background color when the input box is activated
*/
activeBg: string;
/**
* @desc
* @descEN Font size
*/
inputFontSize: number;
/**
* @desc
* @descEN Font size of large
*/
inputFontSizeLG: number;
/**
* @desc
* @descEN Font size of small
*/
inputFontSizeSM: number;
}
export interface ComponentToken extends SharedComponentToken {}
export interface SharedInputToken {
inputAffixPadding: number;
}
export interface InputToken extends FullToken<'Input'>, SharedInputToken {}
export function initInputToken(token: AliasToken): SharedInputToken {
return mergeToken<InputToken>(token, {
inputAffixPadding: token.paddingXXS,
});
}
export const initComponentToken = (token: AliasToken): SharedComponentToken => {
const {
controlHeight,
fontSize,
lineHeight,
lineWidth,
controlHeightSM,
controlHeightLG,
fontSizeLG,
lineHeightLG,
paddingSM,
controlPaddingHorizontalSM,
controlPaddingHorizontal,
colorFillAlter,
colorPrimaryHover,
colorPrimary,
controlOutlineWidth,
controlOutline,
colorErrorOutline,
colorWarningOutline,
2024-01-12 16:31:59 +08:00
colorBgContainer,
} = token;
return {
paddingBlock: Math.max(
Math.round(((controlHeight - fontSize * lineHeight) / 2) * 10) / 10 - lineWidth,
0,
),
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: colorPrimary,
hoverBorderColor: colorPrimaryHover,
activeShadow: `0 0 0 ${controlOutlineWidth}px ${controlOutline}`,
errorActiveShadow: `0 0 0 ${controlOutlineWidth}px ${colorErrorOutline}`,
warningActiveShadow: `0 0 0 ${controlOutlineWidth}px ${colorWarningOutline}`,
2024-01-12 16:31:59 +08:00
hoverBg: colorBgContainer,
activeBg: colorBgContainer,
inputFontSize: fontSize,
inputFontSizeLG: fontSizeLG,
inputFontSizeSM: fontSize,
};
};