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

81 lines
2.2 KiB
TypeScript
Raw Normal View History

2024-01-11 14:43:16 +08:00
import { TinyColor } from '@ctrl/tinycolor';
import type { SharedComponentToken, SharedInputToken } from '../../input/style/token';
import { initComponentToken } from '../../input/style/token';
import type { FullToken, GetDefaultToken } from '../../theme/internal';
export interface ComponentToken extends SharedComponentToken {
/**
* @desc
* @descEN Width of input
*/
controlWidth: number;
/**
* @desc
* @descEN Width of control button
*/
handleWidth: number;
/**
* @desc
* @descEN Icon size of control button
*/
handleFontSize: number;
/**
* Default `auto`. Set `true` will always show the handle
* @desc
* @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;
/**
* @desc
* @descEN Background color of handle in filled variant
*/
filledHandleBg: string;
/**
* @internal
*/
handleOpacity: number;
}
export type InputNumberToken = FullToken<'InputNumber'> & SharedInputToken;
export const prepareComponentToken: GetDefaultToken<'InputNumber'> = (token) => {
const handleVisible = token.handleVisible ?? 'auto';
return {
...initComponentToken(token),
controlWidth: 90,
handleWidth: token.controlHeightSM - token.lineWidth * 2,
handleFontSize: token.fontSize / 2,
handleVisible,
handleActiveBg: token.colorFillAlter,
handleBg: token.colorBgContainer,
filledHandleBg: new TinyColor(token.colorFillSecondary)
.onBackground(token.colorBgContainer)
.toHexString(),
handleHoverColor: token.colorPrimary,
handleBorderColor: token.colorBorder,
handleOpacity: handleVisible === true ? 1 : 0,
};
};