import { css } from '@emotion/css'; import { Dispatch, SetStateAction } from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { Field, Input, Label, useStyles2 } from '@grafana/ui'; import { SanitizedSVG } from 'app/core/components/SVG/SanitizedSVG'; import { getPublicOrAbsoluteUrl } from '../resource'; import { MediaType } from '../types'; interface Props { newValue: string; setNewValue: Dispatch>; mediaType: MediaType; } export const URLPickerTab = (props: Props) => { const { newValue, setNewValue, mediaType } = props; const styles = useStyles2(getStyles); const imgSrc = getPublicOrAbsoluteUrl(newValue!); let shortName = newValue?.substring(newValue.lastIndexOf('/') + 1, newValue.lastIndexOf('.')); if (shortName.length > 20) { shortName = shortName.substring(0, 20) + '...'; } return ( <> setNewValue(e.currentTarget.value)} value={newValue} />
{mediaType === MediaType.Icon && } {mediaType === MediaType.Image && newValue && ( Preview of the selected URL )}
); }; const getStyles = (theme: GrafanaTheme2) => ({ iconContainer: css({ display: 'flex', flexDirection: 'column', width: '80%', alignItems: 'center', alignSelf: 'center', }), iconPreview: css({ width: '238px', height: '198px', border: `1px solid ${theme.colors.border.medium}`, display: 'flex', alignItems: 'center', justifyContent: 'center', }), img: css({ width: '147px', height: '147px', fill: theme.colors.text.primary, }), });