Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
Add Comment
Please, Sign In to add comment