2022-10-28 16:09:38 +08:00
|
|
|
/* eslint-disable import/prefer-default-export */
|
2022-12-12 16:36:46 +08:00
|
|
|
import type { CSSInterpolation, CSSObject } from '@ant-design/cssinjs';
|
2024-04-08 14:04:08 +08:00
|
|
|
|
2024-07-23 17:06:15 +08:00
|
|
|
import type { AliasToken, FullToken, OverrideComponent } from '../theme/internal';
|
|
|
|
import type { CSSUtil } from '../theme/util/genComponentStyleHook';
|
2022-10-28 16:09:38 +08:00
|
|
|
|
2022-12-07 17:11:25 +08:00
|
|
|
interface CompactItemOptions {
|
|
|
|
focus?: boolean;
|
|
|
|
/**
|
|
|
|
* Some component borders are implemented on child elements
|
|
|
|
* like `Select`
|
|
|
|
*/
|
|
|
|
borderElCls?: string;
|
|
|
|
/**
|
|
|
|
* Some components have special `focus` className especially with popovers
|
|
|
|
* like `Select` and `DatePicker`
|
|
|
|
*/
|
|
|
|
focusElCls?: string;
|
|
|
|
}
|
|
|
|
|
2022-10-28 16:09:38 +08:00
|
|
|
// handle border collapse
|
2023-01-17 17:51:59 +08:00
|
|
|
function compactItemBorder(
|
2023-11-08 14:56:15 +08:00
|
|
|
token: AliasToken & CSSUtil,
|
2023-01-17 17:51:59 +08:00
|
|
|
parentCls: string,
|
|
|
|
options: CompactItemOptions,
|
|
|
|
): CSSObject {
|
|
|
|
const { focusElCls, focus, borderElCls } = options;
|
|
|
|
const childCombinator = borderElCls ? '> *' : '';
|
|
|
|
const hoverEffects = ['hover', focus ? 'focus' : null, 'active']
|
2022-12-07 17:11:25 +08:00
|
|
|
.filter(Boolean)
|
|
|
|
.map((n) => `&:${n} ${childCombinator}`)
|
|
|
|
.join(',');
|
2022-10-28 16:09:38 +08:00
|
|
|
return {
|
2023-01-17 17:51:59 +08:00
|
|
|
[`&-item:not(${parentCls}-last-item)`]: {
|
2023-11-08 14:56:15 +08:00
|
|
|
marginInlineEnd: token.calc(token.lineWidth).mul(-1).equal(),
|
2022-10-28 16:09:38 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
'&-item': {
|
2022-12-07 17:11:25 +08:00
|
|
|
[hoverEffects]: {
|
2022-10-28 16:09:38 +08:00
|
|
|
zIndex: 2,
|
|
|
|
},
|
|
|
|
|
2023-01-17 17:51:59 +08:00
|
|
|
...(focusElCls
|
2022-10-28 16:09:38 +08:00
|
|
|
? {
|
2023-01-17 17:51:59 +08:00
|
|
|
[`&${focusElCls}`]: {
|
2022-10-28 16:09:38 +08:00
|
|
|
zIndex: 2,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
: {}),
|
|
|
|
|
|
|
|
[`&[disabled] ${childCombinator}`]: {
|
|
|
|
zIndex: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle border-radius
|
2023-01-17 17:51:59 +08:00
|
|
|
function compactItemBorderRadius(
|
|
|
|
prefixCls: string,
|
|
|
|
parentCls: string,
|
|
|
|
options: CompactItemOptions,
|
|
|
|
): CSSObject {
|
|
|
|
const { borderElCls } = options;
|
|
|
|
const childCombinator = borderElCls ? `> ${borderElCls}` : '';
|
2022-10-28 16:09:38 +08:00
|
|
|
|
|
|
|
return {
|
2023-01-17 17:51:59 +08:00
|
|
|
[`&-item:not(${parentCls}-first-item):not(${parentCls}-last-item) ${childCombinator}`]: {
|
2022-10-28 16:09:38 +08:00
|
|
|
borderRadius: 0,
|
|
|
|
},
|
|
|
|
|
2023-01-17 17:51:59 +08:00
|
|
|
[`&-item:not(${parentCls}-last-item)${parentCls}-first-item`]: {
|
2022-10-28 16:09:38 +08:00
|
|
|
[`& ${childCombinator}, &${prefixCls}-sm ${childCombinator}, &${prefixCls}-lg ${childCombinator}`]:
|
|
|
|
{
|
|
|
|
borderStartEndRadius: 0,
|
|
|
|
borderEndEndRadius: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2023-01-17 17:51:59 +08:00
|
|
|
[`&-item:not(${parentCls}-first-item)${parentCls}-last-item`]: {
|
2022-10-28 16:09:38 +08:00
|
|
|
[`& ${childCombinator}, &${prefixCls}-sm ${childCombinator}, &${prefixCls}-lg ${childCombinator}`]:
|
|
|
|
{
|
|
|
|
borderStartStartRadius: 0,
|
|
|
|
borderEndStartRadius: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-12 16:36:46 +08:00
|
|
|
export function genCompactItemStyle<T extends OverrideComponent>(
|
|
|
|
token: FullToken<T>,
|
2022-12-07 17:11:25 +08:00
|
|
|
options: CompactItemOptions = { focus: true },
|
2022-12-12 16:36:46 +08:00
|
|
|
): CSSInterpolation {
|
2023-01-17 17:51:59 +08:00
|
|
|
const { componentCls } = token;
|
|
|
|
|
|
|
|
const compactCls = `${componentCls}-compact`;
|
|
|
|
|
2022-10-28 16:09:38 +08:00
|
|
|
return {
|
2023-01-17 17:51:59 +08:00
|
|
|
[compactCls]: {
|
|
|
|
...compactItemBorder(token, compactCls, options),
|
|
|
|
...compactItemBorderRadius(componentCls, compactCls, options),
|
2022-10-28 16:09:38 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|