Files
react-native/packages/rn-tester/js/components/RNTOption.js
T
Luna Wei b22a6d6e9d Remove Picker from Modal example
Summary: Changelog: [Internal] - Remove picker from Modal example in RNTester in prep for deprecating Picker from RN

Reviewed By: kacieb

Differential Revision: D29082452

fbshipit-source-id: 01ee5ae2d0978721f7229d824f23cfbccfaf2813
2021-06-14 21:54:16 -07:00

74 lines
1.8 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow strict-local
*/
'use strict';
import * as React from 'react';
import {Text, Pressable, StyleSheet, View} from 'react-native';
import type {PressEvent} from 'react-native/Libraries/Types/CoreEventTypes';
import type {ViewStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet';
type Props = $ReadOnly<{|
testID?: string,
label: string,
onPress?: ?(event: PressEvent) => mixed,
selected?: boolean,
style?: ViewStyleProp,
|}>;
/**
* A reusable toggle button component for RNTester. Highlights when selected.
*/
export default function RNTOption(props: Props): React.Node {
const [pressed, setPressed] = React.useState(false);
return (
<Pressable
accessibilityState={{selected: !!props.selected}}
disabled={props.selected}
hitSlop={4}
onPress={props.onPress}
onPressIn={() => setPressed(true)}
onPressOut={() => setPressed(false)}
testID={props.testID}>
<View
style={[
styles.container,
props.selected === true ? styles.selected : null,
pressed && props.selected !== true ? styles.pressed : null,
props.style,
]}>
<Text style={styles.label}>{props.label}</Text>
</View>
</Pressable>
);
}
const styles = StyleSheet.create({
pressed: {
backgroundColor: 'rgba(100,215,255,.3)',
},
label: {
color: 'black',
},
selected: {
backgroundColor: 'rgba(100,215,255,.3)',
borderColor: 'rgba(100,215,255,.3)',
},
container: {
borderColor: 'rgba(0,0,0, 0.1)',
borderWidth: 1,
borderRadius: 16,
padding: 6,
paddingHorizontal: 10,
alignItems: 'center',
},
});