ant-design/components/cascader/style/index.tsx

157 lines
5.0 KiB
TypeScript
Raw Normal View History

2022-03-09 00:29:00 +08:00
// deps-lint-skip-all
import { getStyle as getCheckboxStyle } from '../../checkbox/style';
import type { FullToken, GenerateStyle } from '../../_util/theme';
import { genComponentStyleHook } from '../../_util/theme';
2022-03-09 00:29:00 +08:00
export interface ComponentToken {
controlWidth: number;
controlItemWidth: number;
dropdownHeight: number;
}
type CascaderToken = FullToken<'Cascader'>;
2022-03-09 00:29:00 +08:00
// =============================== Base ===============================
const genBaseStyle: GenerateStyle<CascaderToken> = token => {
const { prefixCls, componentCls } = token;
const cascaderMenuItemCls = `${componentCls}-menu-item`;
2022-03-09 00:29:00 +08:00
const iconCls = `
&${cascaderMenuItemCls}-expand ${cascaderMenuItemCls}-expand-icon,
2022-03-09 00:29:00 +08:00
${cascaderMenuItemCls}-loading-icon
`;
const itemPaddingVertical = Math.round(
(token.controlHeight - token.fontSize * token.lineHeight) / 2,
);
return [
// =====================================================
// == Control ==
// =====================================================
{
[componentCls]: {
width: token.controlWidth,
2022-03-09 00:29:00 +08:00
},
},
// =====================================================
// == Popup ==
// =====================================================
{
[`${componentCls}-dropdown`]: [
// ==================== Checkbox ====================
getCheckboxStyle(`${prefixCls}-checkbox`, token),
{
[componentCls]: {
// ================== Checkbox ==================
'&-checkbox': {
top: 0,
marginInlineEnd: token.paddingXS,
2022-03-09 00:29:00 +08:00
},
// ==================== Menu ====================
// >>> Menus
'&-menus': {
2022-03-09 00:29:00 +08:00
display: 'flex',
flexWrap: 'nowrap',
alignItems: 'flex-start',
[`&${componentCls}-menu-empty`]: {
[`${componentCls}-menu`]: {
width: '100%',
height: 'auto',
[cascaderMenuItemCls]: {
color: token.colorTextDisabled,
cursor: 'default',
pointerEvents: 'none',
},
},
2022-03-09 00:29:00 +08:00
},
},
// >>> Menu
'&-menu': {
2022-04-15 15:44:02 +08:00
flexGrow: 1,
minWidth: token.controlItemWidth,
height: token.dropdownHeight,
margin: `-${token.paddingXS}px 0`,
padding: `${token.paddingXS}px 0`,
overflow: 'auto',
verticalAlign: 'top',
listStyle: 'none',
borderInlineEnd: `${token.controlLineWidth}px ${token.controlLineType} ${token.colorSplit}`,
'-ms-overflow-style': '-ms-autohiding-scrollbar', // https://github.com/ant-design/ant-design/issues/11857
'&-item': {
display: 'flex',
flexWrap: 'nowrap',
alignItems: 'center',
padding: `${itemPaddingVertical}px ${token.paddingSM}px`,
overflow: 'hidden',
lineHeight: token.lineHeight,
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
cursor: 'pointer',
transition: `all ${token.motionDurationSlow}`,
2022-03-09 00:29:00 +08:00
'&:hover': {
background: token.controlItemBgHover,
2022-03-09 00:29:00 +08:00
},
' &-disabled': {
color: token.colorTextDisabled,
cursor: 'not-allowed',
'&:hover': {
background: 'transparent',
},
[iconCls]: {
color: token.colorTextDisabled,
},
2022-03-09 00:29:00 +08:00
},
[`&-active:not(${cascaderMenuItemCls}-disabled)`]: {
[`&, &:hover`]: {
fontWeight: token.fontWeightStrong,
backgroundColor: token.controlItemBgActive,
},
2022-03-09 00:29:00 +08:00
},
'&-content': {
flex: 'auto',
},
2022-03-09 00:29:00 +08:00
[iconCls]: {
marginInlineStart: token.paddingXXS,
color: token.colorTextSecondary,
fontSize: token.fontSizeIcon,
},
2022-03-09 00:29:00 +08:00
'&-keyword': {
color: token.colorHighlight,
},
2022-03-09 00:29:00 +08:00
},
},
},
},
],
2022-03-09 00:29:00 +08:00
},
// =====================================================
// == RTL ==
// =====================================================
{
[`${componentCls}-dropdown-rtl`]: {
2022-03-09 00:29:00 +08:00
direction: 'rtl',
},
},
];
};
// ============================== Export ==============================
export default genComponentStyleHook('Cascader', token => [genBaseStyle(token)], {
controlWidth: 184,
controlItemWidth: 111,
dropdownHeight: 180,
});