styled.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import styled, { css } from 'styled-components';
  2. const MarkupStyle: Record<string, unknown> = {
  3. Highlight: css<{ isCovered: boolean; bdcolor: string }>`
  4. background-color: ${(props) =>
  5. props.isCovered ? '#297fb8' : props.bdcolor};
  6. `,
  7. Underline: css<{ isCovered: boolean; bdcolor: string; scale: number }>`
  8. border-bottom: ${(props) => props.scale * 2}px solid
  9. ${(props) => (props.isCovered ? '#297fb8' : props.bdcolor)};
  10. `,
  11. Squiggly: css<{ isCovered: boolean; bdcolor: string }>`
  12. overflow: hidden;
  13. &:before {
  14. content: '';
  15. position: absolute;
  16. background: radial-gradient(
  17. ellipse,
  18. transparent,
  19. transparent 8px,
  20. ${(props) => (props.isCovered ? '#297fb8' : props.bdcolor)} 9px,
  21. ${(props) => (props.isCovered ? '#297fb8' : props.bdcolor)} 10px,
  22. transparent 11px
  23. );
  24. background-size: 22px 26px;
  25. width: 100%;
  26. height: 5px;
  27. left: 0;
  28. bottom: 2px;
  29. }
  30. &:after {
  31. content: '';
  32. position: absolute;
  33. background: radial-gradient(
  34. ellipse,
  35. transparent,
  36. transparent 8px,
  37. ${(props) => (props.isCovered ? '#297fb8' : props.bdcolor)} 9px,
  38. ${(props) => (props.isCovered ? '#297fb8' : props.bdcolor)} 10px,
  39. transparent 11px
  40. );
  41. background-size: 22px 26px;
  42. width: 100%;
  43. height: 5px;
  44. bottom: -1px;
  45. left: 11px;
  46. background-position: 0px -22px;
  47. }
  48. `,
  49. StrikeOut: css<{ isCovered: boolean; bdcolor: string; scale: number }>`
  50. &:after {
  51. content: '';
  52. position: absolute;
  53. height: ${(props) => props.scale * 2}px;
  54. width: 100%;
  55. left: 0;
  56. top: 40%;
  57. background-color: ${(props) =>
  58. props.isCovered ? '#297fb8' : props.bdcolor};
  59. }
  60. `,
  61. };
  62. const Markup = styled('div')<{
  63. position: Record<string, number>;
  64. bdcolor: string;
  65. markupType: string;
  66. opacity: number;
  67. isCovered?: boolean;
  68. scale: number;
  69. }>`
  70. position: absolute;
  71. cursor: pointer;
  72. opacity: ${(props) => props.opacity};
  73. ${(props) => css`
  74. top: ${props.position.top}px;
  75. left: ${props.position.left}px;
  76. width: ${props.position.width}px;
  77. height: ${props.position.height}px;
  78. `}
  79. ${(props) => MarkupStyle[props.markupType] as string}
  80. `;
  81. export default Markup;