index.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import React from "react";
  2. import { Modal, Stack, Text, ScrollArea, ModalProps } from "@mantine/core";
  3. import { Prism } from "@mantine/prism";
  4. import { shallow } from "zustand/shallow";
  5. import useGraph from "src/store/useGraph";
  6. import { dataToString } from "src/utils/dataToString";
  7. const CodeBlock: React.FC<{ children: any }> = ({ children }) => {
  8. return (
  9. <ScrollArea>
  10. <Prism
  11. maw={600}
  12. miw={350}
  13. mah={250}
  14. language="json"
  15. copyLabel="Copy to clipboard"
  16. copiedLabel="Copied to clipboard"
  17. withLineNumbers
  18. >
  19. {children}
  20. </Prism>
  21. </ScrollArea>
  22. );
  23. };
  24. export const NodeModal: React.FC<ModalProps> = ({ opened, onClose }) => {
  25. const [nodeData, path] = useGraph(
  26. state => [dataToString(state.selectedNode.text), state.selectedNode.path],
  27. shallow
  28. );
  29. return (
  30. <Modal title="Node Content" size="auto" opened={opened} onClose={onClose} centered>
  31. <Stack py="sm" spacing="sm">
  32. <Stack spacing="xs">
  33. <Text fz="sm" fw={700}>
  34. Content
  35. </Text>
  36. <CodeBlock>{nodeData}</CodeBlock>
  37. </Stack>
  38. <Stack spacing="xs">
  39. <Text fz="sm" fw={700}>
  40. Node Path
  41. </Text>
  42. <CodeBlock>{path}</CodeBlock>
  43. </Stack>
  44. </Stack>
  45. </Modal>
  46. );
  47. };