textOverflow.tsx 895 B

1234567891011121314151617181920212223242526272829303132333435
  1. import * as 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. ['data-test-id']?: string;
  10. className?: string;
  11. };
  12. const TextOverflow = styled(
  13. ({isParagraph, className, children, ['data-test-id']: dataTestId}: Props) => {
  14. const Component = isParagraph ? 'p' : 'div';
  15. return (
  16. <Component className={className} data-test-id={dataTestId}>
  17. {children}
  18. </Component>
  19. );
  20. }
  21. )`
  22. ${p => (p.ellipsisDirection === 'right' ? overflowEllipsis : overflowEllipsisLeft)};
  23. width: auto;
  24. line-height: 1.1;
  25. `;
  26. TextOverflow.defaultProps = {
  27. ellipsisDirection: 'right',
  28. isParagraph: false,
  29. };
  30. export default TextOverflow;