Skip to content

Commit

Permalink
feat(layout): list 增加 click 事件
Browse files Browse the repository at this point in the history
  • Loading branch information
SzHeJason committed Jul 31, 2018
1 parent 5b88597 commit 0d80914
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ class App extends Component {
'pages/navigation/tabs/index',
'pages/navigation/tab-bar/index',
'pages/navigation/segmented-control/index',
'pages/navigation/nav-bar/index'
'pages/navigation/nav-bar/index',
// 'pages/layout/flex/index'
// 'pages/layout/grid/index',
// 'pages/layout/float-layout/index',
// 'pages/layout/card/index'
// 'pages/layout/card/index',
'pages/layout/list/index'
],
window: {
backgroundTextStyle: 'light',
Expand Down
19 changes: 18 additions & 1 deletion src/components/list/item/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import PropTypes from 'prop-types'
import Taro, { Component } from '@tarojs/taro'
import { View, Image, Switch } from '@tarojs/components'

Expand All @@ -12,6 +13,7 @@ export default class AtListItem extends Component {
arrow,
title,
thumb,
onClick,
isSwitch,
extraText,
extraThumb
Expand All @@ -28,7 +30,7 @@ export default class AtListItem extends Component {
}

return (
<View className={rootClass}>
<View className={rootClass} onClick={onClick}>
{thumb && (
<View className='at-list__item-thumb item-thumb'>
<Image className='item-thumb-info' mode='scaleToFill' src={thumb} />
Expand Down Expand Up @@ -72,3 +74,18 @@ export default class AtListItem extends Component {
)
}
}

AtListItem.defaultProps = {
onClick: () => {}
}

AtListItem.propTypes = {
note: PropTypes.string,
title: PropTypes.string,
thumb: PropTypes.string,
onClick: PropTypes.func,
isSwitch: PropTypes.bool,
extraText: PropTypes.string,
extraThumb: PropTypes.string,
arrow: PropTypes.oneOf(['right', 'top', 'bottom', 'left'])
}
5 changes: 4 additions & 1 deletion src/pages/layout/list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export default class ListPage extends Component {
<View className='panel__title'>基础列表</View>
<View className='panel__content'>
<View className='example__body'>
<AtListItem title='标题文字' />
<AtListItem
title='标题文字'
onClick={console.log.bind(this, 1)}
/>
<AtListItem title='标题文字' arrow='right' />
<AtListItem
arrow='right'
Expand Down

0 comments on commit 0d80914

Please sign in to comment.