2022-05-09 22:20:07 +08:00
|
|
|
import type { CSSInterpolation, CSSObject } from '@ant-design/cssinjs';
|
2024-04-08 14:04:08 +08:00
|
|
|
import { unit } from '@ant-design/cssinjs';
|
|
|
|
|
2022-08-10 17:16:46 +08:00
|
|
|
import { resetComponent } from '../../style';
|
2022-11-23 20:22:38 +08:00
|
|
|
import { mergeToken } from '../../theme/internal';
|
2024-04-08 14:04:08 +08:00
|
|
|
import type { SelectToken } from './token';
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
function genSizeStyle(token: SelectToken, suffix?: string): CSSObject {
|
2022-11-01 15:06:38 +08:00
|
|
|
const { componentCls, inputPaddingHorizontalBase, borderRadius } = token;
|
2022-03-08 10:29:00 +08:00
|
|
|
|
2023-11-09 09:35:45 +08:00
|
|
|
const selectHeightWithoutBorder = token
|
|
|
|
.calc(token.controlHeight)
|
|
|
|
.sub(token.calc(token.lineWidth).mul(2))
|
|
|
|
.equal();
|
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}-single${suffixCls}`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
fontSize: token.fontSize,
|
2023-09-11 16:05:26 +08:00
|
|
|
height: token.controlHeight,
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
// ========================= Selector =========================
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-selector`]: {
|
2023-10-07 17:06:28 +08:00
|
|
|
...resetComponent(token, true),
|
2022-08-10 17:16:46 +08:00
|
|
|
|
2022-03-08 10:29:00 +08:00
|
|
|
display: 'flex',
|
2022-11-01 15:06:38 +08:00
|
|
|
borderRadius,
|
2022-08-19 10:10:51 +08:00
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-selection-search`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
2022-03-11 17:07:16 +08:00
|
|
|
insetInlineStart: inputPaddingHorizontalBase,
|
|
|
|
insetInlineEnd: inputPaddingHorizontalBase,
|
2022-03-08 10:29:00 +08:00
|
|
|
bottom: 0,
|
|
|
|
|
|
|
|
'&-input': {
|
|
|
|
width: '100%',
|
2023-11-22 19:10:44 +08:00
|
|
|
WebkitAppearance: 'textfield',
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`
|
2022-04-07 12:20:34 +08:00
|
|
|
${componentCls}-selection-item,
|
|
|
|
${componentCls}-selection-placeholder
|
2022-03-08 10:29:00 +08:00
|
|
|
`]: {
|
|
|
|
padding: 0,
|
2023-11-09 09:35:45 +08:00
|
|
|
lineHeight: unit(selectHeightWithoutBorder),
|
2023-04-10 13:11:51 +08:00
|
|
|
transition: `all ${token.motionDurationSlow}, visibility 0s`,
|
2023-09-11 16:05:26 +08:00
|
|
|
alignSelf: 'center',
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-selection-placeholder`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
transition: 'none',
|
|
|
|
pointerEvents: 'none',
|
|
|
|
},
|
|
|
|
|
|
|
|
// For common baseline align
|
|
|
|
[[
|
|
|
|
'&:after',
|
|
|
|
/* For '' value baseline align */
|
2023-09-18 13:51:17 +08:00
|
|
|
`${componentCls}-selection-item:empty:after`,
|
2022-03-08 10:29:00 +08:00
|
|
|
/* For undefined value baseline align */
|
2023-09-18 13:51:17 +08:00
|
|
|
`${componentCls}-selection-placeholder:empty:after`,
|
2022-03-08 10:29:00 +08:00
|
|
|
].join(',')]: {
|
|
|
|
display: 'inline-block',
|
|
|
|
width: 0,
|
|
|
|
visibility: 'hidden',
|
|
|
|
content: '"\\a0"',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`
|
2022-04-07 12:20:34 +08:00
|
|
|
&${componentCls}-show-arrow ${componentCls}-selection-item,
|
|
|
|
&${componentCls}-show-arrow ${componentCls}-selection-placeholder
|
2022-03-08 10:29:00 +08:00
|
|
|
`]: {
|
2023-11-09 09:35:45 +08:00
|
|
|
paddingInlineEnd: token.showArrowPaddingInlineEnd,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
// Opacity selection if open
|
2022-04-07 12:20:34 +08:00
|
|
|
[`&${componentCls}-open ${componentCls}-selection-item`]: {
|
2022-06-17 18:47:47 +08:00
|
|
|
color: token.colorTextPlaceholder,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
// ========================== Input ==========================
|
|
|
|
// We only change the style of non-customize input which is only support by `combobox` mode.
|
|
|
|
// Not customize
|
2022-04-07 12:20:34 +08:00
|
|
|
[`&:not(${componentCls}-customize-input)`]: {
|
|
|
|
[`${componentCls}-selector`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
width: '100%',
|
2023-09-11 16:05:26 +08:00
|
|
|
height: '100%',
|
2023-11-09 09:35:45 +08:00
|
|
|
padding: `0 ${unit(inputPaddingHorizontalBase)}`,
|
2022-03-08 10:29:00 +08:00
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-selection-search-input`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
height: selectHeightWithoutBorder,
|
|
|
|
},
|
|
|
|
|
|
|
|
'&:after': {
|
2023-11-09 09:35:45 +08:00
|
|
|
lineHeight: unit(selectHeightWithoutBorder),
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`&${componentCls}-customize-input`]: {
|
|
|
|
[`${componentCls}-selector`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
'&:after': {
|
|
|
|
display: 'none',
|
|
|
|
},
|
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-selection-search`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
position: 'static',
|
|
|
|
width: '100%',
|
|
|
|
},
|
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-selection-placeholder`]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
position: 'absolute',
|
2022-03-11 17:07:16 +08:00
|
|
|
insetInlineStart: 0,
|
|
|
|
insetInlineEnd: 0,
|
2023-11-09 09:35:45 +08:00
|
|
|
padding: `0 ${unit(inputPaddingHorizontalBase)}`,
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
'&:after': {
|
|
|
|
display: 'none',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function genSingleStyle(token: SelectToken): CSSInterpolation {
|
2022-04-07 12:20:34 +08:00
|
|
|
const { componentCls } = token;
|
2022-03-08 10:29:00 +08:00
|
|
|
|
2023-11-09 09:35:45 +08:00
|
|
|
const inputPaddingHorizontalSM = token
|
|
|
|
.calc(token.controlPaddingHorizontalSM)
|
|
|
|
.sub(token.lineWidth)
|
|
|
|
.equal();
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
return [
|
|
|
|
genSizeStyle(token),
|
|
|
|
|
|
|
|
// ======================== Small ========================
|
|
|
|
// Shared
|
|
|
|
genSizeStyle(
|
2022-04-11 16:04:00 +08:00
|
|
|
mergeToken<any>(token, {
|
2022-03-08 10:29:00 +08:00
|
|
|
controlHeight: token.controlHeightSM,
|
2022-11-01 15:06:38 +08:00
|
|
|
borderRadius: token.borderRadiusSM,
|
2022-04-11 16:04:00 +08:00
|
|
|
}),
|
2022-03-08 10:29:00 +08:00
|
|
|
'sm',
|
|
|
|
),
|
|
|
|
|
|
|
|
// padding
|
|
|
|
{
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-single${componentCls}-sm`]: {
|
|
|
|
[`&:not(${componentCls}-customize-input)`]: {
|
|
|
|
[`${componentCls}-selection-search`]: {
|
2022-03-11 17:07:16 +08:00
|
|
|
insetInlineStart: inputPaddingHorizontalSM,
|
|
|
|
insetInlineEnd: inputPaddingHorizontalSM,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
|
2022-04-07 12:20:34 +08:00
|
|
|
[`${componentCls}-selector`]: {
|
2023-11-09 09:35:45 +08:00
|
|
|
padding: `0 ${unit(inputPaddingHorizontalSM)}`,
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
// With arrow should provides `padding-right` to show the arrow
|
2022-04-07 12:20:34 +08:00
|
|
|
[`&${componentCls}-show-arrow ${componentCls}-selection-search`]: {
|
2023-11-09 09:35:45 +08:00
|
|
|
insetInlineEnd: token
|
|
|
|
.calc(inputPaddingHorizontalSM)
|
|
|
|
.add(token.calc(token.fontSize).mul(1.5))
|
|
|
|
.equal(),
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`
|
2022-04-07 12:20:34 +08:00
|
|
|
&${componentCls}-show-arrow ${componentCls}-selection-item,
|
|
|
|
&${componentCls}-show-arrow ${componentCls}-selection-placeholder
|
2022-03-08 10:29:00 +08:00
|
|
|
`]: {
|
2023-11-09 09:35:45 +08:00
|
|
|
paddingInlineEnd: token.calc(token.fontSize).mul(1.5).equal(),
|
2022-03-08 10:29:00 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// ======================== Large ========================
|
|
|
|
// Shared
|
|
|
|
genSizeStyle(
|
2022-04-11 16:04:00 +08:00
|
|
|
mergeToken<any>(token, {
|
2023-08-15 17:05:06 +08:00
|
|
|
controlHeight: token.singleItemHeightLG,
|
2022-03-08 10:29:00 +08:00
|
|
|
fontSize: token.fontSizeLG,
|
2022-11-01 15:06:38 +08:00
|
|
|
borderRadius: token.borderRadiusLG,
|
2022-04-11 16:04:00 +08:00
|
|
|
}),
|
2022-03-08 10:29:00 +08:00
|
|
|
'lg',
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|