Skip to content

Commit

Permalink
fix(button): 修复 loading
Browse files Browse the repository at this point in the history
  • Loading branch information
jimczj committed Aug 24, 2018
1 parent 956ede1 commit c934714
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/components/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Taro from '@tarojs/taro'
import { View } from '@tarojs/components'
import PropTypes from 'prop-types'
import AtIcon from '../icon/index'
import AtLoading from '../loading/index'

import './index.scss'

Expand Down Expand Up @@ -47,10 +47,10 @@ export default class AtButton extends Taro.Component {

rootClassName.push(`at-button--${sizeClass}`, typeClass, circleClass, disabledClass)
rootClassName = rootClassName.filter(str => str !== '')

const loadingColor = type === 'primary' ? '#fff' : '#6190E8'
let component
if (loading) {
component = <View className='at-button__icon'><AtIcon value='loading' size='20'></AtIcon></View>
component = <View className='at-button__icon'><AtLoading color={loadingColor} /></View>
rootClassName.push('at-button--icon')
}

Expand Down
16 changes: 3 additions & 13 deletions src/components/button/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ $at-button-height: 92px;
$at-button-height-sm: 60px;

.at-button {
display: flex;
justify-content: center;
margin: 0 auto;
padding: 0 $spacing-h-xl;
height: $at-button-height;
Expand Down Expand Up @@ -46,10 +48,8 @@ $at-button-height-sm: 60px;
}

&__icon {
margin: 0 20px;
margin: 2PX 20px 0 20px;
display: inline-block;
font-size: $font-size-base;
animation: loading-rotate 1s linear infinite;
}

&--circle {
Expand All @@ -71,15 +71,5 @@ $at-button-height-sm: 60px;
height: $at-button-height-sm;
font-size: $font-size-base;
line-height: $at-button-height-sm - 2;

.at-button__icon {
font-size: $font-size-base;
}
}
}

@keyframes loading-rotate {
100% {
transform: rotate(360deg);
}
}
23 changes: 23 additions & 0 deletions src/components/loading/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Taro from '@tarojs/taro'
import { View } from '@tarojs/components'
import './index.scss'

class AtLoading extends Taro.Component {
render () {
const style = {
'border': `1px solid ${this.props.color}`,
'border-color': `${this.props.color} transparent transparent transparent`
}
return (
<View className='at-loading'>
<View className='at-loading__ring' style={style}></View>
<View className='at-loading__ring' style={style}></View>
<View className='at-loading__ring' style={style}></View>
</View>
)
}
}
AtLoading.defaultProps = {
color: '#fff'
}
export default AtLoading
41 changes: 41 additions & 0 deletions src/components/loading/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.at-loading {
display: inline-block;
position: relative;
width: 18PX;
height: 18PX;

&__ring {
box-sizing: border-box;
display: block;
position: absolute;
width: 18PX;
height: 18PX;
margin: 1PX;
border: 1PX solid #fff;
border-radius: 50%;
animation: loading 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
border-color: #fff transparent transparent transparent;

&:nth-child(1) {
animation-delay: -0.45s;
}

&:nth-child(2) {
animation-delay: -0.3s;
}

&:nth-child(3) {
animation-delay: -0.15s;
}
}
}

@keyframes loading {
0% {
transform: rotate(0deg);
}

100% {
transform: rotate(360deg);
}
}

0 comments on commit c934714

Please sign in to comment.