2022-04-04 09:39:31 -05:00
|
|
|
import React, { FC, useState } from 'react';
|
|
|
|
|
2022-04-29 15:42:59 -05:00
|
|
|
import { InlineField, Input, PopoverContent } from '@grafana/ui';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2022-04-04 09:39:31 -05:00
|
|
|
const LABEL_WIDTH = 20;
|
|
|
|
|
|
|
|
interface VariableTextFieldProps {
|
|
|
|
onBlur: (value: string) => void;
|
|
|
|
value: string;
|
|
|
|
label: string;
|
2022-06-03 02:26:57 -05:00
|
|
|
placeholder?: string;
|
2022-04-29 15:42:59 -05:00
|
|
|
tooltip?: PopoverContent;
|
|
|
|
interactive?: boolean;
|
2022-04-04 09:39:31 -05:00
|
|
|
}
|
|
|
|
|
2022-04-29 15:42:59 -05:00
|
|
|
export const VariableTextField: FC<VariableTextFieldProps> = ({
|
|
|
|
interactive,
|
|
|
|
label,
|
|
|
|
onBlur,
|
|
|
|
placeholder,
|
|
|
|
value,
|
|
|
|
tooltip,
|
|
|
|
}) => {
|
2022-04-04 09:39:31 -05:00
|
|
|
const [localValue, setLocalValue] = useState(value);
|
|
|
|
return (
|
2022-04-29 15:42:59 -05:00
|
|
|
<InlineField interactive={interactive} label={label} labelWidth={LABEL_WIDTH} tooltip={tooltip} grow>
|
2022-04-04 09:39:31 -05:00
|
|
|
<Input
|
|
|
|
aria-label={label}
|
|
|
|
placeholder={placeholder}
|
|
|
|
value={localValue}
|
|
|
|
onChange={(e) => setLocalValue(e.currentTarget.value)}
|
|
|
|
onBlur={() => onBlur(localValue)}
|
|
|
|
/>
|
|
|
|
</InlineField>
|
|
|
|
);
|
|
|
|
};
|