mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-05-17 04:32:26 +00:00
73 lines
1.7 KiB
JavaScript
73 lines
1.7 KiB
JavaScript
/**
|
|
* Copyright (c) 2016-present, Nicolas Gallagher.
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @providesModule Button
|
|
* @flow
|
|
*/
|
|
|
|
import ColorPropType from '../../propTypes/ColorPropType';
|
|
import StyleSheet from '../../apis/StyleSheet';
|
|
import TouchableOpacity from '../Touchable/TouchableOpacity';
|
|
import Text from '../Text';
|
|
import { bool, func, string } from 'prop-types';
|
|
import React, { Component } from 'react';
|
|
|
|
class Button extends Component<*> {
|
|
static propTypes = {
|
|
accessibilityLabel: string,
|
|
color: ColorPropType,
|
|
disabled: bool,
|
|
onPress: func.isRequired,
|
|
testID: string,
|
|
title: string.isRequired
|
|
};
|
|
|
|
render() {
|
|
const { accessibilityLabel, color, disabled, onPress, testID, title } = this.props;
|
|
|
|
return (
|
|
<TouchableOpacity
|
|
accessibilityLabel={accessibilityLabel}
|
|
accessibilityRole="button"
|
|
disabled={disabled}
|
|
onPress={onPress}
|
|
style={[
|
|
styles.button,
|
|
color && { backgroundColor: color },
|
|
disabled && styles.buttonDisabled
|
|
]}
|
|
testID={testID}
|
|
>
|
|
<Text style={[styles.text, disabled && styles.textDisabled]}>{title}</Text>
|
|
</TouchableOpacity>
|
|
);
|
|
}
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
button: {
|
|
backgroundColor: '#2196F3',
|
|
borderRadius: 2
|
|
},
|
|
text: {
|
|
color: '#fff',
|
|
fontWeight: '500',
|
|
padding: 8,
|
|
textAlign: 'center',
|
|
textTransform: 'uppercase'
|
|
},
|
|
buttonDisabled: {
|
|
backgroundColor: '#dfdfdf'
|
|
},
|
|
textDisabled: {
|
|
color: '#a1a1a1'
|
|
}
|
|
});
|
|
|
|
export default Button;
|