Skip to content

Commit

Permalink
Merge pull request #469 from githubanuja/master
Browse files Browse the repository at this point in the history
Adding schema docs in examples and api reference
  • Loading branch information
joepuzzo authored Feb 13, 2024
2 parents 7f417fd + 140f430 commit 4989e7a
Show file tree
Hide file tree
Showing 28 changed files with 1,505 additions and 9 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"style-loader": "^0.22.1",
"tsd": "^0.18.0",
"universal-dotenv": "^1.8.3",
"vite": "^4.2.0",
"vite": "^4.5.2",
"webpack": "^4.46.0",
"webpack-bundle-analyzer": "^3.7.0",
"webpack-cli": "^3.3.11",
Expand Down
15 changes: 15 additions & 0 deletions vitedocs/Nav/ApiReferenceNav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ export const ApiReferenceNav = () => {
<NavLink href="/api-reference/conditional-schema-control">
Conditional Schema Control
</NavLink>
<NavLink href="/api-reference/schema-nested">Nested Schema</NavLink>
<NavLink href="/api-reference/schema-conditional-option">
Conditional Option Schema
</NavLink>
<NavLink href="/api-reference/schema-formatted">Formatted Schema</NavLink>
<NavLink href="/api-reference/schema-array-field">
Array Field Schema
</NavLink>
<NavLink href="/api-reference/schema-nested-array-field">
Nested Array Field Schema
</NavLink>
<NavLink href="/api-reference/schema-relevant-array-field">
Relevant ArrayField Schema
</NavLink>
<NavLink href="/api-reference/schema-custom">Custom Schema</NavLink>
<h3>Multistep</h3>
<NavLink href="/api-reference/multistep-intro" exact>
Intro
Expand Down
18 changes: 17 additions & 1 deletion vitedocs/Nav/ExamplesNav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const ExamplesNav = () => {
<NavLink href="/examples/changing-options">Chaning Options</NavLink>
<NavLink href="/examples/dependent-fields">Dependent Fields</NavLink>
<NavLink href="/examples/two-way">Two Way Dependence</NavLink>

<h3>Formatting</h3>
<NavLink href="/examples/formatting-formatter">Formatter</NavLink>
<NavLink href="/examples/formatting-number">Number Formatter</NavLink>
Expand All @@ -30,6 +29,23 @@ export const ExamplesNav = () => {
<NavLink href="/examples/relevant-scoped">Scoped Relevance</NavLink>
<NavLink href="/examples/relevant-arrays">Relevance in Arrays</NavLink>
<NavLink href="/examples/relevant-schema">Schema Relevance</NavLink>

<h3>Schema</h3>
<NavLink href="/examples/schema-intro">Intro</NavLink>
<NavLink href="/examples/schema-conditional">Conditional Schema</NavLink>
<NavLink href="/examples/schema-nested">Nested Schema</NavLink>
<NavLink href="/examples/schema-conditional-option">
Conditional Option Schema
</NavLink>
<NavLink href="/examples/schema-formatted">Formatted Schema</NavLink>
<NavLink href="/examples/schema-array-field">Array Field Schema</NavLink>
<NavLink href="/examples/schema-nested-array-field">
Nested Array Field Schema
</NavLink>
<NavLink href="/examples/schema-relevant-array-field">
Relevant ArrayField Schema
</NavLink>
<NavLink href="/examples/schema-custom">Custom Schema</NavLink>
<h3>Multistep</h3>
<NavLink href="/examples/multistep-intro">Basic Multistep</NavLink>
<NavLink href="/examples/multistep-dynamic">Dynamic Multistep</NavLink>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useEffect } from 'react';
import Example from './Example';
import exampleCode from './Example.jsx?raw';
import Code from '../../../../YourComponents/Code';
import { SideBySide } from '../../../../SideBySide';

export default function ArrayFieldSchema() {
useEffect(() => {
window.scrollTo(0, 0);
}, []);
return (
<>
<h1>
<code>Array Field Schema</code>
</h1>
<SideBySide
leftHeader={<h3>Example:</h3>}
rightHeader={<h3>Code:</h3>}
left={<Example />}
right={<Code links input1={exampleCode} />}
/>
<br />
<br />
</>
);
}
85 changes: 85 additions & 0 deletions vitedocs/Pages/Examples/schemas/ArrayFieldSchema/Example.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { SchemaFields, Debug } from 'informed';
import { Form, Button } from 'YourComponents';
import Ajv from 'ajv';

const initialValue = [
{
name: 'Joe',
age: '26'
},
{
name: 'Elon',
age: '49'
}
];

const schema = {
type: 'object',
required: ['name', 'siblings'],
properties: {
name: {
type: 'string',
title: 'First name',
'ui:control': 'input'
},
siblings: {
type: 'array',
minItems: 2,
'ui:control': 'array',
'ui:props': {
initialValue
},
'ui:before': [{ 'ui:control': 'add' }],
items: {
type: 'object',
required: ['name', 'age'],
properties: {
name: {
type: 'string',
title: 'Sibling name',
'ui:control': 'input'
},
age: {
type: 'number',
title: 'Sibling age',
minimum: 0,
'ui:control': 'input',
'ui:props': {
type: 'number'
}
},
married: {
type: 'string',
title: 'Are you married?',
enum: ['yes', 'no'],
'ui:control': 'radio',
'ui:props': {
notify: ['spouse']
}
},
spouse: {
type: 'string',
title: 'Spouse name',
'ui:control': 'input',
'ui:props': {
relevant: ({ formApi, scope }) => {
return formApi.getValue(`${scope}.married`) == 'yes';
}
}
}
}
},
'ui:component:remove': { 'ui:control': 'remove' }
}
}
};

const Schema = () => (
<Form ajv={Ajv} schema={schema}>
<SchemaFields />
<Button type="submit">Submit</Button>
<Debug />
</Form>
);

export default Schema;
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useEffect } from 'react';
import Example from './Example';
import exampleCode from './Example.jsx?raw';
import Code from '../../../../YourComponents/Code';
import { SideBySide } from '../../../../SideBySide';
import { Info } from '../../../../Info';

export default function ConditionalOptionSchema() {
useEffect(() => {
window.scrollTo(0, 0);
}, []);
return (
<>
<h1>
<code>Conditional Options Schema</code>
</h1>
<Info>
Informed allows you to use conditional change the options of input
fields.
<br />
<br />
Try selecting different options from "Would you like a car or truck?"
and observe the "Product" dropdown.
</Info>
<SideBySide
leftHeader={<h3>Example:</h3>}
rightHeader={<h3>Code:</h3>}
left={<Example />}
right={<Code links input1={exampleCode} />}
/>
<br />
<br />
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { SchemaFields, Debug } from 'informed';
import { Form, Button } from 'YourComponents';

const schema = {
type: 'object',
properties: {
type: {
type: 'string',
'ui:control': 'select',
title: 'Would you like a car or truck?',
oneOf: [
{ const: 'car', title: 'Car' },
{ const: 'truck', title: 'Truck' }
],
'ui:props': {
initialValue: 'car'
}
},
product: {
type: 'string',
'ui:control': 'select',
title: 'Product'
}
},
allOf: [
{
if: { properties: { type: { const: 'car' } }, required: ['type'] },
then: {
properties: {
product: {
oneOf: [
{ const: '', title: '- Select -' },
{ const: 'modelS', title: 'Model S' },
{ const: 'modelX', title: 'Model X' },
{ const: 'model3', title: 'Model 3' }
]
}
}
}
},
{
if: { properties: { type: { const: 'truck' } }, required: ['type'] },
then: {
properties: {
product: {
oneOf: [
{ const: '', title: '- Select -' },
{ const: 'semi', title: 'Semi Truck' },
{ const: 'cyber', title: 'Cyber Truck' }
]
}
}
}
}
]
};

const Schema = () => (
<Form schema={schema}>
<SchemaFields />
<Button type="submit">Submit</Button>
<Debug />
</Form>
);
export default Schema;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { useEffect } from 'react';
import Example from './Example';
import exampleCode from './Example.jsx?raw';
import Code from '../../../../YourComponents/Code';
import { SideBySide } from '../../../../SideBySide';
import { Info } from '../../../../Info';

export default function ConditionalFieldComponent() {
useEffect(() => {
window.scrollTo(0, 0);
}, []);
return (
<>
<h1>
<code>Conditional Schema</code>
</h1>
<Info>
Informed allows you to use advanced JSON schema conditionals.
<br />
</Info>
<SideBySide
leftHeader={<h3>Example:</h3>}
rightHeader={<h3>Code:</h3>}
left={<Example />}
right={<Code links input1={exampleCode} />}
/>
<br />
<br />
</>
);
}
49 changes: 49 additions & 0 deletions vitedocs/Pages/Examples/schemas/ConditionalSchema/Example.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { SchemaFields, Debug } from 'informed';
import { Form, Button } from 'YourComponents';

const schema = {
type: 'object',
required: ['name'],
properties: {
name: {
type: 'string',
title: 'First name',
'ui:control': 'input'
},
married: {
type: 'string',
title: 'Are you married?',
enum: ['yes', 'no'],
'ui:control': 'radio'
}
},
allOf: [
{
if: {
properties: {
married: { const: 'yes' }
},
required: ['married']
},
then: {
properties: {
spouse: {
type: 'string',
title: 'Spouse name',
'ui:control': 'input'
}
}
}
}
]
};

const Example = () => (
<Form schema={schema}>
<SchemaFields />
<Button type="submit">Submit</Button>
<Debug />
</Form>
);

export default Example;
Loading

0 comments on commit 4989e7a

Please sign in to comment.