VariableTextField.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import React, { FormEvent, PropsWithChildren, ReactElement } from 'react';
  2. import { InlineField, Input, PopoverContent } from '@grafana/ui';
  3. interface VariableTextFieldProps {
  4. value: string;
  5. name: string;
  6. placeholder: string;
  7. onChange: (event: FormEvent<HTMLInputElement>) => void;
  8. testId?: string;
  9. tooltip?: PopoverContent;
  10. required?: boolean;
  11. width?: number;
  12. labelWidth?: number;
  13. grow?: boolean;
  14. onBlur?: (event: FormEvent<HTMLInputElement>) => void;
  15. interactive?: boolean;
  16. }
  17. export function VariableTextField({
  18. value,
  19. name,
  20. placeholder,
  21. onChange,
  22. testId,
  23. width,
  24. labelWidth,
  25. required,
  26. onBlur,
  27. tooltip,
  28. grow,
  29. interactive,
  30. }: PropsWithChildren<VariableTextFieldProps>): ReactElement {
  31. return (
  32. <InlineField interactive={interactive} label={name} labelWidth={labelWidth ?? 12} tooltip={tooltip} grow={grow}>
  33. <Input
  34. type="text"
  35. id={name}
  36. name={name}
  37. placeholder={placeholder}
  38. value={value}
  39. onChange={onChange}
  40. onBlur={onBlur}
  41. width={grow ? undefined : width ?? 25}
  42. data-testid={testId}
  43. required={required}
  44. />
  45. </InlineField>
  46. );
  47. }