utils.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import {css} from '@emotion/react';
  2. import space from 'sentry/styles/space';
  3. import {Theme} from 'sentry/utils/theme';
  4. const bulletStyle = (theme: Theme) => css`
  5. padding-left: ${space(3)};
  6. list-style-type: circle;
  7. & > li::marker {
  8. color: ${theme.subText};
  9. }
  10. `;
  11. type Options = {
  12. // setting initialCounterValue to 0 means the first visible step is 1
  13. initialCounterValue?: number;
  14. isSolid?: boolean;
  15. };
  16. const numericStyle = (
  17. theme: Theme,
  18. {isSolid = false, initialCounterValue = 0}: Options
  19. ) => css`
  20. & > li {
  21. padding-left: ${space(4)};
  22. :before {
  23. border-radius: 50%;
  24. position: absolute;
  25. counter-increment: numberedList;
  26. content: counter(numberedList);
  27. display: flex;
  28. align-items: center;
  29. justify-content: center;
  30. text-align: center;
  31. left: 0;
  32. line-height: 1;
  33. ${isSolid
  34. ? css`
  35. width: 24px;
  36. height: 24px;
  37. font-weight: 500;
  38. font-size: ${theme.fontSizeSmall};
  39. background-color: ${theme.yellow300};
  40. color: ${theme.black};
  41. `
  42. : css`
  43. top: 3px;
  44. width: 18px;
  45. height: 18px;
  46. font-weight: 600;
  47. font-size: 10px;
  48. border: 1px solid ${theme.gray500};
  49. `}
  50. }
  51. }
  52. counter-reset: numberedList ${initialCounterValue};
  53. `;
  54. export const listSymbol = {
  55. numeric: 'numeric',
  56. 'colored-numeric': 'colored-numeric',
  57. bullet: 'bullet',
  58. };
  59. export function getListSymbolStyle(
  60. theme: Theme,
  61. symbol: keyof typeof listSymbol,
  62. initialCounterValue?: number
  63. ) {
  64. switch (symbol) {
  65. case 'numeric':
  66. return numericStyle(theme, {initialCounterValue});
  67. case 'colored-numeric':
  68. return numericStyle(theme, {isSolid: true, initialCounterValue});
  69. default:
  70. return bulletStyle(theme);
  71. }
  72. }