@k8ordo/ui

FormControl

入力欄にラベルとヘルプ、エラーの表示を付けるラッパーです。入力欄はrenderInputで描きます。

インポート

ts
import { FormControl } from '@k8ordo/ui';

使い方

tsx
<FormControl
  label="Name"
  renderInput={(props) => (
    <TextField
      {...props}
      placeholder="Enter your name"
    />
  )}
/>

ヘルプテキスト

Please enter a valid email address.

tsx
<FormControl
  helpText="Please enter a valid email address."
  label="Email"
  renderInput={(props) => (
    <TextField
      {...props}
      placeholder="[email protected]"
    />
  )}
/>

エラーテキスト

This field is required.

tsx
<FormControl
  errorText="This field is required."
  invalid
  label="Email"
  renderInput={(props) => (
    <TextField {...props} />
  )}
/>

必須

tsx
<FormControl
  required
  label="Username"
  renderInput={(props) => (
    <TextField
      {...props}
      placeholder="Required field"
    />
  )}
/>

無効

tsx
<FormControl
  disabled
  label="Username"
  renderInput={(props) => (
    <TextField
      {...props}
      placeholder="Disabled field"
    />
  )}
/>

Props

label
Type: string
Default: -
renderInput
Type: (props: { id: string; 'aria-describedby': string | undefined; 'aria-labelledby': string; disabled: boolean; invalid: boolean; required: boolean; }) => ReactElement
Default: -
disabled?
Type: boolean
Default: false
errorText?
Type: string
Default: -
helpText?
Type: string
Default: -
invalid?
Type: boolean
Default: false
labelAs?
Type: 'label'|'legend'
Default: 'label'
ref?
Type: Ref<HTMLElement>
Default: -
required?
Type: boolean
Default: false
PropTypeDefault
labelstring-
renderInput(props: { id: string; 'aria-describedby': string | undefined; 'aria-labelledby': string; disabled: boolean; invalid: boolean; required: boolean; }) => ReactElement-
disabled?booleanfalse
errorText?string-
helpText?string-
invalid?booleanfalse
labelAs?'label'|'legend''label'
ref?Ref<HTMLElement>-
required?booleanfalse

継承する属性(内部で固定するものを除く): HTMLAttributes<HTMLElement>

k8ordo

Baselineに入った機能を、制限なく使うReactのライブラリ群。