-
Notifications
You must be signed in to change notification settings - Fork 297
feat(nav-menu): [nav-menu] 新增 icon 属性及icon slot,支持配置菜单图标 #3181
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -127,6 +127,16 @@ export default { | |||||
}, | ||||||
mode: ['pc'], | ||||||
pcDemo: 'slot-toolbar' | ||||||
}, | ||||||
{ | ||||||
name: 'icon', | ||||||
defaultValue: '', | ||||||
desc: { | ||||||
'zh-CN': '自定义菜单图标插槽', | ||||||
'en-US': 'Customize the menu icon' | ||||||
}, | ||||||
mode: ['pc'], | ||||||
pcDemo: 'menu-icon' | ||||||
} | ||||||
] | ||||||
} | ||||||
|
@@ -153,6 +163,7 @@ interface IMenuItem { | |||||
interface IDataItem { | ||||||
title: string | ||||||
url: string | ||||||
icon?: Commonent | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix typo in IDataItem interface There's a typo in the type definition for the icon property - "Commonent" should be "Component". - icon?: Commonent
+ icon?: Component 📝 Committable suggestion
Suggested change
|
||||||
children?: IDataItem[] | ||||||
}` | ||||||
}, | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<template> | ||
<div class="preview"> | ||
<tiny-nav-menu :data="menuData"></tiny-nav-menu> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="jsx"> | ||
import { ref } from 'vue' | ||
import { TinyNavMenu } from '@opentiny/vue' | ||
import { iconTotal, iconGenerating } from '@opentiny/vue-icon' | ||
|
||
const menuData = ref([ | ||
{ | ||
title: '首页', | ||
url: '', | ||
id: '1', | ||
icon: iconTotal() | ||
}, | ||
{ | ||
title: '指南', | ||
url: '', | ||
id: '2', | ||
children: [ | ||
{ | ||
title: '引入组件', | ||
url: '', | ||
id: '2-1', | ||
icon: iconTotal() | ||
}, | ||
{ | ||
title: '后端适配器', | ||
url: '', | ||
id: '2-2' | ||
} | ||
] | ||
}, | ||
{ | ||
title: '组件', | ||
url: '', | ||
id: '3', | ||
children: [ | ||
{ | ||
title: '表单组件', | ||
url: '', | ||
id: '3-1', | ||
children: [ | ||
{ | ||
title: 'Datepicker 日期', | ||
url: 'datepicker', | ||
id: '3-1-1', | ||
icon: iconTotal() | ||
}, | ||
{ | ||
title: 'Cascader 级联选择器', | ||
url: 'cascader', | ||
id: '3-1-2', | ||
icon: iconGenerating() | ||
}, | ||
{ | ||
title: 'DropTimes 下拉时间', | ||
url: 'droptimes', | ||
id: '3-1-3' | ||
} | ||
] | ||
}, | ||
{ | ||
title: '数据展示', | ||
url: '', | ||
id: '3-2', | ||
children: [ | ||
{ | ||
title: 'Card 卡片', | ||
url: 'card', | ||
id: '3-2-1' | ||
}, | ||
{ | ||
title: 'Collapse 折叠面板', | ||
url: 'collapse', | ||
id: '3-2-2' | ||
}, | ||
{ | ||
title: 'Guide 引导', | ||
url: 'guide', | ||
id: '3-2-3' | ||
} | ||
] | ||
}, | ||
{ | ||
title: '导航组件', | ||
url: '', | ||
id: '3-3', | ||
children: [ | ||
{ | ||
title: 'ToggleMenu 收缩菜单', | ||
url: 'toggleMenu', | ||
id: '3-3-1' | ||
}, | ||
{ | ||
title: 'TreeMenu 树型菜单', | ||
url: 'treemenu', | ||
id: '3-3-2' | ||
}, | ||
{ | ||
title: 'Breadcrumb 面包屑', | ||
url: 'breadcrumb', | ||
id: '3-3-3' | ||
} | ||
] | ||
}, | ||
{ | ||
title: '业务组件', | ||
url: '', | ||
id: '3-4', | ||
children: [ | ||
{ | ||
title: 'Amount 金额', | ||
url: 'amount', | ||
id: '3-4-1' | ||
}, | ||
{ | ||
title: 'Area 片区', | ||
url: 'area', | ||
id: '3-4-2' | ||
}, | ||
{ | ||
title: 'Company 公司', | ||
url: 'company', | ||
id: '3-4-3' | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
title: '其他', | ||
url: 'crop', | ||
id: '4' | ||
} | ||
]) | ||
</script> | ||
|
||
<style scoped> | ||
.preview { | ||
min-height: 450px; | ||
} | ||
|
||
.preview .tiny-nav-menu a:hover { | ||
text-decoration: none; | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { test, expect } from '@playwright/test' | ||
|
||
test('菜单图标', async ({ page }) => { | ||
page.on('pageerror', (exception) => expect(exception).toBeNull()) | ||
await page.goto('nav-menu#menu-icon') | ||
const preview = page.locator('#menu-icon') | ||
const icon = preview.locator('.menu-icon') | ||
const iconSvg = preview.locator('.menu-icon svg') | ||
await expect(icon).toBeVisible() | ||
await expect(iconSvg).toBeVisible() | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
<template> | ||
<div class="preview"> | ||
<h4>配置模式</h4> | ||
<tiny-nav-menu :data="menuData" overflow="fixed"> </tiny-nav-menu> | ||
|
||
<h4>slot 模式</h4> | ||
<tiny-nav-menu :data="menuData" overflow="fixed"> | ||
<template #icon="{ selected, index, item }"> | ||
<IconGenerating v-if="selected" /> | ||
<IconTotal v-else /> | ||
</template> | ||
</tiny-nav-menu> | ||
</div> | ||
</template> | ||
|
||
<script lang="jsx"> | ||
import { TinyNavMenu } from '@opentiny/vue' | ||
import { iconTotal, iconGenerating } from '@opentiny/vue-icon' | ||
|
||
export default { | ||
components: { | ||
TinyNavMenu, | ||
IconGenerating: iconGenerating(), | ||
IconTotal: iconTotal() | ||
}, | ||
data() { | ||
return { | ||
menuData: [ | ||
{ | ||
title: '首页', | ||
url: '', | ||
id: '1', | ||
icon: iconTotal() | ||
}, | ||
{ | ||
title: '指南', | ||
url: '', | ||
id: '2', | ||
children: [ | ||
{ | ||
title: '引入组件', | ||
url: '', | ||
id: '2-1', | ||
icon: iconTotal() | ||
}, | ||
{ | ||
title: '后端适配器', | ||
url: '', | ||
id: '2-2' | ||
} | ||
] | ||
}, | ||
{ | ||
title: '组件', | ||
url: '', | ||
id: '3', | ||
children: [ | ||
{ | ||
title: '表单组件', | ||
url: '', | ||
id: '3-1', | ||
children: [ | ||
{ | ||
title: 'Datepicker 日期', | ||
url: 'datepicker', | ||
id: '3-1-1', | ||
icon: iconTotal() | ||
}, | ||
{ | ||
title: 'Cascader 级联选择器', | ||
url: 'cascader', | ||
id: '3-1-2', | ||
icon: iconGenerating() | ||
}, | ||
{ | ||
title: 'DropTimes 下拉时间', | ||
url: 'droptimes', | ||
id: '3-1-3' | ||
} | ||
] | ||
}, | ||
{ | ||
title: '数据展示', | ||
url: '', | ||
id: '3-2', | ||
children: [ | ||
{ | ||
title: 'Card 卡片', | ||
url: 'card', | ||
id: '3-2-1' | ||
}, | ||
{ | ||
title: 'Collapse 折叠面板', | ||
url: 'collapse', | ||
id: '3-2-2' | ||
}, | ||
{ | ||
title: 'Guide 引导', | ||
url: 'guide', | ||
id: '3-2-3' | ||
} | ||
] | ||
}, | ||
{ | ||
title: '导航组件', | ||
url: '', | ||
id: '3-3', | ||
children: [ | ||
{ | ||
title: 'ToggleMenu 收缩菜单', | ||
url: 'toggleMenu', | ||
id: '3-3-1' | ||
}, | ||
{ | ||
title: 'TreeMenu 树型菜单', | ||
url: 'treemenu', | ||
id: '3-3-2' | ||
}, | ||
{ | ||
title: 'Breadcrumb 面包屑', | ||
url: 'breadcrumb', | ||
id: '3-3-3' | ||
} | ||
] | ||
}, | ||
{ | ||
title: '业务组件', | ||
url: '', | ||
id: '3-4', | ||
children: [ | ||
{ | ||
title: 'Amount 金额', | ||
url: 'amount', | ||
id: '3-4-1' | ||
}, | ||
{ | ||
title: 'Area 片区', | ||
url: 'area', | ||
id: '3-4-2' | ||
}, | ||
{ | ||
title: 'Company 公司', | ||
url: 'company', | ||
id: '3-4-3' | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
title: '其他', | ||
url: 'crop', | ||
id: '4' | ||
} | ||
] | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.preview { | ||
min-height: 450px; | ||
} | ||
|
||
.preview > .tiny-nav-menu { | ||
margin-bottom: 24px; | ||
} | ||
|
||
.preview .tiny-nav-menu a:hover { | ||
text-decoration: none; | ||
} | ||
</style> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
新的api需要说明下版本信息哈:https://github.com/opentiny/tiny-vue/wiki/%E5%AE%98%E7%BD%91%E7%BB%84%E4%BB%B6%E4%BB%A5%E5%8F%8AAPI%E7%89%88%E6%9C%AC%E7%8A%B6%E6%80%81%E7%BB%B4%E6%8A%A4%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E6%96%B9%E6%A1%88