Skip to content

Commit 4679326

Browse files
authored
Add combinators example
1 parent e2708e9 commit 4679326

File tree

3 files changed

+120
-1
lines changed

3 files changed

+120
-1
lines changed

content/examples/combinators.mdx

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
id: combinators
3+
title: Combinators
4+
---
5+
6+
import { AnyOf, AllOf, OneOf } from '../../src/components/examples/Combinators'
7+
8+
## oneOf
9+
10+
<OneOf />
11+
12+
## anyOf
13+
14+
<AnyOf />
15+
16+
## allOf
17+
18+
<AllOf />
+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import React from 'react';
2+
import { Demo } from '../common';
3+
4+
const data = {
5+
addressOrUser: {
6+
street_address: '1600 Pennsylvania Avenue NW',
7+
city: 'Washington',
8+
state: 'DC'
9+
}
10+
}
11+
12+
const uischema = {
13+
type: 'VerticalLayout',
14+
elements: [
15+
{
16+
type: 'Control',
17+
label: "Basic Information",
18+
scope: '#/properties/addressOrUser'
19+
}
20+
]
21+
}
22+
23+
const schema = {
24+
definitions: {
25+
address: {
26+
type: 'object',
27+
title: 'Address',
28+
properties: {
29+
street_address: { type: 'string' },
30+
city: { type: 'string' },
31+
state: { type: 'string' }
32+
},
33+
required: ['street_address', 'city', 'state']
34+
},
35+
user: {
36+
type: 'object',
37+
title: 'User',
38+
properties: {
39+
name: { type: 'string' },
40+
mail: { type: 'string' }
41+
},
42+
required: ['name', 'mail']
43+
},
44+
},
45+
type: 'object'
46+
}
47+
48+
export const AnyOf = () => {
49+
const anySchema = {
50+
...schema,
51+
properties: {
52+
addressOrUser: {
53+
anyOf: [{ $ref: '#/definitions/address' }, { $ref: '#/definitions/user' }]
54+
}
55+
}
56+
}
57+
return (
58+
<Demo
59+
data={data}
60+
schema={anySchema}
61+
uischema={uischema}
62+
/>
63+
);
64+
};
65+
66+
export const AllOf = () => {
67+
const allSchema = {
68+
...schema,
69+
properties: {
70+
addressOrUser: {
71+
allOf: [{ $ref: '#/definitions/address' }, { $ref: '#/definitions/user' }]
72+
}
73+
}
74+
}
75+
return (
76+
<Demo
77+
data={data}
78+
schema={allSchema}
79+
uischema={uischema}
80+
/>
81+
);
82+
}
83+
84+
export const OneOf = () => {
85+
const oneSchema = {
86+
...schema,
87+
properties: {
88+
addressOrUser: {
89+
oneOf: [{ $ref: '#/definitions/address' }, { $ref: '#/definitions/user' }]
90+
}
91+
}
92+
}
93+
return (
94+
<Demo
95+
data={data}
96+
schema={oneSchema}
97+
uischema={uischema}
98+
/>
99+
);
100+
}

src/sidebars/examples.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = {
88
'rule',
99
'custom-controls',
1010
'gen-uischema',
11-
'gen-both-schemas'
11+
'gen-both-schemas',
12+
'combinators'
1213
]
1314
};

0 commit comments

Comments
 (0)