2022-05-09 22:20:07 +08:00
|
|
|
import type { CSSObject } from '@ant-design/cssinjs';
|
2022-06-17 18:47:47 +08:00
|
|
|
import type { SelectToken } from '.';
|
2022-03-08 10:29:00 +08:00
|
|
|
import {
|
2022-06-21 00:34:51 +08:00
|
|
|
initMoveMotion,
|
2022-03-08 10:29:00 +08:00
|
|
|
initSlideMotion,
|
|
|
|
slideDownIn,
|
|
|
|
slideDownOut,
|
2022-06-17 18:47:47 +08:00
|
|
|
slideUpIn,
|
|
|
|
slideUpOut,
|
2022-04-21 17:28:02 +08:00
|
|
|
} from '../../style/motion';
|
2022-06-27 14:25:59 +08:00
|
|
|
import type { GenerateStyle } from '../../theme';
|
|
|
|
import { resetComponent } from '../../theme';
|
2022-03-08 10:29:00 +08:00
|
|
|
|
2022-03-11 14:29:29 +08:00
|
|
|
const genItemStyle: GenerateStyle<SelectToken, CSSObject> = token => {
|
2022-03-08 10:29:00 +08:00
|
|
|
const { controlPaddingHorizontal } = token;
|
|
|
|
|
|
|
|
return {
|
|
|
|
position: 'relative',
|
|
|
|
display: 'block',
|
|
|
|
minHeight: token.controlHeight,
|
|
|
|
padding: `${
|
|
|
|
(token.controlHeight - token.fontSize * token.lineHeight) / 2
|
|
|
|
}px ${controlPaddingHorizontal}px`,
|
2022-03-22 09:37:37 +08:00
|
|
|
color: token.colorText,
|
2022-03-08 10:29:00 +08:00
|
|
|
fontWeight: 'normal',
|
|
|
|
fontSize: token.fontSize,
|
|
|
|
lineHeight: token.lineHeight,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-04-21 02:06:22 +08:00
|
|
|
const genSingleStyle: GenerateStyle<SelectToken> = token => {
|
2022-06-21 00:34:51 +08:00
|
|
|
const { antCls, componentCls } = token;
|
2022-03-08 10:29:00 +08:00
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
const selectItemCls = `${componentCls}-item`;
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-dropdown`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
// ========================== Popup ==========================
|
|
|
|
...resetComponent(token),
|
|
|
|
|
|
|
|
position: 'absolute',
|
|
|
|
top: -9999,
|
2022-05-10 17:30:01 +08:00
|
|
|
zIndex: token.zIndexPopup,
|
2022-03-08 10:29:00 +08:00
|
|
|
boxSizing: 'border-box',
|
|
|
|
padding: `${token.paddingXXS}px 0`,
|
|
|
|
overflow: 'hidden',
|
|
|
|
fontSize: token.fontSize,
|
|
|
|
// Fix select render lag of long text in chrome
|
|
|
|
// https://github.com/ant-design/ant-design/issues/11456
|
|
|
|
// https://github.com/ant-design/ant-design/issues/11843
|
|
|
|
fontVariant: 'initial',
|
2022-06-17 18:47:47 +08:00
|
|
|
backgroundColor: token.colorBgElevated,
|
2022-03-22 13:26:29 +08:00
|
|
|
borderRadius: token.controlRadius,
|
2022-03-08 10:29:00 +08:00
|
|
|
outline: 'none',
|
|
|
|
boxShadow: token.boxShadow,
|
|
|
|
|
|
|
|
[`
|
|
|
|
&${antCls}-slide-up-enter${antCls}-slide-up-enter-active&-placement-bottomLeft,
|
|
|
|
&${antCls}-slide-up-appear${antCls}-slide-up-appear-active&-placement-bottomLeft
|
|
|
|
`]: {
|
2022-04-21 02:06:22 +08:00
|
|
|
animationName: slideUpIn,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`
|
|
|
|
&${antCls}-slide-up-enter${antCls}-slide-up-enter-active&-placement-topLeft,
|
|
|
|
&${antCls}-slide-up-appear${antCls}-slide-up-appear-active&-placement-topLeft
|
|
|
|
`]: {
|
2022-04-21 02:06:22 +08:00
|
|
|
animationName: slideDownIn,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`&${antCls}-slide-up-leave${antCls}-slide-up-leave-active&-placement-bottomLeft`]: {
|
2022-04-21 02:06:22 +08:00
|
|
|
animationName: slideUpOut,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`&${antCls}-slide-up-leave${antCls}-slide-up-leave-active&-placement-topLeft`]: {
|
2022-04-21 02:06:22 +08:00
|
|
|
animationName: slideDownOut,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
'&-hidden': {
|
|
|
|
display: 'none',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-empty': {
|
2022-03-22 13:26:29 +08:00
|
|
|
color: token.colorTextDisabled,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
// ========================= Options =========================
|
|
|
|
[`${selectItemCls}-empty`]: {
|
|
|
|
...genItemStyle(token),
|
2022-03-22 13:26:29 +08:00
|
|
|
color: token.colorTextDisabled,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`${selectItemCls}`]: {
|
|
|
|
...genItemStyle(token),
|
|
|
|
cursor: 'pointer',
|
2022-03-22 20:02:04 +08:00
|
|
|
transition: `background ${token.motionDurationSlow} ease`,
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
// =========== Group ============
|
|
|
|
'&-group': {
|
2022-03-22 13:26:29 +08:00
|
|
|
color: token.colorTextSecondary,
|
2022-03-08 10:29:00 +08:00
|
|
|
fontSize: token.fontSizeSM,
|
|
|
|
cursor: 'default',
|
|
|
|
},
|
|
|
|
|
|
|
|
// =========== Option ===========
|
|
|
|
'&-option': {
|
|
|
|
display: 'flex',
|
|
|
|
|
|
|
|
'&-content': {
|
|
|
|
flex: 'auto',
|
|
|
|
overflow: 'hidden',
|
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
textOverflow: 'ellipsis',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-state': {
|
|
|
|
flex: 'none',
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&-active:not(${selectItemCls}-option-disabled)`]: {
|
2022-03-22 20:02:04 +08:00
|
|
|
backgroundColor: token.controlItemBgHover,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`&-selected:not(${selectItemCls}-option-disabled)`]: {
|
2022-03-22 09:37:37 +08:00
|
|
|
color: token.colorText,
|
2022-03-25 17:54:57 +08:00
|
|
|
fontWeight: token.fontWeightStrong,
|
2022-03-22 20:02:04 +08:00
|
|
|
backgroundColor: token.controlItemBgActive,
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
[`${selectItemCls}-option-state`]: {
|
2022-03-22 09:37:37 +08:00
|
|
|
color: token.colorPrimary,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
'&-disabled': {
|
|
|
|
[`&${selectItemCls}-option-selected`]: {
|
2022-03-22 20:02:04 +08:00
|
|
|
backgroundColor: token.colorBgComponentDisabled,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
|
2022-03-22 13:26:29 +08:00
|
|
|
color: token.colorTextDisabled,
|
2022-03-08 10:29:00 +08:00
|
|
|
cursor: 'not-allowed',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-grouped': {
|
|
|
|
paddingInlineStart: token.controlPaddingHorizontal * 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// =========================== RTL ===========================
|
|
|
|
'&-rtl': {
|
|
|
|
direction: 'rtl',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// Follow code may reuse in other components
|
2022-06-21 00:34:51 +08:00
|
|
|
initSlideMotion(token, 'slide-up'),
|
|
|
|
initSlideMotion(token, 'slide-down'),
|
|
|
|
initMoveMotion(token, 'move-up'),
|
|
|
|
initMoveMotion(token, 'move-down'),
|
2022-03-08 10:29:00 +08:00
|
|
|
];
|
2022-03-11 14:29:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default genSingleStyle;
|