import { useCallback } from "react"; import { ButtonGroup, Icon, IconName } from "@blueprintjs/core"; import { CustomClasses } from "../../../constants"; import "./_index.sass"; export type SortOption = { icon?: IconName | null, label: string, value: T }; type SortButtonOwnProps = { isSelected: boolean, name: string, onClick: (value: T) => void, }; function SortButton(props: SortButtonOwnProps & SortOption){ const { icon = null, isSelected, label, name, onClick, value } = props; const uniqueId = [name, value].join("_"); const handleClick = useCallback(() => onClick(value), [onClick, value]); return ( {}} value={value} /> ); } type SortButtonsProps = { name: string, onSelect: (value: SortOption["value"]) => void, options: SortOption[], selectedOption: SortOption["value"] }; function SortButtons(props: SortButtonsProps){ const { name, onSelect, options, selectedOption } = props; return ( {options.map(op => { return key={op.value} isSelected={op.value == selectedOption} name={name} onClick={onSelect} {...op} />; })} ); } export default SortButtons;