From 328e42a9be8aa2dbafd7f7ec1db4490f3e58f345 Mon Sep 17 00:00:00 2001
From: tangjinzhou <415800467@qq.com>
Date: Fri, 17 Feb 2023 22:02:23 +0800
Subject: [PATCH] feat: tree add leafIcon
---
components/calendar/generateCalendar.tsx | 3 +--
components/tree-select/index.tsx | 8 +++++++-
components/tree/Tree.tsx | 2 +-
components/tree/utils/dictUtil.ts | 6 +-----
components/tree/utils/iconUtil.tsx | 19 ++++++++++++-------
5 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/components/calendar/generateCalendar.tsx b/components/calendar/generateCalendar.tsx
index baf3b141c..a49f5d473 100644
--- a/components/calendar/generateCalendar.tsx
+++ b/components/calendar/generateCalendar.tsx
@@ -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<
)}
>
- {padStart(String(generateConfig.getDate(date)), 2, '0')}
+ {String(generateConfig.getDate(date)).padStart(2, '0')}
{dateCellRender && dateCellRender({ current: date })}
diff --git a/components/tree-select/index.tsx b/components/tree-select/index.tsx
index 2675412b8..680492f65 100644
--- a/components/tree-select/index.tsx
+++ b/components/tree-select/index.tsx
@@ -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}
diff --git a/components/tree/Tree.tsx b/components/tree/Tree.tsx
index 7baf7a84a..6ffecafca 100644
--- a/components/tree/Tree.tsx
+++ b/components/tree/Tree.tsx
@@ -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}
diff --git a/components/tree/utils/dictUtil.ts b/components/tree/utils/dictUtil.ts
index 82eee747b..ea2f79a92 100644
--- a/components/tree/utils/dictUtil.ts
+++ b/components/tree/utils/dictUtil.ts
@@ -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;
diff --git a/components/tree/utils/iconUtil.tsx b/components/tree/utils/iconUtil.tsx
index d134968c1..9593bbc5b 100644
--- a/components/tree/utils/iconUtil.tsx
+++ b/components/tree/utils/iconUtil.tsx
@@ -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 = ;
- } else {
- defaultIcon = ;
- }
+ if (!showLine) {
+ return null;
+ }
+ if (showLeafIcon && leafIcon) {
+ return leafIcon(props);
+ }
+ if (typeof showLine === 'object' && !showLeafIcon) {
+ defaultIcon = ;
+ } else {
+ defaultIcon = ;
}
return defaultIcon;
} else {