{"id":23462509,"url":"https://github.com/vojtechportes/react-query-builder","last_synced_at":"2025-04-14T06:55:03.912Z","repository":{"id":35064696,"uuid":"201463023","full_name":"vojtechportes/react-query-builder","owner":"vojtechportes","description":"Simple, configurable react query builder","archived":false,"fork":false,"pushed_at":"2023-01-07T08:43:27.000Z","size":2018,"stargazers_count":56,"open_issues_count":36,"forks_count":20,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T01:04:24.171Z","etag":null,"topics":["query","query-builder","query-tree","querybuilder","react","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vojtechportes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-09T12:26:37.000Z","updated_at":"2024-04-26T17:45:13.000Z","dependencies_parsed_at":"2023-01-15T13:15:33.114Z","dependency_job_id":null,"html_url":"https://github.com/vojtechportes/react-query-builder","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vojtechportes%2Freact-query-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vojtechportes%2Freact-query-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vojtechportes%2Freact-query-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vojtechportes%2Freact-query-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vojtechportes","download_url":"https://codeload.github.com/vojtechportes/react-query-builder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248837281,"owners_count":21169374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["query","query-builder","query-tree","querybuilder","react","typescript"],"created_at":"2024-12-24T08:17:27.110Z","updated_at":"2025-04-14T06:55:03.888Z","avatar_url":"https://github.com/vojtechportes.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1\u003e:information_source: RFC 1.x.x\u003c/h1\u003e\n\u003cp\u003ePlease note that right now I am planning to start working on version 1.x.x. It will involve lot of refactoring, new features and some breaking changes. I will try to introduce ways how to keep things backwards compatible though.\u003c/p\u003e\n\u003cp\u003eIf you are interested, check https://github.com/vojtechportes/react-query-builder/issues/37 for RFC and let me know what you think and what new features you would welcome.\u003c/p\u003e\n\u003chr /\u003e\n\n\u003ch1 align=\"center\"\u003e\n  \u003cimg src=\"https://i.imgur.com/VXiYZ8g.png\" alt=\"React Query Builder\" /\u003e\n\u003c/h1\u003e\n\n\u003ch3 align=\"center\"\u003e\n  Simple, highly configurable query builder\u003cbr /\u003e for React written in TypeSript\n\n\n\u003c/h3\u003e\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://www.npmjs.com/package/@vojtechportes/react-query-builder\" target=\"_blank\"\u003e\u003cimg src=\"https://badge.fury.io/js/%40vojtechportes%2Freact-query-builder.svg\" alt=\"npm version\" /\u003e\u003c/a\u003e \u003ca href=\"https://opensource.org/licenses/MIT\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-MIT-yellow.svg\" alt=\"License: MIT\" /\u003e\u003c/a\u003e \u003ca href=\"https://travis-ci.org/vojtechportes/react-query-builder\" target=\"_blank\"\u003e\u003cimg src=\"https://travis-ci.org/vojtechportes/react-query-builder.svg?branch=master\" alt=\"Travis CI Status\" /\u003e\u003c/a\u003e \n\u003ca href=\"https://coveralls.io/github/vojtechportes/react-query-builder?branch=master\" target=\"_blank\"\u003e\u003cimg src=\"https://coveralls.io/repos/github/vojtechportes/react-query-builder/badge.svg?branch=master\" alt=\"Coverage Status\" /\u003e\u003c/a\u003e \u003ca href=\"https://deepscan.io/dashboard#view=project\u0026tid=5247\u0026pid=7017\u0026bid=64425\" target=\"_blank\"\u003e\u003cimg src=\"https://deepscan.io/api/teams/5247/projects/7017/branches/64425/badge/grade.svg\" alt=\"DeepScan grade\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cbr /\u003e\n\n---\n\n- [Installation](#installation)\n- [Demo](#demo)\n- [Usage](#usage)\n- [Configuration](#configuration)\n  - [Fields](#lets-start-with-fields)\n    - [Field](#field)\n    - [Label](#label)\n    - [Type](#type)\n    - [Operators](#operators)\n    - [Value](#value)\n  - [Data](#data)\n  - [Components](#components)\n  - [onChange](#onchange)\n- [Localization](#Localization)\n- [Future development](#future-development)\n\n---\n\n## Installation\n\n```bash\nnpm install @vojtechportes/react-query-builder\n```\n\nor\n\n```bash\nyarn add @vojtechportes/react-query-builder\n```\n\n## [Demo](https://react-query-builder-demo.herokuapp.com/)\n\nwith examples of field definition and custom components...\u003cbr /\u003e\n...or check source code on [GitHub](https://github.com/vojtechportes/react-query-builder-demo)\n\n\u003cimg src=\"https://i.imgur.com/N3smtv6.png\" alt=\"React Query Builder\" /\u003e\n\n---\n\n## Usage\n\n```typescript\nimport React from 'react';\nimport {\n  Builder,\n  BuilderFieldProps,\n  BuilderComponentsProps,\n} from 'react-query-builder';\n\nconst fields: BuilderFieldProps[] = [\n  // Fields configuration\n];\n\nconst data: any = [\n  // Initial query tree\n];\n\nconst components: BuilderComponentsProps = {\n  // Custom components configuration\n};\n\nconst MyBuilder: React.FC = () =\u003e (\n  \u003cBuilder\n    readOnly={false}\n    fields={fields}\n    data={data}\n    components={components}\n    onChange={data =\u003e console.log(data)}\n  /\u003e\n);\n```\n\n---\n\n## Configuration\n\nSince React Query Builder is highly configurable, you can define look of the Query Builder, you can define and use your own components, set whether the Builder should be readOnly or not and of course, you will need to set up fields Query Builder will be using.\n\n### Lets start with fields...\n\n```typescript\nimport { BuilderFieldProps } from 'react-query-builder';\n\nconst fields: BuilderFieldProps[] = [\n    {\n        field: 'STATE',\n        label: 'State',\n        type: 'LIST',\n        operators: ['EQUAL', 'NOT_EQUAL'],\n        value: [\n            { value: 'CZ', label: 'Czech Republic' },\n            { value: 'SK', label: 'Slovakia' },\n            { value: 'PL', label: 'Poland' },\n        ],\n    },\n    {\n        field: 'IS_IN_EU',\n        label: 'Is in EU',\n        type: 'BOOLEAN'\n    }\n];\n```\n\nAs you can see, there are few things you can define. `field`, `label`, `type`, `operators` and `value`.\n\n#### Field\n\nField is a key and needs to be unique, since it is used to reference field in query tree as you will see further down in documentation.\n\n#### Label\n\nLabel is pretty obvious, so lets skip to type.\n\n#### Type\n\nType can be any of following constants:\n\n```\nBOOLEAN\nTEXT\nDATE\nNUMBER\nSTATEMENT\nLIST\nMULTI_LIST\nGROUP (*)\n```\n\n\\* GROUP type is not intended to be used in field props definition but only in data object.\n\n#### Operators\n\nOperator can be array of following constants\n\n```\nLARGER\nSMALLER\nLARGER_EQUAL\nSMALLER_EQUAL\nEQUAL\nNOT_EQUAL\nALL_IN\nANY_IN\nNOT_IN\nBETWEEN\nNOT_BETWEEN\nLIKE\nNOT_LIKE\n```\n\n#### Value\n\nValue can be either string (STATEMENT) or array of objects with value and label keys (LIST, MULTI_LIST). Values for other types are empty by default.\n\n### Data\n\nData can be either empty array or array of rules and groups.\n\n```Typescript\n[\n    {\n        \"type\": \"GROUP\",\n        \"value\": \"AND\",\n        \"isNegated\": false,\n        \"children\": [\n            {\n                \"field\": \"IS_IN_EU\", // \u003c- Type here is refering to field property in fields configuration\n                \"value\": false\n            }\n        ]\n    }\n]\n```\n\n### Components\n\nComponents is set of components you can use to customize React Query Builder. You can either just style them using [styled-components](https://www.styled-components.com/ 'styled-components') or use your own components as long as they follow typings of original components.\n\nYou can customize following componetns\n\n```\nSelect\nSelectMulti\nSwitch\nInput\nRemove\nAdd\nComponent\nGroup\nGroupHeaderOption\n```\n\nvia config object\n\n```typescript\nconst components: BuilderComponentsProps = {\n  form: {\n    Select: MyCustomSelect,\n    SelectMulti: MyCustomSelectMulti,\n    Switch: MyCustomSwitch,\n    Input: MyCustomInput,\n  },\n  Remove: MyCustomRemove,\n  Add: MyCustomAdd,\n  Component: MyCustomComponent,\n  Group: MyCustomGroup,\n  GroupHeaderOption: MyCustomHeaderOption,\n};\n```\n\n### onChange\n\nonChange property is allowing you to retrieve query tree after every change that occures in React Query Builder.\n\n---\n\n## Localization\n\nTo either use custom strings or localize ReactBuilder, you can use strings property on Builder component.\n\nYou can work with object of following format:\n\n```typescript\nconst strings: Strings = {\n  \"group\": {\n    \"not\": \"Not\",\n    \"or\": \"Or\",\n    \"and\": \"And\",\n    \"addRule\": \"Add Rule\",\n    \"addGroup\": \"Add Group\",\n    \"delete\": \"Delete\"\n  },\n  \"components\": {\n    \"delete\": \"Delete\"\n  },\n  \"form\": {\n    \"selectYourValue\": \"Select your value\"\n  },\n  \"operators\": {\n    \"LARGER\": \"Larger\",\n    \"SMALLER\": \"Smaller\",\n    \"LARGER_EQUAL\": \"Larger or equal\",\n    \"SMALLER_EQUAL\": \"Smaller or equal\",\n    \"EQUAL\": \"Equal\",\n    \"NOT_EQUAL\": \"Not equal\",\n    \"ALL_IN\": \"All in\",\n    \"ANY_IN\": \"Any in\",\n    \"NOT_IN\": \"Not in\",\n    \"BETWEEN\": \"Between\",\n    \"NOT_BETWEEN\": \"Not between\"\n  }\n};\n```\n\nIt is not required to translate all the strings. Strings that are not specified by you will be loaded from default strings.\n\nTo work with multiple locales, you can use for example amazing [i18next framework](https://www.i18next.com/ 'i18next framework').\n\n```typescript\nimport React from 'react';\nimport { Builder, Strings } from '@vojtechportes/react-query-builder';\nimport { Trans, useTranslation } from 'react-i18next';\n\nexport const QueryBuiler:React.FC = () =\u003e {\n  useTranslation('query-builder')\n\n  const strings: Strings = {\n    operators: {\n      LARGER: \u003cTrans ns=\"query-builder\" i18nKey=\"larger\" /\u003e,\n      SMALLER: \u003cTrans ns=\"query-builder\" i18nKey=\"smaller\" /\u003e\n      /* And so on */\n    }\n  };\n\n  return (\n    \u003cBuilder\n      strings={strings}\n      fields={fields}\n      data={[]}\n      onChange={(data: any) =\u003e console.log(data)} \n      /\u003e\n  );\n};\n```\n\n#Feature development\n\nPlease check https://github.com/vojtechportes/react-query-builder/issues/37\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvojtechportes%2Freact-query-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvojtechportes%2Freact-query-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvojtechportes%2Freact-query-builder/lists"}