Skip to content

Commit

Permalink
feat: add withStyles HOC (#77)
Browse files Browse the repository at this point in the history
- This HOC allows styles to be injected without `ThemeProvider`
  • Loading branch information
miketdonahue committed Dec 24, 2018
1 parent c8550a7 commit bfb808e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/withStyles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import hoistNonReactStatic from 'hoist-non-react-statics';
import * as React from 'react';

const withStyles = (styles: object) => (WrappedComponent: any): any => {
const displayName =
WrappedComponent.displayName || WrappedComponent.name || 'Component';

class WithStyles extends React.Component {
public render() {
return <WrappedComponent {...this.props} wrappedStyles={styles} />;
}
}

(WithStyles as any).displayName = `WithStyles(${displayName})`;
hoistNonReactStatic(WithStyles, WrappedComponent);

return WithStyles;
};

export default withStyles;

0 comments on commit bfb808e

Please sign in to comment.