Skip to content

Commit e1e7492

Browse files
Vojtěch Václav Portešvojtechportes
authored andcommitted
feat: Added ANTD adapters
- Added adatper for ANTD v6 as subpackage - Added adapter for ANTD v5 as subpackage - Updated Documentation, API, and Demo on the library website - Updated README
1 parent 989267d commit e1e7492

36 files changed

Lines changed: 1981 additions & 54 deletions

README.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,20 @@ npm install @vojtechportes/react-query-builder
4040

4141
React Query Builder supports React `18+`.
4242

43-
## MUI Adapters
43+
## UI Adapters
4444

45-
The package also exposes Material UI component mappings through versioned
45+
The package also exposes ready-made component mappings through versioned
4646
subpath exports:
4747

48-
- `@vojtechportes/react-query-builder/mui/v9` for new projects
48+
- `@vojtechportes/react-query-builder/mui/v9` for new Material UI projects
4949
- `@vojtechportes/react-query-builder/mui/v7` for applications still on MUI 7
50+
- `@vojtechportes/react-query-builder/antd/v6` for new Ant Design projects
51+
- `@vojtechportes/react-query-builder/antd/v5` for applications still on Ant Design 5
5052

51-
Install the matching MUI peer dependencies in your app and pass the exported
52-
`components` object to `Builder`:
53+
Install the peer dependencies that match the adapter you want to use and pass
54+
the exported `components` object to `Builder`.
55+
56+
Material UI example:
5357

5458
```bash
5559
npm install @mui/material@^9.0.1 @mui/icons-material@^9.0.1 @emotion/react @emotion/styled
@@ -72,8 +76,32 @@ export const MyMuiBuilder = () => {
7276
};
7377
```
7478

79+
Ant Design example:
80+
81+
```bash
82+
npm install antd@^6.0.0 @ant-design/icons@^6.0.0
83+
```
84+
85+
```tsx
86+
import React from 'react';
87+
import { Builder } from '@vojtechportes/react-query-builder';
88+
import { components } from '@vojtechportes/react-query-builder/antd/v6';
89+
90+
export const MyAntdBuilder = () => {
91+
return (
92+
<Builder
93+
fields={fields}
94+
data={data}
95+
components={components}
96+
onChange={setData}
97+
/>
98+
);
99+
};
100+
```
101+
75102
`ThemeProvider` customizes the built-in default component set. It does not
76-
theme the Material UI adapters, which keep their styling in MUI.
103+
theme the MUI or ANTD adapters, which keep their styling in their host UI
104+
libraries.
77105

78106
More adapter details:
79107

example/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
"preview": "vite preview"
99
},
1010
"dependencies": {
11+
"@ant-design/icons": "^6.1.0",
1112
"@emotion/react": "^11.14.0",
1213
"@emotion/styled": "^11.14.1",
1314
"@mui/icons-material": "^9.0.1",
1415
"@mui/material": "^9.0.1",
16+
"antd": "^6.0.0",
1517
"minisearch": "^7.2.0",
1618
"prism-react-renderer": "^2.4.1",
1719
"react": "^18.3.1",

example/src/components/demo-playground.tsx

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Builder,
55
type DenormalizedQuery,
66
} from '@vojtechportes/react-query-builder';
7+
import { components as antdComponents } from '@vojtechportes/react-query-builder/antd/v6';
78
import { components as muiComponents } from '@vojtechportes/react-query-builder/mui/v9';
89
import type { IColors } from '../../../src/constants/colors';
910
import { ThemeProvider } from '../../../src/theme-provider/theme-provider';
@@ -120,7 +121,7 @@ export interface IDemoPlaygroundProps {
120121
initialData?: DenormalizedQuery;
121122
}
122123

123-
type CustomizationMode = 'default' | 'mui';
124+
type CustomizationMode = 'default' | 'mui' | 'antd';
124125

