Skip to content

Commit bed97cf

Browse files
committed
Merge branch 'next' into feat/pnpm-workspace
2 parents 21584d3 + a10afae commit bed97cf

File tree

7 files changed

+34
-24
lines changed

7 files changed

+34
-24
lines changed

packages/taro-ui-docs/markdown/list.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ import { AtList, AtListItem } from "taro-ui"
159159

160160
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
161161
| ------------- | ---------------- | -------------------------------------------------------------------- | ---------------------- | ------- |
162-
| title | 元素的标题 | String | - | - |
162+
| title | 元素的标题 | JSX.Element | - | - |
163163
| disabled | 是否禁用 | Boolean | - | `false` |
164-
| note | 元素的描述信息 | String | - | - |
164+
| note | 元素的描述信息 | JSX.Element | - | - |
165165
| thumb | 元素的主要缩略图 | String | - | - |
166166
| arrow | 箭头的方向 | String | `right`,`top`,`down` | - |
167-
| extraText | 额外信息的文本 | String | - | - |
167+
| extraText | 额外信息的文本 | JSX.Element | - | - |
168168
| extraThumb | 额外信息的缩略图 | String | - | - |
169169
| isSwitch | 额外信息是否开关 | Boolean | - | `false` |
170170
| switchColor | 开关的颜色 | String | - | `#6190E8` |

packages/taro-ui-docs/markdown/tabbar.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export default class Index extends Taro.Component {
186186

187187
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 可选或必填
188188
| ---------- | -------------------------------------- | ------- | ------------------------------------------------------------------- | -------- |-------- |
189-
| title | 标题 | String | - | 0 | 必填 |
189+
| title | 标题 | ReactNode | - | - | 必填 |
190190
| iconPrefixClass | icon className 前缀,用于第三方字体图标库,比如想使用'fa fa-clock' 的图标,则 传入`iconPrefixClass='fa' iconType='clock'`,[拓展图标库详细](/#/docs/icon) | String | - | - | - |
191191
| iconType | 未选中时展示的 icon 类型,可扩展第三方字体图标库,[拓展图标库详细](/#/docs/icon) | String | - | - | 可选 |
192192
| selectedIconType | 选中时展示的 icon 类型,可扩展第三方字体图标库,[拓展图标库详细](/#/docs/icon) | String | - | - |可选 |

packages/taro-ui/src/common/utils.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Taro from '@tarojs/taro'
2+
import React from 'react'
23
import { SelectorQuery } from '@tarojs/taro/types/index'
34

45
const ENV = Taro.getEnv()
@@ -255,6 +256,21 @@ function mergeStyle(
255256
return objectToString(style1) + objectToString(style2)
256257
}
257258

259+
/**
260+
* 自定义验证器,用于验证参数是否是 JSX.Element
261+
* @param {any} props
262+
* @param {string} propName
263+
* @param {string} componentName
264+
* @returns
265+
*/
266+
function isJSXElement(props, propName, componentName) {
267+
if (!React.isValidElement(props[propName])) {
268+
return new Error(
269+
`Invalid prop ${propName} supplied to ${componentName}. It must be a valid JSX element.`
270+
)
271+
}
272+
}
273+
258274
export {
259275
delay,
260276
delayQuerySelector,
@@ -266,5 +282,6 @@ export {
266282
handleTouchScroll,
267283
delayGetClientRect,
268284
delayGetScrollOffset,
269-
mergeStyle
285+
mergeStyle,
286+
isJSXElement
270287
}

packages/taro-ui/src/components/countdown/index.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export default class AtCountdown extends React.Component<
5555
private clearTimer(): void {
5656
if (this.timer) {
5757
clearTimeout(this.timer as number)
58+
this.timer = 0
5859
}
5960
}
6061

@@ -127,14 +128,9 @@ export default class AtCountdown extends React.Component<
127128
}
128129

129130
public render(): JSX.Element {
130-
const {
131-
className,
132-
customStyle,
133-
format = { day: '天', hours: '时', minutes: '分', seconds: '秒' },
134-
isShowDay,
135-
isCard,
136-
isShowHour
137-
} = this.props
131+
const { className, customStyle, format, isShowDay, isCard, isShowHour } =
132+
this.props
133+
138134
const { _day, _hours, _minutes, _seconds } = this.state
139135

140136
return (

packages/taro-ui/src/components/list/item/index.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React from 'react'
44
import { Image, Switch, Text, View } from '@tarojs/components'
55
import { CommonEvent, ITouchEvent } from '@tarojs/components/types/common'
66
import { AtListItemProps } from '../../../../types/list'
7-
import { mergeStyle } from '../../../common/utils'
7+
import { mergeStyle, isJSXElement } from '../../../common/utils'
88

99
export default class AtListItem extends React.Component<AtListItemProps> {
1010
public static defaultProps: AtListItemProps
@@ -43,10 +43,7 @@ export default class AtListItem extends React.Component<AtListItemProps> {
4343
switchIsCheck
4444
} = this.props
4545

46-
let { extraText, title } = this.props
47-
48-
extraText = String(extraText)
49-
title = String(title)
46+
const { extraText, title } = this.props
5047

5148
const rootClass = classNames(
5249
'at-list__item',
@@ -156,16 +153,16 @@ AtListItem.defaultProps = {
156153
}
157154

158155
AtListItem.propTypes = {
159-
note: PropTypes.string,
156+
note: isJSXElement,
160157
disabled: PropTypes.bool,
161-
title: PropTypes.string,
158+
title: isJSXElement,
162159
thumb: PropTypes.string,
163160
onClick: PropTypes.func,
164161
isSwitch: PropTypes.bool,
165162
hasBorder: PropTypes.bool,
166163
switchColor: PropTypes.string,
167164
switchIsCheck: PropTypes.bool,
168-
extraText: PropTypes.string,
165+
extraText: isJSXElement,
169166
extraThumb: PropTypes.string,
170167
onSwitchChange: PropTypes.func,
171168
arrow: PropTypes.oneOf(['up', 'down', 'right']),

packages/taro-ui/src/components/tab-bar/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default class AtTabBar extends React.Component<AtTabBarProps> {
8282
'at-tab-bar__item--active': current === i
8383
})}
8484
style={current === i ? selectedStyle : defaultStyle}
85-
key={item.title}
85+
key={i}
8686
onClick={this.handleClick.bind(this, i)}
8787
>
8888
{item.iconType ? (

packages/taro-ui/types/tab-bar.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MouseEvent, ComponentClass } from 'react'
1+
import { ReactNode, ComponentClass } from 'react'
22
import { CommonEvent } from '@tarojs/components/types/common'
33

44
import AtComponent from './base'
@@ -20,7 +20,7 @@ export interface TabItem {
2020
/**
2121
* 标题
2222
*/
23-
title: string
23+
title: ReactNode
2424
/**
2525
* icon className 前缀,用于第三方字体图标库,
2626
* 比如想使用'fa fa-clock' 的图标,则传入 iconPrefixClass='fa' iconType='clock',

0 commit comments

Comments
 (0)