import React, { useState } from "react"; import { Box, IconButton, List, ListItem, Pagination, Stack, Typography, Grid, Slide, Collapse, Grow, } from "@mui/material"; import { BasicDataItem, BasicDataViewProps } from "../../types/basicDataView"; import { SearchInput } from "../searchInput"; import Radio from "@mui/material/Radio"; import RadioGroup from "@mui/material/RadioGroup"; import FormControlLabel from "@mui/material/FormControlLabel"; import FormControl from "@mui/material/FormControl"; import FormLabel from "@mui/material/FormLabel"; import ClearIcon from "@mui/icons-material/Clear"; import ChevronRightIcon from "@mui/icons-material/ChevronRight"; import { NixType, nixTypes } from "../../types/nix"; export type BasicListItem = { item: React.ReactNode; key: string; }; export type BasicListProps = BasicDataViewProps & { handleFilter: (t: NixType, mode: "from" | "to") => void; preview: React.ReactNode; selected?: string | null; }; interface SelectOptionProps { label: string; handleChange: (value: string) => void; options: { value: string; label: string; }[]; } const SelectOption = (props: SelectOptionProps) => { const { label, handleChange, options } = props; const [value, setValue] = React.useState("any"); const _handleChange = (event: React.ChangeEvent) => { const newVal = (event.target as HTMLInputElement).value as NixType; setValue(newVal); handleChange(newVal); }; const handleClear = () => { setValue("any"); handleChange("any"); }; return ( {label} {options.map(({ value, label }) => ( } label={label} /> ))} ); }; export function BasicList(props: BasicListProps) { const { items, pageCount = 1, handleSearch, handleFilter, preview, selected = "", } = props; // const [from, setFrom] = useState("any"); // const [to, setTo] = useState("any"); const [page, setPage] = useState(1); const [searchTerm, setSearchTerm] = useState(""); const handlePageChange = ( _event: React.ChangeEvent, value: number ) => { setPage(value); }; const _handleFilter = (t: NixType, mode: "from" | "to") => { handleFilter(t, mode); setPage(1); }; const _handleSearch = (term: string) => { handleSearch && handleSearch(term); setSearchTerm(term); setPage(1); }; // const refs = items.forEach(({,key})=>({key: React.createRef())) const refs: { [key: string]: React.RefObject; } = React.useMemo( () => items.reduce( (prev, curr) => ({ [curr.key]: React.createRef(), ...prev }), {} ), [items] ); return ( _handleSearch("")} /> {/* */} { _handleFilter(value as NixType, "from"); }} options={nixTypes.map((v) => ({ value: v, label: v }))} /> { _handleFilter(value as NixType, "to"); }} options={nixTypes.map((v) => ({ value: v, label: v }))} /> {/* */} {items.map(({ item, key }, idx) => ( {preview} {/* )} */} {item} ))} ); }