Skip to content

Commit 6c7e8c3

Browse files
authored
Merge pull request #404 from rvsia/fixDemo
Fix demo technical debts
2 parents 8504872 + 5cee441 commit 6c7e8c3

File tree

20 files changed

+566
-114
lines changed

20 files changed

+566
-114
lines changed

.circleci/config.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ jobs:
3737
steps:
3838
- attach_workspace:
3939
at: ~/react-forms
40-
- run:
41-
name: 'Setup environment variables'
42-
command: 'export TRAVIS_REPO_SLUG=data-driven-forms/react-forms'
4340
- run:
4441
name: Release new version
4542
command: |

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
}
3838
},
3939
"devDependencies": {
40-
"@khala/commit-analyzer-wildcard": "^2.3.1",
41-
"@khala/npm-release-monorepo": "^2.3.0",
42-
"@khala/wildcard-release-notes": "^2.3.0",
40+
"@khala/commit-analyzer-wildcard": "^2.4.0",
41+
"@khala/npm-release-monorepo": "^2.4.0",
42+
"@khala/wildcard-release-notes": "^2.4.0",
4343
"@semantic-release/github": "^5.5.5",
4444
"@semantic-release/npm": "^5.1.4",
4545
"atob-lite": "^2.0.0",
@@ -74,7 +74,8 @@
7474
"major": "^(major|breaking)\\(",
7575
"minor": "^feat\\(",
7676
"patch": "^(fix|patch)\\("
77-
}
77+
},
78+
"repositoryName": "data-driven-forms/react-forms"
7879
}
7980
],
8081
[
@@ -84,7 +85,8 @@
8485
"major": "^(major|breaking)\\(",
8586
"minor": "^feat\\(",
8687
"patch": "^(fix|patch)\\("
87-
}
88+
},
89+
"defaultRelease": "no-release"
8890
}
8991
],
9092
{

packages/react-renderer-demo/src/app/pages/renderer/action-mapper.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import Grid from '@material-ui/core/Grid'
22
import ListOfContents from '../../src/helpers/list-of-contents';
3+
import RawComponent from '@docs/raw-component';
4+
35

46
<Grid container item>
57
<Grid item xs={12} md={10}>
@@ -68,6 +70,8 @@ Then, in your schema you can map `translateLabel` action to a prop:
6870
}
6971
```
7072

73+
<RawComponent source="action-mapper" />
74+
7175
</Grid>
7276
<Grid item xs={false} md={2}>
7377
<ListOfContents file="renderer/action-mapper" />

packages/react-renderer-demo/src/app/pages/renderer/component-api.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,19 @@ Each mapper provided in `react-forms` provides a default API for standard compon
2323
Standard components are:
2424
<br />
2525

26-
Wrapped in formGroup: <br/>
27-
&nbsp;&nbsp;text field <br/>
28-
&nbsp;&nbsp;text area <br/>
29-
&nbsp;&nbsp;select <br/>
30-
&nbsp;&nbsp;checkbox <br/>
31-
&nbsp;&nbsp;radio <br/>
32-
&nbsp;&nbsp;switch <br/>
33-
&nbsp;&nbsp;timepicker/datepicker <br/>
34-
<br />
35-
36-
Others: <br/>
37-
&nbsp;&nbsp;subform <br/>
38-
&nbsp;&nbsp;tab/tab item <br/>
39-
&nbsp;&nbsp;wizard <br/>
26+
|Change form state (input fields)|Others|
27+
|---------------------------------------|------|
28+
|text field|subform|
29+
|textarea|tabs/tab item|
30+
|select|wizard|
31+
|checkbox|plain text|
32+
|radio|
33+
|switch|
34+
|timepicker/datepicker|
4035

41-
# FormGroup wrapped components
36+
# Form fields components
4237

43-
Basic components are wrapped in formGroup. FormGroup provides a standard API to show labels, helper texts, errors, etc.
44-
45-
All those components provides a shared group of props:
38+
Basic components that can change the form state (inputs) share common props. These components are using [useFieldApi](/renderer/component-mapping#usefieldapi) or [FieldProvider](/renderer/component-mapping#fieldprovider) to access the form state.
4639

4740
|Prop|Type|Description|
4841
|----|:--:|----------:|
@@ -190,6 +183,15 @@ Wizard step <br/>
190183

191184
<ExampleLink to='wizard' />
192185

186+
## Plain text
187+
188+
|Prop|Type|Description|
189+
|----|:--:|----------:|
190+
|label|node/string|A text|
191+
|variant|string|A variant (depends on mappers: html tags)|
192+
193+
<ExampleLink to='plain-text' />
194+
193195
</Grid>
194196
<Grid item xs={false} md={2}>
195197
<ListOfContents file="renderer/component-api" />

packages/react-renderer-demo/src/app/pages/renderer/condition.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ You can show a field only if it meets a condition:
3434

3535
`when` - is name of field where the value is stored, **always required!**. It can be either string `'field-name'` or array of strings `['field-1', 'field-2']`.
3636

37-
### OR condition. At least one condition must be met
37+
### OR
38+
39+
At least one condition must be met.
3840

3941
You can use `or` object to connect two conditions. If either of of fields with name `a` and `b` will have value `x` condition is met.
4042

@@ -81,7 +83,11 @@ Also, you can use a shorthand:
8183
}
8284
```
8385

