-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added withTheme HOC #1226
Merged
Merged
Added withTheme HOC #1226
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5626813
Added withTheme HOC
danbalarin f6a43bb
prettier run
danbalarin d1580e2
renamed restData variable
danbalarin bb0a0f7
data.Fields -> data.fields
danbalarin a95c11d
Created documentation
danbalarin ae687d8
Merge branch 'master' of https://github.com/danbalarin/react-jsonsche…
epicfaace 0643609
Merge branch 'master' into danbalarin-master
epicfaace 58f19f2
doc: update doc
epicfaace 3e4e16f
test: add test
epicfaace 88b7907
removed custom form
danbalarin e7638b4
removed custom form from documentation
danbalarin 3a141fe
Updated withTheme + docs to show pass-through nature of all the props
mirajp 9de51ca
Apply suggestions from code review
mirajp e3f7e17
Update test/withTheme_test.js
mirajp 12ba00c
Updated tests
mirajp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import Form from "./components/Form"; | ||
import withTheme from "./withTheme"; | ||
|
||
export { withTheme }; | ||
export default Form; |
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,35 @@ | ||
import React, { Component } from "react"; | ||
import PropTypes from "prop-types"; | ||
import Form from "./"; | ||
|
||
function withTheme(data) { | ||
return class extends Component { | ||
render() { | ||
let { templates, widgets, fields, ...restData } = this.props; | ||
templates = { ...data.templates, ...templates }; | ||
widgets = { ...data.widgets, ...widgets }; | ||
fields = { ...data.Fields, ...fields }; | ||
let ThemedForm = Form; | ||
if (data.form) { | ||
ThemedForm = data.form; | ||
} | ||
return ( | ||
<ThemedForm | ||
{...restData} | ||
{...templates} | ||
widgets={widgets} | ||
fields={fields} | ||
/> | ||
); | ||
} | ||
}; | ||
} | ||
|
||
withTheme.propTypes = { | ||
form: PropTypes.object, | ||
widgets: PropTypes.object, | ||
fields: PropTypes.object, | ||
templates: PropTypes.object, | ||
}; | ||
|
||
export default withTheme; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rename
restData
tootherProps
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'm very bad at naming variables.