querySymbol.tsx 895 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import styled from '@emotion/styled';
  2. import {space} from 'sentry/styles/space';
  3. const indexToChar = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  4. export const getQuerySymbol = (index: number) => {
  5. let result = '';
  6. let i = index;
  7. do {
  8. result = indexToChar[i % indexToChar.length] + result;
  9. i = Math.floor(i / indexToChar.length) - 1;
  10. } while (i >= 0);
  11. return result;
  12. };
  13. const Symbol = styled('div')`
  14. display: flex;
  15. width: 16px;
  16. height: 16px;
  17. padding: ${space(0.5)};
  18. justify-content: center;
  19. align-items: center;
  20. flex-shrink: 0;
  21. border-radius: 50%;
  22. font-weight: 500;
  23. color: ${p => p.theme.black};
  24. font-size: 10px;
  25. background: ${p => p.theme.yellow300};
  26. `;
  27. export function QuerySymbol({
  28. index,
  29. ...props
  30. }: React.ComponentProps<typeof Symbol> & {index: number}) {
  31. return (
  32. <Symbol {...props}>
  33. <span>{getQuerySymbol(index)}</span>
  34. </Symbol>
  35. );
  36. }