wordWrap.js.flow 675 B

123456789101112131415161718192021222324252627282930313233
  1. // @flow
  2. import type { Styles } from '../types/style'
  3. /**
  4. * Provides an easy way to change the `wordWrap` property.
  5. *
  6. * @example
  7. * // Styles as object usage
  8. * const styles = {
  9. * ...wordWrap('break-word')
  10. * }
  11. *
  12. * // styled-components usage
  13. * const div = styled.div`
  14. * ${wordWrap('break-word')}
  15. * `
  16. *
  17. * // CSS as JS Output
  18. *
  19. * const styles = {
  20. * overflowWrap: 'break-word',
  21. * wordWrap: 'break-word',
  22. * wordBreak: 'break-all',
  23. * }
  24. */
  25. export default function wordWrap(wrap?: string = 'break-word'): Styles {
  26. const wordBreak = wrap === 'break-word' ? 'break-all' : wrap
  27. return {
  28. overflowWrap: wrap,
  29. wordWrap: wrap,
  30. wordBreak,
  31. }
  32. }