Skip to content

Commit

Permalink
feat: tree node slot 支持 hover 参数
Browse files Browse the repository at this point in the history
  • Loading branch information
winixt committed Sep 14, 2024
1 parent c6504dc commit ac53e6a
Show file tree
Hide file tree
Showing 4 changed files with 7,276 additions and 8,802 deletions.
17 changes: 15 additions & 2 deletions components/tree/treeNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ref,
} from 'vue';
import { isFunction, isUndefined } from 'lodash-es';
import { useElementHover } from '@vueuse/core';
import getPrefixCls from '../_util/getPrefixCls';
import CaretDownOutlined from '../icon/CaretDownOutlined';
import LoadingOutlined from '../icon/LoadingOutlined';
Expand Down Expand Up @@ -216,6 +217,17 @@ export default defineComponent({
</span>
);
};

const treeNodeElement = ref();

const isHovered = useElementHover(treeNodeElement);
const slotParams = computed(() => {
return {
isHovered: isHovered.value,
value: props.value,
};
});

const renderPrefix = () => {
if (!slots.prefix) {
return null;
Expand All @@ -225,7 +237,7 @@ export default defineComponent({
class={`${prefixCls}-content-prefix`}
onClick={handleStopClickPrefix}
>
{slots.prefix?.()}
{slots.prefix?.(slotParams.value)}
</span>
);
};
Expand All @@ -238,7 +250,7 @@ export default defineComponent({
class={`${prefixCls}-content-suffix`}
onClick={handleStopClickPrefix}
>
{slots.suffix?.()}
{slots.suffix?.(slotParams.value)}
</span>
);
};
Expand Down Expand Up @@ -269,6 +281,7 @@ export default defineComponent({

return () => (
<div
ref={treeNodeElement}
class={classList.value}
style={style.value}
data-value={props.value}
Expand Down
Empty file added components/tree/useHover.ts
Empty file.
2 changes: 1 addition & 1 deletion docs/.vitepress/components/tree/fix.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function createData(level = 1, baseKey = '', prefix, suffix) {
value: key,
children: createData(level - 1, key, prefix, suffix),
prefix: prefix ? () => h(PictureOutlined) : null,
suffix: suffix ? () => h(PlusCircleOutlined) : null,
suffix: suffix ? (data) => (data.isHovered ? h(PlusCircleOutlined) : null) : null,
};
});
}
Expand Down
Loading

0 comments on commit ac53e6a

Please sign in to comment.