84-
### AND condition. All conditions must be met
86+
<RawComponent source="conditions/or" />
87+
88+
### AND
89+
90+
All conditions must be met.
8591

8692
Field `controlled-field-1` must have value `Bar` and field `controlled-field-2` must include `FooBar` somewhere in its value to display field `BarFoo`.
8793

@@ -154,6 +160,8 @@ Or you can use a shorthand:
154160
}
155161
```
156162

163+
<RawComponent source="conditions/and" />
164+
157165
### Not
158166

159167
You can simple negate a condition by using a `not`. Following condition is a true, when both of values are not a `x`.
@@ -189,9 +197,11 @@ You can simple negate a condition by using a `not`. Following condition is a tru
189197

190198
As the value you can use an array (AND) or another condition.
191199

200+
<RawComponent source="conditions/not" />
201+
192202
### Nesting
193203

194-
Of course it is possible to neste conditions:
204+
Of course it is possible to nest conditions:
195205

196206
```jsx
197207
condition = {
@@ -202,6 +212,8 @@ condition = {
202212
};
203213
```
204214

215+
<RawComponent source="condition" />
216+
205217
## Conditions
206218

207219
### Is
@@ -217,6 +229,9 @@ condition: {
217229
// Foo == 'Bar' => true
218230
// Foo == 'Not a Bar' => false
219231
```
232+
233+
<RawComponent source="conditions/is" />
234+
220235
### Is empty
221236

222237
`isEmpty` - tests if the value is empty (using [lodash function](https://lodash.com/docs/4.17.11#isEmpty))
@@ -237,6 +252,9 @@ condition: {
237252
// Foo = false => true
238253
// Foo = true => false
239254
```
255+
256+
<RawComponent source="conditions/is-empty" />
257+
240258
### Is not empty
241259

242260
`isNotEmpty` - tests if the value is not empty (using [lodash function](https://lodash.com/docs/4.17.11#isEmpty))
@@ -257,6 +275,9 @@ condition: {
257275
// Foo = true => false
258276
// Foo = true => true
259277
```
278+
279+
<RawComponent source="conditions/is-not-empty" />
280+
260281
### Pattern
261282

262283
`pattern` - tests if the value matches the pattern
@@ -284,6 +305,8 @@ condition: {
284305
// Foo = 'bAr!' => true
285306
```
286307

308+
<RawComponent source="conditions/pattern" />
309+
287310
### Not match
288311

289312
`notMatch` - reverse `is`/`pattern` condition
@@ -309,9 +332,7 @@ condition: {
309332
// Foo = 'bar' => false
310333
```
311334

312-
## Example
313-
314-
<RawComponent source="condition" />
335+
<RawComponent source="conditions/not-match" />
315336

316337
## Clearing values
317338

packages/react-renderer-demo/src/app/src/components/code-editor/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const CodeEditor = (props) => (
2727
onLoad={(editor) => {
2828
editor.getSession().setUseWorker(false);
2929
}}
30+
mode="jsx"
3031
{...props}
3132
/>
3233
);

packages/react-renderer-demo/src/app/src/components/common/connected-links.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const ConnectedLinks = () => {
3434
container
3535
justify="space-between"
3636
className={clsx(classNames.linksContainer, {
37-
[classNames.withSideNav]: pathname.includes('/renderer/') && !(pathname === '/renderer/installation' || pathname === '/renderer/get-started')
37+
[classNames.withSideNav]: pathname.includes('/renderer/')
3838
})}
3939
>
4040
<Grid item>

packages/react-renderer-demo/src/app/src/components/common/raw-component.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ const req = require.context('@docs/doc-components', true, /\.js/);
2020
const useStyles = makeStyles((theme) => ({
2121
heading: {
2222
fontSize: theme.typography.pxToRem(15),
23-
fontWeight: theme.typography.fontWeightRegular
23+
fontWeight: theme.typography.fontWeightRegular,
24+
flexGrow: 1
2425
},
2526
formWrapper: {
2627
padding: 16
2728
},
2829
formContainer: {
2930
marginTop: 16
31+
},
32+
secondaryHeading: {
33+
fontSize: theme.typography.pxToRem(15),
34+
color: theme.palette.text.secondary
3035
}
3136
}));
3237

@@ -47,6 +52,7 @@ const RawComponent = (props) => {
4752
<ExpansionPanel>
4853
<ExpansionPanelSummary expandIcon={<CodeIcon />}>
4954
{content.Component && <Typography className={classes.heading}>{content.Component.name}</Typography>}
55+
<Typography className={classes.secondaryHeading}>Click to expand example code</Typography>
5056
</ExpansionPanelSummary>
5157
<ExpansionPanelDetails style={{ padding: 0 }}>
5258
<CodeEditor value={content.text} />
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import React from 'react';
2+
import FormRenderer from '@data-driven-forms/react-form-renderer/dist/cjs/form-renderer';
3+
import componentTypes from '@data-driven-forms/react-form-renderer/dist/cjs/component-types';
4+
5+
import TextField from '@data-driven-forms/pf4-component-mapper/dist/cjs/text-field';
6+
import FormTemplate from '@data-driven-forms/pf4-component-mapper/dist/cjs/form-template';
7+
8+
const translateLabel = (id, locale = 'en') =>
9+
({
10+
en: {
11+
name: 'User name',
12+
password: 'Password'
13+
},
14+
jp: {
15+
name: '名前',
16+
password: 'パスワード'
17+
}
18+
}[locale][id]);
19+
20+
const schema = {
21+
title: 'Action Mapper example (translated strings)',
22+
fields: [
23+
{
24+
component: componentTypes.TEXT_FIELD,
25+
name: 'name',
26+
actions: {
27+
label: ['translateLabel', 'name', 'jp']
28+
}
29+
},
30+
{
31+
component: componentTypes.TEXT_FIELD,
32+
name: 'password',
33+
actions: {
34+
label: ['translateLabel', 'password', 'jp']
35+
}
36+
}
37+
]
38+
};
39+
40+
const componentMapper = {
41+
[componentTypes.TEXT_FIELD]: TextField
42+
};
43+
44+
const actionMapper = {
45+
translateLabel
46+
};
47+
48+
const ActionMapper = () => (
49+
<div className="pf4">
50+
<FormRenderer FormTemplate={FormTemplate} actionMapper={actionMapper} componentMapper={componentMapper} schema={schema} onSubmit={console.log} />
51+
</div>
52+
);
53+
54+
export default ActionMapper;

0 commit comments

Comments
 (0)