utils.tsx 1.9 KB

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