@react-querybuilder/antd 7.8.0-alpha.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  ## @react-querybuilder/antd
2
2
 
3
- Official [react-querybuilder](https://npmjs.com/package/react-querybuilder) components for [Ant Design](https://ant.design/).
3
+ Official [react-querybuilder](https://npmjs.com/package/react-querybuilder) compatibility package for [Ant Design](https://ant.design/).
4
4
 
5
- To see them in action, check out the [`react-querybuilder` demo](https://react-querybuilder.js.org/demo/antd) or [load the example in CodeSandbox](https://githubbox.com/react-querybuilder/react-querybuilder/tree/main/examples/antd).
5
+ - [Demo](https://react-querybuilder.js.org/demo/antd)
6
+ - [Full documentation](https://react-querybuilder.js.org/)
7
+ - [CodeSandbox](https://react-querybuilder.js.org/sandbox?t=antd) / [StackBlitz](https://react-querybuilder.js.org/sandbox?p=stackblitz&t=antd) example projects
6
8
 
7
- **[Full documentation](https://react-querybuilder.js.org/)**
9
+ ![Screenshot](../../_assets/screenshot-antd.png)
8
10
 
9
11
  ## Installation
10
12
 
@@ -15,36 +17,56 @@ npm i react-querybuilder @react-querybuilder/antd @ant-design/icons antd
15
17
 
16
18
  ## Usage
17
19
 
18
- To render Ant Design-compatible components in the query builder, wrap the `<QueryBuilder />` element in `<QueryBuilderAntD />`.
20
+ To configure the query builder to use Ant Design-compatible components, place `QueryBuilderAntD` above `QueryBuilder` in the component hierarchy.
19
21
 
20
22
  ```tsx
21
23
  import { QueryBuilderAntD } from '@react-querybuilder/antd';
22
- import { QueryBuilder, RuleGroupType } from 'react-querybuilder';
24
+ import { useState } from 'react';
25
+ import { type Field, QueryBuilder, type RuleGroupType } from 'react-querybuilder';
23
26
 
24
- const fields = [
27
+ const fields: Field[] = [
25
28
  { name: 'firstName', label: 'First Name' },
26
29
  { name: 'lastName', label: 'Last Name' },
27
30
  ];
28
31
 
29
- const App = () => {
32
+ export function App() {
30
33
  const [query, setQuery] = useState<RuleGroupType>({ combinator: 'and', rules: [] });
31
34
 
32
35
  return (
33
36
  <QueryBuilderAntD>
34
- <QueryBuilder fields={fields} query={query} onQueryChange={setQuery} />
37
+ <QueryBuilder fields={fields} defaultQuery={query} onQueryChange={setQuery} />
35
38
  </QueryBuilderAntD>
36
39
  );
37
- };
40
+ }
38
41
  ```
39
42
 
40
- ## Notes
43
+ > [!NOTE]
44
+ >
45
+ > You may also want to reduce the width of the value editor component (which is 100% by default) with the following CSS rule.
46
+ >
47
+ > ```css
48
+ > .queryBuilder .ant-input {
49
+ > width: auto;
50
+ > }
51
+ > ```
41
52
 
42
- - You may also want to reduce the width of the value editor component (100% by default) with the following CSS rule:
53
+ `QueryBuilderAntD` is a React context provider that assigns the following props to all descendant `QueryBuilder` elements. The props can be overridden on the `QueryBuilder` or used directly without the context provider.
43
54
 
44
- ```css
45
- .queryBuilder .ant-input {
46
- width: auto;
47
- }
48
- ```
55
+ | Export | `QueryBuilder` prop |
56
+ | --------------------- | ------------------------------- |
57
+ | `antdControlElements` | `controlElements` |
58
+ | `antdTranslations` | `translations` |
59
+ | `AntDActionElement` | `controlElements.actionElement` |
60
+ | `AntDDragHandle` | `controlElements.dragHandle` |
61
+ | `AntDNotToggle` | `controlElements.notToggle` |
62
+ | `AntDShiftActions` | `controlElements.shiftActions` |
63
+ | `AntDValueEditor` | `controlElements.valueEditor` |
64
+ | `AntDValueSelector` | `controlElements.valueSelector` |
49
65
 
50
- - This package exports `antdControlElements` which can be assigned directly to the `controlElements` prop on `<QueryBuilder />` (and also exports each component individually), but wrapping `<QueryBuilder />` in `<QueryBuilderAntD />` is the recommended method.
66
+ > [!TIP]
67
+ >
68
+ > By default, this package uses icons from `@ant-design/icons` for button labels. To reset button labels to their default strings, use `defaultTranslations` from `react-querybuilder`.
69
+ >
70
+ > ```tsx
71
+ > <QueryBuilderAntD translations={defaultTranslations}>
72
+ > ```