2022-06-24 11:11:42 +08:00
|
|
|
import type { CSSInterpolation, CSSObject } from '@ant-design/cssinjs';
|
2023-11-09 09:35:45 +08:00
|
|
|
import { unit } from '@ant-design/cssinjs';
|
2022-03-08 10:29:00 +08:00
|
|
|
|
2024-01-15 15:41:40 +08:00
|
|
|
import { resetIcon } from '../../style';
|
|
|
|
import { mergeToken, type AliasToken } from '../../theme/internal';
|
|
|
|
import type { TokenWithCommonCls } from '../../theme/util/genComponentStyleHook';
|
|
|
|
import type { SelectToken } from './token';
|
|
|
|
|
2022-03-08 10:29:00 +08:00
|
|
|
const FIXED_ITEM_MARGIN = 2;
|
|
|
|
|
2024-01-15 15:41:40 +08:00
|
|
|
type SelectItemToken = Pick<
|
|
|
|
SelectToken,
|
|
|
|
| 'multipleSelectItemHeight'
|
|
|
|
| 'multipleSelectorBgDisabled'
|
|
|
|
| 'multipleItemColorDisabled'
|
|
|
|
| 'multipleItemBorderColorDisabled'
|
|
|
|
| 'selectHeight'
|
|
|
|
| 'lineWidth'
|
|
|
|
| 'calc'
|
|
|
|
| 'inputPaddingHorizontalBase'
|
|
|
|
>;
|
|
|
|
|
|
|
|
const getSelectItemStyle = (token: SelectItemToken): number | string => {
|
2023-11-09 09:35:45 +08:00
|
|
|
const { multipleSelectItemHeight, selectHeight, lineWidth } = token;
|
|
|
|
const selectItemDist = token
|
|
|
|
.calc(selectHeight)
|
|
|
|
.sub(multipleSelectItemHeight)
|
|
|
|
.div(2)
|
|
|
|
.sub(lineWidth)
|
|
|
|
.equal();
|
|
|
|
return selectItemDist;
|
2023-04-07 10:18:16 +08:00
|
|
|
};
|
2022-03-08 10:29:00 +08:00
|
|
|
|
2024-01-15 15:41:40 +08:00
|
|
|
export const genSelectionStyle = (
|
|
|
|
token: TokenWithCommonCls<AliasToken> & SelectItemToken,
|
|
|
|
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
|
|
|
|
2023-08-15 17:05:06 +08:00
|
|
|
const selectItemHeight = token.multipleSelectItemHeight;
|
2023-11-09 09:35:45 +08:00
|
|
|
const selectItemDist = getSelectItemStyle(token);
|
2022-03-08 10:29:00 +08:00
|
|
|
|
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}`]: {
|
2024-01-15 15:41:40 +08:00
|
|
|
// fontSize: token.fontSize,
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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',
|
2023-09-11 16:05:26 +08:00
|
|
|
height: '100%',
|
2022-03-08 10:29:00 +08:00
|
|
|
// Multiple is little different that horizontal is follow the vertical
|
2023-12-13 17:31:36 +08:00
|
|
|
paddingInline: token.calc(FIXED_ITEM_MARGIN).mul(2).equal(),
|
|
|
|
paddingBlock: token.calc(selectItemDist).sub(FIXED_ITEM_MARGIN).equal(),
|
2022-11-01 15:06:38 +08:00
|
|
|
borderRadius: token.borderRadius,
|
2022-03-08 10:29:00 +08:00
|
|
|
|
2024-01-15 15:41:40 +08:00
|
|
|
// [`${componentCls}-show-search&`]: {
|
|
|
|
// cursor: 'text',
|
|
|
|
// },
|
2022-03-08 10:29:00 +08:00
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-disabled&`]: {
|
2023-08-15 17:05:06 +08:00
|
|
|
background: token.multipleSelectorBgDisabled,
|
2022-03-08 10:29:00 +08:00
|
|
|
cursor: 'not-allowed',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&:after': {
|
|
|
|
display: 'inline-block',
|
|
|
|
width: 0,
|
2023-11-09 09:35:45 +08:00
|
|
|
margin: `${unit(FIXED_ITEM_MARGIN)} 0`,
|
|
|
|
lineHeight: unit(selectItemHeight),
|
2023-05-26 17:47:57 +08:00
|
|
|
visibility: 'hidden',
|
2022-03-08 10:29:00 +08:00
|
|
|
content: '"\\a0"',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2024-01-15 15:41:40 +08:00
|
|
|
// [`
|
|
|
|
// &${componentCls}-show-arrow ${componentCls}-selector,
|
|
|
|
// &${componentCls}-allow-clear ${componentCls}-selector
|
|
|
|
// `]: {
|
|
|
|
// paddingInlineEnd: token
|
|
|
|
// .calc(token.fontSizeIcon)
|
|
|
|
// .add(token.controlPaddingHorizontal)
|
|
|
|
// .equal(),
|
|
|
|
// },
|
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
|
|
|
display: 'flex',
|
2023-09-11 16:05:26 +08:00
|
|
|
alignSelf: 'center',
|
2022-03-08 10:29:00 +08:00
|
|
|
flex: 'none',
|
|
|
|
boxSizing: 'border-box',
|
|
|
|
maxWidth: '100%',
|
|
|
|
height: selectItemHeight,
|
|
|
|
marginTop: FIXED_ITEM_MARGIN,
|
|
|
|
marginBottom: FIXED_ITEM_MARGIN,
|
2023-11-09 09:35:45 +08:00
|
|
|
lineHeight: unit(
|
|
|
|
token.calc(selectItemHeight).sub(token.calc(token.lineWidth).mul(2)).equal(),
|
|
|
|
),
|
2022-11-01 15:06:38 +08:00
|
|
|
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}`,
|
2023-11-09 09:35:45 +08:00
|
|
|
marginInlineEnd: token.calc(FIXED_ITEM_MARGIN).mul(2).equal(),
|
2022-03-08 10:29:00 +08:00
|
|
|
paddingInlineStart: token.paddingXS,
|
2023-11-09 09:35:45 +08:00
|
|
|
paddingInlineEnd: token.calc(token.paddingXS).div(2).equal(),
|
2022-03-08 10:29:00 +08:00
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-disabled&`]: {
|
2023-08-15 17:05:06 +08:00
|
|
|
color: token.multipleItemColorDisabled,
|
|
|
|
borderColor: token.multipleItemBorderColorDisabled,
|
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',
|
2023-11-09 09:35:45 +08:00
|
|
|
marginInlineEnd: token.calc(token.paddingXS).div(2).equal(),
|
2022-03-08 10:29:00 +08:00
|
|
|
overflow: 'hidden',
|
|
|
|
whiteSpace: 'pre', // fix whitespace wrapping. custom tags display all whitespace within.
|
|
|
|
textOverflow: 'ellipsis',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-remove': {
|
|
|
|
...resetIcon(),
|
|
|
|
|
2023-05-22 11:13:38 +08:00
|
|
|
display: 'inline-flex',
|
|
|
|
alignItems: 'center',
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2023-09-11 16:05:08 +08:00
|
|
|
// https://github.com/ant-design/ant-design/issues/44754
|
|
|
|
[`${selectOverflowPrefixCls}-item-suffix`]: {
|
|
|
|
height: '100%',
|
|
|
|
},
|
|
|
|
|
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%',
|
2023-11-09 09:35:45 +08:00
|
|
|
marginInlineStart: token.calc(token.inputPaddingHorizontalBase).sub(selectItemDist).equal(),
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
[`
|
|
|
|
&-input,
|
|
|
|
&-mirror
|
|
|
|
`]: {
|
|
|
|
height: selectItemHeight,
|
|
|
|
fontFamily: token.fontFamily,
|
2023-11-09 09:35:45 +08:00
|
|
|
lineHeight: unit(selectItemHeight),
|
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 =======================
|
2023-09-11 16:05:26 +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
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2024-01-15 15:41:40 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
function genSizeStyle(token: SelectToken, suffix?: string): CSSInterpolation {
|
|
|
|
const { componentCls } = token;
|
|
|
|
|
|
|
|
const suffixCls = suffix ? `${componentCls}-${suffix}` : '';
|
|
|
|
|
|
|
|
const rawStyle: CSSObject = {
|
|
|
|
[`${componentCls}-multiple${suffixCls}`]: {
|
|
|
|
fontSize: token.fontSize,
|
|
|
|
|
|
|
|
// ========================= Selector =========================
|
|
|
|
[`${componentCls}-selector`]: {
|
|
|
|
[`${componentCls}-show-search&`]: {
|
|
|
|
cursor: 'text',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`
|
|
|
|
&${componentCls}-show-arrow ${componentCls}-selector,
|
|
|
|
&${componentCls}-allow-clear ${componentCls}-selector
|
|
|
|
`]: {
|
|
|
|
paddingInlineEnd: token
|
|
|
|
.calc(token.fontSizeIcon)
|
|
|
|
.add(token.controlPaddingHorizontal)
|
|
|
|
.equal(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
return [genSelectionStyle(token, suffix), rawStyle];
|
2022-03-08 10:29:00 +08:00
|
|
|
}
|
|
|
|
|
2023-04-07 10:18:16 +08:00
|
|
|
const 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, {
|
2023-09-14 19:12:17 +08:00
|
|
|
selectHeight: token.controlHeightSM,
|
2023-08-15 17:05:06 +08:00
|
|
|
multipleSelectItemHeight: token.controlHeightXS,
|
2022-11-01 15:06:38 +08:00
|
|
|
borderRadius: token.borderRadiusSM,
|
|
|
|
borderRadiusSM: token.borderRadiusXS,
|
2022-04-11 16:04:00 +08:00
|
|
|
});
|
2023-04-07 10:18:16 +08:00
|
|
|
|
|
|
|
const largeToken = mergeToken<SelectToken>(token, {
|
|
|
|
fontSize: token.fontSizeLG,
|
2023-09-14 19:12:17 +08:00
|
|
|
selectHeight: token.controlHeightLG,
|
2023-08-15 17:05:06 +08:00
|
|
|
multipleSelectItemHeight: token.multipleItemHeightLG,
|
2023-04-07 10:18:16 +08:00
|
|
|
borderRadius: token.borderRadiusLG,
|
|
|
|
borderRadiusSM: token.borderRadius,
|
|
|
|
});
|
|
|
|
|
2022-03-08 10:29:00 +08:00
|
|
|
return [
|
|
|
|
genSizeStyle(token),
|
|
|
|
// ======================== Small ========================
|
|
|
|
genSizeStyle(smallToken, 'sm'),
|
|
|
|
|
|
|
|
// Padding
|
|
|
|
{
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-multiple${componentCls}-sm`]: {
|
|
|
|
[`${componentCls}-selection-placeholder`]: {
|
2023-11-09 09:35:45 +08:00
|
|
|
insetInline: token.calc(token.controlPaddingHorizontalSM).sub(token.lineWidth).equal(),
|
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`]: {
|
2023-11-09 09:35:45 +08:00
|
|
|
marginInlineStart: 2, // Magic Number
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// ======================== Large ========================
|
2023-04-07 10:18:16 +08:00
|
|
|
genSizeStyle(largeToken, 'lg'),
|
2022-03-08 10:29:00 +08:00
|
|
|
];
|
2023-04-07 10:18:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default genMultipleStyle;
|