Skip to content

Instantly share code, notes, and snippets.

@jrwebdev
Created February 9, 2018 08:05
Show Gist options
  • Select an option

  • Save jrwebdev/d1d44e9a01b6af060e1e2fdbd7364146 to your computer and use it in GitHub Desktop.

Select an option

Save jrwebdev/d1d44e9a01b6af060e1e2fdbd7364146 to your computer and use it in GitHub Desktop.
withBlueBackground Pattern #3
import * as React from 'react';
type ColorShade = 'light' | 'dark';
export interface InjectedBlueBackgroundProps {
backgroundColor: string;
}
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}
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