hiDPI.js.flow 1022 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // @flow
  2. /**
  3. * Generates a media query to target HiDPI devices.
  4. *
  5. * @example
  6. * // Styles as object usage
  7. * const styles = {
  8. * [hiDPI(1.5)]: {
  9. * width: 200px;
  10. * }
  11. * }
  12. *
  13. * // styled-components usage
  14. * const div = styled.div`
  15. * ${hiDPI(1.5)} {
  16. * width: 200px;
  17. * }
  18. * `
  19. *
  20. * // CSS as JS Output
  21. *
  22. * '@media only screen and (-webkit-min-device-pixel-ratio: 1.5),
  23. * only screen and (min--moz-device-pixel-ratio: 1.5),
  24. * only screen and (-o-min-device-pixel-ratio: 1.5/1),
  25. * only screen and (min-resolution: 144dpi),
  26. * only screen and (min-resolution: 1.5dppx)': {
  27. * 'width': '200px',
  28. * }
  29. */
  30. export default function hiDPI(ratio?: number = 1.3): string {
  31. return `
  32. @media only screen and (-webkit-min-device-pixel-ratio: ${ratio}),
  33. only screen and (min--moz-device-pixel-ratio: ${ratio}),
  34. only screen and (-o-min-device-pixel-ratio: ${ratio}/1),
  35. only screen and (min-resolution: ${Math.round(ratio * 96)}dpi),
  36. only screen and (min-resolution: ${ratio}dppx)
  37. `
  38. }