ant-design/components/cascader/style/index.tsx
MadCcc d0c4d7b0ec
feat: add useComponentStyle (#34802)
* feat: add useComponentStyle

* chore: auto generic

* feat: add overload

* feat: filter component token

* feat: genComponentStyleHook

* test: fix lint

* feat: button for test case

* chore: code clean

* chore: code clean

* feat: add componentCls into token

* feat: merge token statistic

* chore: code clean

* fix: cache token merge

* chore: code clean

* chore: add comment & rename variables

* chore: code  enhancement

* chore: FullToken<ComponentName>

* chore: clean input

* chore: code clean

* test: fix lint

* feat: inset prefixCls

Co-authored-by: zombiej <smith3816@gmail.com>
2022-04-02 22:55:02 +08:00

169 lines
5.2 KiB
TypeScript

// import '../../style/index.less';
// import './index.less';
// // style dependencies
// import '../../empty/style';
// import '../../select/style';
// // deps-lint-skip: form
// deps-lint-skip-all
import genComponentStyleHook, { FullToken } from '../../_util/hooks/genComponentStyleHook';
import { GenerateStyle } from '../../_util/theme';
import { getStyle as getCheckboxStyle } from '../../checkbox/style';
export interface ComponentToken {
controlWidth: number;
controlItemWidth: number;
dropdownHeight: number;
}
type CascaderToken = FullToken<'Cascader'>;
// =============================== Base ===============================
const genBaseStyle: GenerateStyle<CascaderToken> = (token, hashId) => {
const { prefixCls, componentCls } = token;
const cascaderMenuItemCls = `${componentCls}-menu-item`;
const iconCls = `
&${cascaderMenuItemCls}-expand ${cascaderMenuItemCls}-expand-icon,
${cascaderMenuItemCls}-loading-icon
`;
const itemPaddingVertical = Math.round(
(token.controlHeight - token.fontSize * token.lineHeight) / 2,
);
return [
// =====================================================
// == Control ==
// =====================================================
{
[componentCls]: {
width: token.controlWidth,
},
},
// =====================================================
// == Popup ==
// =====================================================
{
[`${componentCls}-dropdown`]: [
// ==================== Checkbox ====================
getCheckboxStyle(`${prefixCls}-checkbox`, token, hashId!),
{
[componentCls]: {
// ================== Checkbox ==================
'&-checkbox': {
top: 0,
marginInlineEnd: token.paddingXS,
},
// ==================== Menu ====================
// >>> Menus
'&-menus': {
display: 'flex',
flexWrap: 'nowrap',
alignItems: 'flex-start',
[`&${componentCls}-menu-empty`]: {
[`${componentCls}-menu`]: {
width: '100%',
height: 'auto',
[cascaderMenuItemCls]: {
color: token.colorTextDisabled,
cursor: 'default',
pointerEvents: 'none',
},
},
},
},
// >>> Menu
'&-menu': {
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}`,
'&:hover': {
background: token.controlItemBgHover,
},
' &-disabled': {
color: token.colorTextDisabled,
cursor: 'not-allowed',
'&:hover': {
background: 'transparent',
},
[iconCls]: {
color: token.colorTextDisabled,
},
},
[`&-active:not(${cascaderMenuItemCls}-disabled)`]: {
[`&, &:hover`]: {
fontWeight: token.fontWeightStrong,
backgroundColor: token.controlItemBgActive,
},
},
'&-content': {
flex: 'auto',
},
[iconCls]: {
marginInlineStart: token.paddingXXS,
color: token.colorTextSecondary,
fontSize: token.fontSizeIcon,
},
'&-keyword': {
color: token.colorHighlight,
},
},
},
},
},
],
},
// =====================================================
// == RTL ==
// =====================================================
{
[`${componentCls}-dropdown-rtl`]: {
direction: 'rtl',
},
},
];
};
// ============================== Export ==============================
export default genComponentStyleHook(
'Cascader',
(token, { hashId }) => [genBaseStyle(token, hashId)],
{
controlWidth: 184,
controlItemWidth: 111,
dropdownHeight: 180,
},
);