Guest User

Untitled

a guest
Feb 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. import * as React from 'react';
  2.  
  3. type ColorShade = 'light' | 'dark';
  4.  
  5. export interface InjectedBlueBackgroundProps {
  6. style?: React.CSSProperties;
  7. }
  8.  
  9. interface WithBlueBackgroundProps {
  10. shade?: ColorShade;
  11. }
  12.  
  13. const getBlueShade = (shade?: ColorShade) => {
  14. switch (shade) {
  15. case 'dark':
  16. return 'navy';
  17. case 'light':
  18. return 'skyblue';
  19. default:
  20. return 'blue';
  21. }
  22. };
  23.  
  24. const withBlueBackground = <P extends InjectedBlueBackgroundProps>(
  25. UnwrappedComponent: React.ComponentType<P>
  26. ) =>
  27. class WithBlueBackground extends React.Component<
  28. P & WithBlueBackgroundProps
  29. > {
  30. render() {
  31. return (
  32. <UnwrappedComponent
  33. {...this.props}
  34. style={Object.assign({}, this.props.style, {
  35. backgroundColor: getBlueShade(this.props.shade),
  36. })}
  37. />
  38. );
  39. }
  40. };
  41.  
  42. export default withBlueBackground;
Add Comment
Please, Sign In to add comment