2020-11-25 03:21:48 -06:00
|
|
|
import React, { FormEvent, PropsWithChildren, ReactElement } from 'react';
|
|
|
|
import { InlineField, Input, PopoverContent } from '@grafana/ui';
|
|
|
|
|
|
|
|
interface VariableTextFieldProps {
|
|
|
|
value: string;
|
|
|
|
name: string;
|
|
|
|
placeholder: string;
|
|
|
|
onChange: (event: FormEvent<HTMLInputElement>) => void;
|
2022-02-03 18:55:19 -06:00
|
|
|
testId?: string;
|
2020-11-25 03:21:48 -06:00
|
|
|
tooltip?: PopoverContent;
|
|
|
|
required?: boolean;
|
|
|
|
width?: number;
|
|
|
|
labelWidth?: number;
|
|
|
|
grow?: boolean;
|
|
|
|
onBlur?: (event: FormEvent<HTMLInputElement>) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function VariableTextField({
|
|
|
|
value,
|
|
|
|
name,
|
|
|
|
placeholder,
|
|
|
|
onChange,
|
2022-02-03 18:55:19 -06:00
|
|
|
testId,
|
2020-11-25 03:21:48 -06:00
|
|
|
width,
|
|
|
|
labelWidth,
|
|
|
|
required,
|
|
|
|
onBlur,
|
|
|
|
tooltip,
|
|
|
|
grow,
|
|
|
|
}: PropsWithChildren<VariableTextFieldProps>): ReactElement {
|
|
|
|
return (
|
|
|
|
<InlineField label={name} labelWidth={labelWidth ?? 12} tooltip={tooltip} grow={grow}>
|
|
|
|
<Input
|
|
|
|
type="text"
|
|
|
|
id={name}
|
|
|
|
name={name}
|
|
|
|
placeholder={placeholder}
|
|
|
|
value={value}
|
|
|
|
onChange={onChange}
|
|
|
|
onBlur={onBlur}
|
|
|
|
width={grow ? undefined : width ?? 25}
|
2022-02-03 18:55:19 -06:00
|
|
|
data-testid={testId}
|
2020-11-25 03:21:48 -06:00
|
|
|
required={required}
|
|
|
|
/>
|
|
|
|
</InlineField>
|
|
|
|
);
|
|
|
|
}
|