@react-querybuilder/bootstrap 4.0.0-beta.6 → 4.1.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 +75 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +37 -23
- package/dist/types/BootstrapDragHandle.d.ts +2 -2
- package/dist/types/BootstrapNotToggle.d.ts +2 -3
- package/dist/types/BootstrapValueEditor.d.ts +2 -3
- package/dist/types/index.d.ts +2 -2
- package/dist/types/utils.d.ts +4 -0
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -1,3 +1,77 @@
|
|
|
1
1
|
## @react-querybuilder/bootstrap
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official [Bootstrap](https://getbootstrap.com/) components for [react-querybuilder](https://npmjs.com/package/react-querybuilder).
|
|
4
|
+
|
|
5
|
+
To see them in action, check out the [`react-querybuilder` demo](https://react-querybuilder.js.org/react-querybuilder/) and choose "Bootstrap" from the Style drop-down.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i --save react-querybuilder @react-querybuilder/bootstrap bootstrap bootstrap-icons
|
|
11
|
+
# OR
|
|
12
|
+
yarn add react-querybuilder @react-querybuilder/bootstrap bootstrap bootstrap-icons
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import QueryBuilder, { RuleGroupType } from 'react-querybuilder';
|
|
19
|
+
import {
|
|
20
|
+
BootstrapDragHandle,
|
|
21
|
+
BootstrapNotToggle,
|
|
22
|
+
BootstrapValueEditor
|
|
23
|
+
} from '@react-querybuilder/bootstrap';
|
|
24
|
+
|
|
25
|
+
const fields = [
|
|
26
|
+
{ name: 'firstName', label: 'First Name' },
|
|
27
|
+
{ name: 'lastName', label: 'Last Name' }
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
const App = () => {
|
|
31
|
+
const [query, setQuery] = useState<RuleGroupType>({ combinator: 'and', rules: [] });
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<QueryBuilder
|
|
35
|
+
fields={fields}
|
|
36
|
+
query={query}
|
|
37
|
+
onQueryChange={(q) => setQuery(q)}
|
|
38
|
+
controlClassnames={{
|
|
39
|
+
addGroup: 'btn btn-secondary btn-sm',
|
|
40
|
+
addRule: 'btn btn-primary btn-sm',
|
|
41
|
+
cloneGroup: 'btn btn-secondary btn-sm',
|
|
42
|
+
cloneRule: 'btn btn-secondary btn-sm',
|
|
43
|
+
removeGroup: 'btn btn-danger btn-sm',
|
|
44
|
+
removeRule: 'btn btn-danger btn-sm',
|
|
45
|
+
combinators: 'form-select form-select-sm',
|
|
46
|
+
fields: 'form-select form-select-sm',
|
|
47
|
+
operators: 'form-select form-select-sm',
|
|
48
|
+
value: 'form-control form-control-sm'
|
|
49
|
+
}}
|
|
50
|
+
controlElements={{
|
|
51
|
+
dragHandle: BootstrapDragHandle,
|
|
52
|
+
notToggle: BootstrapNotToggle,
|
|
53
|
+
valueEditor: BootstrapValueEditor
|
|
54
|
+
}}
|
|
55
|
+
/>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
To apply the Bootstrap styles, you can add the following SCSS to your app:
|
|
61
|
+
|
|
62
|
+
```scss
|
|
63
|
+
@import 'bootstrap/scss/functions';
|
|
64
|
+
@import 'bootstrap/scss/variables';
|
|
65
|
+
@import 'bootstrap/scss/mixins';
|
|
66
|
+
@import 'bootstrap/scss/reboot';
|
|
67
|
+
@import 'bootstrap/scss/type';
|
|
68
|
+
@import 'bootstrap/scss/forms';
|
|
69
|
+
@import 'bootstrap/scss/buttons';
|
|
70
|
+
@import 'bootstrap/scss/dropdown';
|
|
71
|
+
|
|
72
|
+
.form-control,
|
|
73
|
+
.form-select {
|
|
74
|
+
display: inline-block;
|
|
75
|
+
width: auto;
|
|
76
|
+
}
|
|
77
|
+
```
|
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";var i=require("react");function b(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var c=b(i);const p=i.forwardRef(({className:e,title:t},a)=>c.default.createElement("span",{ref:a,className:e,title:t},c.default.createElement("i",{className:"bi bi-grip-vertical"})));p.displayName="BootstrapDragHandle";const g=({className:e,handleOnChange:t,title:a,label:n,checked:r,disabled:o})=>{const u=i.useRef(`notToggle-${Math.random()}`);return c.default.createElement("div",{className:`form-check-inline form-switch ${e}`},c.default.createElement("input",{id:u.current,className:"form-check-input",type:"checkbox",onChange:s=>t(s.target.checked),checked:!!r,disabled:o}),c.default.createElement("label",{title:a,htmlFor:u.current,className:"form-check-label"},n))};g.displayName="BootstrapNotToggle";const N=e=>Array.isArray(e)&&e.length>0&&"options"in e[0],B=e=>N(e)?e.map(t=>c.default.createElement("optgroup",{key:t.label,label:t.label},t.options.map(a=>c.default.createElement("option",{key:a.name,value:a.name},a.label)))):Array.isArray(e)?e.map(t=>c.default.createElement("option",{key:t.name,value:t.name},t.label)):null,k=({fieldData:e,operator:t,value:a,handleOnChange:n,title:r,className:o,type:u,inputType:s,values:f,disabled:m})=>{var d;if(i.useEffect(()=>{s==="number"&&!["between","notBetween","in","notIn"].includes(t)&&typeof a=="string"&&a.includes(",")&&n("")},[s,t,a,n]),t==="null"||t==="notNull")return null;const y=(d=e==null?void 0:e.placeholder)!=null?d:"",h=["between","notBetween","in","notIn"].includes(t)?"text":s||"text";switch(u){case"select":return c.default.createElement("select",{className:`${o} form-select form-select-sm`,title:r,onChange:l=>n(l.target.value),value:a,disabled:m},B(f));case"checkbox":return c.default.createElement("input",{type:"checkbox",className:`form-check-input ${o}`,title:r,disabled:m,onChange:l=>n(l.target.checked),checked:!!a});case"radio":return c.default.createElement("span",{title:r},f.map(l=>c.default.createElement("div",{key:l.name,className:"form-check form-check-inline"},c.default.createElement("input",{className:"form-check-input",type:"radio",id:l.name,value:l.name,checked:a===l.name,disabled:m,onChange:E=>n(E.target.value)}),c.default.createElement("label",{className:"form-check-label",htmlFor:l.name},l.label))));default:return c.default.createElement("input",{type:h,value:a,title:r,className:o,disabled:m,placeholder:y,onChange:l=>n(l.target.value)})}};k.displayName="ValueEditor";exports.BootstrapDragHandle=p;exports.BootstrapNotToggle=g;exports.BootstrapValueEditor=k;
|
package/dist/index.es.js
CHANGED
|
@@ -1,36 +1,48 @@
|
|
|
1
|
-
import React, { forwardRef,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
});
|
|
1
|
+
import React, { forwardRef, useRef, useEffect } from "react";
|
|
2
|
+
const BootstrapDragHandle = forwardRef(({ className, title }, dragRef) => /* @__PURE__ */ React.createElement("span", {
|
|
3
|
+
ref: dragRef,
|
|
4
|
+
className,
|
|
5
|
+
title
|
|
6
|
+
}, /* @__PURE__ */ React.createElement("i", {
|
|
7
|
+
className: "bi bi-grip-vertical"
|
|
8
|
+
})));
|
|
9
|
+
BootstrapDragHandle.displayName = "BootstrapDragHandle";
|
|
11
10
|
const BootstrapNotToggle = ({
|
|
12
11
|
className,
|
|
13
12
|
handleOnChange,
|
|
14
13
|
title,
|
|
15
14
|
label,
|
|
16
|
-
checked
|
|
15
|
+
checked,
|
|
16
|
+
disabled
|
|
17
17
|
}) => {
|
|
18
|
-
const
|
|
18
|
+
const id = useRef(`notToggle-${Math.random()}`);
|
|
19
19
|
return /* @__PURE__ */ React.createElement("div", {
|
|
20
20
|
className: `form-check-inline form-switch ${className}`
|
|
21
21
|
}, /* @__PURE__ */ React.createElement("input", {
|
|
22
|
-
id,
|
|
22
|
+
id: id.current,
|
|
23
23
|
className: "form-check-input",
|
|
24
24
|
type: "checkbox",
|
|
25
25
|
onChange: (e) => handleOnChange(e.target.checked),
|
|
26
|
-
checked: !!checked
|
|
26
|
+
checked: !!checked,
|
|
27
|
+
disabled
|
|
27
28
|
}), /* @__PURE__ */ React.createElement("label", {
|
|
28
29
|
title,
|
|
29
|
-
htmlFor: id,
|
|
30
|
+
htmlFor: id.current,
|
|
30
31
|
className: "form-check-label"
|
|
31
32
|
}, label));
|
|
32
33
|
};
|
|
33
34
|
BootstrapNotToggle.displayName = "BootstrapNotToggle";
|
|
35
|
+
const isOptionGroupArray = (arr) => Array.isArray(arr) && arr.length > 0 && "options" in arr[0];
|
|
36
|
+
const toOptions = (arr) => isOptionGroupArray(arr) ? arr.map((og) => /* @__PURE__ */ React.createElement("optgroup", {
|
|
37
|
+
key: og.label,
|
|
38
|
+
label: og.label
|
|
39
|
+
}, og.options.map((opt) => /* @__PURE__ */ React.createElement("option", {
|
|
40
|
+
key: opt.name,
|
|
41
|
+
value: opt.name
|
|
42
|
+
}, opt.label)))) : Array.isArray(arr) ? arr.map((opt) => /* @__PURE__ */ React.createElement("option", {
|
|
43
|
+
key: opt.name,
|
|
44
|
+
value: opt.name
|
|
45
|
+
}, opt.label)) : null;
|
|
34
46
|
const BootstrapValueEditor = ({
|
|
35
47
|
fieldData,
|
|
36
48
|
operator,
|
|
@@ -40,11 +52,12 @@ const BootstrapValueEditor = ({
|
|
|
40
52
|
className,
|
|
41
53
|
type,
|
|
42
54
|
inputType,
|
|
43
|
-
values
|
|
55
|
+
values,
|
|
56
|
+
disabled
|
|
44
57
|
}) => {
|
|
45
58
|
var _a;
|
|
46
59
|
useEffect(() => {
|
|
47
|
-
if (inputType === "number" && !["between", "notBetween"].includes(operator) && typeof value === "string" && value.includes(",")) {
|
|
60
|
+
if (inputType === "number" && !["between", "notBetween", "in", "notIn"].includes(operator) && typeof value === "string" && value.includes(",")) {
|
|
48
61
|
handleOnChange("");
|
|
49
62
|
}
|
|
50
63
|
}, [inputType, operator, value, handleOnChange]);
|
|
@@ -52,23 +65,22 @@ const BootstrapValueEditor = ({
|
|
|
52
65
|
return null;
|
|
53
66
|
}
|
|
54
67
|
const placeHolderText = (_a = fieldData == null ? void 0 : fieldData.placeholder) != null ? _a : "";
|
|
55
|
-
const inputTypeCoerced = ["between", "notBetween"].includes(operator) ? "text" : inputType || "text";
|
|
68
|
+
const inputTypeCoerced = ["between", "notBetween", "in", "notIn"].includes(operator) ? "text" : inputType || "text";
|
|
56
69
|
switch (type) {
|
|
57
70
|
case "select":
|
|
58
71
|
return /* @__PURE__ */ React.createElement("select", {
|
|
59
72
|
className: `${className} form-select form-select-sm`,
|
|
60
73
|
title,
|
|
61
74
|
onChange: (e) => handleOnChange(e.target.value),
|
|
62
|
-
value
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
value: v.name
|
|
66
|
-
}, v.label)));
|
|
75
|
+
value,
|
|
76
|
+
disabled
|
|
77
|
+
}, toOptions(values));
|
|
67
78
|
case "checkbox":
|
|
68
79
|
return /* @__PURE__ */ React.createElement("input", {
|
|
69
80
|
type: "checkbox",
|
|
70
81
|
className: `form-check-input ${className}`,
|
|
71
82
|
title,
|
|
83
|
+
disabled,
|
|
72
84
|
onChange: (e) => handleOnChange(e.target.checked),
|
|
73
85
|
checked: !!value
|
|
74
86
|
});
|
|
@@ -84,6 +96,7 @@ const BootstrapValueEditor = ({
|
|
|
84
96
|
id: v.name,
|
|
85
97
|
value: v.name,
|
|
86
98
|
checked: value === v.name,
|
|
99
|
+
disabled,
|
|
87
100
|
onChange: (e) => handleOnChange(e.target.value)
|
|
88
101
|
}), /* @__PURE__ */ React.createElement("label", {
|
|
89
102
|
className: "form-check-label",
|
|
@@ -95,6 +108,7 @@ const BootstrapValueEditor = ({
|
|
|
95
108
|
value,
|
|
96
109
|
title,
|
|
97
110
|
className,
|
|
111
|
+
disabled,
|
|
98
112
|
placeholder: placeHolderText,
|
|
99
113
|
onChange: (e) => handleOnChange(e.target.value)
|
|
100
114
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { DragHandleProps } from 'react-querybuilder';
|
|
3
|
-
declare const
|
|
4
|
-
export default
|
|
3
|
+
declare const BootstrapDragHandle: import("react").ForwardRefExoticComponent<DragHandleProps & import("react").RefAttributes<HTMLSpanElement>>;
|
|
4
|
+
export default BootstrapDragHandle;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { NotToggleProps } from 'react-querybuilder';
|
|
3
|
-
declare const BootstrapNotToggle: {
|
|
4
|
-
({ className, handleOnChange, title, label, checked }: NotToggleProps): JSX.Element;
|
|
3
|
+
export declare const BootstrapNotToggle: {
|
|
4
|
+
({ className, handleOnChange, title, label, checked, disabled, }: NotToggleProps): JSX.Element;
|
|
5
5
|
displayName: string;
|
|
6
6
|
};
|
|
7
|
-
export default BootstrapNotToggle;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { ValueEditorProps } from 'react-querybuilder';
|
|
3
|
-
declare const BootstrapValueEditor: {
|
|
4
|
-
({ fieldData, operator, value, handleOnChange, title, className, type, inputType, values }: ValueEditorProps): JSX.Element | null;
|
|
3
|
+
export declare const BootstrapValueEditor: {
|
|
4
|
+
({ fieldData, operator, value, handleOnChange, title, className, type, inputType, values, disabled, }: ValueEditorProps): JSX.Element | null;
|
|
5
5
|
displayName: string;
|
|
6
6
|
};
|
|
7
|
-
export default BootstrapValueEditor;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { default as BootstrapDragHandle } from './BootstrapDragHandle';
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
2
|
+
export { BootstrapNotToggle } from './BootstrapNotToggle';
|
|
3
|
+
export { BootstrapValueEditor } from './BootstrapValueEditor';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { Field, NameLabelPair, OptionGroup } from 'react-querybuilder';
|
|
3
|
+
export declare const isOptionGroupArray: (arr: Field['values']) => arr is OptionGroup<NameLabelPair>[];
|
|
4
|
+
export declare const toOptions: (arr?: NameLabelPair[] | OptionGroup<NameLabelPair>[] | undefined) => JSX.Element[] | null;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-querybuilder/bootstrap",
|
|
3
3
|
"description": "Custom Bootstrap components for react-querybuilder",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.1.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -21,16 +21,18 @@
|
|
|
21
21
|
"build": "vite build && tsc --emitDeclarationOnly"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
+
"@react-querybuilder/compat": "^4.1.0",
|
|
24
25
|
"@types/react": "^17.0.0",
|
|
25
26
|
"bootstrap-icons": "^1.7.0",
|
|
26
27
|
"react": "^17.0.1",
|
|
27
|
-
"react-querybuilder": "^4.
|
|
28
|
+
"react-querybuilder": "^4.1.0",
|
|
28
29
|
"typescript": "^4.5.0"
|
|
29
30
|
},
|
|
30
31
|
"peerDependencies": {
|
|
32
|
+
"bootstrap": ">=5",
|
|
31
33
|
"bootstrap-icons": ">=1.7.0",
|
|
32
34
|
"react": ">=16.8.0",
|
|
33
|
-
"react-querybuilder": "4
|
|
35
|
+
"react-querybuilder": ">=4"
|
|
34
36
|
},
|
|
35
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "b73987bada7b64b5df892f92ceb8691a488d096c"
|
|
36
38
|
}
|