-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dropdown): add render-label prop (#321)
* feat(dropdown): add render-label prrop * feat(dropdown): opt code * feat(dropdown): add render-label test * feat(dropdown): update snapshot * feat(dropdown): optimaze test case * Update src/dropdown/tests/Dropdown.spec.ts * Update src/dropdown/tests/Dropdown.spec.ts Co-authored-by: 07akioni <07akioni2@gmail.com>
- Loading branch information
1 parent
8ee2086
commit 8564f95
Showing
10 changed files
with
456 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Render Label | ||
|
||
The `renderLabel` can be used to batch render dropdown options. | ||
|
||
```html | ||
<n-dropdown | ||
:options="options" | ||
placement="bottom-start" | ||
trigger="click" | ||
@select="handleSelect" | ||
:render-label="renderDropdownLabel" | ||
> | ||
<n-button :keyboard="false">People and Some Food to Eat</n-button> | ||
</n-dropdown> | ||
``` | ||
|
||
```js | ||
import { h, defineComponent } from 'vue' | ||
import { NIcon, useMessage } from 'naive-ui' | ||
import { CashOutline as CashIcon } from '@vicons/ionicons5' | ||
|
||
const options = [ | ||
{ | ||
label: 'Jay Gatsby', | ||
key: 'jay gatsby' | ||
}, | ||
{ | ||
label: 'Daisy Buchanan', | ||
icon () { | ||
return h(NIcon, null, { | ||
default: () => h(CashIcon) | ||
}) | ||
}, | ||
key: 'daisy buchanan' | ||
}, | ||
{ | ||
type: 'divider', | ||
key: 'd1' | ||
}, | ||
{ | ||
label: 'Nick Carraway', | ||
key: 'nick carraway' | ||
}, | ||
{ | ||
label: 'Others', | ||
key: 'others1', | ||
children: [ | ||
{ | ||
label: 'Jordan Baker', | ||
key: 'jordan baker' | ||
}, | ||
{ | ||
label: 'Tom Buchanan', | ||
key: 'tom buchanan' | ||
}, | ||
{ | ||
label: 'Others', | ||
key: 'others2', | ||
disabled: true, | ||
children: [ | ||
{ | ||
label: 'Chicken', | ||
key: 'chicken' | ||
}, | ||
{ | ||
label: 'Beef', | ||
key: 'beef' | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
|
||
export default defineComponent({ | ||
data () { | ||
const message = useMessage() | ||
return { | ||
options, | ||
renderDropdownLabel (option) { | ||
return h('span', {}, { default: () => option.label }) | ||
}, | ||
handleSelect (key) { | ||
message.info(key) | ||
} | ||
} | ||
} | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# 批量处理菜单渲染 | ||
|
||
使用 `renderLabel` 可以批量控制下拉菜单的选项渲染。 | ||
|
||
```html | ||
<n-dropdown | ||
:options="options" | ||
placement="bottom-start" | ||
trigger="click" | ||
@select="handleSelect" | ||
:render-label="renderDropdownLabel" | ||
> | ||
<n-button :keyboard="false">人物和食物</n-button> | ||
</n-dropdown> | ||
``` | ||
|
||
```js | ||
import { h, defineComponent } from 'vue' | ||
import { NIcon, useMessage } from 'naive-ui' | ||
import { CashOutline as CashIcon } from '@vicons/ionicons5' | ||
|
||
const options = [ | ||
{ | ||
label: '杰·盖茨比', | ||
key: 'jay gatsby' | ||
}, | ||
{ | ||
label: '黛西·布坎南', | ||
icon () { | ||
return h(NIcon, null, { | ||
default: () => h(CashIcon) | ||
}) | ||
}, | ||
key: 'daisy buchanan' | ||
}, | ||
{ | ||
type: 'divider', | ||
key: 'd1' | ||
}, | ||
{ | ||
label: '尼克·卡拉威', | ||
key: 'nick carraway' | ||
}, | ||
{ | ||
label: '其他', | ||
key: 'others1', | ||
children: [ | ||
{ | ||
label: '乔丹·贝克', | ||
key: 'jordan baker' | ||
}, | ||
{ | ||
label: '汤姆·布坎南', | ||
key: 'tom buchanan' | ||
}, | ||
{ | ||
label: '其他', | ||
key: 'others2', | ||
disabled: true, | ||
children: [ | ||
{ | ||
label: '鸡肉', | ||
key: 'chicken' | ||
}, | ||
{ | ||
label: '牛肉', | ||
key: 'beef' | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
|
||
export default defineComponent({ | ||
setup () { | ||
const message = useMessage() | ||
return { | ||
options, | ||
renderDropdownLabel (option) { | ||
return h('span', {}, { default: () => option.label }) | ||
}, | ||
handleSelect (key) { | ||
message.info(key) | ||
} | ||
} | ||
} | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.