VariableSwitchField.tsx 857 B

1234567891011121314151617181920212223242526272829303132
  1. import React, { ChangeEvent, PropsWithChildren, ReactElement } from 'react';
  2. import { InlineField, InlineSwitch } from '@grafana/ui';
  3. import { useUniqueId } from 'app/plugins/datasource/influxdb/components/useUniqueId';
  4. interface VariableSwitchFieldProps {
  5. value: boolean;
  6. name: string;
  7. onChange: (event: ChangeEvent<HTMLInputElement>) => void;
  8. tooltip?: string;
  9. ariaLabel?: string;
  10. }
  11. export function VariableSwitchField({
  12. value,
  13. name,
  14. tooltip,
  15. onChange,
  16. ariaLabel,
  17. }: PropsWithChildren<VariableSwitchFieldProps>): ReactElement {
  18. const uniqueId = useUniqueId();
  19. return (
  20. <InlineField label={name} labelWidth={20} tooltip={tooltip}>
  21. <InlineSwitch
  22. id={`var-switch-${uniqueId}`}
  23. label={name}
  24. value={value}
  25. onChange={onChange}
  26. aria-label={ariaLabel}
  27. />
  28. </InlineField>
  29. );
  30. }