-
Notifications
You must be signed in to change notification settings - Fork 300
feat(nav-menu): 新增 icon 属性及icon slot,支持配置菜单图标 #3120
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
150 changes: 150 additions & 0 deletions
150
examples/sites/demos/pc/app/nav-menu/menu-icon-composition-api.vue
This file contains hidden or 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,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> |
This file contains hidden or 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,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() | ||
}) |
This file contains hidden or 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,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> |
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -169,7 +169,8 @@ export const initData = | |
id: item.id, | ||
pid: item.pid, | ||
isFullUrl: props.allowFullUrl && isFullUrl(router), | ||
target: item.target | ||
target: item.target, | ||
icon: item.icon | ||
} | ||
} | ||
|
||
|
@@ -577,7 +578,7 @@ export const handleTitleMouseenter = | |
const text = target.textContent | ||
const font = window.getComputedStyle(target).font | ||
const rect = target.getBoundingClientRect() | ||
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 adjustment from |
||
const res = omitText(text, font, rect.width + 2) | ||
const res = omitText(text, font, rect.width + 4) | ||
|
||
if (target && res.o) { | ||
const tooltip = vm.$refs.tooltip | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Fix typo in type declaration
There is a typo in the type declaration for the
icon
property:Commonent
should beComponent
.📝 Committable suggestion