styles.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { Roboto_Mono } from "next/font/google";
  2. import { LinkItUrl } from "react-linkify-it";
  3. import styled, { DefaultTheme } from "styled-components";
  4. const robotoMono = Roboto_Mono({
  5. weight: "500",
  6. subsets: ["latin"],
  7. display: "swap",
  8. fallback: ["Arial, Helvetica, sans-serif", "Tahoma, Verdana, sans-serif"],
  9. });
  10. function getTypeColor(value: string, theme: DefaultTheme) {
  11. if (!Number.isNaN(+value)) return theme.NODE_COLORS.INTEGER;
  12. if (value === "true") return theme.NODE_COLORS.BOOL.TRUE;
  13. if (value === "false") return theme.NODE_COLORS.BOOL.FALSE;
  14. if (value === "null") return theme.NODE_COLORS.NULL;
  15. return theme.NODE_COLORS.NODE_VALUE;
  16. }
  17. export const StyledLinkItUrl = styled(LinkItUrl)`
  18. text-decoration: underline;
  19. pointer-events: all;
  20. `;
  21. export const StyledForeignObject = styled.foreignObject<{
  22. hasCollapse?: boolean;
  23. isObject?: boolean;
  24. }>`
  25. text-align: ${({ isObject }) => !isObject && "center"};
  26. font-size: 12px;
  27. overflow: hidden;
  28. color: ${({ theme }) => theme.NODE_COLORS.TEXT};
  29. pointer-events: none;
  30. padding: ${({ isObject }) => isObject && "10px"};
  31. font-family: ${robotoMono.style.fontFamily};
  32. &.searched {
  33. border: 2px solid ${({ theme }) => theme.TEXT_POSITIVE};
  34. border-radius: 2px;
  35. box-sizing: border-box;
  36. }
  37. .highlight {
  38. background: rgba(255, 214, 0, 0.3);
  39. }
  40. .renderVisible {
  41. display: flex;
  42. justify-content: center;
  43. align-items: center;
  44. font-size: 12px;
  45. width: 100%;
  46. height: 100%;
  47. overflow: hidden;
  48. cursor: pointer;
  49. }
  50. `;
  51. function getKeyColor(theme: DefaultTheme, parent: boolean, type: string, objectKey: boolean) {
  52. if (parent) {
  53. if (type === "array") return theme.NODE_COLORS.PARENT_ARR;
  54. return theme.NODE_COLORS.PARENT_OBJ;
  55. }
  56. if (objectKey) return theme.NODE_COLORS.NODE_KEY;
  57. return theme.NODE_COLORS.TEXT;
  58. }
  59. export const StyledKey = styled.span<{
  60. objectKey?: boolean;
  61. parent?: boolean;
  62. type?: string;
  63. value?: string;
  64. }>`
  65. display: inline;
  66. flex: 1;
  67. font-weight: 500;
  68. color: ${({ theme, type = "null", objectKey = false, parent = false }) =>
  69. getKeyColor(theme, parent, type, objectKey)};
  70. font-size: ${({ parent }) => parent && "14px"};
  71. overflow: hidden;
  72. text-overflow: ellipsis;
  73. padding: ${({ objectKey }) => !objectKey && 10}px;
  74. `;
  75. export const StyledRow = styled.span.attrs<{
  76. "data-type": string;
  77. theme: DefaultTheme;
  78. }>(props => ({
  79. style: {
  80. color: getTypeColor(props["data-type"], props.theme),
  81. },
  82. }))<{ "data-type": string; theme: DefaultTheme }>`
  83. display: block;
  84. height: 18px;
  85. overflow: hidden;
  86. text-overflow: ellipsis;
  87. white-space: nowrap;
  88. padding: 0 auto;
  89. `;
  90. export const StyledChildrenCount = styled.span`
  91. color: ${({ theme }) => theme.NODE_COLORS.CHILD_COUNT};
  92. padding: 10px;
  93. margin-left: -15px;
  94. `;