-
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(menu): add accordion prop (#1184)
* feat(menu): add accordion mode * feat(menu): rebuild accordion to level 1 & add doc * fix(menu): accordion only effect first-level menu * refator(menu): move treeKeysLevelOne to common ref * refactor(menu): use Map instead of Object * refator(menu): use Set instead of Map
- Loading branch information
1 parent
4712721
commit fd4c51a
Showing
7 changed files
with
192 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Accordion | ||
|
||
Like an accordion. You can use `accordion` prop to switch this mode for the first-level menu. | ||
|
||
```html | ||
<n-menu | ||
:options="menuOptions" | ||
:default-expanded-keys="defaultExpandedKeys" | ||
accordion | ||
/> | ||
``` | ||
|
||
```js | ||
import { defineComponent, h } from 'vue' | ||
import { NIcon } from 'naive-ui' | ||
import { | ||
FishOutline as FishIcon, | ||
PawOutline as PawIcon, | ||
BagOutline as BagOutlineIcon | ||
} from '@vicons/ionicons5' | ||
|
||
function renderIcon (icon) { | ||
return () => h(NIcon, null, { default: () => h(icon) }) | ||
} | ||
|
||
const menuOptions = [ | ||
{ | ||
label: 'Fish', | ||
key: 'fish', | ||
icon: renderIcon(FishIcon), | ||
children: [ | ||
{ | ||
label: 'Braise', | ||
key: 'braise', | ||
children: [ | ||
{ | ||
label: 'Spicy', | ||
key: 'spicy' | ||
} | ||
] | ||
}, | ||
{ | ||
label: 'Steamed', | ||
key: 'steamed', | ||
children: [ | ||
{ | ||
label: 'No Green Onion', | ||
key: 'no-green-onion' | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
label: 'Bear Paw', | ||
key: 'bear-paw', | ||
icon: renderIcon(PawIcon), | ||
children: [ | ||
{ | ||
label: 'Protect Wild Animals', | ||
key: 'protect-wild-animals' | ||
} | ||
] | ||
}, | ||
{ | ||
label: 'Both', | ||
key: 'both', | ||
icon: renderIcon(BagOutlineIcon), | ||
children: [ | ||
{ | ||
label: "You can't have your cake and eat it", | ||
key: 'can-not' | ||
} | ||
] | ||
} | ||
] | ||
|
||
export default defineComponent({ | ||
setup () { | ||
return { | ||
menuOptions, | ||
defaultExpandedKeys: ['fish', 'braise'] | ||
} | ||
} | ||
}) | ||
``` |
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,86 @@ | ||
# 手风琴 | ||
|
||
像一个手风琴。使用 `accordion` 属性对一级菜单使用该模式。 | ||
|
||
```html | ||
<n-menu | ||
:options="menuOptions" | ||
:default-expanded-keys="defaultExpandedKeys" | ||
accordion | ||
/> | ||
``` | ||
|
||
```js | ||
import { defineComponent, h } from 'vue' | ||
import { NIcon } from 'naive-ui' | ||
import { | ||
FishOutline as FishIcon, | ||
PawOutline as PawIcon, | ||
BagOutline as BagOutlineIcon | ||
} from '@vicons/ionicons5' | ||
|
||
function renderIcon (icon) { | ||
return () => h(NIcon, null, { default: () => h(icon) }) | ||
} | ||
|
||
const menuOptions = [ | ||
{ | ||
label: '鱼', | ||
key: 'fish', | ||
icon: renderIcon(FishIcon), | ||
children: [ | ||
{ | ||
label: '红烧', | ||
key: 'braise', | ||
children: [ | ||
{ | ||
label: '加辣', | ||
key: 'spicy' | ||
} | ||
] | ||
}, | ||
{ | ||
label: '清蒸', | ||
key: 'steamed', | ||
children: [ | ||
{ | ||
label: '不要葱', | ||
key: 'no-green-onion' | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
label: '熊掌', | ||
key: 'bear-paw', | ||
icon: renderIcon(PawIcon), | ||
children: [ | ||
{ | ||
label: '保护野生动物', | ||
key: 'protect-wild-animals' | ||
} | ||
] | ||
}, | ||
{ | ||
label: '两个都要', | ||
key: 'both', | ||
icon: renderIcon(BagOutlineIcon), | ||
children: [ | ||
{ | ||
label: '鱼和熊掌不可兼得', | ||
key: 'can-not' | ||
} | ||
] | ||
} | ||
] | ||
|
||
export default defineComponent({ | ||
setup () { | ||
return { | ||
menuOptions, | ||
defaultExpandedKeys: ['fish', 'braise'] | ||
} | ||
} | ||
}) | ||
``` |
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