mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 11:11:53 +08:00
110 lines
2.3 KiB
JavaScript
110 lines
2.3 KiB
JavaScript
import PropTypes from 'prop-types';
|
|
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
|
|
|
|
/** Primary UI component for user interaction */
|
|
export const Button = ({
|
|
primary = false,
|
|
size = 'medium',
|
|
backgroundColor,
|
|
label,
|
|
style,
|
|
onPress,
|
|
}) => {
|
|
const modeStyle = primary ? styles.primary : styles.secondary;
|
|
const textModeStyle = primary ? styles.primaryText : styles.secondaryText;
|
|
|
|
const sizeStyle = styles[size];
|
|
const textSizeStyle = textSizeStyles[size];
|
|
|
|
return (
|
|
<TouchableOpacity accessibilityRole="button" activeOpacity={0.6} onPress={onPress}>
|
|
<View
|
|
style={[
|
|
styles.button,
|
|
modeStyle,
|
|
sizeStyle,
|
|
style,
|
|
!!backgroundColor && { backgroundColor },
|
|
{ borderColor: 'black' },
|
|
]}
|
|
>
|
|
<Text style={[textModeStyle, textSizeStyle]}>{label}</Text>
|
|
</View>
|
|
</TouchableOpacity>
|
|
);
|
|
};
|
|
|
|
const styles = StyleSheet.create({
|
|
button: {
|
|
borderWidth: 0,
|
|
borderRadius: 48,
|
|
},
|
|
buttonText: {
|
|
fontWeight: '700',
|
|
lineHeight: 1,
|
|
},
|
|
primary: {
|
|
backgroundColor: '#1ea7fd',
|
|
},
|
|
primaryText: {
|
|
color: 'white',
|
|
},
|
|
secondary: {
|
|
backgroundColor: 'transparent',
|
|
borderColor: 'rgba(0, 0, 0, 0.15)',
|
|
borderWidth: 1,
|
|
},
|
|
secondaryText: {
|
|
color: '#333',
|
|
},
|
|
small: {
|
|
paddingVertical: 10,
|
|
paddingHorizontal: 16,
|
|
},
|
|
smallText: {
|
|
fontSize: 12,
|
|
},
|
|
medium: {
|
|
paddingVertical: 11,
|
|
paddingHorizontal: 20,
|
|
},
|
|
mediumText: {
|
|
fontSize: 14,
|
|
},
|
|
large: {
|
|
paddingVertical: 12,
|
|
paddingHorizontal: 24,
|
|
},
|
|
largeText: {
|
|
fontSize: 16,
|
|
},
|
|
});
|
|
|
|
const textSizeStyles = {
|
|
small: styles.smallText,
|
|
medium: styles.mediumText,
|
|
large: styles.largeText,
|
|
};
|
|
|
|
Button.propTypes = {
|
|
/** Is this the principal call to action on the page? */
|
|
primary: PropTypes.bool,
|
|
/** What background color to use */
|
|
backgroundColor: PropTypes.string,
|
|
/** How large should the button be? */
|
|
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
|
/** Button contents */
|
|
label: PropTypes.string.isRequired,
|
|
/** Optional click handler */
|
|
onPress: PropTypes.func,
|
|
/** Optional extra styles */
|
|
style: PropTypes.object,
|
|
};
|
|
|
|
Button.defaultProps = {
|
|
backgroundColor: null,
|
|
primary: false,
|
|
size: 'medium',
|
|
onClick: undefined,
|
|
};
|