-
Notifications
You must be signed in to change notification settings - Fork 935
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removed withDataStyles. replaced it with a new implementation: <DataS…
…tyles>
- Loading branch information
Showing
16 changed files
with
589 additions
and
461 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
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,65 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import merge from "lodash.merge"; | ||
import get from "lodash.get"; | ||
import { withStyles } from "material-ui/styles"; | ||
|
||
const getStyle = (obj, name) => { | ||
return get(obj, "styles." + name, null); | ||
}; | ||
|
||
const stylePass = (displayName, setFn) => { | ||
const result = class StylePass extends React.Component { | ||
componentWillMount() { | ||
setFn(this.props.classes); | ||
} | ||
|
||
componentWillReceieveProps(nextProps) { | ||
if (this.props.classes !== nextprops.classes) setFn(nextProps.classes); | ||
} | ||
|
||
render() { | ||
return this.props.children; | ||
} | ||
}; | ||
result.displayName = displayName; | ||
return result; | ||
}; | ||
|
||
class DataStyles extends React.Component { | ||
state = { | ||
data: null, | ||
}; | ||
|
||
setStyleClass = data => { | ||
this.setState(() => ({ | ||
styleData: data, | ||
})); | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
this.buildComponent(props); | ||
} | ||
|
||
componentWillReceieveProps(nextProps) { | ||
if (nextProps.styles !== this.props.styles) this.buildComponent(nextProps); | ||
} | ||
|
||
buildComponent(props) { | ||
const defaultStyles = props.defaultStyles ? props.defaultStyles : {}; | ||
const finalStyles = merge(defaultStyles, props.styles); | ||
|
||
// just a pass-through | ||
this.component = withStyles(finalStyles)(stylePass(props.name, this.setStyleClass)); | ||
} | ||
|
||
render() { | ||
const { children, defaultStyles } = this.props; | ||
const WrappedComponent = this.component; | ||
|
||
return <WrappedComponent>{this.state.styleData ? children(this.state.styleData) : false}</WrappedComponent>; | ||
} | ||
} | ||
|
||
export { DataStyles, getStyle }; |
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
Oops, something went wrong.