import { css } from '@emotion/css'; import React, { createRef } from 'react'; import SVG from 'react-inlinesvg'; import { GrafanaTheme2 } from '@grafana/data'; import { Button, InlineField, InlineFieldRow, Input, LinkButton, Popover, PopoverController, useStyles2, useTheme2, } from '@grafana/ui'; import { closePopover } from '@grafana/ui/src/utils/closePopover'; import { getPublicOrAbsoluteUrl } from '../resource'; import { MediaType, ResourceFolderName, ResourcePickerSize } from '../types'; import { ResourcePickerPopover } from './ResourcePickerPopover'; interface Props { onChange: (value?: string) => void; mediaType: MediaType; folderName: ResourceFolderName; size: ResourcePickerSize; onClear?: (event: React.MouseEvent) => void; value?: string; //img/icons/unicons/0-plus.svg src?: string; name?: string; placeholder?: string; color?: string; } export const ResourcePicker = (props: Props) => { const { value, src, name, placeholder, onChange, onClear, mediaType, folderName, size, color } = props; const styles = useStyles2(getStyles); const theme = useTheme2(); const pickerTriggerRef = createRef(); const popoverElement = ( ); let sanitizedSrc = src; if (!sanitizedSrc && value) { sanitizedSrc = getPublicOrAbsoluteUrl(value); } const colorStyle = color && { fill: theme.visualization.getColorByName(color), }; const renderSmallResourcePicker = () => { if (value && sanitizedSrc) { return ; } else { return ( Set icon ); } }; const renderNormalResourcePicker = () => ( } suffix={