Last active
February 9, 2018 08:02
-
-
Save jrwebdev/65d5a2c83c241105b26b238f98d56f6a to your computer and use it in GitHub Desktop.
withBlueBackground Pattern #2
This file contains hidden or 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
| import * as React from 'react'; | |
| type ColorShade = 'light' | 'dark'; | |
| export interface InjectedBlueBackgroundProps { | |
| style?: React.CSSProperties; | |
| } | |
| interface WithBlueBackgroundProps { | |
| shade?: ColorShade; | |
| } | |
| const getBlueShade = (shade?: ColorShade) => { | |
| switch (shade) { | |
| case 'dark': | |
| return 'navy'; | |
| case 'light': | |
| return 'skyblue'; | |
| default: | |
| return 'blue'; | |
| } | |
| }; | |
| const withBlueBackground = <P extends InjectedBlueBackgroundProps>( | |
| UnwrappedComponent: React.ComponentType<P> | |
| ) => | |
| class WithBlueBackground extends React.Component< | |
| P & WithBlueBackgroundProps | |
| > { | |
| render() { | |
| return ( | |
| <UnwrappedComponent | |
| {...this.props} | |
| style={Object.assign({}, this.props.style, { | |
| backgroundColor: getBlueShade(this.props.shade), | |
| })} | |
| /> | |
| ); | |
| } | |
| }; | |
| export default withBlueBackground; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment