cover.js.flow 649 B

123456789101112131415161718192021222324252627282930313233343536
  1. // @flow
  2. import type { Styles } from '../types/style'
  3. /**
  4. * CSS to fully cover an area. Can optionally be passed an offset to act as a "padding".
  5. *
  6. * @example
  7. * // Styles as object usage
  8. * const styles = {
  9. * ...cover()
  10. * }
  11. *
  12. * // styled-components usage
  13. * const div = styled.div`
  14. * ${cover()}
  15. * `
  16. *
  17. * // CSS as JS Output
  18. *
  19. * div: {
  20. * 'position': 'absolute',
  21. * 'top': '0',
  22. * 'right: '0',
  23. * 'bottom': '0',
  24. * 'left: '0'
  25. * }
  26. */
  27. export default function cover(offset?: number | string = 0): Styles {
  28. return {
  29. position: 'absolute',
  30. top: offset,
  31. right: offset,
  32. bottom: offset,
  33. left: offset,
  34. }
  35. }