# react-expression-builder

> A bare-bones react component to build function expressions.

Latest version **1.0.8** (published 2020-06-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-expression-builder
pnpm add react-expression-builder
yarn add react-expression-builder
bun add react-expression-builder
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2020-06-06 |
| First published | 2020-01-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 129 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 29 |
| Author | anshumanv |
| Maintainers | anshumanv |
| Keywords | react, component, expression, statement, build |

## Links

- npm: https://www.npmjs.com/package/react-expression-builder
- Repository: https://github.com/anshumanv/react-expression-builder
- Homepage: https://github.com/anshumanv/react-expression-builder#readme
- Issues: https://github.com/anshumanv/react-expression-builder/issues
- npm.io page: https://npm.io/package/react-expression-builder

## Dependencies (1)

- [downshift](https://npm.io/package/downshift.md) ^4.0.7

## 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

- 1.0.8 (latest) — 2020-06-06
- 1.0.7 — 2020-01-28
- 1.0.6 — 2020-01-28
- 1.0.5 — 2020-01-28
- 1.0.4 — 2020-01-28
- 1.0.3 — 2020-01-28
- 1.0.2 — 2020-01-27
- 1.0.1 — 2020-01-23
- 1.0.0 — 2020-01-23

## README

<h1 align="center"> react-expression-builder </h1>
<p align="center">
<a href="https://www.npmjs.com/package/react-expression-builder">
  <img src="https://img.shields.io/npm/v/react-expression-builder.svg?style=for-the-badge" align="center">
</a>

<a href="https://www.npmjs.com/package/react-expression-builder">
  <img src="https://img.shields.io/npm/dt/react-expression-builder.svg?style=for-the-badge" align="center">
</a>

<a href="https://github.com/anshumanv/react-expression-builder">
  <img src="https://img.shields.io/github/workflow/status/anshumanv/react-expression-builder/test?style=for-the-badge" align="center">
</a>

</p>

<hr>

<p align="center">A bare-bones react component to build function expressions with your data.</p>

### Features

- Typeahead support
- Full keyboard navigation and deletion
- Easy custom styling as per input
- Input validation at granular level
- Customizable options
- Single Dependency, no bloat

### Installation

Install the package -

```sh
npm i react-expression-builder

OR

yarn add react-expression-builder
```

### Usage

```js
import ExpressionBuilder from 'react-expression-builder'

//1. accumulate your options
// fn must have an additional property 'params' -  eg `params: ['dim', 'delimiter', 'occurrence_number']`
const options = [{..., key: '...', type: '...', label: '...',...}, {...}]

// regex to match entires within ""
const stringRegex = /"([^\\"]|\\")*"/

// Optional - Function called on every state change, store your changes on the server
const onChangeFn = editorState => console.log(editorState, editorState.buildExpression())

// Optional - class for the expression element, use for optional styling
const expressionRootClass = 'root-class'

// Optional - class for the input container
const expressionInputClass = 'input-class'

// Optional - Function which validates all the input values and returns a bool.
const validationFn = val => {
	return !isNaN(val) || stringRegex.test(val)
}

<ExpressionBuilder
  onChangeFn={onChangeFn}
  options={options}
  expressionRootClass={expressionRootClass} // Optional
  expressionInputClass={expressionInputClass} // Optional
  placeholder="Enter your expression" // Optional
  initialFocus={true} // if you want your input to be focussed on mount by default
  validationFn={validationFn} // Optional
/>

```

### Data Structure

Uses an N-Ary tree to store/manipulate the expression data, simple recursive function gives you the complete string. You can check [DataStructure.ts](https://github.com/anshumanv/react-expression-builder/blob/master/src/utils/DataStructure.ts) for the simple implementation, if curious.

Note - This only gives the skeleton and functionality, styling is upto the user, you can either make use of respective classes or wrap this component in a CSS-in-JS solution. For example, a nicely styled solution would look somewhat like [this](https://knitui.design/?path=/story/extractor--basic). This is not complete yet, need more work. Meanwhile, suggestions are appreciated.

## Author

[Anshuman Verma](https://github.com/anshumanv)

[<img src="https://image.flaticon.com/icons/svg/185/185961.svg" width="35" padding="10">](https://twitter.com/Anshumaniac12)
[<img src="https://image.flaticon.com/icons/svg/185/185964.svg" width="35" padding="10">](https://linkedin.com/in/anshumanv12)
[<img src="https://image.flaticon.com/icons/svg/185/185981.svg" width="35" padding="10">](https://www.facebook.com/anshumanv12)
[<img src="https://image.flaticon.com/icons/svg/985/985680.svg" width="35" padding="10">](https://www.paypal.me/AnshumanVerma)

## Contribute

Found a bug, please [create an issue](https://github.com/anshumanv/react-expression-builder/issues/new)

## License

[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/anshumanv/react-expression-builder/blob/master/LICENSE)

> © Anshuman Verma

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