This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some more progress in form styling
- Loading branch information
Dom Harrington
committed
Sep 14, 2017
1 parent
d1766c7
commit 6fb63d6
Showing
3 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
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
87 changes: 87 additions & 0 deletions
87
packages/api-explorer-ui/src/form-components/ObjectField.jsx
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,87 @@ | ||
// https://github.com/mozilla-services/react-jsonschema-form/blob/03b54d086036167d5e1aa970c9d4d103dd766617/src/components/fields/ObjectField.js | ||
const React = require('react'); | ||
const ObjectField = require('react-jsonschema-form/lib/components/fields/ObjectField').default; | ||
|
||
const { | ||
orderProperties, | ||
retrieveSchema, | ||
getDefaultRegistry, | ||
} = require('react-jsonschema-form/lib/utils'); | ||
|
||
class CustomObjectField extends ObjectField { | ||
render() { | ||
const { | ||
uiSchema, | ||
formData, | ||
errorSchema, | ||
idSchema, | ||
name, | ||
required, | ||
disabled, | ||
readonly, | ||
onBlur, | ||
onFocus, | ||
registry = getDefaultRegistry(), | ||
} = this.props; | ||
const { definitions, fields, formContext } = registry; | ||
const { SchemaField, TitleField, DescriptionField } = fields; | ||
const schema = retrieveSchema(this.props.schema, definitions); | ||
const title = schema.title === undefined ? name : schema.title; | ||
let orderedProperties; | ||
try { | ||
const properties = Object.keys(schema.properties); | ||
orderedProperties = orderProperties(properties, uiSchema["ui:order"]); | ||
} catch (err) { | ||
return ( | ||
<div> | ||
<p className="config-error" style={{ color: "red" }}> | ||
Invalid {name || "root"} object field configuration: | ||
<em>{err.message}</em>. | ||
</p> | ||
<pre>{JSON.stringify(schema)}</pre> | ||
</div> | ||
); | ||
} | ||
return ( | ||
<div className="param-item"> | ||
{(uiSchema["ui:title"] || title) && ( | ||
<TitleField | ||
id={`${idSchema.$id}__title`} | ||
title={uiSchema["ui:title"] || title} | ||
required={required} | ||
formContext={formContext} | ||
/> | ||
)} | ||
{(uiSchema["ui:description"] || schema.description) && ( | ||
<DescriptionField | ||
id={`${idSchema.$id}__description`} | ||
description={uiSchema["ui:description"] || schema.description} | ||
formContext={formContext} | ||
/> | ||
)} | ||
{orderedProperties.map((name, index) => { | ||
return ( | ||
<SchemaField | ||
key={index} | ||
name={name} | ||
required={this.isRequired(name)} | ||
schema={schema.properties[name]} | ||
uiSchema={uiSchema[name]} | ||
errorSchema={errorSchema[name]} | ||
idSchema={idSchema[name]} | ||
formData={formData[name]} | ||
onChange={this.onPropertyChange(name)} | ||
onBlur={onBlur} | ||
onFocus={onFocus} | ||
registry={registry} | ||
disabled={disabled} | ||
readonly={readonly} | ||
/> | ||
); | ||
})} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
module.exports = CustomObjectField; |
17 changes: 17 additions & 0 deletions
17
packages/api-explorer-ui/src/form-components/TitleField.jsx
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,17 @@ | ||
// https://github.com/mozilla-services/react-jsonschema-form/blob/03b54d086036167d5e1aa970c9d4d103dd766617/src/components/fields/TitleField.js | ||
const React = require('react'); | ||
const PropTypes = require('prop-types'); | ||
|
||
function TitleField(props) { | ||
return <div className="param-item-name"><strong>{props.title}</strong></div>; | ||
} | ||
|
||
TitleField.propTypes = { | ||
title: PropTypes.string, | ||
}; | ||
|
||
TitleField.defaultProps = { | ||
title: '', | ||
}; | ||
|
||
module.exports = TitleField; |