textOverflow.tsx 765 B

12345678910111213141516171819202122232425262728
  1. import React from 'react';
  2. import styled from '@emotion/styled';
  3. import overflowEllipsis from 'app/styles/overflowEllipsis';
  4. import overflowEllipsisLeft from 'app/styles/overflowEllipsisLeft';
  5. type Props = {
  6. children: React.ReactNode;
  7. isParagraph?: boolean;
  8. ellipsisDirection?: 'left' | 'right';
  9. className?: string;
  10. };
  11. const TextOverflow = styled(({isParagraph, className, children}: Props) => {
  12. const Component = isParagraph ? 'p' : 'div';
  13. return <Component className={className}>{children}</Component>;
  14. })`
  15. ${p => (p.ellipsisDirection === 'right' ? overflowEllipsis : overflowEllipsisLeft)};
  16. width: auto;
  17. line-height: 1.1;
  18. `;
  19. TextOverflow.defaultProps = {
  20. ellipsisDirection: 'right',
  21. isParagraph: false,
  22. };
  23. export default TextOverflow;