-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements the CheckBox component and adds a web-only 'color' prop to allow the color of the checkbox to be customized.
- Loading branch information
Showing
14 changed files
with
578 additions
and
4 deletions.
There are no files selected for viewing
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,93 @@ | ||
/* eslint-disable react/jsx-sort-props */ | ||
|
||
/** | ||
* @flow | ||
*/ | ||
|
||
import CustomSize from './examples/CustomSize'; | ||
import PropColor from './examples/PropColor'; | ||
import PropDisabled from './examples/PropDisabled'; | ||
import PropOnValueChange from './examples/PropOnValueChange'; | ||
import PropValue from './examples/PropValue'; | ||
import React from 'react'; | ||
import UIExplorer, { | ||
AppText, | ||
Code, | ||
Description, | ||
DocItem, | ||
Section, | ||
storiesOf | ||
} from '../../ui-explorer'; | ||
|
||
const CheckBoxScreen = () => ( | ||
<UIExplorer title="CheckBox" url="components/CheckBox"> | ||
<Description> | ||
<AppText> | ||
This is a controlled component that requires an <Code>onValueChange</Code> callback that | ||
updates the value prop in order for the component to reflect user actions. If the{' '} | ||
<Code>value</Code> prop is not updated, the component will continue to render the supplied{' '} | ||
<Code>value</Code> prop instead of the expected result of any user actions. | ||
</AppText> | ||
</Description> | ||
|
||
<Section title="Props"> | ||
<DocItem name="...View props" /> | ||
|
||
<DocItem | ||
description="Customize the color of the checkbox." | ||
example={{ | ||
render: () => <PropColor /> | ||
}} | ||
label="web" | ||
name="color" | ||
typeInfo="?color" | ||
/> | ||
|
||
<DocItem | ||
description="If true, the user won't be able to interact with the checkbox." | ||
example={{ | ||
render: () => <PropDisabled /> | ||
}} | ||
name="disabled" | ||
typeInfo="?boolean = false" | ||
/> | ||
|
||
<DocItem | ||
description="Invoked with the event when the value changes." | ||
name="onChange" | ||
typeInfo="?function" | ||
/> | ||
|
||
<DocItem | ||
description="Invoked with the new value when the value changes." | ||
example={{ | ||
render: () => <PropOnValueChange /> | ||
}} | ||
name="onValueChange" | ||
typeInfo="?function" | ||
/> | ||
|
||
<DocItem | ||
description="The value of the checkbox. If `true` the checkbox will be checked." | ||
example={{ | ||
render: () => <PropValue /> | ||
}} | ||
name="value" | ||
typeInfo="?boolean = false" | ||
/> | ||
</Section> | ||
|
||
<Section title="More examples"> | ||
<DocItem | ||
description="The checkbox size can be controlled by the 'height' and 'width' style properties" | ||
example={{ | ||
code: '<CheckBox style={{ height: 32, width: 32 }} />', | ||
render: () => <CustomSize /> | ||
}} | ||
name="Custom size" | ||
/> | ||
</Section> | ||
</UIExplorer> | ||
); | ||
|
||
storiesOf('Components', module).add('CheckBox', CheckBoxScreen); |
20 changes: 20 additions & 0 deletions
20
docs/storybook/1-components/CheckBox/examples/CustomSize.js
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,20 @@ | ||
/** | ||
* @flow | ||
*/ | ||
|
||
import React from 'react'; | ||
import styles from './styles'; | ||
import { CheckBox, View } from 'react-native'; | ||
|
||
const CustomSizeExample = () => ( | ||
<View style={styles.row}> | ||
<View style={styles.marginRight}> | ||
<CheckBox style={{ height: 20, width: 20 }} value /> | ||
</View> | ||
<View style={styles.marginRight}> | ||
<CheckBox style={{ height: 32, width: 32 }} value /> | ||
</View> | ||
</View> | ||
); | ||
|
||
export default CustomSizeExample; |
20 changes: 20 additions & 0 deletions
20
docs/storybook/1-components/CheckBox/examples/PropColor.js
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,20 @@ | ||
/** | ||
* @flow | ||
*/ | ||
|
||
import React from 'react'; | ||
import styles from './styles'; | ||
import { CheckBox, View } from 'react-native'; | ||
|
||
const CheckBoxColorExample = () => ( | ||
<View style={styles.row}> | ||
<View style={styles.marginRight}> | ||
<CheckBox color="#1DA1F2" value /> | ||
</View> | ||
<View style={styles.marginRight}> | ||
<CheckBox color="#F45D22" value /> | ||
</View> | ||
</View> | ||
); | ||
|
||
export default CheckBoxColorExample; |
20 changes: 20 additions & 0 deletions
20
docs/storybook/1-components/CheckBox/examples/PropDisabled.js
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,20 @@ | ||
/** | ||
* @flow | ||
*/ | ||
|
||
import React from 'react'; | ||
import styles from './styles'; | ||
import { CheckBox, View } from 'react-native'; | ||
|
||
const CheckBoxDisabledExample = () => ( | ||
<View style={styles.row}> | ||
<View style={styles.marginRight}> | ||
<CheckBox disabled value={false} /> | ||
</View> | ||
<View style={styles.marginRight}> | ||
<CheckBox disabled value /> | ||
</View> | ||
</View> | ||
); | ||
|
||
export default CheckBoxDisabledExample; |
59 changes: 59 additions & 0 deletions
59
docs/storybook/1-components/CheckBox/examples/PropOnValueChange.js
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,59 @@ | ||
/** | ||
* @flow | ||
*/ | ||
|
||
import styles from './styles'; | ||
import React, { PureComponent } from 'react'; | ||
import { CheckBox, Text, View } from 'react-native'; | ||
|
||
class CheckBoxOnValueChangeExample extends PureComponent { | ||
state = { | ||
eventSwitchIsOn: false, | ||
eventSwitchRegressionIsOn: true | ||
}; | ||
|
||
render() { | ||
const { eventSwitchIsOn, eventSwitchRegressionIsOn } = this.state; | ||
|
||
return ( | ||
<View style={styles.row}> | ||
<View style={[styles.alignCenter, styles.marginRight]}> | ||
<CheckBox | ||
onValueChange={this._handleEventSwitch} | ||
style={styles.marginBottom} | ||
value={eventSwitchIsOn} | ||
/> | ||
<CheckBox | ||
onValueChange={this._handleEventSwitch} | ||
style={styles.marginBottom} | ||
value={eventSwitchIsOn} | ||
/> | ||
<Text>{eventSwitchIsOn ? 'On' : 'Off'}</Text> | ||
</View> | ||
<View style={styles.alignCenter}> | ||
<CheckBox | ||
onValueChange={this._handleEventSwitchRegression} | ||
style={styles.marginBottom} | ||
value={eventSwitchRegressionIsOn} | ||
/> | ||
<CheckBox | ||
onValueChange={this._handleEventSwitchRegression} | ||
style={styles.marginBottom} | ||
value={eventSwitchRegressionIsOn} | ||
/> | ||
<Text>{eventSwitchRegressionIsOn ? 'On' : 'Off'}</Text> | ||
</View> | ||
</View> | ||
); | ||
} | ||
|
||
_handleEventSwitch = value => { | ||
this.setState({ eventSwitchIsOn: value }); | ||
}; | ||
|
||
_handleEventSwitchRegression = value => { | ||
this.setState({ eventSwitchRegressionIsOn: value }); | ||
}; | ||
} | ||
|
||
export default CheckBoxOnValueChangeExample; |
20 changes: 20 additions & 0 deletions
20
docs/storybook/1-components/CheckBox/examples/PropValue.js
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,20 @@ | ||
/** | ||
* @flow | ||
*/ | ||
|
||
import React from 'react'; | ||
import styles from './styles'; | ||
import { CheckBox, View } from 'react-native'; | ||
|
||
const CheckBoxValueExample = () => ( | ||
<View style={styles.row}> | ||
<View style={styles.marginRight}> | ||
<CheckBox value={false} /> | ||
</View> | ||
<View style={styles.marginRight}> | ||
<CheckBox value /> | ||
</View> | ||
</View> | ||
); | ||
|
||
export default CheckBoxValueExample; |
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,23 @@ | ||
/** | ||
* @flow | ||
*/ | ||
|
||
import { StyleSheet } from 'react-native'; | ||
|
||
const styles = StyleSheet.create({ | ||
row: { | ||
flexDirection: 'row', | ||
flexWrap: 'wrap' | ||
}, | ||
marginRight: { | ||
marginRight: 10 | ||
}, | ||
marginBottom: { | ||
marginBottom: 10 | ||
}, | ||
alignCenter: { | ||
alignItems: 'center' | ||
} | ||
}); | ||
|
||
export default styles; |
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,36 @@ | ||
/** | ||
* @flow | ||
*/ | ||
|
||
import React from 'react'; | ||
import { StyleSheet, View } from 'react-native'; | ||
|
||
const DividerHorizontal = () => <View style={styles.horizontalDivider} />; | ||
const DividerVertical = () => <View style={styles.verticalDivider} />; | ||
|
||
export const styles = StyleSheet.create({ | ||
horizontalDivider: { | ||
width: '0.6rem' | ||
}, | ||
verticalDivider: { | ||
height: '1.3125rem' | ||
}, | ||
row: { | ||
flexDirection: 'row', | ||
flexWrap: 'wrap' | ||
}, | ||
marginRight: { | ||
marginRight: 10 | ||
}, | ||
marginBottom: { | ||
marginBottom: 10 | ||
}, | ||
marginVertical: { | ||
marginVertical: 5 | ||
}, | ||
alignCenter: { | ||
alignItems: 'center' | ||
} | ||
}); | ||
|
||
export { DividerHorizontal, DividerVertical }; |
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
Oops, something went wrong.