Skip to content
This repository was archived by the owner on May 25, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';
import { InputTextTypes } from '@constants';
import { FormModelConfig } from '@context';

import { InputGroup } from '../Input/input.styles';

const Email = ({ id, value, modifyFormObject, formObject, onSave, autoSave, onBlur, ...rest }) => {
const type = rest['rdf:type'];
const label = rest['ui:label'] || '';
const maxLength = rest['ui:maxLength'] || 256;
const size = rest['ui:size'] || 40;
const pattern = rest['ui:pattern'] || '';
const actualValue = formObject[id] || formObject[id] === '' ? formObject[id].value : value;
const onChange = ({ target }) => {
const obj = { value: target.value, ...rest };
modifyFormObject(id, obj);
};

return (
<FormModelConfig.Consumer>
{({ theme }) => (
<InputGroup className={theme && theme.inputText}>
<label htmlFor={id} id={id}>
{label}
</label>
<input
id={id}
name={id}
type={InputTextTypes[type]}
pattern={pattern}
{...{ maxLength, size, value: actualValue || '', onChange, onBlur }}
/>
</InputGroup>
)}
</FormModelConfig.Consumer>
);
};

export default Email;
13 changes: 13 additions & 0 deletions src/lib/components/FormModel/children/Form/UI/Email/email.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import { render, cleanup } from 'react-testing-library';
import 'jest-dom/extend-expect';

afterAll(cleanup);

describe('Provider Login Container', () => {
const { container } = render(<div />);

it('shoud renders without crashing', () => {
expect(container).toBeTruthy();
});
});
3 changes: 3 additions & 0 deletions src/lib/components/FormModel/children/Form/UI/Email/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Email from './email.component';

export default Email;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const Input = ({ id, value, modifyFormObject, formObject, onSave, autoSave, onBl
const label = rest['ui:label'] || '';
const maxLength = rest['ui:maxLength'] || 256;
const size = rest['ui:size'] || 40;
const pattern = rest['ui:pattern'] || '';
const actualValue = formObject[id] || formObject[id] === '' ? formObject[id].value : value;
const onChange = ({ target }) => {
const obj = { value: target.value, ...rest };
Expand All @@ -27,7 +26,6 @@ const Input = ({ id, value, modifyFormObject, formObject, onSave, autoSave, onBl
id={id}
name={id}
type={InputTextTypes[type]}
pattern={pattern}
{...{ maxLength, size, value: actualValue || '', onChange, onBlur }}
/>
</InputGroup>
Expand Down
3 changes: 3 additions & 0 deletions src/lib/components/FormModel/children/Form/UI/Phone/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Phone from './phone.component';

export default Phone;
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';
import { InputTextTypes } from '@constants';
import { FormModelConfig } from '@context';

import { InputGroup } from '../Input/input.styles';

const Phone = ({ id, value, modifyFormObject, formObject, onSave, autoSave, onBlur, ...rest }) => {
const type = rest['rdf:type'];
const label = rest['ui:label'] || '';
const maxLength = rest['ui:maxLength'] || 256;
const size = rest['ui:size'] || 40;
const pattern = rest['ui:pattern'] || '';
const actualValue = formObject[id] || formObject[id] === '' ? formObject[id].value : value;
const onChange = ({ target }) => {
const obj = { value: target.value, ...rest };
modifyFormObject(id, obj);
};

return (
<FormModelConfig.Consumer>
{({ theme }) => (
<InputGroup className={theme && theme.inputText}>
<label htmlFor={id} id={id}>
{label}
</label>
<input
id={id}
name={id}
type={InputTextTypes[type]}
pattern={pattern}
{...{ maxLength, size, value: actualValue || '', onChange, onBlur }}
/>
</InputGroup>
)}
</FormModelConfig.Consumer>
);
};

export default Phone;
13 changes: 13 additions & 0 deletions src/lib/components/FormModel/children/Form/UI/Phone/phone.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import { render, cleanup } from 'react-testing-library';
import 'jest-dom/extend-expect';

afterAll(cleanup);

describe('Provider Login Container', () => {
const { container } = render(<div />);

it('shoud renders without crashing', () => {
expect(container).toBeTruthy();
});
});
6 changes: 5 additions & 1 deletion src/lib/components/FormModel/children/Form/UI/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import TextArea from './TextArea';
import CheckBoxList from './CheckBoxList';
import RadioButtonList from './RadioButtonList';
import ColorPicker from './ColorPicker';
import Email from './Email';
import Phone from './Phone';

export {
CheckBox,
Expand All @@ -17,5 +19,7 @@ export {
RadioButtonList,
Select,
TextArea,
ColorPicker
ColorPicker,
Email,
Phone
};
6 changes: 4 additions & 2 deletions src/lib/components/FormModel/children/Form/UI/ui-mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Decimal from './Decimal';
import Integer from './Integer';
import Float from './Float';
import ColorPicker from './ColorPicker';
import Email from './Email';
import Phone from './Phone';

import { UITypes } from '@constants';

Expand Down Expand Up @@ -52,10 +54,10 @@ const UIMapping = type => {
component = ColorPicker;
break;
case UITypes.EmailField:
component = Input;
component = Email;
break;
case UITypes.PhoneField:
component = Input;
component = Phone;
break;
default:
component = Input;
Expand Down