UNPKG

react-native-ui-lib

Version:

<p align="center"> <img src="https://user-images.githubusercontent.com/1780255/105469025-56759000-5ca0-11eb-993d-3568c1fd54f4.png" height="250px" style="display:block"/> </p> <p align="center">UI Toolset & Components Library for React Native</p> <p a

37 lines (33 loc) 1.21 kB
import _pt from "prop-types"; import React, { Component } from 'react'; import hoistStatics from 'hoist-non-react-statics'; import RadioGroupContext from "./RadioGroupContext"; export default function asRadioGroupChild(WrappedComponent) { class RadioGroupChild extends Component { static propTypes = { /** * The identifier value of the radio button. must be different than other RadioButtons in the same group */ value: _pt.oneOfType([_pt.string, _pt.number, _pt.bool]), /** * When using RadioButton without a RadioGroup, use this prop to toggle selection */ selected: _pt.bool }; render() { const { value: buttonValue, selected } = this.props; return <RadioGroupContext.Consumer> {({ value, onValueChange }) => <WrappedComponent {...this.props} selectedValue={value} selected={buttonValue !== undefined ? value === buttonValue : selected} onValueChange={onValueChange} />} </RadioGroupContext.Consumer>; } } hoistStatics(RadioGroupChild, WrappedComponent); RadioGroupChild.displayName = WrappedComponent.displayName; return RadioGroupChild; }