3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
A bare-bones react component to build function expressions with your data.
20 | 21 | ### Features 22 | 23 | - Typeahead support 24 | - Full keyboard navigation and deletion 25 | - Easy custom styling as per input 26 | - Input validation at granular level 27 | - Customizable options 28 | - Single Dependency, no bloat 29 | 30 | ### Installation 31 | 32 | Install the package - 33 | 34 | ```sh 35 | npm i react-expression-builder 36 | 37 | OR 38 | 39 | yarn add react-expression-builder 40 | ``` 41 | 42 | ### Usage 43 | 44 | ```js 45 | import ExpressionBuilder from 'react-expression-builder' 46 | 47 | //1. accumulate your options 48 | // fn must have an additional property 'params' - eg `params: ['dim', 'delimiter', 'occurrence_number']` 49 | const options = [{..., key: '...', type: '...', label: '...',...}, {...}] 50 | 51 | // regex to match entires within "" 52 | const stringRegex = /"([^\\"]|\\")*"/ 53 | 54 | // Optional - Function called on every state change, store your changes on the server 55 | const onChangeFn = editorState => console.log(editorState, editorState.buildExpression()) 56 | 57 | // Optional - class for the expression element, use for optional styling 58 | const expressionRootClass = 'root-class' 59 | 60 | // Optional - class for the input container 61 | const expressionInputClass = 'input-class' 62 | 63 | // Optional - Function which validates all the input values and returns a bool. 64 | const validationFn = val => { 65 | return !isNaN(val) || stringRegex.test(val) 66 | } 67 | 68 |