Guest User

Untitled

a guest
Mar 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import styled, from 'styled-components';
  2. import React from 'react';
  3. import Media from 'react-media';
  4.  
  5. const isFunction = f => typeof f === 'function';
  6.  
  7. const IS_SERVER = typeof window === 'undefined';
  8.  
  9. export const DesktopOnly = ({ children }) => (
  10. <Media query="@media screen and (max-width: 990px)">
  11. {matches => matches && (isFunction(children) ? children() : children)}
  12. </Media>
  13. );
  14.  
  15. const CSSDesktopOnly = styled.div`
  16. @media screen and (max-width: 990px) {
  17. display: none;
  18. }
  19. `;
  20.  
  21. export function SmartDesktopOnly(props) {
  22. if (IS_SERVER) {
  23. const { children, ...otherProps } = props;
  24. return (
  25. <CSSDesktopOnly {...otherProps}>
  26. {isFunction(children) ? children() : children}
  27. </CSSDesktopOnly>
  28. );
  29. }
  30.  
  31. return <DesktopOnly {...this.props} />;
  32. }
Add Comment
Please, Sign In to add comment