UNPKG

eldav1d-marvel-ui

Version:

UI library for (and from) Playing with Marvel API

1 lines 1.91 kB
{"version":3,"file":"CheckboxList.cjs","sources":["../../../../lib/molecules/CheckboxList/CheckboxList.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\nimport CheckboxGroup, { ICheckboxGroupProps } from '../CheckboxGroup/CheckboxGroup';\n\nexport interface ICheckboxListProps {\n /**\n * List of options to be displayed\n * @type {string[]}\n */\n options: string[];\n /**\n * Children to be rendered\n * should be a CheckboxGroup instance\n * @type {(option: string, index: number) => React.ReactElement<ICheckboxGroupProps>}\n */\n children: (option: string, index: number) => React.ReactElement<ICheckboxGroupProps>;\n}\n\nconst CheckboxList = ({ options, children }: ICheckboxListProps) => {\n useEffect(() => {\n options.forEach((option, index) => {\n const child = children(option, index);\n if (React.isValidElement(child) && child.type !== CheckboxGroup) {\n throw new Error('Children must be an instance of CheckboxGroup');\n }\n });\n }, [options, children]);\n\n return (\n <ul className='md:h-full flex flex-col md:flex-row gap-2 md:items-center'>\n {options.map((option, index) => (\n <li className='flex items-center' key={`${option}${index}`}>\n {children(option, index)}\n </li>\n ))}\n </ul>\n );\n};\n\nexport default CheckboxList;\n"],"names":["CheckboxList","options","children","useEffect","option","index","child","React","CheckboxGroup","_jsx"],"mappings":"oNAiBMA,EAAe,CAAC,CAAE,QAAAC,EAAS,SAAAC,MAC/BC,EAAAA,UAAU,IAAK,CACLF,EAAA,QAAQ,CAACG,EAAQC,IAAS,CAC1B,MAAAC,EAAQJ,EAASE,EAAQC,CAAK,EACpC,GAAIE,EAAM,eAAeD,CAAK,GAAKA,EAAM,OAASE,UAC1C,MAAA,IAAI,MAAM,+CAA+C,CACjE,CACD,CAAA,EACA,CAACP,EAASC,CAAQ,CAAC,EAGpBO,EAAI,IAAA,KAAA,CAAA,UAAU,4DAA2D,SACtER,EAAQ,IAAI,CAACG,EAAQC,IACpBI,EAAAA,IAAI,KAAA,CAAA,UAAU,6BACXP,EAASE,EAAQC,CAAK,CADc,EAAA,GAAGD,CAAM,GAAGC,CAAK,EAAE,CAG3D,CAAC,CAAA"}