feat: tree add leafIcon

pull/6295/head
tangjinzhou 2023-02-17 22:02:23 +08:00
parent 634675e032
commit 328e42a9be
5 changed files with 22 additions and 16 deletions

View File

@ -1,5 +1,4 @@
import useMergedState from '../_util/hooks/useMergedState';
import padStart from 'lodash-es/padStart';
import { PickerPanel } from '../vc-picker';
import type { Locale } from '../vc-picker/interface';
import type { GenerateConfig } from '../vc-picker/generate';
@ -245,7 +244,7 @@ function generateCalendar<
)}
>
<div class={`${calendarPrefixCls.value}-date-value`}>
{padStart(String(generateConfig.getDate(date)), 2, '0')}
{String(generateConfig.getDate(date)).padStart(2, '0')}
</div>
<div class={`${calendarPrefixCls.value}-date-content`}>
{dateCellRender && dateCellRender({ current: date })}

View File

@ -273,7 +273,13 @@ const TreeSelect = defineComponent({
removeIcon={removeIcon}
clearIcon={clearIcon}
switcherIcon={(nodeProps: SwitcherIconProps) =>
renderSwitcherIcon(treePrefixCls.value, switcherIcon, treeLine, nodeProps)
renderSwitcherIcon(
treePrefixCls.value,
switcherIcon,
nodeProps,
slots.leafIcon,
treeLine,
)
}
showTreeIcon={treeIcon as any}
notFoundContent={mergedNotFound}

View File

@ -260,7 +260,7 @@ export default defineComponent({
checkable={checkable}
selectable={selectable}
switcherIcon={(nodeProps: SwitcherIconProps) =>
renderSwitcherIcon(prefixCls.value, switcherIcon, showLine, nodeProps)
renderSwitcherIcon(prefixCls.value, switcherIcon, nodeProps, slots.leafIcon, showLine)
}
onCheck={handleCheck}
onExpand={handleExpand}

View File

@ -74,11 +74,7 @@ export function calcRangeKeys({
keys.push(key);
}
if (expandedKeys.indexOf(key) === -1) {
return false;
}
return true;
return expandedKeys.includes(key);
});
return keys;

View File

@ -14,8 +14,9 @@ export interface SwitcherIconProps extends AntTreeNodeProps {
export default function renderSwitcherIcon(
prefixCls: string,
switcherIcon: any,
showLine: boolean | { showLeafIcon: boolean } | undefined,
props: SwitcherIconProps,
leafIcon?: (props: SwitcherIconProps) => any,
showLine?: boolean | { showLeafIcon: boolean } | undefined,
) {
const { isLeaf, expanded, loading } = props;
let icon = switcherIcon;
@ -29,12 +30,16 @@ export default function renderSwitcherIcon(
let defaultIcon = null;
const switcherCls = `${prefixCls}-switcher-icon`;
if (isLeaf) {
if (showLine) {
if (typeof showLine === 'object' && !showLeafIcon) {
defaultIcon = <span class={`${prefixCls}-switcher-leaf-line`} />;
} else {
defaultIcon = <FileOutlined class={`${prefixCls}-switcher-line-icon`} />;
}
if (!showLine) {
return null;
}
if (showLeafIcon && leafIcon) {
return leafIcon(props);
}
if (typeof showLine === 'object' && !showLeafIcon) {
defaultIcon = <span class={`${prefixCls}-switcher-leaf-line`} />;
} else {
defaultIcon = <FileOutlined class={`${prefixCls}-switcher-line-icon`} />;
}
return defaultIcon;
} else {