ant-design/components/tree-select/style/index.ts

79 lines
2.5 KiB
TypeScript
Raw Normal View History

import { getStyle as getCheckboxStyle } from '../../checkbox/style';
import type { AliasToken, FullToken, GenerateStyle } from '../../theme/internal';
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
2023-08-18 10:23:57 +08:00
import type { TreeSharedToken } from '../../tree/style';
import { genTreeStyle, initComponentToken } from '../../tree/style';
export interface ComponentToken extends TreeSharedToken {}
interface TreeSelectToken extends FullToken<'TreeSelect'> {
treePrefixCls: string;
}
// =============================== Base ===============================
const genBaseStyle: GenerateStyle<TreeSelectToken> = (token) => {
2022-06-21 11:06:06 +08:00
const { componentCls, treePrefixCls, colorBgElevated } = token;
const treeCls = `.${treePrefixCls}`;
return [
// ======================================================
// == Dropdown ==
// ======================================================
{
[`${componentCls}-dropdown`]: [
{
padding: `${token.paddingXS}px ${token.paddingXS / 2}px`,
},
// ====================== Tree ======================
2022-06-21 11:06:06 +08:00
genTreeStyle(
treePrefixCls,
2023-08-18 10:23:57 +08:00
mergeToken<AliasToken & TreeSharedToken>(token, { colorBgContainer: colorBgElevated }),
2022-06-21 11:06:06 +08:00
),
{
[treeCls]: {
borderRadius: 0,
[`${treeCls}-list-holder-inner`]: {
alignItems: 'stretch',
[`${treeCls}-treenode`]: {
[`${treeCls}-node-content-wrapper`]: {
flex: 'auto',
},
},
},
},
},
// ==================== Checkbox ====================
getCheckboxStyle(`${treePrefixCls}-checkbox`, token),
// ====================== RTL =======================
{
'&-rtl': {
direction: 'rtl',
[`${treeCls}-switcher${treeCls}-switcher_close`]: {
[`${treeCls}-switcher-icon svg`]: {
transform: 'rotate(90deg)',
},
},
},
},
],
},
];
};
// ============================== Export ==============================
export default function useTreeSelectStyle(prefixCls: string, treePrefixCls: string) {
2023-08-18 10:23:57 +08:00
return genComponentStyleHook(
'TreeSelect',
(token) => {
const treeSelectToken = mergeToken<TreeSelectToken>(token, { treePrefixCls });
return [genBaseStyle(treeSelectToken)];
},
initComponentToken,
)(prefixCls);
}