125126
export const DemoPlayground: React.FC<IDemoPlaygroundProps> = ({
126127
initialData = initialQueryTree,
@@ -140,6 +141,22 @@ export const DemoPlayground: React.FC<IDemoPlaygroundProps> = ({
140141
defaultTheme.colors
141142
);
142143
const isMuiMode = customizationMode === 'mui';
144+
const isAntdMode = customizationMode === 'antd';
145+
const usesAdapterMode = isMuiMode || isAntdMode;
146+
147+
const builderProps = {
148+
data,
149+
fields: demoFields,
150+
readOnly,
151+
lockable,
152+
cloneable,
153+
onChange: setData,
154+
draggable,
155+
history,
156+
groupTypes: 'both' as const,
157+
singleRootGroup,
158+
showValidation,
159+
};
143160

144161
const outputText = React.useMemo(() => {
145162
if (outputFormat === 'Native') {
@@ -242,17 +259,29 @@ export const DemoPlayground: React.FC<IDemoPlaygroundProps> = ({
242259
/>
243260
<span>MUI adapter</span>
244261
</ToggleRow>
262+
263+
<ToggleRow>
264+
<Toggle
265+
type="radio"
266+
name="customization-mode"
267+
checked={customizationMode === 'antd'}
268+
onChange={() => setCustomizationMode('antd')}
269+
/>
270+
<span>ANTD v6 adapter</span>
271+
</ToggleRow>
245272
</ChoiceGroup>
246273
</Panel>
247274

248275
<Panel>
249276
<ThemeEditor
250277
value={themeColors}
251278
onChange={setThemeColors}
252-
disabled={isMuiMode}
279+
disabled={usesAdapterMode}
253280
disabledMessage={
254-
isMuiMode
255-
? 'ThemeProvider colors style the default builder components only. The MUI adapter uses Material UI styling instead.'
281+
usesAdapterMode
282+
? isMuiMode
283+
? 'ThemeProvider colors style the default builder components only. The MUI adapter uses Material UI styling instead.'
284+
: 'ThemeProvider colors style the default builder components only. The ANTD v6 adapter uses Ant Design styling instead.'
256285
: undefined
257286
}
258287
/>
@@ -264,34 +293,17 @@ export const DemoPlayground: React.FC<IDemoPlaygroundProps> = ({
264293
<BuilderSurface>
265294
{isMuiMode ? (
266295
<Builder
267-
data={data}
268-
fields={demoFields}
269-
readOnly={readOnly}
270-
lockable={lockable}
271-
cloneable={cloneable}
272-
onChange={setData}
273-
draggable={draggable}
274-
history={history}
275-
groupTypes="both"
276-
singleRootGroup={singleRootGroup}
277-
showValidation={showValidation}
296+
{...builderProps}
278297
components={muiComponents}
279298
/>
299+
) : isAntdMode ? (
300+
<Builder
301+
{...builderProps}
302+
components={antdComponents}
303+
/>
280304
) : (
281305
<ThemeProvider colors={themeColors}>
282-
<Builder
283-
data={data}
284-
fields={demoFields}
285-
readOnly={readOnly}
286-
lockable={lockable}
287-
cloneable={cloneable}
288-
onChange={setData}
289-
draggable={draggable}
290-
history={history}
291-
groupTypes="both"
292-
singleRootGroup={singleRootGroup}
293-
showValidation={showValidation}
294-
/>
306+
<Builder {...builderProps} />
295307
</ThemeProvider>
296308
)}
297309
</BuilderSurface>

example/src/pages/api-page/pages/api-content.tsx

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,19 @@ const muiAdapterSnippet = `import { components } from '@vojtechportes/react-quer
122122
onChange={setData}
123123
/>;`;
124124

125+
const antdAdapterSnippet = `import { components } from '@vojtechportes/react-query-builder/antd/v6';
126+
127+
<Builder
128+
fields={fields}
129+
data={data}
130+
components={components}
131+
onChange={setData}
132+
/>;`;
133+
125134
const muiV7Snippet = `import { components } from '@vojtechportes/react-query-builder/mui/v7';`;
126135

136+
const antdV5Snippet = `import { components } from '@vojtechportes/react-query-builder/antd/v5';`;
137+
127138
const muiCreateComponentsSnippet = `import {
128139
Builder,
129140
type DenormalizedQuery,
@@ -153,6 +164,35 @@ export const MyMuiBuilder = () => {
153164
);
154165
};`;
155166

167+
const antdCreateComponentsSnippet = `import {
168+
Builder,
169+
type DenormalizedQuery,
170+
} from '@vojtechportes/react-query-builder';
171+
import {
172+
createAntdComponents,
173+
components as antdComponents,
174+
} from '@vojtechportes/react-query-builder/antd/v6';
175+
176+
const components = createAntdComponents(antdComponents, {
177+
form: {
178+
Input: MyInput,
179+
},
180+
Add: MyAddButton,
181+
});
182+
183+
export const MyAntdBuilder = () => {
184+
const [data, setData] = useState<DenormalizedQuery>(initialData);
185+
186+
return (
187+
<Builder
188+
fields={fields}
189+
data={data}
190+
components={components}
191+
onChange={setData}
192+
/>
193+
);
194+
};`;
195+
156196
const historyControlsSignature = `export interface IHistoryControlsProps {
157197
undoButton: React.ReactNode;
158198
redoButton: React.ReactNode;
@@ -519,32 +559,33 @@ export const apiPages: IApiPage[] = [
519559
description:
520560
'API reference for packaged UI adapter entrypoints such as Material UI v7 and v9 and how they map onto the components override surface.',
521561
searchText:
522-
'Adapters API mui material ui v7 v9 components object adapter entrypoints customization antd future',
562+
'Adapters API mui material ui v7 v9 antd ant design v5 v6 components object adapter entrypoints customization',
523563
content: (
524564
<>
525565
<CodeBlock code={muiAdapterSnippet} language="tsx" label="MUI v9 adapter usage" />
566+
<CodeBlock code={antdAdapterSnippet} language="tsx" label="ANTD v6 adapter usage" />
526567
<CodeBlock code={muiV7Snippet} language="tsx" label="MUI v7 import" />
527-
<CodeBlock
528-
code={muiCreateComponentsSnippet}
529-
language="tsx"
530-
label="createMuiComponents"
531-
/>
568+
<CodeBlock code={antdV5Snippet} language="tsx" label="ANTD v5 import" />
569+
<CodeBlock code={muiCreateComponentsSnippet} language="tsx" label="createMuiComponents" />
570+
<CodeBlock code={antdCreateComponentsSnippet} language="tsx" label="createAntdComponents" />
532571
<SectionTitle>Available adapter entrypoints</SectionTitle>
533572
<List>
534573
<li><ItemTitle><InlineCode>@vojtechportes/react-query-builder/mui/v9</InlineCode>:</ItemTitle> Recommended Material UI adapter for new projects.</li>
535574
<li><ItemTitle><InlineCode>@vojtechportes/react-query-builder/mui/v7</InlineCode>:</ItemTitle> Material UI adapter for applications still on MUI 7.</li>
575+
<li><ItemTitle><InlineCode>@vojtechportes/react-query-builder/antd/v6</InlineCode>:</ItemTitle> Recommended Ant Design adapter for new projects.</li>
576+
<li><ItemTitle><InlineCode>@vojtechportes/react-query-builder/antd/v5</InlineCode>:</ItemTitle> Ant Design adapter for applications still on Ant Design 5.</li>
536577
</List>
537578
<SectionTitle>What adapters export</SectionTitle>
538579
<List>
539580
<li><ItemTitle><InlineCode>components</InlineCode>:</ItemTitle> A ready-to-pass object that matches <InlineCode>IBuilderComponentsProps</InlineCode>.</li>
540-
<li><ItemTitle>Individual mapped components:</ItemTitle> Named exports such as <InlineCode>MuiSelect</InlineCode> and <InlineCode>MuiInput</InlineCode> for partial customization.</li>
541-
<li><ItemTitle><InlineCode>createMuiComponents</InlineCode>:</ItemTitle> Helper for merging the adapter defaults with local overrides while preserving the nested <InlineCode>form</InlineCode> mapping.</li>
581+
<li><ItemTitle>Individual mapped components:</ItemTitle> Named exports such as <InlineCode>MuiSelect</InlineCode>, <InlineCode>MuiInput</InlineCode>, <InlineCode>AntdSelect</InlineCode>, and <InlineCode>AntdInput</InlineCode> for partial customization.</li>
582+
<li><ItemTitle><InlineCode>createMuiComponents</InlineCode> and <InlineCode>createAntdComponents</InlineCode>:</ItemTitle> Helpers for merging adapter defaults with local overrides while preserving the nested <InlineCode>form</InlineCode> mapping.</li>
542583
</List>
543584
<SectionTitle>Relationship to the Components API</SectionTitle>
544585
<List>
545586
<li>Adapters are built on top of the same override surface documented in <TextLink to="/api/components">Components</TextLink>.</li>
546587
<li>They are a convenience layer, not a separate rendering engine.</li>
547-
<li><InlineCode>createMuiComponents(base, overrides)</InlineCode> returns a merged <InlineCode>IBuilderComponentsProps</InlineCode> object and handles shallow top-level merging plus nested <InlineCode>form</InlineCode> merging for you.</li>
588+
<li><InlineCode>createMuiComponents(base, overrides)</InlineCode> and <InlineCode>createAntdComponents(base, overrides)</InlineCode> return merged <InlineCode>IBuilderComponentsProps</InlineCode> objects and handle shallow top-level merging plus nested <InlineCode>form</InlineCode> merging for you.</li>
548589
</List>
549590
<AlertBox title="Documentation" variant="info">
550591
<TextLink to="/documentation/adapters">Adapters</TextLink>,{' '}

0 commit comments

Comments
 (0)