-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e39984
commit f7fc2d0
Showing
13 changed files
with
213 additions
and
50 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Message from './Message.component'; | ||
|
||
export default Message; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { PropTypes } from 'react'; | ||
import { sfPath } from 'talend-json-schema-form-core'; | ||
|
||
import widgets from '../utils/widgets'; | ||
import { getValue } from '../utils/properties'; | ||
|
||
export default function Widget({ formName, onChange, properties, schema, validations }) { | ||
const { key, type, validationMessage } = schema; | ||
const id = sfPath.name(key, '-', formName); | ||
const { error, valid } = validations[key] || {}; | ||
const errorMessage = validationMessage || (error && error.message); | ||
const WidgetImpl = widgets[type]; | ||
return WidgetImpl ? | ||
( | ||
<WidgetImpl | ||
id={id} | ||
key={id} | ||
errorMessage={errorMessage} | ||
formName={formName} | ||
isValid={valid} | ||
onChange={onChange} | ||
properties={properties} | ||
schema={schema} | ||
validations={validations} | ||
value={getValue(properties, key)} | ||
/> | ||
) : null; | ||
} | ||
|
||
Widget.propTypes = { | ||
formName: PropTypes.string, | ||
onChange: PropTypes.func, | ||
schema: PropTypes.shape({ | ||
key: PropTypes.array, | ||
type: PropTypes.string.isRequired, | ||
validationMessage: PropTypes.string, | ||
}).isRequired, | ||
properties: PropTypes.object, // eslint-disable-line react/forbid-prop-types | ||
validations: PropTypes.object, // eslint-disable-line react/forbid-prop-types | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Widget from './Widget.component'; | ||
|
||
export default Widget; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React, { PropTypes } from 'react'; | ||
import Widget from '../Widget'; | ||
|
||
export default function Fieldset(props) { | ||
const { schema, ...restProps } = props; | ||
const { title, items } = schema; | ||
|
||
return ( | ||
<fieldset className="form-group"> | ||
{title && (<legend>{title}</legend>)} | ||
{items.map((itemSchema, index) => ( | ||
<Widget | ||
{...restProps} | ||
key={index} | ||
schema={itemSchema} | ||
/> | ||
))} | ||
</fieldset> | ||
); | ||
} | ||
|
||
Fieldset.propTypes = { | ||
schema: PropTypes.shape({ | ||
items: PropTypes.array.isRequired, | ||
title: PropTypes.string, | ||
}).isRequired, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Fieldset from '../fieldsets/Fieldset'; | ||
import Text from '../fields/Text'; | ||
|
||
const widgets = { | ||
fieldset: Fieldset, | ||
number: Text, | ||
text: Text, | ||
}; | ||
|
||
export default widgets; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
{ | ||
"jsonSchema": { | ||
"type": "object", | ||
"title": "Comment", | ||
"properties": { | ||
"name": { | ||
"type": "string" | ||
}, | ||
"lastname": { | ||
"type": "string" | ||
}, | ||
"firstname": { | ||
"type": "string" | ||
}, | ||
"age": { | ||
"type": "number" | ||
}, | ||
"nochange": { | ||
"type": "string" | ||
}, | ||
"email": { | ||
"type": "string", | ||
"pattern": "^\\S+@\\S+$" | ||
}, | ||
"comment": { | ||
"type": "string", | ||
"maxLength": 20 | ||
} | ||
}, | ||
"required": [ | ||
"name", | ||
"firstname", | ||
"email", | ||
"comment" | ||
] | ||
}, | ||
"uiSchema": [ | ||
{ | ||
"type": "fieldset", | ||
"title": "My awesome USER form", | ||
"items": [ | ||
{ | ||
"key": "name", | ||
"title": "Name" | ||
}, | ||
{ | ||
"key": "lastname", | ||
"title": "Last Name (with description)", | ||
"description": "Hint: this is the last name" | ||
}, | ||
{ | ||
"key": "firstname", | ||
"title": "First Name (with placeholder)", | ||
"placeholder": "Enter your firstname here" | ||
}, | ||
{ | ||
"key": "age", | ||
"title": "Age" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "fieldset", | ||
"title": "My awesome OTHER form", | ||
"items": [ | ||
{ | ||
"key": "email", | ||
"title": "Email (with pattern validation and custom validation message)", | ||
"description": "Email will be used for evil.", | ||
"validationMessage": "Please enter a valid email address, e.g. [email protected]" | ||
}, | ||
{ | ||
"key": "nochange", | ||
"title": "Field (read only mode)", | ||
"readOnly": true | ||
}, | ||
{ | ||
"key": "comment", | ||
"type": "textarea", | ||
"title": "Comment", | ||
"placeholder": "Make a comment", | ||
"validationMessage": "Don't be greedy!" | ||
} | ||
] | ||
} | ||
], | ||
"properties": { | ||
"name": "Chuck Norris", | ||
"nochange": "You can't change that", | ||
"email": "[email protected]", | ||
"comment": "lol" | ||
} | ||
} |