Skip to content

Commit 0a20031

Browse files
authored
Merge pull request #15 from react-querybuilder/versioned-docs
Versioned docs
2 parents e1876b5 + 3d88814 commit 0a20031

35 files changed

+16367
-8105
lines changed

.github/workflows/gh-pages.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
node-version: '16.x'
1818
- name: Test Build
1919
run: |
20-
yarn install --frozen-lockfile
20+
yarn install --immutable
2121
npm run build
2222
gh-release:
2323
if: github.event_name != 'pull_request'
@@ -37,5 +37,5 @@ jobs:
3737
run: |
3838
git config --global user.email "jakeboone02@gmail.com"
3939
git config --global user.name "Jake Boone"
40-
yarn install --frozen-lockfile
40+
yarn install --immutable
4141
npm run deploy

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@
1818
npm-debug.log*
1919
yarn-debug.log*
2020
yarn-error.log*
21+
22+
.pnp.*
23+
.yarn/*
24+
!.yarn/patches
25+
!.yarn/plugins
26+
!.yarn/releases
27+
!.yarn/sdks
28+
!.yarn/versions

.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

Lines changed: 541 additions & 0 deletions
Large diffs are not rendered by default.

.yarn/plugins/@yarnpkg/plugin-typescript.cjs

Lines changed: 9 additions & 0 deletions
Large diffs are not rendered by default.

.yarn/releases/yarn-3.2.3.cjs

Lines changed: 783 additions & 0 deletions
Large diffs are not rendered by default.

.yarnrc.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
nodeLinker: node-modules
2+
3+
plugins:
4+
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
5+
spec: "@yarnpkg/plugin-typescript"
6+
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
7+
spec: "@yarnpkg/plugin-interactive-tools"
8+
9+
yarnPath: .yarn/releases/yarn-3.2.3.cjs

docs/api/misc.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import TypeScriptAdmonition from './_ts_admonition.md';
88

99
<TypeScriptAdmonition />
1010

11+
A non-comprehensive list of exports from `react-querybuilder`.
12+
1113
## Utilities
1214

1315
### `defaultValidator`
@@ -40,7 +42,7 @@ function convertQuery(query: RuleGroupTypeIC): RuleGroupType;
4042

4143
`convertQuery` toggles a query between the conventional `RuleGroupType` structure (with combinators at the group level) and the "independent combinators" structure (`RuleGroupTypeIC`, used with the [`independentCombinators` prop](./querybuilder#independentcombinators)).
4244

43-
`convertToIC` and `convertFromIC` do the same thing as `convertQuery`, but only in one direction.
45+
`convertToIC` and `convertFromIC` do the same thing as `convertQuery`, but only in the directions indicated by their respective names.
4446

4547
### `transformQuery`
4648

@@ -85,6 +87,7 @@ The default components are also exported:
8587

8688
- `ActionElement` - used for action buttons (to add rules, remove groups, etc.)
8789
- `DragHandle` - used for the drag handle on rules and group headers
90+
- `InlineCombinator` - used when either `showCombinatorsBetweenRules` or `independentCombinators` are `true`
8891
- `NotToggle` - used for the "Invert this group" toggle switch
8992
- `Rule` - the default rule component
9093
- `RuleGroup` - the default rule group component

docs/api/querybuilder.mdx

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,12 @@ The array of combinators that should be used for RuleGroups. The default set inc
171171

172172
```ts
173173
interface Controls {
174-
addGroupAction?: React.ComponentType<ActionWithRulesProps>;
175-
addRuleAction?: React.ComponentType<ActionWithRulesProps>;
174+
addGroupAction?: React.ComponentType<ActionWithRulesAndAddersProps>;
175+
addRuleAction?: React.ComponentType<ActionWithRulesAndAddersProps>;
176176
cloneGroupAction?: React.ComponentType<ActionWithRulesProps>;
177177
cloneRuleAction?: React.ComponentType<ActionProps>;
178178
combinatorSelector?: React.ComponentType<CombinatorSelectorProps>;
179+
inlineCombinator: ComponentType<InlineCombinatorProps>;
179180
dragHandle?: React.ForwardRefExoticComponent<
180181
DragHandleProps & React.RefAttributes<HTMLSpanElement>
181182
>;
@@ -198,11 +199,11 @@ This is a custom controls object that allows you to override the default control
198199
By default a `<button />` is used. The following props are passed:
199200

200201
```ts
201-
interface ActionWithRulesProps {
202+
interface ActionWithRulesAndAddersProps {
202203
label: string; // translations.addGroup.label, e.g. "+Group"
203204
title: string; // translations.addGroup.title, e.g. "Add group"
204205
className: string; // CSS classNames to be applied
205-
handleOnClick: (e: React.MouseEvent) => void; // Callback function to invoke adding a <RuleGroup />
206+
handleOnClick: (e: React.MouseEvent, context?: any) => void; // Callback function to invoke adding a <RuleGroup />
206207
rules: (RuleGroupType | RuleType)[]; // Provides the number of rules already present for this group
207208
level: number; // The level of the current group
208209
context: any; // Container for custom props that are passed to all components
@@ -266,11 +267,11 @@ interface ActionWithRulesProps {
266267
By default a `<button />` is used. The following props are passed:
267268

268269
```ts
269-
interface ActionWithRulesProps {
270+
interface ActionWithRulesAndAddersProps {
270271
label: string; // translations.addGroup.label, e.g. "+Rule"
271272
title: string; // translations.addGroup.title, e.g. "Add rule"
272273
className: string; // CSS classNames to be applied
273-
handleOnClick: (e: React.MouseEvent) => void; // Callback function to invoke adding a <RuleGroup />
274+
handleOnClick: (e: React.MouseEvent, context?: any) => void; // Callback function to invoke adding a <RuleGroup />
274275
rules: (RuleGroupType | RuleType)[]; // Provides the number of rules already present for this group
275276
level: number; // The level of the current group
276277
context: any; // Container for custom props that are passed to all components
@@ -343,6 +344,19 @@ interface CombinatorSelectorProps {
343344
}
344345
```
345346

347+
#### `inlineCombinator`
348+
349+
A small wrapper around the `combinatorSelector` component. The following props are passed:
350+
351+
```ts
352+
interface InlineCombinatorProps extends CombinatorSelectorProps {
353+
component: Schema['controls']['combinatorSelector'];
354+
path: number[];
355+
moveRule: QueryActions['moveRule'];
356+
independentCombinators?: boolean;
357+
}
358+
```
359+
346360
#### `dragHandle`
347361

348362
By default a `<span />` is used. Note that this component must be based on `React.forwardRef`, and must always render an element (i.e. never return `null`). The following props are passed:
@@ -536,9 +550,9 @@ This function returns the default value for new rules.
536550

537551
### `onAddRule`
538552

539-
`(rule: RuleType, parentPath: number[], query: RuleGroupTypeAny) => RuleType | false`
553+
`(rule: RuleType, parentPath: number[], query: RuleGroupTypeAny, context?: any) => RuleType | false`
540554

541-
This callback is invoked before a new rule is added. The function should either manipulate the rule and return it as an object of type `RuleType`, or return `false` to cancel the addition of the rule. You can use [`findPath`](./misc#findpath) to locate the parent group to which the new rule will be added within the query hierarchy.
555+
This callback is invoked before a new rule is added. The function should either manipulate the rule and return it as an object of type `RuleType`, or return `false` to cancel the addition of the rule. You can use [`findPath`](./misc#findpath) to locate the parent group to which the new rule will be added within the query hierarchy. The `context` parameter (fourth argument) can be passed from a custom [`addRuleAction`](#addruleaction) component to its `onHandleClick` callback prop, which will in turn pass it to `onAddRule`. This allows one to change the rule that gets added (or avoid the action completely) based on arbitrary information.
542556

543557
:::tip
544558

@@ -548,9 +562,9 @@ To completely [prevent the addition of new rules](../tips/limit-groups), pass `c
548562

549563
### `onAddGroup`
550564

551-
`<RG extends RuleGroupTypeAny>(ruleGroup: RG, parentPath: number[], query: RG) => RG | false`
565+
`<RG extends RuleGroupTypeAny>(ruleGroup: RG, parentPath: number[], query: RG, context?: any) => RG | false`
552566

553-
This callback is invoked before a new group is added. The function should either manipulate the group and return it as an object of the same type (either `RuleGroupType` or `RuleGroupTypeIC`), or return `false` to cancel the addition of the group. You can use [`findPath`](./misc#findpath) to locate the parent group to which the new group will be added within the query hierarchy.
567+
This callback is invoked before a new group is added. The function should either manipulate the group and return it as an object of the same type (either `RuleGroupType` or `RuleGroupTypeIC`), or return `false` to cancel the addition of the group. You can use [`findPath`](./misc#findpath) to locate the parent group to which the new group will be added within the query hierarchy. The `context` parameter (fourth argument) can be passed from a custom [`addGroupAction`](#addgroupaction) component to its `onHandleClick` callback prop, which will in turn pass it to `onAddGroup`. This allows one to change the group that gets added (or avoid the action completely) based on arbitrary information.
554568

555569
:::tip
556570

@@ -766,11 +780,39 @@ When the `independentCombinators` option is enabled, the `query` (or `defaultQue
766780

767781
`boolean` (default `false`) [_Click for demo_](https://react-querybuilder.js.org/react-querybuilder/#enableDragAndDrop=true)
768782

769-
Pass `true` to display a drag handle to the left of each group header and rule. Clicking and dragging the handle element allows visual reordering of rules and groups.
770-
771783
:::caution
772784

773-
`react-querybuilder` uses [`react-dnd`](https://react-dnd.github.io/react-dnd/) to enable drag-and-drop features. If your application already uses `react-dnd`, you should import and render `<QueryBuilderWithoutDndProvider />` instead of `<QueryBuilder />`. They are functionally the same, but the former will rely on your pre-existing `DndProvider` wrapper while the latter implements its own and will clash with a separate `DndProvider` higher up in the component tree (the error will typically look like this: "Cannot have two HTML5 backends at the same time.").
785+
This prop does not need to be set directly. If used directly, it has no effect unless the following conditions are met:
786+
787+
1. A `QueryBuilderDnD` context provider from the companion package [`@react-querybuilder/dnd`](https://www.npmjs.com/package/@react-querybuilder/dnd) is rendered higher up in the component tree.
788+
2. [`react-dnd`](https://www.npmjs.com/package/react-dnd) and [`react-dnd-html5-backend`](https://www.npmjs.com/package/react-dnd-html5-backend) are also installed.
789+
790+
If those conditions are met, and `enableDragAndDrop` is not explicitly set to `false` on the `<QueryBuilder />` element, then `enableDragAndDrop` is implicitly set to `true`.
791+
792+
:::
793+
794+
When `true` (under the conditions detailed above), a drag handle is displayed on the left-hand side of each group header and each rule. Clicking and dragging the handle element allows users to visually reorder the rules and groups.
795+
796+
#### Example usage
797+
798+
```bash
799+
yarn add react-querybuilder @react-querybuilder/dnd react-dnd react-dnd-html5-backend
800+
```
801+
802+
```tsx
803+
import { QueryBuilderDnD } from '@react-querybuilder/dnd';
804+
import { QueryBuilder } from 'react-querybuilder';
805+
806+
const App = () => (
807+
<QueryBuilderDnD>
808+
<QueryBuilder />
809+
</QueryBuilderDnD>
810+
);
811+
```
812+
813+
:::tip
814+
815+
If your application already uses [`react-dnd`](https://react-dnd.github.io/react-dnd/), use `QueryBuilderWithoutDndProvider` instead of `QueryBuilderDnD`. They are functionally equivalent, but the former relies on your pre-existing `<DndProvider />` (as long as it is higher up in the component tree). The latter renders its own provider which will clash with an ancestor `DndProvider`. (If you use the wrong component, you will probably see the error message "Cannot have two HTML5 backends at the same time.")
774816

775817
:::
776818

0 commit comments

Comments
 (0)