import _ from 'lodash'; import React from 'react'; import PropTypes from 'prop-types'; import { lucidClassNames } from '../../util/style-helpers'; import { StandardProps, findTypes } from '../../util/component-types'; import RadioButton, { IRadioButtonProps, defaultProps as radioButtonDefaultProps, } from '../RadioButton/RadioButton'; const cx = lucidClassNames.bind('&-RadioButtonLabeled'); const { any, object, string } = PropTypes; export interface IRadioButtonLabeledLabelProps extends StandardProps, React.DetailedHTMLProps< React.HTMLAttributes, HTMLDivElement > { description?: string; } const RadioButtonLabeledLabel = (_props: IRadioButtonLabeledLabelProps): null => null; RadioButtonLabeledLabel.displayName = 'RadioButtonLabeled.Label'; RadioButtonLabeledLabel.peek = { description: `Used to identify the purpose of this radio button to the user -- can be any renderable content.`, }; RadioButtonLabeledLabel.propName = 'Label'; /** TODO: Remove nonPassThroughs when the component is converted to a functional component */ const nonPassThroughs = ['className', 'style', 'Label']; export interface IRadioButtonLabeledProps extends IRadioButtonProps { /** Child element whose children are used to identify the purpose of this radio button to the user. */ Label?: string | (React.ReactNode & { props: IRadioButtonLabeledLabelProps }); } export const RadioButtonLabeled = ( props: IRadioButtonLabeledProps ): React.ReactElement => { const { className, isDisabled, isSelected, onSelect, style, ...passThroughs } = props; const labelChildProps = _.first( _.map(findTypes(props, RadioButtonLabeled.Label), 'props') ); return (