2022-06-24 11:11:42 +08:00
|
|
|
import type { CSSInterpolation, CSSObject } from '@ant-design/cssinjs';
|
2024-01-15 16:28:45 +08:00
|
|
|
import { unit } from '@ant-design/cssinjs';
|
2024-01-15 15:41:40 +08:00
|
|
|
|
2024-01-29 15:34:48 +08:00
|
|
|
import { resetIcon } from '../../style';
|
2024-04-08 14:04:08 +08:00
|
|
|
import { mergeToken } from '../../theme/internal';
|
2024-07-23 17:49:35 +08:00
|
|
|
import type { AliasToken, TokenWithCommonCls } from '../../theme/internal';
|
2024-01-29 15:34:48 +08:00
|
|
|
import type { SelectToken } from './token';
|
|
|
|
|
|
|
|
type SelectItemToken = Pick<
|
|
|
|
SelectToken,
|
|
|
|
| 'multipleSelectItemHeight'
|
|
|
|
| 'multipleSelectorBgDisabled'
|
|
|
|
| 'multipleItemColorDisabled'
|
|
|
|
| 'multipleItemBorderColorDisabled'
|
|
|
|
| 'selectHeight'
|
|
|
|
| 'lineWidth'
|
|
|
|
| 'calc'
|
|
|
|
| 'inputPaddingHorizontalBase'
|
2024-04-22 13:50:24 +08:00
|
|
|
| 'INTERNAL_FIXED_ITEM_MARGIN'
|
2024-01-29 15:34:48 +08:00
|
|
|
>;
|
|
|
|
|
2024-03-15 10:54:54 +08:00
|
|
|
/**
|
|
|
|
* Get multiple selector needed style. The calculation:
|
|
|
|
*
|
|
|
|
* ContainerPadding = BasePadding - ItemMargin
|
|
|
|
*
|
|
|
|
* Border: ╔═══════════════════════════╗ ┬
|
|
|
|
* ContainerPadding: ║ ║ │
|
|
|
|
* ╟───────────────────────────╢ ┬ │
|
|
|
|
* Item Margin: ║ ║ │ │
|
|
|
|
* ║ ┌──────────┐ ║ │ │
|
|
|
|
* Item(multipleItemHeight): ║ BasePadding │ Item │ ║ Overflow Container(ControlHeight)
|
|
|
|
* ║ └──────────┘ ║ │ │
|
|
|
|
* Item Margin: ║ ║ │ │
|
|
|
|
* ╟───────────────────────────╢ ┴ │
|
|
|
|
* ContainerPadding: ║ ║ │
|
|
|
|
* Border: ╚═══════════════════════════╝ ┴
|
|
|
|
*/
|
|
|
|
export const getMultipleSelectorUnit = (
|
|
|
|
token: Pick<
|
|
|
|
SelectToken,
|
2024-04-22 13:50:24 +08:00
|
|
|
| 'max'
|
|
|
|
| 'calc'
|
|
|
|
| 'multipleSelectItemHeight'
|
|
|
|
| 'paddingXXS'
|
|
|
|
| 'lineWidth'
|
|
|
|
| 'INTERNAL_FIXED_ITEM_MARGIN'
|
2024-03-15 10:54:54 +08:00
|
|
|
>,
|
|
|
|
) => {
|
2024-04-22 13:50:24 +08:00
|
|
|
const { multipleSelectItemHeight, paddingXXS, lineWidth, INTERNAL_FIXED_ITEM_MARGIN } = token;
|
2024-03-15 10:54:54 +08:00
|
|
|
|
|
|
|
const basePadding = token.max(token.calc(paddingXXS).sub(lineWidth).equal(), 0);
|
2024-04-22 13:50:24 +08:00
|
|
|
const containerPadding = token.max(
|
|
|
|
token.calc(basePadding).sub(INTERNAL_FIXED_ITEM_MARGIN).equal(),
|
|
|
|
0,
|
|
|
|
);
|
2024-03-15 10:54:54 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
basePadding,
|
|
|
|
containerPadding,
|
|
|
|
itemHeight: unit(multipleSelectItemHeight),
|
|
|
|
itemLineHeight: unit(
|
|
|
|
token.calc(multipleSelectItemHeight).sub(token.calc(token.lineWidth).mul(2)).equal(),
|
|
|
|
),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-01-29 15:34:48 +08:00
|
|
|
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-03-15 10:54:54 +08:00
|
|
|
/**
|
|
|
|
* Get the `rc-overflow` needed style.
|
|
|
|
* It's a share style which means not affected by `size`.
|
|
|
|
*/
|
|
|
|
export const genOverflowStyle = (
|
|
|
|
token: Pick<
|
|
|
|
SelectToken,
|
|
|
|
| 'calc'
|
|
|
|
| 'componentCls'
|
|
|
|
| 'iconCls'
|
|
|
|
| 'borderRadiusSM'
|
|
|
|
| 'motionDurationSlow'
|
|
|
|
| 'paddingXS'
|
|
|
|
| 'multipleItemColorDisabled'
|
|
|
|
| 'multipleItemBorderColorDisabled'
|
|
|
|
| 'colorIcon'
|
|
|
|
| 'colorIconHover'
|
2024-04-22 13:50:24 +08:00
|
|
|
| 'INTERNAL_FIXED_ITEM_MARGIN'
|
2024-03-15 10:54:54 +08:00
|
|
|
>,
|
2024-01-29 15:34:48 +08:00
|
|
|
): CSSObject => {
|
2024-03-15 10:54:54 +08:00
|
|
|
const {
|
|
|
|
componentCls,
|
|
|
|
iconCls,
|
|
|
|
borderRadiusSM,
|
|
|
|
motionDurationSlow,
|
|
|
|
paddingXS,
|
|
|
|
multipleItemColorDisabled,
|
|
|
|
multipleItemBorderColorDisabled,
|
|
|
|
colorIcon,
|
|
|
|
colorIconHover,
|
2024-04-22 13:50:24 +08:00
|
|
|
INTERNAL_FIXED_ITEM_MARGIN,
|
2024-03-15 10:54:54 +08:00
|
|
|
} = 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
|
|
|
|
|
|
|
return {
|
2024-03-15 10:54:54 +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',
|
2022-03-08 10:29:00 +08:00
|
|
|
maxWidth: '100%',
|
2024-03-15 10:54:54 +08:00
|
|
|
display: 'inline-flex',
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
|
2024-03-15 10:54:54 +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%',
|
2024-04-22 13:50:24 +08:00
|
|
|
marginBlock: INTERNAL_FIXED_ITEM_MARGIN,
|
2024-03-15 10:54:54 +08:00
|
|
|
borderRadius: borderRadiusSM,
|
2022-03-08 10:29:00 +08:00
|
|
|
cursor: 'default',
|
2024-03-15 10:54:54 +08:00
|
|
|
transition: `font-size ${motionDurationSlow}, line-height ${motionDurationSlow}, height ${motionDurationSlow}`,
|
2024-04-22 13:50:24 +08:00
|
|
|
marginInlineEnd: token.calc(INTERNAL_FIXED_ITEM_MARGIN).mul(2).equal(),
|
2024-03-15 10:54:54 +08:00
|
|
|
paddingInlineStart: paddingXS,
|
|
|
|
paddingInlineEnd: token.calc(paddingXS).div(2).equal(),
|
2022-03-08 10:29:00 +08:00
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-disabled&`]: {
|
2024-03-15 10:54:54 +08:00
|
|
|
color: multipleItemColorDisabled,
|
|
|
|
borderColor: 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',
|
2024-03-15 10:54:54 +08:00
|
|
|
marginInlineEnd: token.calc(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',
|
2024-03-15 10:54:54 +08:00
|
|
|
color: 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': {
|
2024-03-15 10:54:54 +08:00
|
|
|
color: colorIconHover,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-03-15 10:54:54 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const genSelectionStyle = (
|
|
|
|
token: TokenWithCommonCls<AliasToken> & SelectItemToken,
|
|
|
|
suffix?: string,
|
|
|
|
): CSSObject => {
|
2024-04-22 13:50:24 +08:00
|
|
|
const { componentCls, INTERNAL_FIXED_ITEM_MARGIN } = token;
|
2024-03-15 10:54:54 +08:00
|
|
|
|
|
|
|
const selectOverflowPrefixCls = `${componentCls}-selection-overflow`;
|
|
|
|
|
|
|
|
const selectItemHeight = token.multipleSelectItemHeight;
|
|
|
|
const selectItemDist = getSelectItemStyle(token);
|
|
|
|
|
|
|
|
const suffixCls = suffix ? `${componentCls}-${suffix}` : '';
|
|
|
|
|
|
|
|
const multipleSelectorUnit = getMultipleSelectorUnit(token);
|
|
|
|
|
|
|
|
return {
|
|
|
|
[`${componentCls}-multiple${suffixCls}`]: {
|
|
|
|
// ========================= Overflow =========================
|
|
|
|
...genOverflowStyle(token),
|
|
|
|
|
|
|
|
// ========================= Selector =========================
|
|
|
|
[`${componentCls}-selector`]: {
|
|
|
|
display: 'flex',
|
|
|
|
flexWrap: 'wrap',
|
|
|
|
alignItems: 'center',
|
|
|
|
height: '100%',
|
|
|
|
// Multiple is little different that horizontal is follow the vertical
|
|
|
|
paddingInline: multipleSelectorUnit.basePadding,
|
|
|
|
paddingBlock: multipleSelectorUnit.containerPadding,
|
|
|
|
borderRadius: token.borderRadius,
|
|
|
|
|
|
|
|
[`${componentCls}-disabled&`]: {
|
|
|
|
background: token.multipleSelectorBgDisabled,
|
|
|
|
cursor: 'not-allowed',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&:after': {
|
|
|
|
display: 'inline-block',
|
|
|
|
width: 0,
|
2024-04-22 13:50:24 +08:00
|
|
|
margin: `${unit(INTERNAL_FIXED_ITEM_MARGIN)} 0`,
|
2024-03-15 10:54:54 +08:00
|
|
|
lineHeight: unit(selectItemHeight),
|
|
|
|
visibility: 'hidden',
|
|
|
|
content: '"\\a0"',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// ======================== Selections ========================
|
|
|
|
[`${componentCls}-selection-item`]: {
|
|
|
|
height: multipleSelectorUnit.itemHeight,
|
|
|
|
lineHeight: unit(multipleSelectorUnit.itemLineHeight),
|
|
|
|
},
|
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-29 15:34:48 +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,
|
2024-03-15 10:54:54 +08:00
|
|
|
multipleSelectItemHeight: token.multipleItemHeightSM,
|
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;
|