import React, { useEffect, useMemo, useState } from "react"; import { DPItemProps, Item, MenuGroup, SelectedItemType } from "../types"; import "../classes.css"; import { DropdownGroup, DropdownNoresults, DropdownOption, FlexContainer, } from "../styles"; import Icons, { ICONS } from "../icons"; const MenuGroupComp: React.FC< DPItemProps & { layout?: "horizontal" | "vertical" } > = (props) => { const { menuGroup, activeItem, selectedItems, displayValue, showNext, handleItemSelection, handleMultipleChildrenSel, level, layout = "horizontal", } = props; const { options, groupHeading, id: groupId } = menuGroup; const { options: opt, ...parentItemObj } = menuGroup; // choose the default value via prop const isMultiSelection = menuGroup.isMultiSelection !== undefined ? menuGroup.isMultiSelection : true; const width = 13; const [allItemsChecked, setAllItemsChecked] = useState(false); const handleSelectAll = () => { setAllItemsChecked((prev: boolean) => { handleMultipleChildrenSel(options || [], groupId, !prev); return !prev; }); }; // tick the allItemsChecked checkbox based on the options count const checkIfAllItemChecked = useMemo(() => { if (!options) { return false; } return options?.every((e) => selectedItems[e.id]); }, [selectedItems]); useEffect(() => { setAllItemsChecked(checkIfAllItemChecked); }, [checkIfAllItemChecked]); /** * * Handled the selection of item */ return ( <> {layout !== "vertical" && (
{menuGroup.groupHeading}
)} {/* {isMultiSelection && options && (
0 : false} isChecked={allItemsChecked} />
)} */}
{options?.map((ele: Item) => { const label = ele?.[displayValue]; const isActive = activeItem?.[ele.id]?.id === ele.id; const fadeActive = !isActive && selectedItems?.[ele.id]?.id === ele.id; const hasOptions = ele.options; return ( // TODO: use only the part of the parentItemObj handleItemSelection( ele, groupHeading, parentItemObj.id, isMultiSelection ) } >
{label}
{layout === "vertical" && hasOptions && ( )}
); })}
{layout === "horizontal" && showNext && options?.length && options.map((ele) => activeItem?.[ele.id]?.id === ele.id && ele.options ? ( ) : null )} ); }; export default MenuGroupComp; interface SelectionIconProps { isMultiSelection: boolean; isChecked: boolean; layout: "horizontal" | "vertical"; } const SelectionIcon = ({ isMultiSelection, isChecked, layout, }: SelectionIconProps) => { return ( <> {isChecked ? ( ) : ( )} ); }; MenuGroupComp.defaultProps = { showNext: true, };