FormField.tsx 696 B

12345678910111213141516171819202122232425
  1. import React, { InputHTMLAttributes, FunctionComponent } from 'react';
  2. import { FormLabel } from '../FormLabel/FormLabel';
  3. export interface Props extends InputHTMLAttributes<HTMLInputElement> {
  4. label: string;
  5. labelWidth?: number;
  6. inputWidth?: number;
  7. }
  8. const defaultProps = {
  9. labelWidth: 6,
  10. inputWidth: 12,
  11. };
  12. const FormField: FunctionComponent<Props> = ({ label, labelWidth, inputWidth, ...inputProps }) => {
  13. return (
  14. <div className="form-field">
  15. <FormLabel width={labelWidth}>{label}</FormLabel>
  16. <input type="text" className={`gf-form-input width-${inputWidth}`} {...inputProps} />
  17. </div>
  18. );
  19. };
  20. FormField.defaultProps = defaultProps;
  21. export { FormField };