eventTitleTreeLabel.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import overflowEllipsis from 'app/styles/overflowEllipsis';
  4. import space from 'app/styles/space';
  5. import {TreeLabelPart} from 'app/types';
  6. import {formatTreeLabelPart} from 'app/utils/events';
  7. type Props = {
  8. treeLabel: TreeLabelPart[];
  9. };
  10. function EventTitleTreeLabel({treeLabel}: Props) {
  11. const firstFourParts = treeLabel.slice(0, 4);
  12. const remainingParts = treeLabel.slice(firstFourParts.length);
  13. return (
  14. <Wrapper>
  15. <FirstFourParts>
  16. {firstFourParts.map((part, index) => {
  17. if (index !== firstFourParts.length - 1) {
  18. return (
  19. <Fragment key={index}>
  20. <PriorityPart>{formatTreeLabelPart(part)}</PriorityPart>
  21. <Divider>{'|'}</Divider>
  22. </Fragment>
  23. );
  24. }
  25. return <PriorityPart key={index}>{formatTreeLabelPart(part)}</PriorityPart>;
  26. })}
  27. </FirstFourParts>
  28. {!!remainingParts.length && (
  29. <RemainingLabels>
  30. {remainingParts.map((part, index) => {
  31. return (
  32. <Fragment key={index}>
  33. <Divider>{'|'}</Divider>
  34. {formatTreeLabelPart(part)}
  35. </Fragment>
  36. );
  37. })}
  38. </RemainingLabels>
  39. )}
  40. </Wrapper>
  41. );
  42. }
  43. export default EventTitleTreeLabel;
  44. const Wrapper = styled('span')`
  45. display: inline-grid;
  46. grid-template-columns: auto 1fr;
  47. `;
  48. const FirstFourParts = styled('span')`
  49. display: grid;
  50. grid-auto-flow: column;
  51. `;
  52. const PriorityPart = styled('div')`
  53. ${overflowEllipsis}
  54. `;
  55. const RemainingLabels = styled('div')`
  56. ${overflowEllipsis}
  57. min-width: 50px;
  58. `;
  59. const Divider = styled('span')`
  60. color: ${p => p.theme.gray200};
  61. display: inline-block;
  62. margin: 0 ${space(1)};
  63. `;