DocsComponentsTemplatesThemesGitHub

Field

Label + control + hint/error wrapper; adds a required asterisk or an (optional) marker.

Code

import * as React from 'react';
import { Field, NumberInput } from '@fruit-labs/design';

export default function Demo() {
  return (
    <div
      style={{
        maxWidth: 320,
      }}
    >
      <Field label="Team size" required hint="Billed per seat.">
        {(id) => <NumberInput id={id} defaultValue={5} min={1} suffix="seats" />}
      </Field>
    </div>
  );
}

Install

From npm:

npm install @fruit-labs/design

import { Field } from '@fruit-labs/design';

Or copy the TypeScript source into your project:

npx shadcn@latest add https://design.fruitlabs.online/r/field.json

Guidelines

  • Children may be a function receiving the generated id for htmlFor.
  • Mark the minority: if most fields are required, mark the optional ones with optional; otherwise mark required.

Props

PropTypeRequired
labelReact.ReactNodeNo
hintReact.ReactNodeNo
errorReact.ReactNodeNo
requiredbooleanNo
optionalbooleanNo
idstringNo
classNamestringNo
styleReact.CSSPropertiesNo
childrenReact.ReactNode | ((id: string) => React.ReactNode)Yes

Edit this example on GitHub