2022-06-24 11:11:42 +08:00
|
|
|
import type { CSSInterpolation, CSSObject } from '@ant-design/cssinjs';
|
2022-03-08 10:29:00 +08:00
|
|
|
import type { SelectToken } from '.';
|
2022-11-23 20:22:38 +08:00
|
|
|
import { mergeToken } from '../../theme/internal';
|
2022-07-11 15:35:58 +08:00
|
|
|
import { resetIcon } from '../../style';
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
const FIXED_ITEM_MARGIN = 2;
|
|
|
|
|
2022-03-22 13:26:29 +08:00
|
|
|
function getSelectItemStyle({
|
|
|
|
controlHeightSM,
|
|
|
|
controlHeight,
|
2022-11-01 15:06:38 +08:00
|
|
|
lineWidth: borderWidth,
|
2022-03-22 13:26:29 +08:00
|
|
|
}: SelectToken) {
|
2022-03-08 10:29:00 +08:00
|
|
|
const selectItemDist = (controlHeight - controlHeightSM) / 2 - borderWidth;
|
|
|
|
const selectItemMargin = Math.ceil(selectItemDist / 2);
|
|
|
|
return [selectItemDist, selectItemMargin];
|
|
|
|
}
|
|
|
|
|
|
|
|
function genSizeStyle(token: SelectToken, suffix?: string): CSSObject {
|
2022-04-07 12:20:34 +08:00
|
|
|
const { componentCls, iconCls } = token;
|
2022-03-08 10:29:00 +08:00
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
const selectOverflowPrefixCls = `${componentCls}-selection-overflow`;
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
const selectItemHeight = token.controlHeightSM;
|
|
|
|
const [selectItemDist] = getSelectItemStyle(token);
|
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
const suffixCls = suffix ? `${componentCls}-${suffix}` : '';
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
return {
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-multiple${suffixCls}`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
fontSize: token.fontSize,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Do not merge `height` & `line-height` under style with `selection` & `search`, since chrome
|
|
|
|
* may update to redesign with its align logic.
|
|
|
|
*/
|
|
|
|
// =========================== Overflow ===========================
|
|
|
|
[selectOverflowPrefixCls]: {
|
|
|
|
position: 'relative',
|
|
|
|
display: 'flex',
|
|
|
|
flex: 'auto',
|
|
|
|
flexWrap: 'wrap',
|
|
|
|
maxWidth: '100%',
|
|
|
|
|
|
|
|
'&-item': {
|
|
|
|
flex: 'none',
|
|
|
|
alignSelf: 'center',
|
|
|
|
maxWidth: '100%',
|
|
|
|
display: 'inline-flex',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// ========================= Selector =========================
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-selector`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
display: 'flex',
|
|
|
|
flexWrap: 'wrap',
|
|
|
|
alignItems: 'center',
|
|
|
|
// Multiple is little different that horizontal is follow the vertical
|
|
|
|
padding: `${selectItemDist - FIXED_ITEM_MARGIN}px ${FIXED_ITEM_MARGIN * 2}px`,
|
2022-11-01 15:06:38 +08:00
|
|
|
borderRadius: token.borderRadius,
|
2022-03-08 10:29:00 +08:00
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-show-search&`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
cursor: 'text',
|
|
|
|
},
|
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-disabled&`]: {
|
2022-06-28 20:33:01 +08:00
|
|
|
background: token.colorBgContainerDisabled,
|
2022-03-08 10:29:00 +08:00
|
|
|
cursor: 'not-allowed',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&:after': {
|
|
|
|
display: 'inline-block',
|
|
|
|
width: 0,
|
|
|
|
margin: `${FIXED_ITEM_MARGIN}px 0`,
|
|
|
|
lineHeight: `${selectItemHeight}px`,
|
|
|
|
content: '"\\a0"',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`
|
2022-04-07 12:20:34 +08:00
|
|
|
&${componentCls}-show-arrow ${componentCls}-selector,
|
|
|
|
&${componentCls}-allow-clear ${componentCls}-selector
|
2022-03-08 10:29:00 +08:00
|
|
|
`]: {
|
2022-03-29 15:57:39 +08:00
|
|
|
paddingInlineEnd: token.fontSizeIcon + token.controlPaddingHorizontal,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
// ======================== Selections ========================
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-selection-item`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
position: 'relative',
|
|
|
|
display: 'flex',
|
|
|
|
flex: 'none',
|
|
|
|
boxSizing: 'border-box',
|
|
|
|
maxWidth: '100%',
|
|
|
|
height: selectItemHeight,
|
|
|
|
marginTop: FIXED_ITEM_MARGIN,
|
|
|
|
marginBottom: FIXED_ITEM_MARGIN,
|
2022-11-01 15:06:38 +08:00
|
|
|
lineHeight: `${selectItemHeight - token.lineWidth * 2}px`,
|
2022-07-21 17:00:42 +08:00
|
|
|
background: token.colorFillSecondary,
|
2022-11-01 15:06:38 +08:00
|
|
|
border: `${token.lineWidth}px solid ${token.colorSplit}`,
|
|
|
|
borderRadius: token.borderRadiusSM,
|
2022-03-08 10:29:00 +08:00
|
|
|
cursor: 'default',
|
2022-03-22 20:02:04 +08:00
|
|
|
transition: `font-size ${token.motionDurationSlow}, line-height ${token.motionDurationSlow}, height ${token.motionDurationSlow}`,
|
2022-03-08 10:29:00 +08:00
|
|
|
userSelect: 'none',
|
|
|
|
marginInlineEnd: FIXED_ITEM_MARGIN * 2,
|
|
|
|
paddingInlineStart: token.paddingXS,
|
|
|
|
paddingInlineEnd: token.paddingXS / 2,
|
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-disabled&`]: {
|
2022-03-22 13:26:29 +08:00
|
|
|
color: token.colorTextDisabled,
|
|
|
|
borderColor: token.colorBorder,
|
2022-03-08 10:29:00 +08:00
|
|
|
cursor: 'not-allowed',
|
|
|
|
},
|
|
|
|
|
|
|
|
// It's ok not to do this, but 24px makes bottom narrow in view should adjust
|
|
|
|
'&-content': {
|
|
|
|
display: 'inline-block',
|
|
|
|
marginInlineEnd: token.paddingXS / 2,
|
|
|
|
overflow: 'hidden',
|
|
|
|
whiteSpace: 'pre', // fix whitespace wrapping. custom tags display all whitespace within.
|
|
|
|
textOverflow: 'ellipsis',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-remove': {
|
|
|
|
...resetIcon(),
|
|
|
|
|
|
|
|
display: 'inline-block',
|
2022-07-21 17:00:42 +08:00
|
|
|
color: token.colorIcon,
|
2022-03-08 10:29:00 +08:00
|
|
|
fontWeight: 'bold',
|
|
|
|
fontSize: 10,
|
|
|
|
lineHeight: 'inherit',
|
|
|
|
cursor: 'pointer',
|
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`> ${iconCls}`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
verticalAlign: '-0.2em',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&:hover': {
|
2022-07-21 17:00:42 +08:00
|
|
|
color: token.colorIconHover,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// ========================== Input ==========================
|
|
|
|
[`${selectOverflowPrefixCls}-item + ${selectOverflowPrefixCls}-item`]: {
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-selection-search`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
marginInlineStart: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-selection-search`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
display: 'inline-flex',
|
|
|
|
position: 'relative',
|
|
|
|
maxWidth: '100%',
|
|
|
|
marginInlineStart: token.inputPaddingHorizontalBase - selectItemDist,
|
|
|
|
|
|
|
|
[`
|
|
|
|
&-input,
|
|
|
|
&-mirror
|
|
|
|
`]: {
|
|
|
|
height: selectItemHeight,
|
|
|
|
fontFamily: token.fontFamily,
|
|
|
|
lineHeight: `${selectItemHeight}px`,
|
2022-03-22 20:02:04 +08:00
|
|
|
transition: `all ${token.motionDurationSlow}`,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
'&-input': {
|
|
|
|
width: '100%',
|
|
|
|
minWidth: 4.1, // fix search cursor missing
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-mirror': {
|
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
|
|
|
insetInlineStart: 0,
|
|
|
|
insetInlineEnd: 'auto',
|
|
|
|
zIndex: 999,
|
|
|
|
whiteSpace: 'pre', // fix whitespace wrapping caused width calculation bug
|
|
|
|
visibility: 'hidden',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// ======================= Placeholder =======================
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-selection-placeholder `]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
position: 'absolute',
|
|
|
|
top: '50%',
|
|
|
|
insetInlineStart: token.inputPaddingHorizontalBase,
|
|
|
|
insetInlineEnd: token.inputPaddingHorizontalBase,
|
|
|
|
transform: 'translateY(-50%)',
|
2022-03-22 20:02:04 +08:00
|
|
|
transition: `all ${token.motionDurationSlow}`,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function genMultipleStyle(token: SelectToken): CSSInterpolation {
|
2022-04-07 12:20:34 +08:00
|
|
|
const { componentCls } = token;
|
2022-03-08 10:29:00 +08:00
|
|
|
|
2022-04-11 16:04:00 +08:00
|
|
|
const smallToken = mergeToken<SelectToken>(token, {
|
2022-03-08 10:29:00 +08:00
|
|
|
controlHeight: token.controlHeightSM,
|
|
|
|
controlHeightSM: token.controlHeightXS,
|
2022-11-01 15:06:38 +08:00
|
|
|
borderRadius: token.borderRadiusSM,
|
|
|
|
borderRadiusSM: token.borderRadiusXS,
|
2022-04-11 16:04:00 +08:00
|
|
|
});
|
2022-03-08 10:29:00 +08:00
|
|
|
const [, smSelectItemMargin] = getSelectItemStyle(token);
|
|
|
|
|
|
|
|
return [
|
|
|
|
genSizeStyle(token),
|
|
|
|
// ======================== Small ========================
|
|
|
|
// Shared
|
|
|
|
genSizeStyle(smallToken, 'sm'),
|
|
|
|
|
|
|
|
// Padding
|
|
|
|
{
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-multiple${componentCls}-sm`]: {
|
|
|
|
[`${componentCls}-selection-placeholder`]: {
|
2023-01-31 16:53:49 +08:00
|
|
|
insetInline: token.controlPaddingHorizontalSM - token.lineWidth,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/29559
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-selection-search`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
marginInlineStart: smSelectItemMargin,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// ======================== Large ========================
|
|
|
|
// Shared
|
|
|
|
genSizeStyle(
|
2022-04-11 16:04:00 +08:00
|
|
|
mergeToken<any>(token, {
|
2022-03-08 10:29:00 +08:00
|
|
|
fontSize: token.fontSizeLG,
|
|
|
|
controlHeight: token.controlHeightLG,
|
|
|
|
controlHeightSM: token.controlHeight,
|
2022-11-01 15:06:38 +08:00
|
|
|
borderRadius: token.borderRadiusLG,
|
|
|
|
borderRadiusSM: token.borderRadius,
|
2022-04-11 16:04:00 +08:00
|
|
|
}),
|
2022-03-08 10:29:00 +08:00
|
|
|
'lg',
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|