Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/packages/menu/demos/h5/demo6.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react'
import { Menu } from '@nutui/nutui-react'
import { ArrowDown, Star } from '@nutui/icons-react'
import { ArrowDown, Star, Filter } from '@nutui/icons-react'

const Demo6 = () => {
const [options] = useState([
Expand All @@ -15,7 +15,12 @@ const Demo6 = () => {
])
return (
<Menu icon={<ArrowDown />}>
<Menu.Item options={options} defaultValue={0} icon={<Star />} />
<Menu.Item
options={options}
defaultValue={0}
icon={<Star />}
titleIcon={<Filter />}
/>
<Menu.Item options={options1} defaultValue="a" />
</Menu>
)
Expand Down
9 changes: 7 additions & 2 deletions src/packages/menu/demos/taro/demo6.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react'
import { Menu } from '@nutui/nutui-react-taro'
import { ArrowDown, Star } from '@nutui/icons-react-taro'
import { ArrowDown, Star, Filter } from '@nutui/icons-react-taro'

const Demo6 = () => {
const [options] = useState([
Expand All @@ -15,7 +15,12 @@ const Demo6 = () => {
])
return (
<Menu icon={<ArrowDown />}>
<Menu.Item options={options} defaultValue={0} icon={<Star />} />
<Menu.Item
options={options}
defaultValue={0}
icon={<Star />}
titleIcon={<Filter />}
/>
<Menu.Item options={options1} defaultValue="a" />
</Menu>
)
Expand Down
1 change: 1 addition & 0 deletions src/packages/menu/doc.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Popup can be closed with toggle method in menu instance.
| Property | Description | Type | Default |
| --- | --- | --- | --- |
| title | Item title | `string` | `Current selected value` |
| titleIcon | menu item icon | `React.ReactNode` | `ArrowUp/ArrowDown` |
| options | Options | `Array` | `-` |
| disabled | Whether to disable dropdown item | `boolean` | `false` |
| columns | Display how many options in one line | `number` | `1` |
Expand Down
1 change: 1 addition & 0 deletions src/packages/menu/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import { Menu } from '@nutui/nutui-react'
| 属性 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| title | 菜单项标题 | `string` | `当前选中项文字` |
| titleIcon | 菜单项 icon | `React.ReactNode` | `ArrowUp/ArrowDown` |
| options | 选项数组 | `array` | `-` |
| disabled | 是否禁用菜单 | `boolean` | `false` |
| columns | 可以设置一行展示多少列 options | `number` | `1` |
Expand Down
1 change: 1 addition & 0 deletions src/packages/menu/doc.taro.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import { Menu } from '@nutui/nutui-react-taro'
| 属性 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| title | 菜单项标题 | `string` | `当前选中项文字` |
| titleIcon | 菜单项 icon | `React.ReactNode` | `ArrowUp/ArrowDown` |
| options | 选项数组 | `array` | `-` |
| disabled | 是否禁用菜单 | `boolean` | `false` |
| columns | 可以设置一行展示多少列 options | `number` | `1` |
Expand Down
1 change: 1 addition & 0 deletions src/packages/menu/doc.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import { Menu } from '@nutui/nutui-react'
| 屬性 | 說明 | 類型 | 默認值 |
| --- | --- | --- | --- |
| title | 菜單項標題 | `string` | `當前選中項文字` |
| titleIcon | 菜單項 icon | `React.ReactNode` | `ArrowUp/ArrowDown` |
| options | 選項數組 | `array` | `-` |
| disabled | 是否禁用菜單 | `boolean` | `false` |
| columns | 可以設置一行展示多少列 options | `number` | `1` |
Expand Down
35 changes: 27 additions & 8 deletions src/packages/menu/menu.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,15 @@ export const Menu: FunctionComponent<Partial<MenuProps>> & {
const menuTitle = () => {
return React.Children.map(children, (child, index) => {
if (React.isValidElement(child)) {
const { title, options, value, defaultValue, disabled, direction } =
child.props
const {
title,
titleIcon,
options,
value,
defaultValue,
disabled,
direction,
} = child.props
const selected = options?.filter(
(option: OptionItem) =>
option.value === (value !== undefined ? value : defaultValue)
Expand All @@ -133,6 +140,23 @@ export const Menu: FunctionComponent<Partial<MenuProps>> & {
return selected[0].text
return ''
}
const finallyIcon = () => {
if (titleIcon) return titleIcon
if (icon) return icon
return direction === 'up' ? (
<ArrowUp
className="nut-menu-title-icon"
width="12px"
height="12px"
/>
) : (
<ArrowDown
className="nut-menu-title-icon"
width="12px"
height="12px"
/>
)
}
return (
<div
className={classNames('nut-menu-title', `nut-menu-title-${index}`, {
Expand All @@ -147,12 +171,7 @@ export const Menu: FunctionComponent<Partial<MenuProps>> & {
}}
>
<div className="nut-menu-title-text">{finallyTitle()}</div>
{icon ||
(direction === 'up' ? (
<ArrowUp className="nut-menu-title-icon" size="12px" />
) : (
<ArrowDown className="nut-menu-title-icon" size="12px" />
))}
{finallyIcon()}
</div>
)
}
Expand Down
43 changes: 27 additions & 16 deletions src/packages/menu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,15 @@ export const Menu: FunctionComponent<Partial<MenuProps>> & {
const menuTitle = () => {
return React.Children.map(children, (child, index) => {
if (React.isValidElement(child)) {
const { title, options, value, defaultValue, disabled, direction } =
child.props
const {
title,
titleIcon,
options,
value,
defaultValue,
disabled,
direction,
} = child.props
const selected = options?.filter(
(option: OptionItem) =>
option.value === (value !== undefined ? value : defaultValue)
Expand All @@ -133,6 +140,23 @@ export const Menu: FunctionComponent<Partial<MenuProps>> & {
return selected[0].text
return ''
}
const finallyIcon = () => {
if (titleIcon) return titleIcon
if (icon) return icon
return direction === 'up' ? (
<ArrowUp
className="nut-menu-title-icon"
width="12px"
height="12px"
/>
) : (
<ArrowDown
className="nut-menu-title-icon"
width="12px"
height="12px"
/>
)
}
return (
<div
className={classNames('nut-menu-title', `nut-menu-title-${index}`, {
Expand All @@ -148,20 +172,7 @@ export const Menu: FunctionComponent<Partial<MenuProps>> & {
}}
>
<div className="nut-menu-title-text">{finallyTitle()}</div>
{icon ||
(direction === 'up' ? (
<ArrowUp
className="nut-menu-title-icon"
width="12px"
height="12px"
/>
) : (
<ArrowDown
className="nut-menu-title-icon"
width="12px"
height="12px"
/>
))}
{finallyIcon()}
</div>
)
}
Expand Down
2 changes: 2 additions & 0 deletions src/packages/menuitem/menuitem.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface OptionItem {

export interface MenuItemProps extends BasicComponent {
title: React.ReactNode
titleIcon: React.ReactNode
options: OptionItem[]
disabled: boolean
columns: number
Expand All @@ -40,6 +41,7 @@ export interface MenuItemProps extends BasicComponent {

const defaultProps = {
...ComponentDefaults,
titleIcon: null,
columns: 1,
direction: 'down',
icon: null,
Expand Down
2 changes: 2 additions & 0 deletions src/packages/menuitem/menuitem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface OptionItem {

export interface MenuItemProps extends BasicComponent {
title: React.ReactNode
titleIcon: React.ReactNode
options: OptionItem[]
disabled: boolean
columns: number
Expand All @@ -39,6 +40,7 @@ export interface MenuItemProps extends BasicComponent {

const defaultProps = {
...ComponentDefaults,
titleIcon: null,
columns: 1,
direction: 'down',
icon: null,
Expand Down