styled.ts 2.2 KB

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