Skip to content

Commit 3e4e0b3

Browse files
Freeze docs for v5 (rjsf-team#4565)
* Freeze docs for v5 Use `npm run docusaurus docs:version 5.24.9` to freeze docs for v5.24.9. Update the label for these frozen docs to 'v5'. Update the label for the current docs to indicate the current version. Update tsconfig to allow importing package.json to resolve the package version. Any changes to v5 docs after this is merged must be made to the versioned copy. * version should be 5.24.10 --------- Co-authored-by: Heath C <51679588+heath-freenome@users.noreply.github.com>
1 parent e171966 commit 3e4e0b3

37 files changed

+7975
-2
lines changed

packages/docs/docusaurus.config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
const lightCodeTheme = require('prism-react-renderer/themes/github');
55
const darkCodeTheme = require('prism-react-renderer/themes/dracula');
66

7+
const currentProjectVersion = require('./package.json').version;
8+
79
/** @type {import('@docusaurus/types').Config} */
810
const config = {
911
title: 'react-jsonschema-form',
@@ -44,9 +46,13 @@ const config = {
4446
lastVersion: 'current',
4547
versions: {
4648
current: {
47-
label: 'v5',
49+
label: `Current (v${currentProjectVersion})`,
4850
path: '',
4951
},
52+
'5.24.10': {
53+
label: 'v5',
54+
path: 'version-5.24.10',
55+
},
5056
'4.2.3': {
5157
label: 'v4',
5258
path: 'version-4.2.3',

packages/docs/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// This file is not used in compilation. It is here just for a nice editor experience.
33
"extends": "@tsconfig/docusaurus/tsconfig.json",
44
"compilerOptions": {
5-
"baseUrl": "."
5+
"baseUrl": ".",
6+
"resolveJsonModule": true
67
}
78
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
---
2+
id: intro
3+
title: Introduction
4+
slug: /
5+
---
6+
7+
# react-jsonschema-form
8+
9+
![Build Status](https://github.com/rjsf-team/react-jsonschema-form/workflows/CI/badge.svg)
10+
11+
A simple [React](https://reactjs.org/) component capable of building HTML forms out of a [JSON schema](http://json-schema.org/).
12+
13+
A [live playground](https://rjsf-team.github.io/react-jsonschema-form/) is hosted on GitHub Pages:
14+
15+
<a target='_blank' href='https://rjsf-team.github.io/react-jsonschema-form/'>
16+
<img alt='Playground' src='https://i.imgur.com/M8ZCES5.gif'/>
17+
</a>
18+
19+
## Philosophy
20+
21+
react-jsonschema-form is meant to automatically generate a React form based on a [JSON Schema](http://json-schema.org/). If you want to generate a form for any data, sight unseen, simply given a JSON schema, react-jsonschema-form may be for you. If you have _a priori_ knowledge of your data and want a toolkit for generating forms for it, you might look elsewhere.
22+
23+
react-jsonschema-form also comes with tools such as `uiSchema` and other form props to customize the look and feel of the form beyond the default themes.
24+
25+
## Installation
26+
27+
First install the dependencies from npm, along with a validator implementation (such as `@rjsf/validator-ajv8`):
28+
29+
```bash
30+
$ npm install @rjsf/core @rjsf/utils @rjsf/validator-ajv8 --save
31+
```
32+
33+
Then import the dependencies as follows:
34+
35+
```ts
36+
import Form from '@rjsf/core';
37+
import validator from '@rjsf/validator-ajv8';
38+
```
39+
40+
Our latest version requires React 16+.
41+
42+
## Usage
43+
44+
```tsx
45+
import Form from '@rjsf/core';
46+
import { RJSFSchema } from '@rjsf/utils';
47+
import validator from '@rjsf/validator-ajv8';
48+
49+
const schema: RJSFSchema = {
50+
title: 'Todo',
51+
type: 'object',
52+
required: ['title'],
53+
properties: {
54+
title: { type: 'string', title: 'Title', default: 'A new task' },
55+
done: { type: 'boolean', title: 'Done?', default: false },
56+
},
57+
};
58+
59+
const log = (type) => console.log.bind(console, type);
60+
61+
render(
62+
<Form
63+
schema={schema}
64+
validator={validator}
65+
onChange={log('changed')}
66+
onSubmit={log('submitted')}
67+
onError={log('errors')}
68+
/>,
69+
document.getElementById('app')
70+
);
71+
```
72+
73+
## Theming
74+
75+
For more information on what themes we support, see [Using Themes](usage/themes).
76+
77+
<!--
78+
79+
disabled until https://github.com/rjsf-team/react-jsonschema-form/issues/1584 is resolved
80+
81+
## Useful samples
82+
83+
- Custom field template: <https://jsfiddle.net/hdp1kgn6/1/>
84+
- Multi-step wizard: <https://jsfiddle.net/sn4bnw9h/1/>
85+
- Using classNames with uiSchema: <https://jsfiddle.net/gfwp25we/1/>
86+
- Conditional fields: <https://jsfiddle.net/69z2wepo/88541/>
87+
- Advanced conditional fields: <https://jsfiddle.net/cowbellerina/zbfh96b1/>
88+
- Use radio list for enums: <https://jsfiddle.net/f2y3fq7L/2/>
89+
- Reading file input data: <https://jsfiddle.net/f9vcb6pL/1/>
90+
- Custom errors messages with transformErrors: <https://jsfiddle.net/revolunet/5r3swnr4/>
91+
- 2 columns form with CSS and FieldTemplate: <https://jsfiddle.net/n1k0/bw0ffnz4/1/>
92+
- Validate and submit form from external control: <https://jsfiddle.net/spacebaboon/g5a1re63/>
93+
- Custom component for Help text with `ui:help`: <https://codesandbox.io/s/14pqx97xl7/>
94+
- Collapsing / Showing and Hiding individual fields: <https://codesandbox.io/s/examplereactjsonschemaformcollapsefieldtemplate-t41dn>
95+
96+
-->
97+
98+
## License
99+
100+
Apache 2
101+
102+
## Credits
103+
104+
<table>
105+
<tr>
106+
<th>
107+
<img src="https://avatars1.githubusercontent.com/u/1066228?s=200&v=4" alt="mozilla-services-logo" style={{maxHeight: '100px'}} />
108+
</th>
109+
<td>
110+
This project initially started as a <a href="https://github.com/mozilla-services">mozilla-services</a> project.
111+
</td>
112+
</tr>
113+
<tr>
114+
<th>
115+
<img src="https://user-images.githubusercontent.com/1689183/51487090-4ea04f80-1d57-11e9-9a91-79b7ef8d2013.png" alt='browserstack logo' style={{maxHeight: '100px'}}/>
116+
</th>
117+
<td>
118+
Testing is powered by <a href="https://www.browserstack.com/" >BrowserStack</a>.
119+
</td>
120+
</tr>
121+
<tr>
122+
<th>
123+
<img src="https://www.netlify.com/img/global/badges/netlify-color-accent.svg" alt='netlify logo' style={{maxHeight: '100px'}}/>
124+
</th>
125+
<td>
126+
Deploy Previews are provided by <a href="https://www.netlify.com">Netlify</a>.
127+
</td>
128+
</tr>
129+
</table>
130+
131+
## Who uses react-jsonschema-form?
132+
133+
- ...
134+
135+
Add your own company / organization by making a [pull request](https://github.com/rjsf-team/react-jsonschema-form/pulls).
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# Quickstart
2+
3+
Let's walk through setup of a form after installing the dependency properly.
4+
NOTE: As of version 5, the `Form` now requires you to provide a `validator` implementation. We recommend the one from `@rjsf/validator-ajv8`.
5+
6+
## Form schema
7+
8+
First, specify a schema using the [JSON Schema specification](https://json-schema.org/). The below schema renders a single string field:
9+
10+
```tsx
11+
import Form from '@rjsf/core';
12+
import { RJSFSchema } from '@rjsf/utils';
13+
import validator from '@rjsf/validator-ajv8';
14+
15+
const schema: RJSFSchema = {
16+
title: 'Test form',
17+
type: 'string',
18+
};
19+
20+
render(<Form schema={schema} validator={validator} />, document.getElementById('app'));
21+
```
22+
23+
You can also render an object with multiple fields with the below schema:
24+
25+
```tsx
26+
import Form from '@rjsf/core';
27+
import { RJSFSchema } from '@rjsf/utils';
28+
import validator from '@rjsf/validator-ajv8';
29+
30+
const schema: RJSFSchema = {
31+
title: 'Test form',
32+
type: 'object',
33+
properties: {
34+
name: {
35+
type: 'string',
36+
},
37+
age: {
38+
type: 'number',
39+
},
40+
},
41+
};
42+
43+
render(<Form schema={schema} validator={validator} />, document.getElementById('app'));
44+
```
45+
46+
For more information and examples of JSON Schema properties that this library supports, see [Using JSON Schema](json-schema/single.md).
47+
48+
## Form uiSchema
49+
50+
The uiSchema is used to add more customization to the form's look and feel. Use the `classNames`
51+
attribute of the uiSchema to add a custom CSS class name to the form:
52+
53+
```tsx
54+
import Form from '@rjsf/core';
55+
import { RJSFSchema, UiSchema } from '@rjsf/utils';
56+
import validator from '@rjsf/validator-ajv8';
57+
58+
const schema: RJSFSchema = {
59+
title: 'Test form',
60+
type: 'string',
61+
};
62+
63+
const uiSchema: UiSchema = {
64+
'ui:classNames': 'custom-css-class',
65+
};
66+
67+
render(<Form schema={schema} uiSchema={uiSchema} validator={validator} />, document.getElementById('app'));
68+
```
69+
70+
To customize object fields in the uiSchema, the structure of the
71+
uiSchema should be `{key: value}`, where `key` is the property key and `value` is an
72+
object with the uiSchema configuration for that particular property. For example:
73+
74+
```tsx
75+
import Form from '@rjsf/core';
76+
import { RJSFSchema, UiSchema } from '@rjsf/utils';
77+
import validator from '@rjsf/validator-ajv8';
78+
79+
const schema: RJSFSchema = {
80+
title: 'Test form',
81+
type: 'object',
82+
properties: {
83+
name: {
84+
type: 'string',
85+
},
86+
age: {
87+
type: 'number',
88+
},
89+
},
90+
};
91+
92+
const uiSchema: UiSchema = {
93+
name: {
94+
'ui:classNames': 'custom-class-name',
95+
},
96+
age: {
97+
'ui:classNames': 'custom-class-age',
98+
},
99+
};
100+
101+
render(<Form schema={schema} uiSchema={uiSchema} validator={validator} />, document.getElementById('app'));
102+
```
103+
104+
## Form initialization
105+
106+
Often you'll want to prefill a form with existing data; this is done by passing a `formData` prop object matching the schema:
107+
108+
```tsx
109+
import Form from '@rjsf/core';
110+
import { RJSFSchema } from '@rjsf/utils';
111+
import validator from '@rjsf/validator-ajv8';
112+
113+
const schema: RJSFSchema = {
114+
type: 'object',
115+
properties: {
116+
title: {
117+
type: 'string',
118+
},
119+
done: {
120+
type: 'boolean',
121+
},
122+
},
123+
};
124+
125+
const formData = {
126+
title: 'First task',
127+
done: true,
128+
};
129+
130+
render(<Form schema={schema} formData={formData} validator={validator} />, document.getElementById('app'));
131+
```
132+
133+
> Note: If your form has a single field, pass a single value to `formData`. ex: `formData="Charlie"`
134+
135+
> WARNING: If you have situations where your parent component can re-render, make sure you listen to the `onChange` event and update the data you pass to the `formData` attribute.
136+
137+
### Form event handlers
138+
139+
You can use event handlers such as `onChange`, `onError`, `onSubmit`, `onFocus`, and `onBlur` on the `<Form />` component; see the [Form Props Reference](./api-reference/form-props.md) for more details.
140+
141+
### Controlled component
142+
143+
By default, `<Form />` is an [uncontrolled component](https://reactjs.org/docs/uncontrolled-components.html). To make it a controlled component, use the
144+
`onChange` and `formData` props as in the below example:
145+
146+
```tsx
147+
import Form from '@rjsf/core';
148+
import validator from '@rjsf/validator-ajv8';
149+
150+
const App = () => {
151+
const [formData, setFormData] = React.useState(null);
152+
return (
153+
<Form
154+
schema={{ type: 'string' }}
155+
formData={formData}
156+
onChange={(e) => setFormData(e.formData)}
157+
validator={validator}
158+
/>
159+
);
160+
};
161+
162+
render(<App />, document.getElementById('app'));
163+
```

0 commit comments

Comments
 (0)