textOverflow.tsx 789 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import styled from '@emotion/styled';
  2. type Props = {
  3. children: React.ReactNode;
  4. className?: string;
  5. ['data-test-id']?: string;
  6. ellipsisDirection?: 'left' | 'right';
  7. isParagraph?: boolean;
  8. };
  9. const TextOverflow = styled(
  10. ({isParagraph, className, children, ['data-test-id']: dataTestId}: Props) => {
  11. const Component = isParagraph ? 'p' : 'div';
  12. return (
  13. <Component className={className} data-test-id={dataTestId}>
  14. {children}
  15. </Component>
  16. );
  17. }
  18. )`
  19. ${p => p.theme.overflowEllipsis}
  20. ${p =>
  21. p.ellipsisDirection === 'left' &&
  22. `
  23. direction: rtl;
  24. text-align: left;
  25. `};
  26. width: auto;
  27. line-height: 1.2;
  28. `;
  29. TextOverflow.defaultProps = {
  30. ellipsisDirection: 'right',
  31. isParagraph: false,
  32. };
  33. export default TextOverflow;