import classNames from 'classnames'; import React, { useEffect, useState } from 'react'; import { FaRegTimesCircle, FaToggleOn } from 'react-icons/fa'; import { Tooltip } from '../../data-display/Tooltip'; import { PublicationButton } from '../../publications/PublicationButton'; import './FilterField.css'; interface FilterFieldProps { id?: string; className?: string; /** * Label to display above the filter component */ label?: string; /** * Tooltip to show when hovering over the filter label */ tooltip?: string; /** * Units used in this filter */ units?: string; /** * List of DOIs to display as compact publication buttons next to the label. * Use this for filters that need to cite specific publications. */ dois?: string[]; /** * Control whether the filter appears to be active */ active?: boolean; resetFilter?: (id: any) => any; } /** * Common wrapper for filters/inputs and their labels */ export const FilterField: React.FC = ({ dois = [], ...otherProps }) => { const props = { dois, ...otherProps }; const renderUnitsComponent = (units?: string) => { if (units) { return ({units}); } else { return null; } }; const renderFilterLabel = () => { const cancelButton = props.active ? ( ) : null; const innerLabel = ( {props.label} {renderUnitsComponent(props.units)} {cancelButton} {props.tooltip && {props.tooltip}} ); if (props.active && props.resetFilter) { return props.resetFilter!(props.id)}>{innerLabel}; } else { return innerLabel; } }; return (
{props.label && (
{renderFilterLabel()} {props.dois.map((doi, i) => ( ))}
)} {props.children}
); };