mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-05 09:49:57 +08:00
f94c23fdd2
* Revert "fix: CascaderProps Multiple boolean type issue" This reverts commit91199fefc3
. * Revert "fix: eslint type issue" This reverts commit03146a9d69
. * Update index.tsx Signed-off-by: 叶枫 <7971419+crazyair@users.noreply.github.com> * test: update type test for cascader props * feat: add panel * feat: type --------- Signed-off-by: 叶枫 <7971419+crazyair@users.noreply.github.com> Co-authored-by: 叶枫 <7971419+crazyair@users.noreply.github.com> Co-authored-by: 叶枫 <645381995@qq.com>
84 lines
2.9 KiB
TypeScript
84 lines
2.9 KiB
TypeScript
import * as React from 'react';
|
|
import classNames from 'classnames';
|
|
import type { CascaderProps as RcCascaderProps } from 'rc-cascader';
|
|
import { Panel } from 'rc-cascader';
|
|
import type { PickType } from 'rc-cascader/lib/Panel';
|
|
|
|
import type { CascaderProps, DefaultOptionType } from '.';
|
|
import DefaultRenderEmpty from '../config-provider/defaultRenderEmpty';
|
|
import useCSSVarCls from '../config-provider/hooks/useCSSVarCls';
|
|
import useBase from './hooks/useBase';
|
|
import useCheckable from './hooks/useCheckable';
|
|
import useColumnIcons from './hooks/useColumnIcons';
|
|
import useStyle from './style';
|
|
import usePanelStyle from './style/panel';
|
|
|
|
export type PanelPickType = Exclude<PickType, 'checkable'> | 'multiple' | 'rootClassName';
|
|
|
|
export type CascaderPanelProps<
|
|
OptionType extends DefaultOptionType = DefaultOptionType,
|
|
ValueField extends keyof OptionType = keyof OptionType,
|
|
Multiple extends boolean = boolean,
|
|
> = Pick<CascaderProps<OptionType, ValueField, Multiple>, PanelPickType>;
|
|
|
|
export type CascaderPanelAutoProps<
|
|
OptionType extends DefaultOptionType = DefaultOptionType,
|
|
ValueField extends keyof OptionType = keyof OptionType,
|
|
> =
|
|
| (CascaderPanelProps<OptionType, ValueField> & { multiple?: false })
|
|
| (CascaderPanelProps<OptionType, ValueField, true> & { multiple: true });
|
|
|
|
function CascaderPanel<
|
|
OptionType extends DefaultOptionType = DefaultOptionType,
|
|
ValueField extends keyof OptionType = keyof OptionType,
|
|
>(props: CascaderPanelAutoProps<OptionType, ValueField>) {
|
|
const {
|
|
prefixCls: customizePrefixCls,
|
|
className,
|
|
multiple,
|
|
rootClassName,
|
|
notFoundContent,
|
|
direction,
|
|
expandIcon,
|
|
} = props;
|
|
|
|
const [prefixCls, cascaderPrefixCls, mergedDirection, renderEmpty] = useBase(
|
|
customizePrefixCls,
|
|
direction,
|
|
);
|
|
|
|
const rootCls = useCSSVarCls(cascaderPrefixCls);
|
|
const [wrapCSSVar, hashId, cssVarCls] = useStyle(cascaderPrefixCls, rootCls);
|
|
usePanelStyle(cascaderPrefixCls);
|
|
|
|
const isRtl = mergedDirection === 'rtl';
|
|
|
|
// ===================== Icon ======================
|
|
const [mergedExpandIcon, loadingIcon] = useColumnIcons(prefixCls, isRtl, expandIcon);
|
|
|
|
// ===================== Empty =====================
|
|
const mergedNotFoundContent = notFoundContent || renderEmpty?.('Cascader') || (
|
|
<DefaultRenderEmpty componentName="Cascader" />
|
|
);
|
|
|
|
// =================== Multiple ====================
|
|
const checkable = useCheckable(cascaderPrefixCls, multiple);
|
|
|
|
// ==================== Render =====================
|
|
|
|
return wrapCSSVar(
|
|
<Panel
|
|
{...(props as Pick<RcCascaderProps, PickType>)}
|
|
checkable={checkable}
|
|
prefixCls={cascaderPrefixCls}
|
|
className={classNames(className, hashId, rootClassName, cssVarCls, rootCls)}
|
|
notFoundContent={mergedNotFoundContent}
|
|
direction={mergedDirection}
|
|
expandIcon={mergedExpandIcon}
|
|
loadingIcon={loadingIcon}
|
|
/>,
|
|
);
|
|
}
|
|
|
|
export default CascaderPanel;
|