Skip to content

Commit

Permalink
feat(menu): support passing a function as icon options
Browse files Browse the repository at this point in the history
  • Loading branch information
qmhc committed Oct 25, 2022
1 parent e909ea3 commit 257a150
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
10 changes: 7 additions & 3 deletions components/menu/menu-item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
>
<div v-if="props.icon" :class="nh.be('icon')">
<slot name="icon">
<Icon v-bind="props.iconProps" :icon="props.icon"></Icon>
<Renderer v-if="typeof props.icon === 'function'" :renderer="props.icon"></Renderer>
<Icon v-else v-bind="props.iconProps" :icon="props.icon"></Icon>
</slot>
</div>
<span
Expand Down Expand Up @@ -137,7 +138,7 @@ const MenuItem = defineComponent({
},
props: {
label: String,
icon: Object,
icon: [Object, Function],
iconProps: Object as PropType<IconMinorProps>,
disabled: booleanProp,
transfer: booleanStringProp,
Expand All @@ -155,7 +156,10 @@ const MenuItem = defineComponent({
default: null,
static: true
},
icon: null,
icon: {
isFunc: true,
default: null
},
iconProps: null,
disabled: {
default: false,
Expand Down
2 changes: 1 addition & 1 deletion components/menu/symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type MenuGroupType = 'collapse' | 'dropdown'

export interface MenuOptions {
label: string,
icon?: Record<string, any>,
icon?: Record<string, any> | (() => any),
iconProps?: IconMinorProps,
name?: string | (() => string),
disabled?: boolean,
Expand Down
2 changes: 1 addition & 1 deletion docs/demos/menu/api.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { RouteLocationRaw } from 'vue-router'

interface MenuOptions {
label: string,
icon?: Record<string, any>,
icon?: Record<string, any> | (() => any),
iconProps?: IconMinorProps,
name?: string | (() => string),
disabled?: boolean,
Expand Down
2 changes: 1 addition & 1 deletion docs/demos/menu/api.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { RouteLocationRaw } from 'vue-router'

interface MenuOptions {
label: string,
icon?: Record<string, any>,
icon?: Record<string, any> | (() => any),
iconProps?: IconMinorProps,
name?: string | (() => string),
disabled?: boolean,
Expand Down
4 changes: 3 additions & 1 deletion docs/demos/menu/options/demo.en-US.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
</template>

<script setup lang="ts">
import { h } from 'vue'
import { Icon } from 'vexip-ui'
import { EnvelopesBulk, City, ChartPie, User, Marker } from '@vexip-ui/icons'
import type { MenuOptions } from 'vexip-ui'
Expand Down Expand Up @@ -42,7 +44,7 @@ const options: MenuOptions[] = [
{
label: '4',
name: () => 'Menu 4',
icon: User
icon: () => h(Icon, { icon: User })
},
{
label: '5',
Expand Down
4 changes: 3 additions & 1 deletion docs/demos/menu/options/demo.zh-CN.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
</template>

<script setup lang="ts">
import { h } from 'vue'
import { Icon } from 'vexip-ui'
import { EnvelopesBulk, City, ChartPie, User, Marker } from '@vexip-ui/icons'
import type { MenuOptions } from 'vexip-ui'
Expand Down Expand Up @@ -42,7 +44,7 @@ const options: MenuOptions[] = [
{
label: '4',
name: () => '菜单 4',
icon: User
icon: () => h(Icon, { icon: User })
},
{
label: '5',
Expand Down

0 comments on commit 257a150

Please sign in to comment.