Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions example/src/CheckboxExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* @flow */

import React, { Component } from 'react';
import {
View,
StyleSheet,
} from 'react-native';
import {
Paragraph,
Checkbox,
Colors,
} from 'react-native-paper';

export default class CheckboxExample extends Component {

static title = 'Checkbox';

state = {
checkedNormal: true,
checkedCustom: true,
};

render() {
return (
<View style={styles.container}>
<View style={styles.row}>
<Paragraph>Normal</Paragraph>
<Checkbox
checked={this.state.checkedNormal}
onPress={() => this.setState(state => ({ checkedNormal: !state.checkedNormal }))}
/>
</View>
<View style={styles.row}>
<Paragraph>Custom</Paragraph>
<Checkbox
color={Colors.pink500}
checked={this.state.checkedCustom}
onPress={() => this.setState(state => ({ checkedCustom: !state.checkedCustom }))}
/>
</View>
<View style={styles.row}>
<Paragraph>Checked (Disabled)</Paragraph>
<Checkbox checked disabled />
</View>
<View style={styles.row}>
<Paragraph>Unchecked (Disabled)</Paragraph>
<Checkbox checked={false} disabled />
</View>
</View>
);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: Colors.white,
padding: 8,
},

row: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
padding: 8,
},
});
10 changes: 7 additions & 3 deletions example/src/ExampleList.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@ import {
StyleSheet,
} from 'react-native';
import { Colors, TouchableRipple } from 'react-native-paper';
import ButtonExample from './ButtonExample';
import CardExample from './CardExample';
import RippleExample from './RippleExample';
import CheckboxExample from './CheckboxExample';
import DividerExample from './DividerExample';
import PaperExample from './PaperExample';
import RippleExample from './RippleExample';
import RadioButtonExample from './RadioButtonExample';
import TextExample from './TextExample';
import ButtonExample from './ButtonExample';
import DividerExample from './DividerExample';

export const examples = {
button: ButtonExample,
card: CardExample,
checkbox: CheckboxExample,
divider: DividerExample,
paper: PaperExample,
ripple: RippleExample,
radio: RadioButtonExample,
text: TextExample,
};

Expand Down
67 changes: 67 additions & 0 deletions example/src/RadioButtonExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* @flow */

import React, { Component } from 'react';
import {
View,
StyleSheet,
} from 'react-native';
import {
Paragraph,
RadioButton,
Colors,
} from 'react-native-paper';

export default class RadioButtonExample extends Component {

static title = 'Radio button';

state = {
checkedNormal: true,
checkedCustom: true,
};

render() {
return (
<View style={styles.container}>
<View style={styles.row}>
<Paragraph>Normal</Paragraph>
<RadioButton
checked={this.state.checkedNormal}
onPress={() => this.setState(state => ({ checkedNormal: !state.checkedNormal }))}
/>
</View>
<View style={styles.row}>
<Paragraph>Custom</Paragraph>
<RadioButton
color={Colors.pink500}
checked={this.state.checkedCustom}
onPress={() => this.setState(state => ({ checkedCustom: !state.checkedCustom }))}
/>
</View>
<View style={styles.row}>
<Paragraph>Checked (Disabled)</Paragraph>
<RadioButton checked disabled />
</View>
<View style={styles.row}>
<Paragraph>Unchecked (Disabled)</Paragraph>
<RadioButton checked={false} disabled />
</View>
</View>
);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: Colors.white,
padding: 8,
},

row: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
padding: 8,
},
});
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ export { default as withTheme } from './src/core/withTheme';

export * as Colors from './src/styles/colors';

export { default as Paper } from './src/components/Paper';
export { default as TouchableRipple } from './src/components/TouchableRipple';

export { default as Button } from './src/components/Button';
export { default as Card } from './src/components/Card';
export { default as Checkbox } from './src/components/Checkbox';
export { default as Paper } from './src/components/Paper';
export { default as RadioButton } from './src/components/RadioButton';
export { default as TouchableRipple } from './src/components/TouchableRipple';

export { default as Caption } from './src/components/Typography/Caption';
export { default as Headline } from './src/components/Typography/Headline';
Expand Down
82 changes: 82 additions & 0 deletions src/components/Checkbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* @flow */

