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

View File

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

View File

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

View File

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

View File

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