-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
194 additions
and
10 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.at-grid { | ||
display: flex; | ||
flex-wrap: wrap; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,66 @@ | ||
/* eslint taro/custom-component-children: 0 */ | ||
import Taro from '@tarojs/taro' | ||
import { View, Text } from '@tarojs/components' | ||
|
||
import { View } from '@tarojs/components' | ||
import _isFunction from 'lodash/isFunction' | ||
|
||
import AtIcon from '../../icon/index' | ||
|
||
import './index.scss' | ||
|
||
export default class AtGridItem extends Taro.Component { | ||
handleClick = () => { | ||
const { onClick } = this.props | ||
if (_isFunction(onClick)) { | ||
onClick() | ||
} | ||
} | ||
|
||
render () { | ||
const { children } = this.props | ||
return <View className='at-grid-item'>{children}</View> | ||
const { | ||
icon, | ||
mode = 'square', | ||
order, | ||
total, | ||
value, | ||
iconSize, | ||
iconColor | ||
} = this.props | ||
let { columnNum } = this.props | ||
|
||
if (mode === 'rect' && !columnNum) { | ||
columnNum = 2 | ||
} | ||
if (mode === 'square' && !columnNum) { | ||
columnNum = 3 | ||
} | ||
|
||
const maxRow = Math.ceil(total / columnNum) | ||
const isLastRow = order > (maxRow - 1) * columnNum | ||
const isLastCol = order % columnNum === 0 | ||
|
||
const rootStyle = { | ||
flex: `0 0 ${100 / columnNum}%` | ||
} | ||
|
||
const contentStyle = { | ||
borderRightColor: isLastCol ? 'transparent' : '', | ||
borderBottomColor: isLastRow ? 'transparent' : '' | ||
} | ||
|
||
const rootClass = ['at-grid-item', `at-grid-item--${mode}`] | ||
|
||
return ( | ||
<View style={rootStyle} className={rootClass} onClick={this.handleClick}> | ||
<View className='at-grid-item__content' style={contentStyle}> | ||
<View className='at-grid-item__content-inner'> | ||
<View className='content-inner__icon'> | ||
<AtIcon value={icon} color={iconColor} size={iconSize} /> | ||
</View> | ||
<Text className='content-inner__text'>{value}</Text> | ||
</View> | ||
</View> | ||
</View> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
@import "../../../style/mixins/index.scss"; | ||
@import "../../../style/theme/default.scss"; | ||
|
||
.at-grid-item { | ||
display: block; | ||
position: relative; | ||
|
||
&__content { | ||
position: absolute; | ||
width: 100%; | ||
height: 100%; | ||
left: 0; | ||
top: 0; | ||
border-right: 1px solid $color-grey-4; | ||
border-bottom: 1px solid $color-grey-4; | ||
|
||
&-inner { | ||
@include display-flex; | ||
@include align-items(center); | ||
@include justify-content(center); | ||
|
||
height: 100%; | ||
flex-direction: column; | ||
} | ||
} | ||
|
||
&--square { | ||
&::before { | ||
display: block; | ||
content: " "; | ||
padding-bottom: 100%; | ||
} | ||
} | ||
|
||
&--rect { | ||
&::before { | ||
display: block; | ||
content: " "; | ||
padding-bottom: 130px; | ||
} | ||
|
||
.at-grid-item__content-inner { | ||
flex-direction: row; | ||
|
||
&__text { | ||
margin-top: initial; | ||
} | ||
} | ||
} | ||
|
||
&--active { | ||
background-color: $color-grey-6; | ||
} | ||
} | ||
|
||
.content-inner { | ||
&__text { | ||
flex: 0 0 auto; | ||
font-size: 32px; | ||
margin-top: 10px; | ||
} | ||
|
||
&__icon { | ||
flex: 0 0 auto; | ||
line-height: 0; | ||
margin-top: -1px; | ||
} | ||
} | ||
|
||
.at-grid-item--rect .content-inner { | ||
&__text { | ||
margin-left: 10px; | ||
margin-top: initial; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters