Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@pirireis/react-two-way-querybuilder
Advanced tools
A simple react component that lets you build queries dynamically on UI. Doesn't depend on any 3-d party libraries.
npm i react-two-way-querybuilder --save
Two way query builder is flexible and configurable component with a set of possible options.
Simple usage:
import React, { Component } from 'react';
import TwoWayQuerybuilder from 'react-two-way-querybuilder';
const fields = [
{ name: 'firstName', operators: 'all', label: 'First Name', input: { type: 'text' } },
{ name: 'lastName', operators: 'all', label: 'Last Name', input: { type: 'text' } },
{ name: 'age', operators: 'all', label: 'Age', input: { type: 'text' } },
{ name: 'birthDate', operators: 'all', label: 'Birth date', input: { type: 'text' } },
];
class App extends Component {
handleChange(event) {
console.log('query', event.query);
}
render() {
return (
<TwoWayQuerybuilder fields={fields} onChange={this.handleChange} />
);
}
}
export default App;
###Props:
fields
: your fields used to build a query
['=', '<', '>']
text
, textarea
, select
. If you are using select
input type pass options to the object in the following way:
input: {type: 'select', options: [{value: '1', name: 'one'}, {value: '2', name: 'two'}]}
. Also, it supports validation by passing pattern
property with regexp pattern and
errorText
property for validation error message text.onChange
: pass here your function that will be called when data was changedconfig
: configuration object with possible options:
query
: pass here prepared query, so UI will be built using it.operators
: array of operators, the default one is:
[
{ operator: '=', label: '=' },
{ operator: '<>', label: '<>' },
{ operator: '<', label: '<' },
{ operator: '>', label: '>' },
{ operator: '>=', label: '>=' },
{ operator: '<=', label: '<=' },
{ operator: 'IS NULL', label: 'Null' },
{ operator: 'IS NOT NULL', label: 'Not Null' },
{ operator: 'IN', label: 'In' },
{ operator: 'NOT IN', label: 'Not In' },
]
combinators
: array of combinators, the default one is:[
{ combinator: 'AND', label: 'And' },
{ combinator: 'OR', label: 'Or' },
{ combinator: 'NOT', label: 'Not' },
]
style
: use this object to redefine styles. Properties:
primaryBtn
: used for primary button styles,deleteBtn
: delete button styles,rule
: rule styles,condition
: condition styles,select
: select styles,input
: input styles,txtArea
: text area styles :Derror
: error message stylingbuttonsText
: text of the buttons, you can redefine it for multilanguage support or because you just want. By default used following text:
'Add rule'
,'Add group'
,'Clear'
,'Delete'
Visit DEMO storybook to take a look at basic usage cases:
existing query:
import React, { Component } from 'react';
import TwoWayQuerybuilder from 'react-two-way-querybuilder';;
const fields = [
{ name: 'firstName', operators: 'all', label: 'First Name', input: { type: 'text' } },
{ name: 'lastName', operators: 'all', label: 'Last Name', input: { type: 'text' } },
{ name: 'age', operators: 'all', label: 'Age', input: { type: 'text' } },
{ name: 'birthDate', operators: 'all', label: 'Birth date', input: { type: 'text' } },
];
const config = {
query: "((firstname='Jack' AND lastName='London') OR lastName='Smith')",
};
class App extends Component {
handleChange(event) {
console.log('query', event.query);
}
render() {
return (
<TwoWayQuerybuilder config={config} fields={fields} onChange={this.handleChange} />
);
}
}
export default App;
changed input types:
import React, { Component } from 'react';
import TwoWayQuerybuilder from 'react-two-way-querybuilder';;
const changedFields = [
{ name: 'firstName', operators: 'all', label: 'First Name', input: { type: 'text' } },
{ name: 'lastName', operators: 'all', label: 'Last Name', input: {
type: 'select',
options: [
{ value: 'Smith', name: 'Smith' },
{ value: 'London', name: 'London' },
] } },
{ name: 'age', operators: 'all', label: 'Age',
input: {
type: 'select',
options: [
{ value: '28', name: 'twenty eight' },
{ value: '30', name: 'thirty' },
] } },
{ name: 'birthDate', operators: 'all', label: 'Birth date', input: { type: 'text' } },
];
class App extends Component {
handleChange(event) {
console.log('query', event.query);
}
render() {
return (
<TwoWayQuerybuilder config={config} fields={changedFields} onChange={this.handleChange} />
);
}
}
export default App;
custom styles
import React, { Component } from 'react';
import TwoWayQuerybuilder from 'react-two-way-querybuilder';;
const fields = [
{ name: 'firstName', operators: 'all', label: 'First Name', input: { type: 'text' } },
{ name: 'lastName', operators: 'all', label: 'Last Name', input: { type: 'text' } },
{ name: 'age', operators: 'all', label: 'Age', input: { type: 'text' } },
{ name: 'birthDate', operators: 'all', label: 'Birth date', input: { type: 'text' } },
];
const styles = {
primaryBtn: 'customPrimaryBtn',
deleteBtn: 'customDeleteBtn',
rule: 'rule',
condition: 'condition',
select: 'querySelect',
input: 'queryInput',
txtArea: 'queryText',
};
const changedStyles = {
styles,
};
class App extends Component {
handleChange(event) {
console.log('query', event.query);
}
render() {
return (
<TwoWayQuerybuilder config={changedStyles} fields={fields} onChange={this.handleChange} />
);
}
}
export default App;
validation
import React, { Component } from 'react';
import TwoWayQuerybuilder from 'react-two-way-querybuilder';;
const validationFields = [
{ name: 'firstName', operators: 'all', label: 'First Name', input: {
type: 'text', errorText: 'Only letters allowed', pattern: new RegExp("[a-z]+", "gi") } },
{ name: 'lastName', operators: 'all', label: 'Last Name', input: {
type: 'text', errorText: 'Only letters allowed', pattern: new RegExp("[a-z]+", "gi") } },
{ name: 'age', operators: 'all', label: 'Age', input: {
type: 'text', errorText: 'Only nubmers allowed', pattern: new RegExp('[0-9]+', 'gi') } },
{ name: 'birthDate', operators: 'all', label: 'Birth date', input: {
type: 'text', errorText: 'Only nubmers allowed', pattern: new RegExp('[0-9]+', 'gi') }
},
];
class App extends Component {
handleChange(event) {
console.log('query', event.query);
}
render() {
return (
<TwoWayQuerybuilder fields={validationFields} onChange={this.handleChange} />
);
}
}
export default App;
##License
React-two-way-quierybuidler is MIT licensed
FAQs
React Two Way Querybuilder Component
We found that @pirireis/react-two-way-querybuilder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.