2023-08-17 15:03:23 +08:00
|
|
|
|
import type { CSSProperties } from 'react';
|
2022-03-09 00:29:00 +08:00
|
|
|
|
import { getStyle as getCheckboxStyle } from '../../checkbox/style';
|
2022-10-28 16:44:19 +08:00
|
|
|
|
import { textEllipsis } from '../../style';
|
2022-10-28 16:09:38 +08:00
|
|
|
|
import { genCompactItemStyle } from '../../style/compact-item';
|
2023-07-05 17:49:59 +08:00
|
|
|
|
import type { FullToken, GenerateStyle } from '../../theme/internal';
|
|
|
|
|
import { genComponentStyleHook } from '../../theme/internal';
|
2022-03-09 00:29:00 +08:00
|
|
|
|
|
2022-03-29 15:57:39 +08:00
|
|
|
|
export interface ComponentToken {
|
2023-07-05 17:49:59 +08:00
|
|
|
|
/**
|
|
|
|
|
* @desc 选择器宽度
|
|
|
|
|
* @descEN Width of Cascader
|
|
|
|
|
*/
|
2022-03-29 15:57:39 +08:00
|
|
|
|
controlWidth: number;
|
2023-07-05 17:49:59 +08:00
|
|
|
|
/**
|
|
|
|
|
* @desc 选项宽度
|
|
|
|
|
* @descEN Width of item
|
|
|
|
|
*/
|
2022-03-29 15:57:39 +08:00
|
|
|
|
controlItemWidth: number;
|
2023-07-05 17:49:59 +08:00
|
|
|
|
/**
|
|
|
|
|
* @desc 下拉菜单高度
|
|
|
|
|
* @descEN Height of dropdown
|
|
|
|
|
*/
|
2022-03-29 15:57:39 +08:00
|
|
|
|
dropdownHeight: number;
|
2023-08-17 15:03:23 +08:00
|
|
|
|
/**
|
|
|
|
|
* @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'];
|
2022-03-29 15:57:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-02 22:55:02 +08:00
|
|
|
|
type CascaderToken = FullToken<'Cascader'>;
|
2022-03-09 00:29:00 +08:00
|
|
|
|
|
|
|
|
|
// =============================== Base ===============================
|
2022-11-17 23:31:41 +08:00
|
|
|
|
const genBaseStyle: GenerateStyle<CascaderToken> = (token) => {
|
2022-09-09 17:47:17 +08:00
|
|
|
|
const { prefixCls, componentCls, antCls } = token;
|
2022-04-02 22:55:02 +08:00
|
|
|
|
const cascaderMenuItemCls = `${componentCls}-menu-item`;
|
2022-03-09 00:29:00 +08:00
|
|
|
|
const iconCls = `
|
2022-03-29 15:57:39 +08:00
|
|
|
|
&${cascaderMenuItemCls}-expand ${cascaderMenuItemCls}-expand-icon,
|
2022-03-09 00:29:00 +08:00
|
|
|
|
${cascaderMenuItemCls}-loading-icon
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
// =====================================================
|
|
|
|
|
// == Control ==
|
|
|
|
|
// =====================================================
|
|
|
|
|
{
|
2022-04-02 22:55:02 +08:00
|
|
|
|
[componentCls]: {
|
2022-03-29 15:57:39 +08:00
|
|
|
|
width: token.controlWidth,
|
2022-03-09 00:29:00 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
// =====================================================
|
|
|
|
|
// == Popup ==
|
|
|
|
|
// =====================================================
|
|
|
|
|
{
|
2022-04-02 22:55:02 +08:00
|
|
|
|
[`${componentCls}-dropdown`]: [
|
2022-03-09 15:33:39 +08:00
|
|
|
|
// ==================== Checkbox ====================
|
2022-04-21 02:06:22 +08:00
|
|
|
|
getCheckboxStyle(`${prefixCls}-checkbox`, token),
|
2022-09-09 17:47:17 +08:00
|
|
|
|
{
|
|
|
|
|
[`&${antCls}-select-dropdown`]: {
|
|
|
|
|
padding: 0,
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-03-09 15:33:39 +08:00
|
|
|
|
{
|
2022-04-02 22:55:02 +08:00
|
|
|
|
[componentCls]: {
|
2022-03-09 15:33:39 +08:00
|
|
|
|
// ================== Checkbox ==================
|
|
|
|
|
'&-checkbox': {
|
|
|
|
|
top: 0,
|
|
|
|
|
marginInlineEnd: token.paddingXS,
|
2022-03-09 00:29:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
2022-03-09 15:33:39 +08:00
|
|
|
|
// ==================== Menu ====================
|
|
|
|
|
// >>> Menus
|
|
|
|
|
'&-menus': {
|
2022-03-09 00:29:00 +08:00
|
|
|
|
display: 'flex',
|
|
|
|
|
flexWrap: 'nowrap',
|
2022-03-09 15:33:39 +08:00
|
|
|
|
alignItems: 'flex-start',
|
|
|
|
|
|
2022-04-02 22:55:02 +08:00
|
|
|
|
[`&${componentCls}-menu-empty`]: {
|
|
|
|
|
[`${componentCls}-menu`]: {
|
2022-03-09 15:33:39 +08:00
|
|
|
|
width: '100%',
|
|
|
|
|
height: 'auto',
|
|
|
|
|
|
|
|
|
|
[cascaderMenuItemCls]: {
|
2022-03-22 13:26:29 +08:00
|
|
|
|
color: token.colorTextDisabled,
|
2022-03-09 15:33:39 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
2022-03-09 00:29:00 +08:00
|
|
|
|
},
|
2022-03-09 15:33:39 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// >>> Menu
|
|
|
|
|
'&-menu': {
|
2022-04-15 15:44:02 +08:00
|
|
|
|
flexGrow: 1,
|
2022-03-29 15:57:39 +08:00
|
|
|
|
minWidth: token.controlItemWidth,
|
|
|
|
|
height: token.dropdownHeight,
|
2022-12-09 17:10:31 +08:00
|
|
|
|
margin: 0,
|
2023-08-17 15:03:23 +08:00
|
|
|
|
padding: token.menuPadding,
|
2022-03-09 15:33:39 +08:00
|
|
|
|
overflow: 'auto',
|
|
|
|
|
verticalAlign: 'top',
|
|
|
|
|
listStyle: 'none',
|
|
|
|
|
'-ms-overflow-style': '-ms-autohiding-scrollbar', // https://github.com/ant-design/ant-design/issues/11857
|
|
|
|
|
|
2022-09-09 17:47:17 +08:00
|
|
|
|
'&:not(:last-child)': {
|
2022-11-01 15:06:38 +08:00
|
|
|
|
borderInlineEnd: `${token.lineWidth}px ${token.lineType} ${token.colorSplit}`,
|
2022-09-09 17:47:17 +08:00
|
|
|
|
},
|
|
|
|
|
|
2022-03-09 15:33:39 +08:00
|
|
|
|
'&-item': {
|
2022-10-28 16:44:19 +08:00
|
|
|
|
...textEllipsis,
|
2022-03-09 15:33:39 +08:00
|
|
|
|
display: 'flex',
|
|
|
|
|
flexWrap: 'nowrap',
|
|
|
|
|
alignItems: 'center',
|
2023-08-17 15:03:23 +08:00
|
|
|
|
padding: token.optionPadding,
|
2022-03-09 15:33:39 +08:00
|
|
|
|
lineHeight: token.lineHeight,
|
|
|
|
|
cursor: 'pointer',
|
2022-11-17 23:31:41 +08:00
|
|
|
|
transition: `all ${token.motionDurationMid}`,
|
2022-11-01 15:06:38 +08:00
|
|
|
|
borderRadius: token.borderRadiusSM,
|
2022-03-09 00:29:00 +08:00
|
|
|
|
|
|
|
|
|
'&:hover': {
|
2022-03-22 20:02:04 +08:00
|
|
|
|
background: token.controlItemBgHover,
|
2022-03-09 00:29:00 +08:00
|
|
|
|
},
|
2022-12-19 15:21:38 +08:00
|
|
|
|
'&-disabled': {
|
2022-03-22 13:26:29 +08:00
|
|
|
|
color: token.colorTextDisabled,
|
2022-03-09 15:33:39 +08:00
|
|
|
|
cursor: 'not-allowed',
|
|
|
|
|
|
|
|
|
|
'&:hover': {
|
|
|
|
|
background: 'transparent',
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
[iconCls]: {
|
2022-03-22 13:26:29 +08:00
|
|
|
|
color: token.colorTextDisabled,
|
2022-03-09 15:33:39 +08:00
|
|
|
|
},
|
2022-03-09 00:29:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
2022-03-09 15:33:39 +08:00
|
|
|
|
[`&-active:not(${cascaderMenuItemCls}-disabled)`]: {
|
|
|
|
|
[`&, &:hover`]: {
|
2023-08-17 15:03:23 +08:00
|
|
|
|
fontWeight: token.optionSelectedFontWeight,
|
|
|
|
|
backgroundColor: token.optionSelectedBg,
|
2022-03-09 15:33:39 +08:00
|
|
|
|
},
|
2022-03-09 00:29:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
2022-03-09 15:33:39 +08:00
|
|
|
|
'&-content': {
|
|
|
|
|
flex: 'auto',
|
|
|
|
|
},
|
2022-03-09 00:29:00 +08:00
|
|
|
|
|
2022-03-09 15:33:39 +08:00
|
|
|
|
[iconCls]: {
|
|
|
|
|
marginInlineStart: token.paddingXXS,
|
2022-08-04 16:16:50 +08:00
|
|
|
|
color: token.colorTextDescription,
|
2022-03-29 15:57:39 +08:00
|
|
|
|
fontSize: token.fontSizeIcon,
|
2022-03-09 15:33:39 +08:00
|
|
|
|
},
|
2022-03-09 00:29:00 +08:00
|
|
|
|
|
2022-03-09 15:33:39 +08:00
|
|
|
|
'&-keyword': {
|
2022-03-24 14:30:48 +08:00
|
|
|
|
color: token.colorHighlight,
|
2022-03-09 15:33:39 +08:00
|
|
|
|
},
|
2022-03-09 00:29:00 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-03-09 15:33:39 +08:00
|
|
|
|
],
|
2022-03-09 00:29:00 +08:00
|
|
|
|
},
|
|
|
|
|
// =====================================================
|
|
|
|
|
// == RTL ==
|
|
|
|
|
// =====================================================
|
|
|
|
|
{
|
2022-04-02 22:55:02 +08:00
|
|
|
|
[`${componentCls}-dropdown-rtl`]: {
|
2022-03-09 00:29:00 +08:00
|
|
|
|
direction: 'rtl',
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-12-12 16:36:46 +08:00
|
|
|
|
// =====================================================
|
|
|
|
|
// == Space Compact ==
|
|
|
|
|
// =====================================================
|
|
|
|
|
genCompactItemStyle(token),
|
2022-03-09 00:29:00 +08:00
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ============================== Export ==============================
|
2023-08-17 15:03:23 +08:00
|
|
|
|
export default genComponentStyleHook(
|
|
|
|
|
'Cascader',
|
|
|
|
|
(token) => [genBaseStyle(token)],
|
|
|
|
|
(token) => {
|
|
|
|
|
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,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
);
|