textTruncateOverflow.tsx 829 B

123456789101112131415161718192021222324252627
  1. import {ComponentProps, ElementType} from 'react';
  2. import styled from '@emotion/styled';
  3. import {space} from 'sentry/styles/space';
  4. type TextOverflowProps<T extends ElementType> = ComponentProps<T> & {
  5. children: string;
  6. as?: T;
  7. };
  8. function TextOverflow<T extends ElementType>(props: TextOverflowProps<T>) {
  9. const {children, as: Element = 'div', ...rest} = props;
  10. return (
  11. <Element {...rest} title={children}>
  12. {children}
  13. </Element>
  14. );
  15. }
  16. // TextTruncateOverflow is strictly a css based text truncate component
  17. export const TextTruncateOverflow = styled(TextOverflow)`
  18. min-width: 0;
  19. overflow: hidden;
  20. white-space: nowrap;
  21. text-overflow: ellipsis;
  22. margin-right: ${space(1)};
  23. ` as typeof TextOverflow; // styled wasn't inferring the passed component properly this assertion is sufficient for now