styles.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { LinkItUrl } from "react-linkify-it";
  2. import styled, { DefaultTheme } from "styled-components";
  3. function getTypeColor(value: string, theme: DefaultTheme) {
  4. if (!Number.isNaN(+value)) return theme.NODE_COLORS.INTEGER;
  5. if (value === "true") return theme.NODE_COLORS.BOOL.TRUE;
  6. if (value === "false") return theme.NODE_COLORS.BOOL.FALSE;
  7. if (value === "null") return theme.NODE_COLORS.NULL;
  8. return theme.NODE_COLORS.NODE_VALUE;
  9. }
  10. export const StyledLinkItUrl = styled(LinkItUrl)`
  11. text-decoration: underline;
  12. pointer-events: all;
  13. `;
  14. export const StyledForeignObject = styled.foreignObject<{
  15. hasCollapse?: boolean;
  16. hideCollapse?: boolean;
  17. isObject?: boolean;
  18. }>`
  19. text-align: ${({ isObject }) => !isObject && "center"};
  20. font-size: 12px;
  21. overflow: hidden;
  22. color: ${({ theme }) => theme.NODE_COLORS.TEXT};
  23. pointer-events: none;
  24. padding: ${({ isObject }) => isObject && "10px"};
  25. * {
  26. font-family: "Roboto Mono", monospace;
  27. }
  28. &.searched {
  29. border: 2px solid ${({ theme }) => theme.TEXT_POSITIVE};
  30. border-radius: 2px;
  31. box-sizing: border-box;
  32. }
  33. .highlight {
  34. border: 2px dashed #ff2970;
  35. background: rgba(255, 214, 0, 0.3);
  36. }
  37. .renderVisible {
  38. display: flex;
  39. justify-content: center;
  40. align-items: center;
  41. font-size: 12px;
  42. width: 100%;
  43. height: 100%;
  44. overflow: hidden;
  45. cursor: pointer;
  46. }
  47. `;
  48. function getKeyColor(
  49. theme: DefaultTheme,
  50. parent: "array" | "object" | false,
  51. objectKey: boolean
  52. ) {
  53. if (parent) {
  54. if (parent === "array") return theme.NODE_COLORS.PARENT_ARR;
  55. return theme.NODE_COLORS.PARENT_OBJ;
  56. }
  57. if (objectKey) return theme.NODE_COLORS.NODE_KEY;
  58. return theme.NODE_COLORS.TEXT;
  59. }
  60. export const StyledKey = styled.span<{
  61. objectKey?: boolean;
  62. parent?: "array" | "object" | false;
  63. value?: string;
  64. }>`
  65. display: inline;
  66. flex: 1;
  67. font-weight: 500;
  68. color: ${({ theme, objectKey = false, parent = false }) =>
  69. getKeyColor(theme, parent, 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-key": string;
  77. theme: DefaultTheme;
  78. }>(props => ({
  79. style: {
  80. color: getTypeColor(props["data-key"], props.theme),
  81. },
  82. }))<{ "data-key": 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. `;