import React, {
PropTypes,
} from 'react';
import {
StyleSheet,
} from 'react-native';
import color from 'color';
import Icon from './Icon';
import TouchableRipple from './TouchableRipple';
import withTheme from '../core/withTheme';
import type { Theme } from '../types/Theme';

type Props = {
checked: boolean;
disabled?: boolean;
onPress?: Function;
color?: string;
theme: Theme;
}

const Checkbox = (props: Props) => {
const {
checked,
disabled,
onPress,
theme,
} = props;

const checkboxColor = props.color || theme.colors.primary;

let rippleColor, checkboxStyle;

if (disabled) {
rippleColor = 'rgba(0, 0, 0, .16)';
checkboxStyle = { color: 'rgba(0, 0, 0, .26)' };
} else {
rippleColor = color(checkboxColor).clearer(0.32).rgbaString();
if (checked) {
checkboxStyle = { color: checkboxColor };
}
}

return (
<TouchableRipple
{...props}
borderless
rippleColor={rippleColor}
onPress={disabled ? undefined : onPress}
style={styles.container}
>
<Icon
name={checked ? 'check-box' : 'check-box-outline-blank'}
size={24}
style={[ styles.checkbox, checkboxStyle ]}
/>
</TouchableRipple>
);
};

Checkbox.propTypes = {
checked: PropTypes.bool.isRequired,
disabled: PropTypes.bool,
onPress: PropTypes.func,
color: PropTypes.string,
theme: PropTypes.object.isRequired,
};

const styles = StyleSheet.create({
container: {
borderRadius: 18,
},

checkbox: {
/* FIXME: using opacity doesn't work properly with TouchableHighlight */
color: 'rgba(0, 0, 0, .54)',
margin: 6,
},
});

export default withTheme(Checkbox);
82 changes: 82 additions & 0 deletions src/components/RadioButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* @flow */

import React, {
PropTypes,
} from 'react';
import {
StyleSheet,
} from 'react-native';
import color from 'color';
import Icon from './Icon';
import TouchableRipple from './TouchableRipple';
import withTheme from '../core/withTheme';
import type { Theme } from '../types/Theme';

type Props = {
checked: boolean;
disabled?: boolean;
onPress?: Function;
color?: string;
theme: Theme;
}

const RadioButton = (props: Props) => {
const {
checked,
disabled,
onPress,
theme,
} = props;

const radioColor = props.color || theme.colors.primary;

let rippleColor, radioStyle;

if (disabled) {
rippleColor = 'rgba(0, 0, 0, .16)';
radioStyle = { color: 'rgba(0, 0, 0, .26)' };
} else {
rippleColor = color(radioColor).clearer(0.32).rgbaString();
if (checked) {
radioStyle = { color: radioColor };
}
}

return (
<TouchableRipple
{...props}
borderless
rippleColor={rippleColor}
onPress={disabled ? undefined : onPress}
style={styles.container}
>
<Icon
name={checked ? 'radio-button-checked' : 'radio-button-unchecked'}
size={24}
style={[ styles.radio, radioStyle ]}
/>
</TouchableRipple>
);
};

RadioButton.propTypes = {
checked: PropTypes.bool.isRequired,
disabled: PropTypes.bool,
onPress: PropTypes.func,
color: PropTypes.string,
theme: PropTypes.object.isRequired,
};

const styles = StyleSheet.create({
container: {
borderRadius: 18,
},

radio: {
/* FIXME: using opacity doesn't work properly with TouchableHighlight */
color: 'rgba(0, 0, 0, .54)',
margin: 6,
},
});

export default withTheme(RadioButton);
2 changes: 1 addition & 1 deletion src/components/TouchableRipple/TouchableRipple.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Props = {
onPress?: ?Function;
onPressIn?: ?Function;
onPressOut?: ?Function;
rippleColor?: string;
rippleColor: string;
children?: any;
style?: any;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/TouchableRipple/TouchableRipple.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Props = {
onPress?: ?Function;
onPressIn?: ?Function;
onPressOut?: ?Function;
rippleColor?: string;
rippleColor: string;
children?: any;
style?: any;
}
Expand Down