FormLabel.tsx 1020 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import React, { FunctionComponent, ReactNode } from 'react';
  2. import classNames from 'classnames';
  3. import { Tooltip } from '../Tooltip/Tooltip';
  4. interface Props {
  5. children: ReactNode;
  6. className?: string;
  7. htmlFor?: string;
  8. isFocused?: boolean;
  9. isInvalid?: boolean;
  10. tooltip?: string;
  11. width?: number;
  12. }
  13. export const FormLabel: FunctionComponent<Props> = ({
  14. children,
  15. isFocused,
  16. isInvalid,
  17. className,
  18. htmlFor,
  19. tooltip,
  20. width,
  21. ...rest
  22. }) => {
  23. const classes = classNames(`gf-form-label width-${width ? width : '10'}`, className, {
  24. 'gf-form-label--is-focused': isFocused,
  25. 'gf-form-label--is-invalid': isInvalid,
  26. });
  27. return (
  28. <label className={classes} {...rest} htmlFor={htmlFor}>
  29. {children}
  30. {tooltip && (
  31. <Tooltip placement="top" content={tooltip} theme={'info'}>
  32. <div className="gf-form-help-icon gf-form-help-icon--right-normal">
  33. <i className="fa fa-info-circle" />
  34. </div>
  35. </Tooltip>
  36. )}
  37. </label>
  38. );
  39. };