Skip to content

Commit

Permalink
feat(n-tree-select): add get-children demo
Browse files Browse the repository at this point in the history
  • Loading branch information
jahnli committed Jan 1, 2025
1 parent 8bd232c commit 3aef1a8
Show file tree
Hide file tree
Showing 9 changed files with 472 additions and 1 deletion.
3 changes: 2 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export default antfu(
'style/comma-dangle': 'off',
'style/quote-props': 'off',
'jsdoc/require-returns-description': 'off',
'jsdoc/check-param-names': 'off'
'jsdoc/check-param-names': 'off',
'no-console': 'off'
}
}
)
1 change: 1 addition & 0 deletions src/tree-select/demos/enUS/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ action.vue
async.vue
status.vue
file-picker.vue
node-display-mode.vue
debug.vue
```

Expand Down
171 changes: 171 additions & 0 deletions src/tree-select/demos/enUS/node-display-mode.demo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<markdown>
# Node display mode

You can use `get-children` to implement different ways of displaying nodes.
</markdown>

<script lang="ts">
import type { TreeSelectOption } from 'naive-ui'
import { defineComponent, ref } from 'vue'
export default defineComponent({
setup() {
return {
active: ref(false),
handleUpdateValue(
value: string | number | Array<string | number> | null,
option: TreeSelectOption | null | Array<TreeSelectOption | null>
) {
console.log(value, option)
},
options: [
{
label: 'Rubber Soul',
key: 'Rubber Soul',
children: [
{
label:
'Everybody\'s Got Something to Hide Except Me and My Monkey',
key: 'Everybody\'s Got Something to Hide Except Me and My Monkey',
children: []
},
{
label: 'Drive My Car',
key: 'Drive My Car',
disabled: true,
children: []
},
{
label: 'Norwegian Wood',
key: 'Norwegian Wood',
children: []
},
{
label: 'You Won\'t See',
key: 'You Won\'t See',
disabled: true,
children: []
},
{
label: 'Nowhere Man',
key: 'Nowhere Man',
children: []
},
{
label: 'Think For Yourself',
key: 'Think For Yourself',
children: []
},
{
label: 'The Word',
key: 'The Word',
children: []
},
{
label: 'Michelle',
key: 'Michelle',
disabled: true,
children: []
},
{
label: 'What goes on',
key: 'What goes on',
children: []
},
{
label: 'Girl',
key: 'Girl',
children: []
},
{
label: 'I\'m looking through you',
key: 'I\'m looking through you',
children: []
},
{
label: 'In My Life',
key: 'In My Life',
children: []
},
{
label: 'Wait',
key: 'Wait',
children: []
}
]
},
{
label: 'Let It Be',
key: 'Let It Be Album',
children: [
{
label: 'Two Of Us',
key: 'Two Of Us'
},
{
label: 'Dig A Pony',
key: 'Dig A Pony'
},
{
label: 'Across The Universe',
key: 'Across The Universe'
},
{
label: 'I Me Mine',
key: 'I Me Mine'
},
{
label: 'Dig It',
key: 'Dig It'
},
{
label: 'Let It Be',
key: 'Let It Be'
},
{
label: 'Maggie Mae',
key: 'Maggie Mae'
},
{
label: 'I\'ve Got A Feeling',
key: 'I\'ve Got A Feeling'
},
{
label: 'One After 909',
key: 'One After 909'
},
{
label: 'The Long And Winding Road',
key: 'The Long And Winding Road'
},
{
label: 'For You Blue',
key: 'For You Blue'
},
{
label: 'Get Back',
key: 'Get Back'
}
]
}
]
}
}
})
</script>

<template>
<n-flex vertical align="start">
<n-switch v-model:value="active" />
<n-tree-select
:options="options"
default-value="Drive My Car"
:get-children="
active
? (v) => (v.children?.length ? v.children : undefined)

Check failure on line 165 in src/tree-select/demos/enUS/node-display-mode.demo.vue

View workflow job for this annotation

GitHub Actions / lint (18)

Parameter 'v' implicitly has an 'any' type.

Check failure on line 165 in src/tree-select/demos/enUS/node-display-mode.demo.vue

View workflow job for this annotation

GitHub Actions / lint (20)

Parameter 'v' implicitly has an 'any' type.
: undefined
"
@update:value="handleUpdateValue"
/>
</n-flex>
</template>
1 change: 1 addition & 0 deletions src/tree-select/demos/zhCN/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ action.vue
async.vue
status.vue
file-picker.vue
node-display-mode.vue
debug.vue
field-search-debug.vue
render-debug.vue
Expand Down
171 changes: 171 additions & 0 deletions src/tree-select/demos/zhCN/node-display-mode.demo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<markdown>
# 节点展示方式

你可以使用 `get-children` 实现不同的节点展示方式
</markdown>

<script lang="ts">
import type { TreeSelectOption } from 'naive-ui'
import { defineComponent, ref } from 'vue'
export default defineComponent({
setup() {
return {
active: ref(false),
handleUpdateValue(
value: string | number | Array<string | number> | null,
option: TreeSelectOption | null | Array<TreeSelectOption | null>
) {
console.log(value, option)
},
options: [
{
label: 'Rubber Soul',
key: 'Rubber Soul',
children: [
{
label:
'Everybody\'s Got Something to Hide Except Me and My Monkey',
key: 'Everybody\'s Got Something to Hide Except Me and My Monkey',
children: []
},
{
label: 'Drive My Car',
key: 'Drive My Car',
disabled: true,
children: []
},
{
label: 'Norwegian Wood',
key: 'Norwegian Wood',
children: []
},
{
label: 'You Won\'t See',
key: 'You Won\'t See',
disabled: true,
children: []
},
{
label: 'Nowhere Man',
key: 'Nowhere Man',
children: []
},
{
label: 'Think For Yourself',
key: 'Think For Yourself',
children: []
},
{
label: 'The Word',
key: 'The Word',
children: []
},
{
label: 'Michelle',
key: 'Michelle',
disabled: true,
children: []
},
{
label: 'What goes on',
key: 'What goes on',
children: []
},
{
label: 'Girl',
key: 'Girl',
children: []
},
{
label: 'I\'m looking through you',
key: 'I\'m looking through you',
children: []
},
{
label: 'In My Life',
key: 'In My Life',
children: []
},
{
label: 'Wait',
key: 'Wait',
children: []
}
]
},
{
label: 'Let It Be',
key: 'Let It Be Album',
children: [
{
label: 'Two Of Us',
key: 'Two Of Us'
},
{
label: 'Dig A Pony',
key: 'Dig A Pony'
},
{
label: 'Across The Universe',
key: 'Across The Universe'
},
{
label: 'I Me Mine',
key: 'I Me Mine'
},
{
label: 'Dig It',
key: 'Dig It'
},
{
label: 'Let It Be',
key: 'Let It Be'
},
{
label: 'Maggie Mae',
key: 'Maggie Mae'
},
{
label: 'I\'ve Got A Feeling',
key: 'I\'ve Got A Feeling'
},
{
label: 'One After 909',
key: 'One After 909'
},
{
label: 'The Long And Winding Road',
key: 'The Long And Winding Road'
},
{
label: 'For You Blue',
key: 'For You Blue'
},
{
label: 'Get Back',
key: 'Get Back'
}
]
}
]
}
}
})
</script>

<template>
<n-flex vertical align="start">
<n-switch v-model:value="active" />
<n-tree-select
:options="options"
default-value="Drive My Car"
:get-children="
active
? (v) => (v.children?.length ? v.children : undefined)

Check failure on line 165 in src/tree-select/demos/zhCN/node-display-mode.demo.vue

View workflow job for this annotation

GitHub Actions / lint (18)

Parameter 'v' implicitly has an 'any' type.

Check failure on line 165 in src/tree-select/demos/zhCN/node-display-mode.demo.vue

View workflow job for this annotation

GitHub Actions / lint (20)

Parameter 'v' implicitly has an 'any' type.
: undefined
"
@update:value="handleUpdateValue"
/>
</n-flex>
</template>
1 change: 1 addition & 0 deletions src/tree/demos/enUS/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ node-props.vue
show-line.vue
checkbox-placement.vue
override-click-behavior.vue
node-display-mode.vue
```

## API
Expand Down
Loading

0 comments on commit 3aef1a8

Please sign in to comment.