import React from 'react' import classNames from 'classnames' import { Header } from '../Header/Header' import { ArrayFilterProps } from './ArrayFilter.types' import './ArrayFilter.css' const getNewValues = (value: string, values: string[]) => { return values.some((x) => x === value) ? values.filter((x) => x !== value) : [...values, value] } const ArrayFilter = (props: ArrayFilterProps) => { const { className, name, values, options, onChange } = props const handleKeyDown = (option: string) => (evt: React.KeyboardEvent) => { if (evt.key === 'Enter') { onChange(getNewValues(option, values)) } } const handleOnClick = (option: string) => () => { onChange(getNewValues(option, values)) } return (
{name ? (
{name}
) : null}
{options.map((option) => { const isActive = values.includes(option.value) return (
{option.text}
) })}
) } export { ArrayFilter }