Cursor.jsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import React from "react";
  2. import styled from "styled-components";
  3. import { readableColorIsBlack } from "color2k";
  4. const StyledCursor = styled.div.attrs(({ top, left }) => ({
  5. style: {
  6. transform: `translate(${left}px, ${top}px)`,
  7. },
  8. }))`
  9. top: 0;
  10. left: 0;
  11. position: fixed;
  12. display: flex;
  13. flex-direction: row;
  14. align-items: center;
  15. z-index: 210;
  16. `;
  17. const CursorName = styled.div`
  18. color: ${({ textColor }) => textColor};
  19. font-weight: bold;
  20. padding: 0 0.5em;
  21. border-radius: 2px;
  22. max-width: 5em;
  23. overflow: hidden;
  24. text-overflow: ellipsis;
  25. margin-left: -0.5em;
  26. margin-top: 1.7em;
  27. whitespace: nowrap;
  28. background-color: ${({ color }) => color};
  29. `;
  30. export const Cursor = ({ color = "#666", size = 40, pos, text }) => {
  31. const textColor = readableColorIsBlack(color) ? "#222" : "#EEE";
  32. return (
  33. <StyledCursor top={pos.y - 10} left={pos.x - 5}>
  34. <svg
  35. version="1.1"
  36. id="Layer_1"
  37. xmlns="http://www.w3.org/2000/svg"
  38. viewBox="1064.7701 445.5539 419.8101 717.0565"
  39. width={size}
  40. height={size}
  41. >
  42. <path
  43. d="m 1197.1015,869.718 -62.2719,-154.49286 133.3276,-9.05842 -257.6915,-253.12748 1.2392,356.98609 88.2465,-79.47087 61.702,152.78366 z"
  44. style={{
  45. fill: textColor,
  46. }}
  47. />
  48. <path
  49. d="m 1193.0939,861.12419 -62.2719,-154.49286 133.3276,-9.05842 -257.6915,-253.12748 1.2392,356.98609 88.2465,-79.47087 61.702,152.78366 z"
  50. style={{
  51. fill: "white",
  52. stroke: "#111",
  53. strokeWidth: 20,
  54. }}
  55. />
  56. </svg>
  57. <CursorName color={color} textColor={textColor}>
  58. {text}
  59. </CursorName>
  60. </StyledCursor>
  61. );
  62. };
  63. export default Cursor;