summaryrefslogtreecommitdiff
path: root/src/components/Input.tsx
blob: a8a6f31612ca67585256d3b606c4bf03c3f5ee1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import React from 'react';
import { Field } from 'formik';

export interface Props extends React.InputHTMLAttributes<HTMLInputElement> {
  label?: string;
}

const focusStyles = 'focus:outline-none focus:shadow focus:border-gray-400';
const baseStyles = 'p-2 border bg-white border-gray-300 rounded-sm';

const InputBase: React.FC<Props> = ({ label, ...props }) => {
  return (
    <div className="m-2 mb-4 flex flex-col">
      <label htmlFor={props?.name} className="mb-1 text-sm text-gray-600">{label}</label>
      <input
        id={props?.name}
        placeholder={label}
        className={`${baseStyles} ${focusStyles}`}
        {...props}
      />
    </div>
  );
};

const Input: React.FC<Props> = props => <Field {...props} as={InputBase} />;

export default Input;