diff --git a/playbook/app/pb_kits/playbook/pb_radio/_radio.tsx b/playbook/app/pb_kits/playbook/pb_radio/_radio.tsx index a1436f8135..1868dee9da 100644 --- a/playbook/app/pb_kits/playbook/pb_radio/_radio.tsx +++ b/playbook/app/pb_kits/playbook/pb_radio/_radio.tsx @@ -1,27 +1,28 @@ -import React, { forwardRef, isValidElement, useRef } from 'react' +/*eslint-disable react/no-multi-comp, flowtype/space-before-type-colon */ + +import React, { forwardRef } from 'react' import Body from '../pb_body/_body' -import Flex from '../pb_flex/_flex' import classnames from 'classnames' import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../utilities/props' import { globalProps, GlobalProps } from '../utilities/globalProps' type RadioProps = { - aria?: { [key: string]: string }, + aria?: {[key: string]: string}, alignment?: string, checked?: boolean, children?: React.ReactChild[] | React.ReactChild, className?: string, dark?: boolean, - data?: { [key: string]: string }, + data?: {[key: string]: string}, disabled?: boolean, error?: boolean, - htmlOptions?: { [key: string]: string | number | boolean | (() => void) }, + htmlOptions?: {[key: string]: string | number | boolean | (() => void)}, id?: string, label: string, name?: string, value?: string, text?: string, - onChange: (event: React.FormEvent | null) => void, + onChange: (event: React.FormEvent | null)=>void, } & GlobalProps const Radio = ({ @@ -30,9 +31,9 @@ const Radio = ({ children, className, dark = false, + data = {}, disabled = false, error = false, - data = {}, htmlOptions = {}, id, label, @@ -41,103 +42,52 @@ const Radio = ({ value = 'radio_text', onChange = () => { void 0 }, ...props -}: RadioProps ) => { - const radioRef = useRef(null); - - const ariaProps = buildAriaProps(aria); - const dataProps = buildDataProps(data); - const htmlProps = buildHtmlProps(htmlOptions); +}: RadioProps, ref: any) => { + const ariaProps = buildAriaProps(aria) + const dataProps = buildDataProps(data) + const htmlProps = buildHtmlProps(htmlOptions) const classes = classnames( - buildCss('pb_radio_kit', alignment), - dark ? 'dark' : null, - error ? 'error' : null, + buildCss('pb_radio_kit', alignment ), + dark ? 'dark': null, error ? 'error': null, globalProps(props), - className - ); - - const classesCustom = classnames( - dark ? 'dark' : null, - error ? 'error' : null, - globalProps(props), - className - ); - - const isCustomChild = children && isValidElement(children) && children.type !== 'input'; + className) const displayRadio = (props: RadioProps & any) => { - if (isValidElement(children) && children.type === 'input') { - return children; - } else if (isCustomChild || !children) { - return ( - - ); - } - }; - - const handleContainerClick = (event: React.MouseEvent | undefined) => { - if (event) { - const target = event.target as HTMLElement; - if ( - target.id === 'pb-radio-children-wrapper' || - target.closest('#pb-radio-children-wrapper') - ) { - radioRef.current?.click(); - } - } - }; + if (children) + return (children) + else + return ( + + )} return ( - isCustomChild ? ( - ) => { - handleContainerClick(event); - }) as unknown as () => void - }} - id="radio-container" - > - -
{children}
-
- ) : ( - - ) - ); -}; + + ) +} -export default forwardRef(Radio); +export default forwardRef(Radio) diff --git a/playbook/app/pb_kits/playbook/pb_radio/docs/_radio_children.jsx b/playbook/app/pb_kits/playbook/pb_radio/docs/_radio_children.jsx deleted file mode 100644 index 70f42d7c84..0000000000 --- a/playbook/app/pb_kits/playbook/pb_radio/docs/_radio_children.jsx +++ /dev/null @@ -1,56 +0,0 @@ -import React from 'react' -import Radio from '../_radio' -import Select from '../../pb_select/_select' -import Typeahead from '../../pb_typeahead/_typeahead' -import Title from '../../pb_title/_title' - -const RadioChildren = (props) => { - - - const options = [ - { label: 'Orange', value: 'Orange' }, - { label: 'Red', value: 'Red' }, - { label: 'Green', value: 'Green' }, - { label: 'Blue', value: 'Blue' }, - ] - - return ( -
- -