import React, {useState} from "react"; import "./MultiBox.scss"; import classNames from "classnames"; import Button from "../button/Button"; import {s4} from "../../utils/utils"; type IProps = { labels: string[]; selectedValue: string[]; value: string[]; onChange: (value: string[]) => void; withAllToogler?: boolean; defaultAllToogle?: boolean; withAllTooglerLabel?: string; } const JDmultiBox: React.FC = ({ value, selectedValue, defaultAllToogle = false, labels, onChange, withAllToogler, withAllTooglerLabel }) => { const [onAllToggle, setAllToggle] = useState(defaultAllToogle); const handleMultiBoxAllChange = () => { setAllToggle(!onAllToggle); onChange(!onAllToggle ? value : []); }; const handleMultiBoxChange = (inValue: string) => { const index = selectedValue.findIndex(inInValue => inInValue === inValue); if (index === -1) { selectedValue.push(inValue); } else { selectedValue.splice(index, 1); } onChange(selectedValue.slice()); }; const classes = classNames({ JDswitch__input: true }); return (
{withAllToogler && (
); }; export default JDmultiBox;