Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(n-tree): adds option prop to the render-switcher-icon #4815

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- `n-tree-select` adds `focusInput` `blurInput` methods.
- `n-image-group` adds `on-preview-prev` `on-preview-next` prop
- `n-tree` adds `show-line` prop, closes [#3796](https://github.com/tusen-ai/naive-ui/issues/3796), [#4554](https://github.com/tusen-ai/naive-ui/pull/4554)
- `n-tree` adds node information for `render-switcher-icon` props, closes [#4815](https://github.com/tusen-ai/naive-ui/issues/4815).

## 2.34.4

Expand Down Expand Up @@ -62,6 +63,7 @@
- `n-tabs` adds `placement` prop.
- `n-spin` adds `delay` prop.


### i18n

- Update `zhTW` locale.
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- `n-tree-select` 新增 `focusInput` `blurInput` 方法
- `n-image-group` 新增 `on-preview-prev` `on-preview-next` 属性
- `n-tree` 新增 `show-line` 属性,关闭 [#3796](https://github.com/tusen-ai/naive-ui/issues/3796), [#4554](https://github.com/tusen-ai/naive-ui/issues/4554)
- `n-tree` 为 `render-switcher-icon` 属性添加节点信息,关闭 [#4815](https://github.com/tusen-ai/naive-ui/issues/4815)

## 2.34.4

Expand Down
2 changes: 1 addition & 1 deletion src/tree/demos/enUS/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ checkbox-placement.vue
| render-label | `(info: { option: TreeOption, checked: boolean, selected: boolean }) => VNodeChild` | `undefined` | Render function of all the options' label. | |
| render-prefix | `(info: { option: TreeOption, checked: boolean, selected: boolean }) => VNodeChild` | `undefined` | Render function of all the options' prefix. | |
| render-suffix | `(info: { option: TreeOption, checked: boolean, selected: boolean }) => VNodeChild` | `undefined` | Render function of all the options' suffix. | |
| render-switcher-icon | `(props: { expanded: boolean, selected: boolean }) => VNodeChild` | `undefined` | Render function of option switcher icon. | 2.24.0, `props` 2.34.0 |
| render-switcher-icon | `(props: { option: TreeOption, expanded: boolean, selected: boolean }) => VNodeChild` | `undefined` | Render function of option switcher icon. | 2.24.0, `props` 2.34.0 |
| scrollbar-props | `object` | `undefined` | See [Scrollbar props](scrollbar#Scrollbar-Props) | |
| selectable | `boolean` | `true` | Whether the node can be selected. | |
| selected-keys | `Array<string \| number>` | `undefined` | If set, selected status will work in controlled manner. | |
Expand Down
2 changes: 1 addition & 1 deletion src/tree/demos/zhCN/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ expand-debug.vue
| render-label | `(info: { option: TreeOption, checked: boolean, selected: boolean }) => VNodeChild` | `undefined` | 节点内容的渲染函数 | |
| render-prefix | `(info: { option: TreeOption, checked: boolean, selected: boolean }) => VNodeChild` | `undefined` | 节点前缀的渲染函数 | |
| render-suffix | `(info: { option: TreeOption, checked: boolean, selected: boolean }) => VNodeChild` | `undefined` | 节点后缀的渲染函数 | |
| render-switcher-icon | `(props: { expanded: boolean, selected: boolean }) => VNodeChild` | `undefined` | 节点展开开关的渲染函数 | 2.24.0, `props` 2.34.0 |
| render-switcher-icon | `(props: { option: TreeOption, expanded: boolean, selected: boolean }) => VNodeChild` | `undefined` | 节点展开开关的渲染函数 | 2.24.0, `props` 2.34.0 |
| scrollbar-props | `object` | `undefined` | 属性参考 [Scrollbar props](scrollbar#Scrollbar-Props) |   |
| selectable | `boolean` | `true` | 节点是否可以被选中 | |
| selected-keys | `Array<string \| number>` | `undefined` | 如果设定则 `selected` 状态受控 | |
Expand Down
1 change: 1 addition & 0 deletions src/tree/src/TreeNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ const TreeNode = defineComponent({
selected={selected}
loading={this.loading}
hide={tmNode.isLeaf}
tmNode={this.tmNode}
indent={indent}
onClick={this.handleSwitcherClick}
/>
Expand Down
11 changes: 8 additions & 3 deletions src/tree/src/TreeNodeSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { h, defineComponent, type PropType, inject } from 'vue'
import { SwitcherIcon } from '../../_internal/icons'
import { NIconSwitchTransition, NBaseLoading, NBaseIcon } from '../../_internal'
import { treeInjectionKey } from './interface'
import { type TmNode, treeInjectionKey } from './interface'

export default defineComponent({
name: 'NTreeSwitcher',
Expand All @@ -15,7 +15,11 @@ export default defineComponent({
selected: Boolean,
hide: Boolean,
loading: Boolean,
onClick: Function as PropType<(e: MouseEvent) => void>
onClick: Function as PropType<(e: MouseEvent) => void>,
tmNode: {
type: Object as PropType<TmNode>,
required: true
}
},
setup (props) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand Down Expand Up @@ -51,7 +55,8 @@ export default defineComponent({
return renderSwitcherIcon ? (
renderSwitcherIcon({
expanded: props.expanded,
selected: props.selected
selected: props.selected,
option: props.tmNode.rawNode
})
) : (
<NBaseIcon clsPrefix={clsPrefix} key="switcher">
Expand Down
1 change: 1 addition & 0 deletions src/tree/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export interface InternalDropInfo {
export type RenderSwitcherIcon = (props: {
expanded: boolean
selected: boolean
option: TreeOption
}) => VNodeChild

export type CheckOnClick = (option: TreeOption) => boolean
Expand Down