import React, { FC, useEffect, useMemo, useState } from 'react'; import { SelectableValue } from '@grafana/data'; import { Input, Select } from '@grafana/ui'; interface Props { onChange: (value: string) => void; options: Array>; value?: string; addLabel?: string; className?: string; placeholder?: string; custom?: boolean; onCustomChange?: (custom: boolean) => void; width?: number; disabled?: boolean; 'aria-label'?: string; } export const SelectWithAdd: FC = ({ value, onChange, options, className, placeholder, width, custom, onCustomChange, disabled = false, addLabel = '+ Add new', 'aria-label': ariaLabel, }) => { const [isCustom, setIsCustom] = useState(custom); useEffect(() => { if (custom) { setIsCustom(custom); } }, [custom]); const _options = useMemo( (): Array> => [...options, { value: '__add__', label: addLabel }], [options, addLabel] ); if (isCustom) { return ( onChange((e.target as HTMLInputElement).value)} /> ); } else { return (