From 13025ce6ce5c4856cd6d37caa50e384a5cc19d4d Mon Sep 17 00:00:00 2001 From: ej9x Date: Wed, 9 Sep 2020 16:51:33 +0300 Subject: [PATCH] feat(Radio): add render prop feature --- src/components/Radio/RadioItem.js | 26 ++++++++++++++----- .../RadioGroupField/RadioGroupField.js | 14 +++++++++- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/components/Radio/RadioItem.js b/src/components/Radio/RadioItem.js index 9719e5c8..e50e4c8a 100644 --- a/src/components/Radio/RadioItem.js +++ b/src/components/Radio/RadioItem.js @@ -21,10 +21,11 @@ type RadioItemClonedProps = { } type RadioItemProps = { + children?: React$Node | ({ checked: boolean }) => React$Node, /** text of the label */ label?: string, /** radio value */ - value: string | number, + value: string | number | boolean, /** possible colors */ color?: 'primary' | 'secondary', /** when true then disable radio */ @@ -53,6 +54,7 @@ class RadioItem extends PureComponent { selectedValue, equalsFunc, onChange, + children, ...rest } = this.props; const hasLabel = !!label; @@ -61,12 +63,22 @@ class RadioItem extends PureComponent { return ( - - - - - { label } - + + + { children({ checked }) } + + + { children } + + + + + + + { label } + + + ); } diff --git a/src/components/RadioGroupField/RadioGroupField.js b/src/components/RadioGroupField/RadioGroupField.js index f3bce193..341b6009 100644 --- a/src/components/RadioGroupField/RadioGroupField.js +++ b/src/components/RadioGroupField/RadioGroupField.js @@ -5,7 +5,7 @@ import React from 'react'; import * as formUtils from '../../utils/forms'; import { Radio } from '../Radio'; import { FormField } from '../Form/FormField'; -import type { InputType, MetaType, PropSizes } from '../../types'; +import type { InputType, MetaType, PropLayout, PropLayoutStretch, PropSizes } from '../../types'; type RadioGroupFieldProps = { /** Grop.Item components */ @@ -26,6 +26,10 @@ type RadioGroupFieldProps = { disabled?: boolean, /** stretch */ stretch?: boolean, + justifyContent?: PropLayoutStretch, + alignContent?: PropLayout, + alignItems?: PropLayoutStretch, + flexWrap?: 'wrap' | 'nowrap' | 'wrap-reverse', }; const RadioGroupField = ({ @@ -38,6 +42,10 @@ const RadioGroupField = ({ options, disabled, stretch, + justifyContent, + alignContent, + alignItems, + flexWrap, ...rest }: RadioGroupFieldProps) => { const { name, value, onChange } = input; @@ -56,6 +64,10 @@ const RadioGroupField = ({ value={ value } disabled={ disabled } stretch={ stretch } + justifyContent={ justifyContent } + alignContent={ alignContent } + alignItems={ alignItems } + flexWrap={ flexWrap } > { children }