-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
49 lines (44 loc) · 1.22 KB
/
App.tsx
File metadata and controls
49 lines (44 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { ChakraProvider, extendTheme } from '@chakra-ui/react';
// @ts-ignore
import { QueryBuilderChakra } from '@react-querybuilder/chakra2';
import { useState } from 'react';
import type { Field, RuleGroupType } from 'react-querybuilder';
import { QueryBuilder, formatQuery } from 'react-querybuilder';
import './styles.scss';
const chakraTheme = extendTheme({
config: {
initialColorMode: 'light',
useSystemColorMode: false,
},
});
const fields: Field[] = [
{ name: 'firstName', label: 'First Name' },
{ name: 'lastName', label: 'Last Name' },
];
const initialQuery: RuleGroupType = {
combinator: 'and',
rules: [
{ field: 'firstName', operator: 'beginsWith', value: 'Stev' },
{ field: 'lastName', operator: 'in', value: 'Vai,Vaughan' },
],
};
export const App = () => {
const [query, setQuery] = useState(initialQuery);
return (
<div>
<ChakraProvider theme={chakraTheme}>
<QueryBuilderChakra>
<QueryBuilder
fields={fields}
query={query}
onQueryChange={setQuery}
/>
</QueryBuilderChakra>
</ChakraProvider>
<h4>Query</h4>
<pre>
<code>{formatQuery(query, 'json')}</code>
</pre>
</div>
);
};