ant-design/components/cascader/style/index.ts

112 lines
3.2 KiB
TypeScript
Raw Normal View History

import type { CSSProperties } from 'react';
import { genCompactItemStyle } from '../../style/compact-item';
import type { GlobalToken } from '../../theme';
import type { FullToken, GenerateStyle } from '../../theme/internal';
import { genComponentStyleHook } from '../../theme/internal';
import getColumnsStyle from './columns';
2022-03-09 00:29:00 +08:00
export interface ComponentToken {
/**
* @desc
* @descEN Width of Cascader
*/
controlWidth: number;
/**
* @desc
* @descEN Width of item
*/
controlItemWidth: number;
/**
* @desc
* @descEN Height of dropdown
*/
dropdownHeight: number;
/**
* @desc
* @descEN Background color of selected item
*/
optionSelectedBg: string;
/**
* @desc
* @descEN Font weight of selected item
*/
optionSelectedFontWeight: CSSProperties['fontWeight'];
/**
* @desc
* @descEN Padding of menu item
*/
optionPadding: CSSProperties['padding'];
/**
* @desc
* @descEN Padding of menu item (single column)
*/
menuPadding: CSSProperties['padding'];
}
export type CascaderToken = FullToken<'Cascader'>;
2022-03-09 00:29:00 +08:00
// =============================== Base ===============================
const genBaseStyle: GenerateStyle<CascaderToken> = (token) => {
const { componentCls, antCls } = token;
2022-03-09 00:29:00 +08:00
return [
// =====================================================
// == Control ==
// =====================================================
{
[componentCls]: {
width: token.controlWidth,
2022-03-09 00:29:00 +08:00
},
},
// =====================================================
// == Popup ==
// =====================================================
{
[`${componentCls}-dropdown`]: [
{
[`&${antCls}-select-dropdown`]: {
padding: 0,
},
},
getColumnsStyle(token),
],
2022-03-09 00:29:00 +08:00
},
// =====================================================
// == RTL ==
// =====================================================
{
[`${componentCls}-dropdown-rtl`]: {
2022-03-09 00:29:00 +08:00
direction: 'rtl',
},
},
// =====================================================
// == Space Compact ==
// =====================================================
genCompactItemStyle(token),
2022-03-09 00:29:00 +08:00
];
};
// ============================== Export ==============================
export const prepareComponentToken = (token: GlobalToken) => {
const itemPaddingVertical = Math.round(
(token.controlHeight - token.fontSize * token.lineHeight) / 2,
);
return {
controlWidth: 184,
controlItemWidth: 111,
dropdownHeight: 180,
optionSelectedBg: token.controlItemBgActive,
optionSelectedFontWeight: token.fontWeightStrong,
optionPadding: `${itemPaddingVertical}px ${token.paddingSM}px`,
menuPadding: token.paddingXXS,
};
};
export default genComponentStyleHook(
'Cascader',
(token) => [genBaseStyle(token)],
prepareComponentToken,
);