11/*
2- ReactNativeCircleCheckbox 0.1.3
3- https://github.com/ParamoshkinAndrew /ReactNativeCircleCheckbox
2+ ReactNativeCircleCheckbox 0.1.5
3+ https://github.com/paramoshkinandrew /ReactNativeCircleCheckbox
44 (c) 2016 Andrew Paramoshkin <[email protected] > 55 ReactNativeCircleCheckbox may be freely distributed under the MIT license.
66 */
77
8- 'use strict'
8+ 'use strict' ;
99
10- import React , { Component } from 'react'
11- import PropTypes from 'prop-types'
12- import {
13- StyleSheet ,
14- View ,
15- ViewPropTypes ,
16- Text ,
17- TouchableOpacity ,
18- } from 'react-native'
10+ import * as React from 'react' ;
11+ import PropTypes from 'prop-types' ;
12+ import { StyleSheet , Text , TouchableOpacity , View , ViewPropTypes } from 'react-native' ;
1913
20- class CircleCheckBox extends Component {
14+ export const LABEL_POSITION = {
15+ RIGHT : 'right' ,
16+ LEFT : 'left'
17+ } ;
2118
19+ export default class CircleCheckBox extends React . Component {
2220 static propTypes = {
23- checked : PropTypes . bool ,
24- label : PropTypes . string ,
25- outerSize : PropTypes . number ,
26- filterSize : PropTypes . number ,
27- innerSize : PropTypes . number ,
28- outerColor : PropTypes . string ,
29- filterColor : PropTypes . string ,
30- innerColor : PropTypes . string ,
31- onToggle : PropTypes . func . isRequired ,
32- labelPosition : PropTypes . oneOf ( [ 'right' , 'left' ] ) ,
33- styleCheckboxContainer : ViewPropTypes . style ,
34- styleLabel : Text . propTypes . style ,
21+ checked : PropTypes . bool ,
22+ label : PropTypes . string ,
23+ outerSize : PropTypes . number ,
24+ filterSize : PropTypes . number ,
25+ innerSize : PropTypes . number ,
26+ outerColor : PropTypes . string ,
27+ filterColor : PropTypes . string ,
28+ innerColor : PropTypes . string ,
29+ onToggle : PropTypes . func . isRequired ,
30+ labelPosition : PropTypes . oneOf ( [ LABEL_POSITION . RIGHT , LABEL_POSITION . LEFT ] ) ,
31+ styleCheckboxContainer : ViewPropTypes . style ,
32+ styleLabel : Text . propTypes . style ,
3533 } ;
3634
3735 static defaultProps = {
@@ -49,27 +47,27 @@ class CircleCheckBox extends Component {
4947
5048 constructor ( props ) {
5149 super ( props ) ;
52- var outerSize = ( parseInt ( props . outerSize ) < 10 || isNaN ( parseInt ( props . outerSize ) ) ) ? 10 : parseInt ( props . outerSize ) ;
53- var filterSize = ( parseInt ( props . filterSize ) > outerSize + 3 || isNaN ( parseInt ( props . filterSize ) ) ) ? outerSize - 3 : parseInt ( props . filterSize ) ;
54- var innerSize = ( parseInt ( props . innerSize ) > filterSize + 5 || isNaN ( parseInt ( props . innerSize ) ) ) ? filterSize - 5 : parseInt ( props . innerSize ) ;
50+ const outerSize = ( parseInt ( props . outerSize ) < 10 || isNaN ( parseInt ( props . outerSize ) ) ) ? 10 : parseInt ( props . outerSize ) ;
51+ const filterSize = ( parseInt ( props . filterSize ) > outerSize + 3 || isNaN ( parseInt ( props . filterSize ) ) ) ? outerSize - 3 : parseInt ( props . filterSize ) ;
52+ const innerSize = ( parseInt ( props . innerSize ) > filterSize + 5 || isNaN ( parseInt ( props . innerSize ) ) ) ? filterSize - 5 : parseInt ( props . innerSize ) ;
5553
56- var customStyle = StyleSheet . create ( {
54+ const customStyle = StyleSheet . create ( {
5755 _circleOuterStyle : {
5856 width : outerSize ,
5957 height : outerSize ,
60- borderRadius : outerSize / 2 ,
58+ borderRadius : outerSize / 2 ,
6159 backgroundColor : props . outerColor
6260 } ,
6361 _circleFilterStyle : {
6462 width : filterSize ,
6563 height : filterSize ,
66- borderRadius : filterSize / 2 ,
64+ borderRadius : filterSize / 2 ,
6765 backgroundColor : props . filterColor
6866 } ,
6967 _circleInnerStyle : {
7068 width : innerSize ,
7169 height : innerSize ,
72- borderRadius : innerSize / 2 ,
70+ borderRadius : innerSize / 2 ,
7371 backgroundColor : props . innerColor
7472 }
7573 } ) ;
@@ -83,39 +81,36 @@ class CircleCheckBox extends Component {
8381 return (
8482 < TouchableOpacity onPress = { this . _onToggle . bind ( this ) } >
8583 < View style = { [ styles . checkBoxContainer , this . props . styleCheckboxContainer ] } >
86- { this . _renderLabel ( 'left' ) }
84+ { this . _renderLabel ( LABEL_POSITION . LEFT ) }
8785 < View style = { [ styles . alignStyle , this . state . customStyle . _circleOuterStyle ] } >
8886 < View style = { [ styles . alignStyle , this . state . customStyle . _circleFilterStyle ] } >
8987 { this . _renderInner ( ) }
9088 </ View >
9189 </ View >
92- { this . _renderLabel ( 'right' ) }
90+ { this . _renderLabel ( LABEL_POSITION . RIGHT ) }
9391 </ View >
9492 </ TouchableOpacity >
9593 ) ;
9694 }
9795
9896 _onToggle ( ) {
99- if ( this . props . onToggle ) {
97+ if ( this . props . onToggle ) {
10098 this . props . onToggle ( ! this . props . checked ) ;
10199 }
102100 }
103101
104102 _renderInner ( ) {
105- return this . props . checked ? ( < View style = { this . state . customStyle . _circleInnerStyle } /> ) : ( < View /> ) ;
103+ return this . props . checked ? ( < View style = { this . state . customStyle . _circleInnerStyle } /> ) : ( < View /> ) ;
106104 }
107105
108106 _renderLabel ( position ) {
109- var templ = ( < View > </ View > ) ;
110- if ( ( this . props . label . length > 0 ) && ( position === this . props . labelPosition ) ) {
111- templ = ( < Text style = { [ styles . checkBoxLabel , this . props . styleLabel ] } > { this . props . label } </ Text > ) ;
112- }
113- return templ ;
114-
107+ return ( ( this . props . label . length > 0 ) && ( position === this . props . labelPosition ) )
108+ ? < Text style = { [ styles . checkBoxLabel , this . props . styleLabel ] } > { this . props . label } </ Text >
109+ : < View />
115110 }
116111}
117112
118- var styles = StyleSheet . create ( {
113+ const styles = StyleSheet . create ( {
119114 checkBoxContainer : {
120115 flexDirection : 'row' ,
121116 alignItems : 'center'
@@ -129,5 +124,3 @@ var styles = StyleSheet.create({
129124 marginRight : 5
130125 }
131126} ) ;
132-
133- module . exports = CircleCheckBox ;
0 commit comments