Skip to content
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 15 commits into from
May 25, 2019
2 changes: 2 additions & 0 deletions src/index.js
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;
35 changes: 35 additions & 0 deletions src/withTheme.js
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename restData to otherProps?

Copy link
Contributor Author

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.

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;