Skip to content

Commit d39c56d

Browse files
authored
Merge pull request #144 from data-driven-forms/plain-text-component
Plain text component
2 parents 4a7451c + db7efa5 commit d39c56d

File tree

14 files changed

+117
-8
lines changed

14 files changed

+117
-8
lines changed

packages/mui-component-mapper/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
1818
"@babel/preset-env": "^7.1.6",
1919
"@babel/preset-react": "^7.0.0",
20-
"@data-driven-forms/react-form-renderer": "^1.9.3",
20+
"@data-driven-forms/react-form-renderer": "*",
2121
"@material-ui/core": "^4.2.1",
2222
"@material-ui/icons": "^4.2.1",
2323
"@material-ui/styles": "^4.2.1",

packages/mui-component-mapper/src/form-fields/component-mapper.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import React from 'react';
22
import { componentTypes } from '@data-driven-forms/react-form-renderer';
3-
import { TextField, TextareaField, SelectField, CheckboxGroup, Radio, SwitchField, DatePickerField, TimePickerField } from './form-fields';
3+
import {
4+
TextField,
5+
TextareaField,
6+
SelectField,
7+
CheckboxGroup,
8+
Radio,
9+
SwitchField,
10+
DatePickerField,
11+
TimePickerField,
12+
PlainTextField,
13+
} from './form-fields';
414
import SubForm from './sub-form';
515
import Tabs from './tabs';
616

@@ -16,6 +26,7 @@ const mapper = {
1626
[componentTypes.TIME_PICKER]: TimePickerField,
1727
[componentTypes.TAG_CONTROL]: props => <div>tag control</div>,
1828
[componentTypes.SWITCH]: SwitchField,
29+
[componentTypes.PLAIN_TEXT]: PlainTextField,
1930
};
2031

2132
export default mapper;

packages/mui-component-mapper/src/form-fields/form-fields.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import MomentUtils from '@date-io/moment';
2020
import RadioGroup from './radio';
2121

2222
import './form-fields.scss';
23+
import PlainText from './plain-text';
2324
const selectValue = option => option.sort((a, b) => a.label.localeCompare(b.label, 'en', { sensitivity: 'base' })).map(item => item.value);
2425

