Skip to content

Commit 0803d29

Browse files
committed
refactor(NavBar): backArrow -> backIcon
1 parent ab0d47b commit 0803d29

File tree

8 files changed

+25
-21
lines changed

8 files changed

+25
-21
lines changed

src/components/config-provider/config-provider.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React, { useContext } from 'react'
21
import type { FC, ReactNode } from 'react'
2+
import React, { useContext } from 'react'
33
import { Locale } from '../../locales/base'
44
import zhCN from '../../locales/zh-CN'
55
import { mergeProps } from '../../utils/with-default-props'
@@ -29,7 +29,7 @@ type Config = {
2929
arrow?: ReactNode
3030
}
3131
navBar?: {
32-
backArrow?: ReactNode
32+
backIcon?: ReactNode
3333
}
3434
noticeBar?: {
3535
icon?: ReactNode

src/components/config-provider/index.en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Configure locale messages and custom icons globally.
2727
| imageUploader | ImageUploader config | `{ uploadIcon?: ReactNode, deleteIcon?: ReactNode }` | - |
2828
| input | Input config | `{ clearIcon?: ReactNode }` | - |
2929
| listItem | List.Item config | `{ arrow?: ReactNode }` | - |
30-
| navBar | NavBar config | `{ backArrow?: ReactNode }` | - |
30+
| navBar | NavBar config | `{ backIcon?: ReactNode }` | - |
3131
| noticeBar | NoticeBar config | `{ icon?: ReactNode, closeIcon?: ReactNode }` | - |
3232
| numberKeyboard | NumberKeyboard config | `{ closeIcon?: ReactNode, deleteIcon?: ReactNode }` | - |
3333
| popup | Popup config | `{ closeIcon?: ReactNode }` | - |

src/components/config-provider/index.zh.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
| imageUploader | ImageUploader 配置 | `{ uploadIcon?: ReactNode, deleteIcon?: ReactNode }` | - |
2828
| input | Input 配置 | `{ clearIcon?: ReactNode }` | - |
2929
| listItem | List.Item 配置 | `{ arrow?: ReactNode }` | - |
30-
| navBar | NavBar 配置 | `{ backArrow?: ReactNode }` | - |
30+
| navBar | NavBar 配置 | `{ backIcon?: ReactNode }` | - |
3131
| noticeBar | NoticeBar 配置 | `{ icon?: ReactNode, closeIcon?: ReactNode }` | - |
3232
| numberKeyboard | NumberKeyboard 配置 | `{ closeIcon?: ReactNode, deleteIcon?: ReactNode }` | - |
3333
| popup | Popup 配置 | `{ closeIcon?: ReactNode }` | - |

src/components/nav-bar/demos/demo1.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React from 'react'
21
import { NavBar, Space, Toast } from 'antd-mobile'
2+
import { CloseOutline, MoreOutline, SearchOutline } from 'antd-mobile-icons'
33
import { DemoBlock } from 'demos'
4-
import { SearchOutline, MoreOutline, CloseOutline } from 'antd-mobile-icons'
4+
import React from 'react'
55

66
import './demo1.less'
77

@@ -34,13 +34,13 @@ export default () => {
3434
</DemoBlock>
3535

3636
<DemoBlock title='返回按钮不显示图标' padding='0'>
37-
<NavBar back='返回' onBack={back} backArrow={false}>
37+
<NavBar back='返回' onBack={back} backIcon={false}>
3838
标题
3939
</NavBar>
4040
</DemoBlock>
4141

4242
<DemoBlock title='自定义返回按钮图标' padding='0'>
43-
<NavBar back='返回' backArrow={<CloseOutline />} onBack={back}>
43+
<NavBar back='返回' backIcon={<CloseOutline />} onBack={back}>
4444
标题
4545
</NavBar>
4646
</DemoBlock>

src/components/nav-bar/index.en.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Need to display the title and action of the current page content.
1616

1717
| Name | Description | Type | Default |
1818
| --- | --- | --- | --- |
19-
| back | The returned text of the area, if `null` returned, `backArrow` would not be rendered | `ReacNode \| null` | `''` |
20-
| backArrow | Whether to display the arrow of the return area, you can also pass in `ReactNode` for customization | `boolean \| ReactNode` | `true` |
19+
| back | The returned text of the area, if `null` returned, `backIcon` would not be rendered | `ReacNode \| null` | `''` |
20+
| backIcon | Whether to display the back arrow icon of the return area, you can also pass in `ReactNode` for customization | `boolean \| ReactNode` | `true` |
2121
| children | Title | `ReactNode` | - |
2222
| left | Content on the left, rendered on the right side of the return area | `ReactNode` | - |
2323
| onBack | Callback after clicking the return area | `() => void` | - |

src/components/nav-bar/index.zh.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
| 属性 | 说明 | 类型 | 默认值 |
1818
| --- | --- | --- | --- |
19-
| back | 返回区域的文字,如果为 `null` 的话,`backArrow` 也不会渲染 | `ReactNode \| null` | `''` |
20-
| backArrow | 是否显示返回区域的箭头,也可以传入 `ReactNode` 进行自定义 | `boolean \| ReactNode` | `true` |
19+
| back | 返回区域的文字,如果为 `null` 的话,`backIcon` 也不会渲染 | `ReactNode \| null` | `''` |
20+
| backIcon | 是否显示返回区域的箭头,也可以传入 `ReactNode` 进行自定义 | `boolean \| ReactNode` | `true` |
2121
| children | 标题 | `ReactNode` | - |
2222
| left | 左侧内容,渲染在返回区域的右侧 | `ReactNode` | - |
2323
| onBack | 点击返回区域后的回调 | `() => void` | - |

src/components/nav-bar/nav-bar.tsx

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React from 'react'
2-
import type { FC, ReactNode } from 'react'
3-
import classNames from 'classnames'
41
import { LeftOutline } from 'antd-mobile-icons'
2+
import classNames from 'classnames'
3+
import type { FC, ReactNode } from 'react'
4+
import React from 'react'
55
import { NativeProps, withNativeProps } from '../../utils/native-props'
66
import { mergeProps } from '../../utils/with-default-props'
77
import { useConfig } from '../config-provider'
@@ -10,6 +10,10 @@ const classPrefix = `adm-nav-bar`
1010

1111
export type NavBarProps = {
1212
back?: ReactNode
13+
backIcon?: boolean | ReactNode
14+
/**
15+
* @deprecated use `backIcon` instead
16+
*/
1317
backArrow?: boolean | ReactNode
1418
left?: ReactNode
1519
right?: ReactNode
@@ -18,23 +22,23 @@ export type NavBarProps = {
1822
} & NativeProps<'--height' | '--border-bottom'>
1923

2024
const defaultProps = {
21-
backArrow: true,
25+
backIcon: true,
2226
}
2327

2428
export const NavBar: FC<NavBarProps> = p => {
2529
const { navBar: componentConfig = {} } = useConfig()
2630
const props = mergeProps(defaultProps, componentConfig, p)
27-
const { back, backArrow } = props
31+
const { back, backIcon, backArrow } = props
2832

2933
return withNativeProps(
3034
props,
3135
<div className={classNames(classPrefix)}>
3236
<div className={`${classPrefix}-left`} role='button'>
3337
{back !== null && (
3438
<div className={`${classPrefix}-back`} onClick={props.onBack}>
35-
{backArrow && (
39+
{(backIcon || backArrow) && (
3640
<span className={`${classPrefix}-back-arrow`}>
37-
{backArrow === true ? <LeftOutline /> : backArrow}
41+
{(backIcon === true || backArrow === true) ? <LeftOutline /> : ( backIcon || backArrow)}
3842
</span>
3943
)}
4044
<span aria-hidden='true'>{back}</span>

src/components/nav-bar/tests/nav-bar.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ describe('NavBar', () => {
1010
expect(screen.getByText('Title')).toBeInTheDocument()
1111
})
1212
test('render back arrow', () => {
13-
render(<NavBar backArrow>Title</NavBar>)
13+
render(<NavBar backIcon>Title</NavBar>)
1414
expect(screen.getByText('Title')).toBeInTheDocument()
1515
})
1616
test('render custom back arrow', () => {
17-
render(<NavBar backArrow={'Back'}>Title</NavBar>)
17+
render(<NavBar backIcon={'Back'}>Title</NavBar>)
1818
expect(screen.getByText('Back')).toBeInTheDocument()
1919
})
2020
})

0 commit comments

Comments
 (0)