# @formbricks/react

> Building React forms has never been quicker.

Latest version **0.3.1** (published 2022-12-09) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @formbricks/react
pnpm add @formbricks/react
yarn add @formbricks/react
bun add @formbricks/react
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2022-12-09 |
| First published | 2022-11-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 132.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12841 |
| Author | Formbricks |
| Maintainers | matthiasnannt |
| Keywords | react, form, forms, form-validation, validation, typescript, formbricks, survey, surveys, select |

## Links

- npm: https://www.npmjs.com/package/@formbricks/react
- Repository: https://github.com/formbricks/formbricks
- Homepage: https://formbricks.com
- Issues: https://github.com/formbricks/formbricks/issues
- npm.io page: https://npm.io/package/@formbricks/react

## Dependencies (4)

- [clsx](https://npm.io/package/clsx.md) ^1.2.1
- [react-hook-form](https://npm.io/package/react-hook-form.md) ^7.39.1
- [@headlessui/react](https://npm.io/package/@headlessui/react.md) ^1.7.4
- [@hookform/error-message](https://npm.io/package/@hookform/error-message.md) ^2.0.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.3.1 (latest) — 2022-12-09
- 0.3.0 — 2022-12-08
- 0.2.2 — 2022-11-24
- 0.2.1 — 2022-11-23
- 0.2.0 — 2022-11-23
- 0.1.1 — 2022-11-22
- 0.1.0 — 2022-11-22
- 0.0.9 — 2022-11-21
- 0.0.8 — 2022-11-21
- 0.0.7 — 2022-11-17
- 0.0.6 — 2022-11-17
- 0.0.5 — 2022-11-17
- 0.0.4 — 2022-11-17
- 0.0.3 — 2022-11-16
- 0.0.1 — 2022-11-15

## README

# Building React forms just got really easy 🤸

Every developer works with forms, few like their experience. Building Forms, especially in React, can be pretty annoying. State management, validation, form components, accessibility, internationalization and performance are all things you have to deal with, but don't really want to.

We make building - and maintaining - forms easier than ever in the world of React.

### Example

```jsx
import { Form, Text, Email, Checkbox, Submit } from "@formbricks/react";
import "@formbricks/react/styles.css";

export default function WaitlistForm() {
  return (
    <Form onSubmit={({ data, schema }) => console.log("data:", data, "schema:", schema)}>
      <Text name="name" label="What's your name?" validation="required" />
      <Email name="email" label="How can we reach you?" validation="required|email" />
      <Checkbox
        name="terms"
        label="Terms & Conditions"
        help="To use our service, please accept."
        validation="accepted"
      />
      <Submit label="Let's go!" />
    </Form>
  );
}
```

### Why is this easier already?

- One easy to use syntax for all input types
- HTML & non-HTML input types available out of the box
- Easily maintainable with component-based approach
- All characteristics adjustable via props
- Automatic schema generation

### What is to come?

- Conditional logic
- Multi-page forms
- Accessibility
- Internationalization
- Form templates (content & styles)

## Custom Styling (CSS & Tailwind)

Giving your form the right look and feel is very likely why you chose to use code. Formbricks React supports styling with a custom style sheet as well as Tailwind CSS.

### Custom Stylesheet

Simply create a style sheet, import it and add your CSS to these classes:

![Checkbox-input-form-survey-react-lib-easy-build-forms-fast-validation-multi-step](https://user-images.githubusercontent.com/72809645/203558901-c692fa28-6b8e-44c7-a381-0779fd85853c.png)

| CSS Class           | Description                                                                                |
| ------------------- | ------------------------------------------------------------------------------------------ |
| formbricks-form     | The outermost wrapping element.                                                            |
| formbricks-outer    | A wrapper around the label input, help text and error messages.                            |
| formbricks-legend   | The legend (often a question)                                                              |
| formbricks-help     | The help text itself.                                                                      |
| formbricks-options  | A wrapper around all options.                                                              |
| formbricks-option   | A wrapper around each option.                                                              |
| formbricks-wrapper  | A wrapper around the label and the input field (no help text).                             |
| formbricks-label    | The label itself.                                                                          |
| formbricks-inner    | A wrapper around the input element.                                                        |
| formbricks-input    | The input element itself, here the radio button.                                           |
| formbricks-message  | The element (or many elements) containing a message — often validation and error messages. |
| formbricks-messages | A wrapper around all the messages.                                                         |

### Tailwind CSS

We love Tailwind! This is why Formbricks React natively supports Tailwind. All you have to do is target the classes using props. For example, to extend “formbricks-outer” class:

```jsx
<Text name="firstname" label="What's your first name?" outerClassName="bg-gray-800 my-5" />
```

## Validation & Error Messages

Validation prevents users from submitting missing of false data.

To add a validation to your inputs, add the `validation` prop and write the rules in string syntax. Rules are divided by a pipe (`|`), e.g.:

```jsx
<Text name="age" label="What's your age?" validation="required|number|min:0|max:100" />
```

| Rule     | Explanation                                                                | Example    |
| -------- | -------------------------------------------------------------------------- | ---------- |
| required | Only accepts non-empty fields                                              | “required” |
| number   | Only accepts fields with a number or float value                           | “number”   |
| min      | Only accepts number values that are greater or equal to the value provided | “min:10”   |
| max      | Only accepts number values that are greater or equal to the value provided | “max:50”   |
| accepted | Only accepts a truish value (true or 1)                                    | "accepted" |
| url      | Only accepts URLs e.g. "https://formbricks.com"                            | "url"      |
| email    | Only accepts email addresses                                               | "email"    |

## Docs

[Dive into the Docs](https://formbricks.com/docs) and join our Discord [to request features and report bugs.](https://formbricks.com/discord)

### Shoutout

The Formbricks React Library is built on top of [React Hook Form](https://react-hook-form.com/) to make use of their data handling and performance optimizations.

The developer experience is inspired by the great [FormKit for Vue.js](https://formkit.com/) Library.

---
_Source: https://npm.io/package/@formbricks/react · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
