WebJamApps/breakpointministries

View on GitHub
src/lib/forms.tsx

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import React from 'react';

export interface InputParams {
  type: string | undefined,
  label: string, isRequired: boolean | undefined,
  onChange: ((event: React.ChangeEvent<HTMLInputElement>) => void | string), value: string, width: string
}
function makeInput(p: InputParams): JSX.Element {
  let fId = p.label && p.label.toLowerCase();
  fId = fId.replace(/\s/g, '');
  return (
    <label className="inquiryLabel" htmlFor={fId}>
      {p.isRequired ? '* ' : ''}
      {p.label}
      <br />
      <input
        style={{ width: p.width }}
        id={fId}
        type={p.type}
        name={fId}
        onChange={p.onChange}
        required={p.isRequired}
        value={p.value || ''}
      />
    </label>
  );
}

export default {
  makeInput,
};