em.js.flow 638 B

12345678910111213141516171819202122232425262728
  1. // @flow
  2. import pixelsto from '../internalHelpers/_pxto'
  3. /**
  4. * Convert pixel value to ems. The default base value is 16px, but can be changed by passing a
  5. * second argument to the function.
  6. * @function
  7. * @param {string|number} pxval
  8. * @param {string|number} [base='16px']
  9. * @example
  10. * // Styles as object usage
  11. * const styles = {
  12. * 'height': em('16px')
  13. * }
  14. *
  15. * // styled-components usage
  16. * const div = styled.div`
  17. * height: ${em('16px')}
  18. * `
  19. *
  20. * // CSS in JS Output
  21. *
  22. * element {
  23. * 'height': '1em'
  24. * }
  25. */
  26. const em: (value: string | number, base?: string | number) => string = pixelsto('em')
  27. export default em