Files
grafana/public/app/features/dashboard-scene/settings/variables/components/VariableTextField.tsx
Ivan Ortega Alba 3b401d0d4d CustomVariable: Be able to edit them using scenes (#80193)
---------
Co-authored-by: Alexandra Vargas <alexa1866@gmail.com>
2024-01-17 19:14:01 +02:00

59 lines
1.3 KiB
TypeScript

import { useId } from '@react-aria/utils';
import React, { FormEvent, PropsWithChildren } from 'react';
import { Field, Input } from '@grafana/ui';
interface VariableTextFieldProps {
value?: string;
defaultValue?: string;
name: string;
placeholder?: string;
onChange?: (event: FormEvent<HTMLInputElement>) => void;
testId?: string;
required?: boolean;
width?: number;
grow?: boolean;
onBlur?: (event: FormEvent<HTMLInputElement>) => void;
maxLength?: number;
description?: React.ReactNode;
invalid?: boolean;
error?: React.ReactNode;
}
export function VariableTextField({
value,
defaultValue,
name,
placeholder = '',
onChange,
testId,
width,
required,
onBlur,
grow,
description,
invalid,
error,
maxLength,
}: PropsWithChildren<VariableTextFieldProps>) {
const id = useId(name);
return (
<Field label={name} description={description} invalid={invalid} error={error} htmlFor={id}>
<Input
type="text"
id={id}
placeholder={placeholder}
value={value}
defaultValue={defaultValue}
onChange={onChange}
onBlur={onBlur}
width={grow ? undefined : width ?? 30}
data-testid={testId}
maxLength={maxLength}
required={required}
/>
</Field>
);
}