2022-05-09 22:20:07 +08:00
|
|
|
import type { CSSObject } from '@ant-design/cssinjs';
|
2022-06-27 14:25:59 +08:00
|
|
|
import type { FullToken, GenerateStyle } from '../../theme';
|
2022-07-11 15:35:58 +08:00
|
|
|
import { genComponentStyleHook, mergeToken } from '../../theme';
|
2022-03-08 10:29:00 +08:00
|
|
|
import genDropdownStyle from './dropdown';
|
2022-06-17 18:47:47 +08:00
|
|
|
import genMultipleStyle from './multiple';
|
|
|
|
import genSingleStyle from './single';
|
2022-07-11 15:35:58 +08:00
|
|
|
import { resetComponent, resetIcon } from '../../style';
|
2022-03-08 10:29:00 +08:00
|
|
|
|
2022-03-29 15:57:39 +08:00
|
|
|
export interface ComponentToken {
|
2022-05-10 17:30:01 +08:00
|
|
|
zIndexPopup: number;
|
2022-03-29 15:57:39 +08:00
|
|
|
}
|
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
export interface SelectToken extends FullToken<'Select'> {
|
2022-03-08 10:29:00 +08:00
|
|
|
rootPrefixCls: string;
|
|
|
|
inputPaddingHorizontalBase: number;
|
2022-03-29 15:57:39 +08:00
|
|
|
}
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
// ============================= Selector =============================
|
2022-03-11 14:29:29 +08:00
|
|
|
const genSelectorStyle: GenerateStyle<SelectToken, CSSObject> = token => {
|
2022-04-07 12:20:34 +08:00
|
|
|
const { componentCls } = token;
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
position: 'relative',
|
2022-06-28 20:33:01 +08:00
|
|
|
backgroundColor: token.colorBgContainer,
|
2022-03-22 13:26:29 +08:00
|
|
|
border: `${token.controlLineWidth}px ${token.controlLineType} ${token.colorBorder}`,
|
|
|
|
borderRadius: token.controlRadius,
|
2022-03-22 20:02:04 +08:00
|
|
|
transition: `all ${token.motionDurationSlow} ${token.motionEaseInOut}`,
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
input: {
|
|
|
|
cursor: 'pointer',
|
|
|
|
},
|
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-show-search&`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
cursor: 'text',
|
|
|
|
|
|
|
|
input: {
|
|
|
|
cursor: 'auto',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-disabled&`]: {
|
2022-03-22 13:26:29 +08:00
|
|
|
color: token.colorTextDisabled,
|
2022-06-28 20:33:01 +08:00
|
|
|
background: token.colorBgContainerDisabled,
|
2022-03-08 10:29:00 +08:00
|
|
|
cursor: 'not-allowed',
|
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-multiple&`]: {
|
2022-06-28 20:33:01 +08:00
|
|
|
background: token.colorBgContainerDisabled,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
input: {
|
|
|
|
cursor: 'not-allowed',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// ============================== Status ==============================
|
|
|
|
const genStatusStyle = (
|
|
|
|
rootSelectCls: string,
|
|
|
|
token: {
|
2022-04-07 12:20:34 +08:00
|
|
|
componentCls: string;
|
2022-03-08 10:29:00 +08:00
|
|
|
borderHoverColor: string;
|
|
|
|
outlineColor: string;
|
2022-03-22 13:26:29 +08:00
|
|
|
controlOutlineWidth: number;
|
|
|
|
controlLineWidth: number;
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
overwriteDefaultBorder: boolean = false,
|
|
|
|
): CSSObject => {
|
2022-04-07 12:20:34 +08:00
|
|
|
const { componentCls, borderHoverColor, outlineColor } = token;
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
const overwriteStyle: CSSObject = overwriteDefaultBorder
|
|
|
|
? {
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-selector`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
borderColor: borderHoverColor,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
: {};
|
|
|
|
|
|
|
|
return {
|
|
|
|
[rootSelectCls]: {
|
2022-04-07 12:20:34 +08:00
|
|
|
[`&:not(${componentCls}-disabled):not(${componentCls}-customize-input)`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
...overwriteStyle,
|
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-focused& ${componentCls}-selector`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
borderColor: borderHoverColor,
|
2022-03-22 13:26:29 +08:00
|
|
|
boxShadow: `0 0 0 ${token.controlOutlineWidth}px ${outlineColor}`,
|
|
|
|
borderInlineEndWidth: `${token.controlLineWidth}px !important`,
|
2022-03-08 10:29:00 +08:00
|
|
|
outline: 0,
|
|
|
|
},
|
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`&:hover ${componentCls}-selector`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
borderColor: borderHoverColor,
|
2022-03-22 13:26:29 +08:00
|
|
|
borderInlineEndWidth: `${token.controlLineWidth}px !important`,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// ============================== Styles ==============================
|
|
|
|
// /* Reset search input style */
|
2022-03-11 14:29:29 +08:00
|
|
|
const getSearchInputWithoutBorderStyle: GenerateStyle<SelectToken, CSSObject> = token => {
|
2022-04-07 12:20:34 +08:00
|
|
|
const { componentCls } = token;
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
return {
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-selection-search-input`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
margin: 0,
|
|
|
|
padding: 0,
|
|
|
|
background: 'transparent',
|
|
|
|
border: 'none',
|
|
|
|
outline: 'none',
|
|
|
|
appearance: 'none',
|
|
|
|
|
|
|
|
'&::-webkit-search-cancel-button': {
|
|
|
|
display: 'none',
|
|
|
|
'-webkit-appearance': 'none',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// =============================== Base ===============================
|
2022-03-11 14:29:29 +08:00
|
|
|
const genBaseStyle: GenerateStyle<SelectToken> = token => {
|
2022-04-07 12:20:34 +08:00
|
|
|
const { componentCls, inputPaddingHorizontalBase, iconCls } = token;
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
return {
|
2022-04-07 12:20:34 +08:00
|
|
|
[componentCls]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
...resetComponent(token),
|
|
|
|
position: 'relative',
|
|
|
|
display: 'inline-block',
|
|
|
|
cursor: 'pointer',
|
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`&:not(&-customize-input) ${componentCls}-selector`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
...genSelectorStyle(token),
|
|
|
|
...getSearchInputWithoutBorderStyle(token),
|
|
|
|
},
|
|
|
|
|
|
|
|
// [`&:not(&-disabled):hover ${selectCls}-selector`]: {
|
|
|
|
// ...genHoverStyle(token),
|
|
|
|
// },
|
|
|
|
|
|
|
|
// ======================== Selection ========================
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-selection-item`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
flex: 1,
|
|
|
|
overflow: 'hidden',
|
|
|
|
fontWeight: 'normal',
|
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
textOverflow: 'ellipsis',
|
|
|
|
},
|
|
|
|
|
|
|
|
// ======================= Placeholder =======================
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-selection-placeholder`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
flex: 1,
|
|
|
|
overflow: 'hidden',
|
2022-06-17 18:47:47 +08:00
|
|
|
color: token.colorTextPlaceholder,
|
2022-03-08 10:29:00 +08:00
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
textOverflow: 'ellipsis',
|
|
|
|
pointerEvents: 'none',
|
|
|
|
},
|
|
|
|
|
|
|
|
// ========================== Arrow ==========================
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-arrow`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
...resetIcon(),
|
|
|
|
position: 'absolute',
|
|
|
|
top: '50%',
|
|
|
|
insetInlineStart: 'auto',
|
|
|
|
insetInlineEnd: inputPaddingHorizontalBase,
|
2022-03-29 15:57:39 +08:00
|
|
|
height: token.fontSizeIcon,
|
|
|
|
marginTop: -token.fontSizeIcon / 2,
|
2022-03-22 13:26:29 +08:00
|
|
|
color: token.colorTextDisabled,
|
2022-03-29 15:57:39 +08:00
|
|
|
fontSize: token.fontSizeIcon,
|
2022-03-08 10:29:00 +08:00
|
|
|
lineHeight: 1,
|
|
|
|
textAlign: 'center',
|
|
|
|
pointerEvents: 'none',
|
2022-03-25 20:08:05 +08:00
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
2022-03-08 10:29:00 +08:00
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[iconCls]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
verticalAlign: 'top',
|
2022-03-22 20:02:04 +08:00
|
|
|
transition: `transform ${token.motionDurationSlow}`,
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
'> svg': {
|
|
|
|
verticalAlign: 'top',
|
|
|
|
},
|
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`&:not(${componentCls}-suffix)`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
pointerEvents: 'auto',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-disabled &`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
cursor: 'not-allowed',
|
|
|
|
},
|
2022-03-25 20:08:05 +08:00
|
|
|
|
|
|
|
'> *:not(:last-child)': {
|
|
|
|
marginInlineEnd: 8, // FIXME: magic
|
|
|
|
},
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
// ========================== Clear ==========================
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-clear`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
position: 'absolute',
|
|
|
|
top: '50%',
|
|
|
|
insetInlineStart: 'auto',
|
|
|
|
insetInlineEnd: inputPaddingHorizontalBase,
|
|
|
|
zIndex: 1,
|
|
|
|
display: 'inline-block',
|
2022-03-29 15:57:39 +08:00
|
|
|
width: token.fontSizeIcon,
|
|
|
|
height: token.fontSizeIcon,
|
|
|
|
marginTop: -token.fontSizeIcon / 2,
|
2022-03-22 13:26:29 +08:00
|
|
|
color: token.colorTextDisabled,
|
2022-03-29 15:57:39 +08:00
|
|
|
fontSize: token.fontSizeIcon,
|
2022-03-08 10:29:00 +08:00
|
|
|
fontStyle: 'normal',
|
|
|
|
lineHeight: 1,
|
|
|
|
textAlign: 'center',
|
|
|
|
textTransform: 'none',
|
2022-06-28 20:33:01 +08:00
|
|
|
background: token.colorBgContainer,
|
2022-03-08 10:29:00 +08:00
|
|
|
cursor: 'pointer',
|
|
|
|
opacity: 0,
|
2022-03-22 20:02:04 +08:00
|
|
|
transition: `color ${token.motionDurationSlow} ease, opacity ${token.motionDurationSlow} ease`,
|
2022-03-08 10:29:00 +08:00
|
|
|
textRendering: 'auto',
|
|
|
|
|
|
|
|
'&:before': {
|
|
|
|
display: 'block',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&:hover': {
|
2022-08-04 16:16:50 +08:00
|
|
|
color: token.colorTextDescription,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
2022-03-25 17:54:57 +08:00
|
|
|
},
|
2022-03-08 10:29:00 +08:00
|
|
|
|
2022-03-25 17:54:57 +08:00
|
|
|
'&:hover': {
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-clear`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
opacity: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// ========================= Feedback ==========================
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-has-feedback`]: {
|
|
|
|
[`${componentCls}-clear`]: {
|
2022-03-25 17:54:57 +08:00
|
|
|
insetInlineEnd: inputPaddingHorizontalBase + token.fontSize + token.paddingXXS,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// ============================== Styles ==============================
|
2022-04-21 02:06:22 +08:00
|
|
|
const genSelectStyle: GenerateStyle<SelectToken> = token => {
|
2022-04-07 12:20:34 +08:00
|
|
|
const { componentCls } = token;
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
2022-04-07 12:20:34 +08:00
|
|
|
[componentCls]: {
|
2022-03-24 22:58:40 +08:00
|
|
|
// ==================== BorderLess ====================
|
2022-04-07 12:20:34 +08:00
|
|
|
[`&-borderless ${componentCls}-selector`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
backgroundColor: `transparent !important`,
|
|
|
|
borderColor: `transparent !important`,
|
|
|
|
boxShadow: `none !important`,
|
|
|
|
},
|
2022-03-24 22:58:40 +08:00
|
|
|
|
|
|
|
// ==================== In Form ====================
|
|
|
|
'&&-in-form-item': {
|
|
|
|
width: '100%',
|
|
|
|
},
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// == LTR ==
|
|
|
|
// =====================================================
|
|
|
|
// Base
|
2022-03-29 15:57:39 +08:00
|
|
|
genBaseStyle(token),
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
// Single
|
2022-03-29 15:57:39 +08:00
|
|
|
genSingleStyle(token),
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
// Multiple
|
2022-03-29 15:57:39 +08:00
|
|
|
genMultipleStyle(token),
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
// Dropdown
|
2022-04-21 02:06:22 +08:00
|
|
|
genDropdownStyle(token),
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// == RTL ==
|
|
|
|
// =====================================================
|
|
|
|
{
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-rtl`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
direction: 'rtl',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// == Status ==
|
|
|
|
// =====================================================
|
2022-04-11 16:04:00 +08:00
|
|
|
genStatusStyle(
|
|
|
|
componentCls,
|
|
|
|
mergeToken<any>(token, {
|
|
|
|
borderHoverColor: token.colorPrimaryHover,
|
2022-07-21 17:00:42 +08:00
|
|
|
outlineColor: token.controlOutline,
|
2022-04-11 16:04:00 +08:00
|
|
|
}),
|
|
|
|
),
|
2022-03-08 10:29:00 +08:00
|
|
|
genStatusStyle(
|
2022-04-07 12:20:34 +08:00
|
|
|
`${componentCls}-status-error`,
|
2022-04-11 16:04:00 +08:00
|
|
|
mergeToken<any>(token, {
|
2022-03-22 20:02:04 +08:00
|
|
|
borderHoverColor: token.colorErrorHover,
|
|
|
|
outlineColor: token.colorErrorOutline,
|
2022-04-11 16:04:00 +08:00
|
|
|
}),
|
2022-03-08 10:29:00 +08:00
|
|
|
true,
|
|
|
|
),
|
|
|
|
genStatusStyle(
|
2022-04-07 12:20:34 +08:00
|
|
|
`${componentCls}-status-warning`,
|
2022-04-11 16:04:00 +08:00
|
|
|
mergeToken<any>(token, {
|
2022-03-22 20:02:04 +08:00
|
|
|
borderHoverColor: token.colorWarningHover,
|
|
|
|
outlineColor: token.colorWarningOutline,
|
2022-04-11 16:04:00 +08:00
|
|
|
}),
|
2022-03-08 10:29:00 +08:00
|
|
|
true,
|
|
|
|
),
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
// ============================== Export ==============================
|
2022-04-07 12:20:34 +08:00
|
|
|
export default genComponentStyleHook(
|
|
|
|
'Select',
|
2022-04-21 02:06:22 +08:00
|
|
|
(token, { rootPrefixCls }) => {
|
2022-04-11 16:04:00 +08:00
|
|
|
const selectToken: SelectToken = mergeToken<SelectToken>(token, {
|
2022-04-07 12:20:34 +08:00
|
|
|
rootPrefixCls,
|
|
|
|
inputPaddingHorizontalBase: token.controlPaddingHorizontal - 1,
|
2022-04-11 16:04:00 +08:00
|
|
|
});
|
2022-03-29 15:57:39 +08:00
|
|
|
|
2022-04-21 02:06:22 +08:00
|
|
|
return [genSelectStyle(selectToken)];
|
2022-04-07 12:20:34 +08:00
|
|
|
},
|
|
|
|
token => ({
|
2022-05-10 17:30:01 +08:00
|
|
|
zIndexPopup: token.zIndexPopupBase + 50,
|
2022-04-07 12:20:34 +08:00
|
|
|
}),
|
|
|
|
);
|