Related components

Input

InputField is the preferred way to render a form field for single-line text, such as a name, an email address or a UPN. It wraps an Input with a Label, an optional description and prompt, and an error message.

InputField accepts all the props of Input and passes them on. Its className is applied to the containing div.

<div className="rounded-md bg-white p-8">
  <Form onSubmit={() => {}}>
    <InputField
      name="email"
      label="Email address"
      placeholder="[email protected]"
      type="email"
      appearance="modern"
      className="w-80"
    />
  </Form>
</div>

Appearance

standard (default) has a white background and a grey-700 border. modern has a filled background and no border.

<div className="rounded-md bg-white p-8">
  <Form onSubmit={() => {}}>
    <div className="flex w-80 flex-col gap-6">
      <InputField label="Pupil UPN" placeholder="A123456789012" name="standard" appearance="standard" />
      <InputField label="Pupil UPN" placeholder="A123456789012" name="modern" appearance="modern" />
    </div>
  </Form>
</div>

Theme

With appearance="modern", use theme="grey" on white surfaces and theme="white" on grey surfaces.

<Form onSubmit={() => {}}>
  <div className="flex flex-col gap-4">
    <div className="w-80 rounded-md border border-grey-200 bg-white p-6">
      <InputField label="Pupil UPN" placeholder="A123456789012" name="grey" appearance="modern" theme="grey" />
    </div>
    <div className="w-80 rounded-md bg-grey-100 p-6">
      <InputField label="Pupil UPN" placeholder="A123456789012" name="white" appearance="modern" theme="white" />
    </div>
  </div>
</Form>

Size

sm, md (default), lg and xl.

<div className="rounded-md bg-white p-8">
  <Form onSubmit={() => {}}>
    <div className="flex w-80 flex-col gap-6">
      <InputField placeholder="A123456789012" name="sm" size="sm" appearance="modern" label="Size sm" />
      <InputField placeholder="A123456789012" name="md" size="md" appearance="modern" label="Size md" />
      <InputField placeholder="A123456789012" name="lg" size="lg" appearance="modern" label="Size lg" />
      <InputField placeholder="A123456789012" name="xl" size="xl" appearance="modern" label="Size xl" />
    </div>
  </Form>
</div>

States

Placeholder, filled, read-only and disabled. A read-only input can be focused and selected but not changed, and shows a lock icon.

<div className="rounded-md bg-white p-8">
  <Form onSubmit={() => {}} appearance="modern">
    <div className="flex w-80 flex-col gap-6">
      <InputField name="placeholder" label="Placeholder" placeholder="A123456789012" />
      <InputField name="filled" label="Filled" defaultValue="A123456789012" />
      <InputField name="readonly" label="Read-only" defaultValue="A123456789012" readOnly />
      <InputField name="disabled" label="Disabled" defaultValue="A123456789012" disabled />
    </div>
  </Form>
</div>

Error

Errors appear on blur and on submit. Standard turns the border danger. Modern turns the background dangerLight and the text and message dangerDark.

const ShowErrors = ({ trigger }) => {
  React.useEffect(() => {
    trigger()
  }, [trigger])
  return null
}

render(
  <Form onSubmit={() => {}}>
    {({ trigger }) => (
      <div className="flex w-96 flex-col gap-6 rounded-md bg-white p-8">
        <InputField
          name="standard"
          label="Pupil UPN (standard)"
          validation={{ required: 'Enter the pupil’s UPN' }}
        />
        <InputField
          name="modern"
          label="Pupil UPN (modern)"
          appearance="modern"
          validation={{ required: 'Enter the pupil’s UPN' }}
        />
        <ShowErrors trigger={trigger} />
      </div>
    )}
  </Form>
)

Description, prompt and required

<div className="rounded-md bg-white p-8">
  <Form onSubmit={() => {}} appearance="modern">
    <InputField
      name="upn"
      label="Pupil UPN"
      description="13 characters: a letter followed by 12 numbers."
      prompt={{ label: 'Where do I find this?', link: '#' }}
      placeholder="A123456789012"
      validation={{ required: 'Enter the pupil’s UPN' }}
      className="w-96"
    />
  </Form>
</div>