@spark-web/text-area
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

title: Text Area storybookPath: forms-textarea--default isExperimentalPackage: false

Allows the user to input plain text spanning multiple lines.

Usage

Field

Each text area input must be accompanied by a Field with a label. Effective form labeling helps inform users the context and information required of the text area.

Examples

Controlled

const [textInput, setTextInput] = React.useState('');

return (
  <Stack gap="large">
    <Field label="Add some text">
      <TextArea
        value={textInput}
        onChange={event => setTextInput(event.target.value)}
      />
    </Field>
    {textInput && (
      <Text>
        You have inputted: “<Strong>{textInput}</Strong></Text>
    )}
  </Stack>
);

Uncontrolled

const textAreaRef = React.useRef(null);
const [, setKey] = React.useState(0);

return (
  <Stack gap="large">
    <Field label="Add some text">
      <TextArea ref={textAreaRef} placeholder="Add some text" />
    </Field>
    <Button onClick={() => setKey(currentKey => currentKey + 1)}>Submit</Button>
    {textAreaRef.current?.value && (
      <Text>
        You have inputted: “<Strong>{textAreaRef.current.value}</Strong></Text>
    )}
  </Stack>
);

Disabled

<Stack gap="large">
  <Field label="Disabled" disabled>
    <TextArea placeholder="This textarea is disabled" />
  </Field>
</Stack>

Message and tone

The message is used to communicate the status of a field, such as an error message. This will be announced on focus and can be combined with a tone to illustrate intent. The supported tones are: critical, positive and neutral.

<Stack gap="large">
  <Field label="Critical" message="Critical message" tone="critical">
    <TextArea placeholder="Critical" />
  </Field>
  <Field label="Positive" message="Positive message" tone="positive">
    <TextArea placeholder="Positive" />
  </Field>
  <Field label="Neutral" message="Neutral message" tone="neutral">
    <TextArea placeholder="Neutral" />
  </Field>
</Stack>

Props

Readme

Keywords

none

Package Sidebar

Install

npm i @spark-web/text-area

Weekly Downloads

345

Version

2.0.0

License

none

Unpacked Size

367 kB

Total Files

11

Last publish

Collaborators

  • brighte
  • brighte-release-bot