Skip to content

Commit

Permalink
style(segmented-control): 修改代码风格
Browse files Browse the repository at this point in the history
  • Loading branch information
jimczj committed Jan 25, 2019
1 parent da3d0fd commit 44dbf9c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
6 changes: 6 additions & 0 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,19 @@ function handleTouchScroll (flag) {
}
}

function pxTransform(size) {
if (!size) return ''
return Taro.pxTransform(size)
}

export {
delay,
delayQuerySelector,
uuid,
getEventDetail,
initTestEnv,
isTest,
pxTransform,
handleTouchScroll,
delayGetClientRect,
delayGetScrollOffset
Expand Down
29 changes: 12 additions & 17 deletions src/components/segmented-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ import Taro from '@tarojs/taro'
import { View } from '@tarojs/components'
import PropTypes from 'prop-types'
import classNames from 'classnames'

import { initTestEnv, pxTransform } from '../../common/utils'
import AtComponent from '../../common/component'

export default class AtSegmentedControl extends AtComponent {
constructor () {
super(...arguments)
if (process.env.NODE_ENV === 'test') {
Taro.initPxTransform({ designWidth: 750 })
}
}
initTestEnv()

export default class AtSegmentedControl extends AtComponent {
handleClick () {
if (this.props.disable) return
this.props.onClick(...arguments)
Expand All @@ -34,25 +31,23 @@ export default class AtSegmentedControl extends AtComponent {
}
const itemStyle = {
color: selectedColor,
fontSize: fontSize ? Taro.pxTransform(fontSize) : '',
fontSize: pxTransform(fontSize),
borderColor: selectedColor,
backgroundColor: color,
}
const selectedItemStyle = {
color,
fontSize: fontSize ? Taro.pxTransform(fontSize) : '',
fontSize: pxTransform(fontSize),
borderColor: selectedColor,
backgroundColor: selectedColor,
}
const rootCls = classNames('at-segmented-control', {
'at-segmented-control--disabled': disabled
}, className)

return (
<View
className={
classNames({
'at-segmented-control': true,
'at-segmented-control--disabled': disabled
}, className)
}
className={rootCls}
style={this.mergeStyle(rootStyle, customStyle)}
>
{
Expand All @@ -64,8 +59,8 @@ export default class AtSegmentedControl extends AtComponent {
style={current === i ? selectedItemStyle : itemStyle}
key={value}
onClick={this.handleClick.bind(this, i)}
>{value}</View>)
)
>{value}</View>
))
}
</View>
)
Expand Down

0 comments on commit 44dbf9c

Please sign in to comment.