import _ from 'lodash'; import React from 'react'; import PropTypes from 'prop-types'; import { lucidClassNames } from '../../util/style-helpers'; import { findTypes, StandardProps } from '../../util/component-types'; import Checkbox, { ICheckboxProps, defaultProps as defaultPropsCheckbox, } from '../Checkbox/Checkbox'; const cx = lucidClassNames.bind('&-CheckboxLabeled'); const { any, node, object, string, bool, func } = PropTypes; /** Label */ export interface ILabelProps extends StandardProps {} const Label = (props: ILabelProps): null => null; Label.displayName = 'CheckboxLabeled.Label'; Label.peek = { description: `Renders a \`Label\` for the \`Checkbox\`.`, categories: ['controls', 'toggles'], madeFrom: ['Checkbox'], }; Label.propName = 'Label'; Label.propTypes = { /** Used to identify the purpose of this checkbox to the user -- can be any renderable content. */ children: node, }; /** Checkbox Labeled */ /** TODO: Remove the nonPassThroughs when the component is converted to a functional component */ const nonPassThroughs = [ 'isIndeterminate', 'isDisabled', 'isSelected', 'onSelect', 'className', 'style', 'Label', 'initialState', ]; export interface ICheckboxLabeledProps extends ICheckboxProps { /** Child element whose children are used to identify the purpose of this checkbox to the user. */ Label?: | string | string[] | Element[] | (React.ReactNode & { props: ILabelProps }); } export const CheckboxLabeled = ( props: ICheckboxLabeledProps ): React.ReactElement => { const { className, isIndeterminate, isDisabled, isSelected, onSelect, style, ...passThroughs } = props; const labelChildProps = _.first( _.map(findTypes(props, CheckboxLabeled.Label), 'props') ); return (