import classNames from 'classnames'; import React, { ReactNode, useRef, useState } from 'react'; import { FaDownload } from 'react-icons/fa'; import { v4 as uuidv4 } from 'uuid'; import { PublicationButton } from '../../publications/PublicationButton'; import { Formula } from '../Formula'; import { validateRangedFormula } from '../../data-entry/MaterialsInput/utils'; import { Tooltip } from '../Tooltip'; interface Props { id?: string; setProps?: (value: any) => any; className?: string; chips: any[]; chipTooltips?: string[]; chipLinks?: string[]; chipLinksTarget?: string; chipType?: 'normal' | 'publications' | 'dynamic-publications'; showDownloadIcon?: boolean; } export const ArrayChips: React.FC = ({ chipType = 'normal', chipLinksTarget = '_blank', ...otherProps }) => { const props = { chipType, chipLinksTarget, ...otherProps }; return ( {props.chips.map((item, i) => { const chipContent = validateRangedFormula(item) ? {item} : item; const tooltipId = uuidv4(); const tooltip = props.chipTooltips && props.chipTooltips[i] && ( {props.chipTooltips[i]} ); const isLink = props.chipLinks && props.chipLinks[i]; let isPublicationButton = isLink && props.chipType === 'publications'; if (isLink && props.chipType === 'dynamic-publications') { isPublicationButton = props.chipLinks![i].indexOf('https://doi.org/') === 0; } if (isPublicationButton) { return ( {chipContent} {tooltip} ); } else if (isLink) { return ( e.stopPropagation()} data-tip data-for={tooltipId} > {props.showDownloadIcon && } {chipContent} {tooltip} ); } else { return ( {chipContent} {tooltip} ); } })} ); };