2526
const selectComponent = ({
@@ -250,3 +251,4 @@ export const SwitchField = ({ FieldProvider, ...props }) =>
250251
<FieldProvider { ...props } render={ props => <FieldInterface { ...props } name={ props.input.name } componentType={ componentTypes.SWITCH } /> }/>;
251252
export const DatePickerField = props => <FieldInterface { ...props } name={ props.input.name } componentType={ componentTypes.DATE_PICKER } />;
252253
export const TimePickerField = props => <FieldInterface { ...props } name={ props.input.name } componentType={ componentTypes.TIME_PICKER } />;
254+
export const PlainTextField = ({ label, name }) => <PlainText name={ name } label={ label }/>;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import Typography from '@material-ui/core/Typography';
3+
import PropTypes from 'prop-types';
4+
5+
const PlainText = ({ label, name }) => label.split('\n').map((paragraph, index) =>
6+
<Typography key={ `${index}-${name}` } gutterBottom variant="body1">{ paragraph }</Typography>
7+
);
8+
9+
PlainText.propTypes = {
10+
label: PropTypes.string.isRequired,
11+
name: PropTypes.string.isRequired,
12+
};
13+
14+
export default PlainText;

packages/pf3-component-mapper/src/form-fields/component-mapper.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import React from 'react';
22
import { componentTypes } from '@data-driven-forms/react-form-renderer';
3-
import { TextField, TextareaField, SelectField, CheckboxGroup, Radio, SwitchField, DatePickerField } from './form-fields';
3+
import {
4+
TextField,
5+
TextareaField,
6+
SelectField,
7+
CheckboxGroup,
8+
Radio,
9+
SwitchField,
10+
DatePickerField,
11+
PlainTextField,
12+
} from './form-fields';
413
import SubForm from './sub-form';
514
import Tabs from './tabs';
615
import Wizard from './wizzard/wizzard';
@@ -19,6 +28,7 @@ const mapper = {
1928
[componentTypes.TAG_CONTROL]: props => <div>tag control</div>,
2029
[componentTypes.SWITCH]: SwitchField,
2130
[componentTypes.WIZARD]: Wizard,
31+
[componentTypes.PLAIN_TEXT]: PlainTextField,
2232
};
2333

2434
export default mapper;
@@ -34,6 +44,7 @@ export const components = {
3444
DatePickerField,
3545
SwitchField,
3646
Wizard,
47+
PlainTextField,
3748
};
3849

3950
export const rawComponents = {

packages/pf3-component-mapper/src/form-fields/form-fields.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Switch from './switch-field';
99
import { DateTimePicker } from './date-time-picker/date-time-picker';
1010
import Select from './select';
1111
import RagioGroup from './radio';
12+
import PlainText from './plain-text';
1213

1314
const selectComponent = ({
1415
componentType,
@@ -169,3 +170,4 @@ export const SwitchField = ({ FieldProvider, ...props }) =>
169170
<FieldProvider { ...props } render={ props => <FieldInterface { ...props } name={ props.input.name } componentType={ componentTypes.SWITCH } /> }/>;
170171
export const DatePickerField = props =>
171172
<FieldInterface { ...props } name={ props.input.name } variant={ props.variant } componentType={ componentTypes.DATE_PICKER } />;
173+
export const PlainTextField = ({ input, label }) => <PlainText { ...input } label={ label } />;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
const PlainText = ({ label, name }) => label.split('\n').map((paragraph, index) => <p key={ `${name}-${index}` }>{ paragraph }</p>);
5+
6+
PlainText.propTypes = {
7+
label: PropTypes.string.isRequired,
8+
name: PropTypes.string.isRequired,
9+
};
10+
11+
export default PlainText;

packages/pf4-component-mapper/src/form-fields/component-mapper.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
DatePickerField,
1212
TimePickerField,
1313
SwitchField,
14+
PlainTextField,
1415
} from './form-fields';
1516
import Wizard from './wizard/wizard';
1617
import { Select } from './select/select';
@@ -28,6 +29,7 @@ const mapper = {
2829
[componentTypes.TAG_CONTROL]: props => <div>Unsupported tag control</div>,
2930
[componentTypes.WIZARD]: Wizard,
3031
[componentTypes.SWITCH]: SwitchField,
32+
[componentTypes.PLAIN_TEXT]: PlainTextField,
3133
};
3234

3335
export default mapper;
@@ -41,6 +43,7 @@ export const components = {
4143
DatePickerField,
4244
TimePickerField,
4345
SwitchField,
46+
PlainTextField,
4447
};
4548

4649
export const rawComponents = {

packages/pf4-component-mapper/src/form-fields/form-fields.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import { componentTypes } from '@data-driven-forms/react-form-renderer';
1515
import Select from './select/select';
1616
import RadioGroup from './radio';
17+
import PlainText from './plain-text';
1718

1819
const selectComponent = ({
1920
componentType,
@@ -177,3 +178,4 @@ export const SwitchField = ({ FieldProvider, ...props }) =>
177178
{ ...props }
178179
render={ props => <FieldInterface { ...props } hideLabel={ true } name={ props.input.name } componentType={ componentTypes.SWITCH } /> }
179180
/>;
181+
export const PlainTextField = ({ label, name }) => <PlainText label={ label } name={ name } />;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { Text, TextContent, TextVariants } from '@patternfly/react-core';
4+
5+
const PlainText = ({ label, name }) => (
6+
<TextContent>
7+
{ label.split('\n').map((paragraph, index) => <Text component={ TextVariants.p } key={ `${name}-${index}` }>{ paragraph }</Text>) }
8+
</TextContent>
9+
);
10+
11+
PlainText.propTypes = {
12+
label: PropTypes.string.isRequired,
13+
name: PropTypes.string.isRequired,
14+
};
15+
16+
export default PlainText;

0 commit comments

Comments
 (0)