Skip to content

Commit 328e42a

Browse files
committed
feat: tree add leafIcon
1 parent 634675e commit 328e42a

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed

components/calendar/generateCalendar.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import useMergedState from '../_util/hooks/useMergedState';
2-
import padStart from 'lodash-es/padStart';
32
import { PickerPanel } from '../vc-picker';
43
import type { Locale } from '../vc-picker/interface';
54
import type { GenerateConfig } from '../vc-picker/generate';
@@ -245,7 +244,7 @@ function generateCalendar<
245244
)}
246245
>
247246
<div class={`${calendarPrefixCls.value}-date-value`}>
248-
{padStart(String(generateConfig.getDate(date)), 2, '0')}
247+
{String(generateConfig.getDate(date)).padStart(2, '0')}
249248
</div>
250249
<div class={`${calendarPrefixCls.value}-date-content`}>
251250
{dateCellRender && dateCellRender({ current: date })}

components/tree-select/index.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,13 @@ const TreeSelect = defineComponent({
273273
removeIcon={removeIcon}
274274
clearIcon={clearIcon}
275275
switcherIcon={(nodeProps: SwitcherIconProps) =>
276-
renderSwitcherIcon(treePrefixCls.value, switcherIcon, treeLine, nodeProps)
276+
renderSwitcherIcon(
277+
treePrefixCls.value,
278+
switcherIcon,
279+
nodeProps,
280+
slots.leafIcon,
281+
treeLine,
282+
)
277283
}
278284
showTreeIcon={treeIcon as any}
279285
notFoundContent={mergedNotFound}

components/tree/Tree.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export default defineComponent({
260260
checkable={checkable}
261261
selectable={selectable}
262262
switcherIcon={(nodeProps: SwitcherIconProps) =>
263-
renderSwitcherIcon(prefixCls.value, switcherIcon, showLine, nodeProps)
263+
renderSwitcherIcon(prefixCls.value, switcherIcon, nodeProps, slots.leafIcon, showLine)
264264
}
265265
onCheck={handleCheck}
266266
onExpand={handleExpand}

components/tree/utils/dictUtil.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,7 @@ export function calcRangeKeys({
7474
keys.push(key);
7575
}
7676

77-
if (expandedKeys.indexOf(key) === -1) {
78-
return false;
79-
}
80-
81-
return true;
77+
return expandedKeys.includes(key);
8278
});
8379

8480
return keys;

components/tree/utils/iconUtil.tsx

+12-7
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ export interface SwitcherIconProps extends AntTreeNodeProps {
1414
export default function renderSwitcherIcon(
1515
prefixCls: string,
1616
switcherIcon: any,
17-
showLine: boolean | { showLeafIcon: boolean } | undefined,
1817
props: SwitcherIconProps,
18+
leafIcon?: (props: SwitcherIconProps) => any,
19+
showLine?: boolean | { showLeafIcon: boolean } | undefined,
1920
) {
2021
const { isLeaf, expanded, loading } = props;
2122
let icon = switcherIcon;
@@ -29,12 +30,16 @@ export default function renderSwitcherIcon(
2930
let defaultIcon = null;
3031
const switcherCls = `${prefixCls}-switcher-icon`;
3132
if (isLeaf) {
32-
if (showLine) {
33-
if (typeof showLine === 'object' && !showLeafIcon) {
34-
defaultIcon = <span class={`${prefixCls}-switcher-leaf-line`} />;
35-
} else {
36-
defaultIcon = <FileOutlined class={`${prefixCls}-switcher-line-icon`} />;
37-
}
33+
if (!showLine) {
34+
return null;
35+
}
36+
if (showLeafIcon && leafIcon) {
37+
return leafIcon(props);
38+
}
39+
if (typeof showLine === 'object' && !showLeafIcon) {
40+
defaultIcon = <span class={`${prefixCls}-switcher-leaf-line`} />;
41+
} else {
42+
defaultIcon = <FileOutlined class={`${prefixCls}-switcher-line-icon`} />;
3843
}
3944
return defaultIcon;
4045
} else {

0 commit comments

Comments
 (0)