UNPKG

react-native-paper

Version:
100 lines (93 loc) 3.38 kB
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } import * as React from 'react'; import { StyleSheet, View } from 'react-native'; import color from 'color'; import { RadioButtonContext } from './RadioButtonGroup'; import { handlePress, isChecked } from './utils'; import MaterialCommunityIcon from '../MaterialCommunityIcon'; import TouchableRipple from '../TouchableRipple/TouchableRipple'; import { withTheme } from '../../core/theming'; /** * Radio buttons allow the selection a single option from a set. * This component follows platform guidelines for iOS, but can be used * on any platform. * * <div class="screenshots"> * <figure> * <img src="screenshots/radio-enabled.ios.png" /> * <figcaption>Enabled</figcaption> * </figure> * <figure> * <img src="screenshots/radio-disabled.ios.png" /> * <figcaption>Disabled</figcaption> * </figure> * </div> */ const RadioButtonIOS = _ref => { let { disabled, onPress, theme, status, value, testID, ...rest } = _ref; const checkedColor = disabled ? theme.colors.disabled : rest.color || theme.colors.accent; let rippleColor; if (disabled) { rippleColor = color(theme.colors.text).alpha(0.16).rgb().string(); } else { rippleColor = color(checkedColor).fade(0.32).rgb().string(); } return /*#__PURE__*/React.createElement(RadioButtonContext.Consumer, null, context => { const checked = isChecked({ contextValue: context === null || context === void 0 ? void 0 : context.value, status, value }) === 'checked'; return /*#__PURE__*/React.createElement(TouchableRipple, _extends({}, rest, { borderless: true, rippleColor: rippleColor, onPress: disabled ? undefined : () => { handlePress({ onPress, value, onValueChange: context === null || context === void 0 ? void 0 : context.onValueChange }); } // @ts-expect-error We keep old a11y props for backwards compat with old RN versions , accessibilityTraits: disabled ? ['button', 'disabled'] : 'button', accessibilityComponentType: checked ? 'radiobutton_checked' : 'radiobutton_unchecked', accessibilityRole: "radio", accessibilityState: { disabled, checked }, accessibilityLiveRegion: "polite", style: styles.container, testID: testID }), /*#__PURE__*/React.createElement(View, { style: { opacity: checked ? 1 : 0 } }, /*#__PURE__*/React.createElement(MaterialCommunityIcon, { allowFontScaling: false, name: "check", size: 24, color: checkedColor, direction: "ltr" }))); }); }; RadioButtonIOS.displayName = 'RadioButton.IOS'; const styles = StyleSheet.create({ container: { borderRadius: 18, padding: 6 } }); export default withTheme(RadioButtonIOS); // @component-docs ignore-next-line const RadioButtonIOSWithTheme = withTheme(RadioButtonIOS); // @component-docs ignore-next-line export { RadioButtonIOSWithTheme as RadioButtonIOS }; //# sourceMappingURL=RadioButtonIOS.js.map