From e62deaf17cfba1cffebbf96d3d6ad2a3880af388 Mon Sep 17 00:00:00 2001 From: James Ritchie Date: Fri, 11 Mar 2022 13:37:05 +0000 Subject: [PATCH] Added a copy text button to a json preview --- app/components/CopyText.tsx | 2 +- app/components/JsonPreview.tsx | 23 ++++++++++++++++++-- app/components/Preview/PreviewBox.tsx | 2 +- app/components/Preview/Types/PreviewJson.tsx | 6 ++--- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/components/CopyText.tsx b/app/components/CopyText.tsx index b73ba9b..4a8cc80 100644 --- a/app/components/CopyText.tsx +++ b/app/components/CopyText.tsx @@ -21,7 +21,7 @@ export function CopyText({ }, [value]); return ( -
+
{children}
); diff --git a/app/components/JsonPreview.tsx b/app/components/JsonPreview.tsx index fe74fdb..e7ab427 100644 --- a/app/components/JsonPreview.tsx +++ b/app/components/JsonPreview.tsx @@ -10,9 +10,12 @@ import { TransactionSpec, } from "@uiw/react-codemirror"; import jsonMap from "json-source-map"; -import { useRef, useEffect, useMemo } from "react"; +import { useRef, useEffect, useMemo, useState } from "react"; import { getPreviewSetup } from "~/utilities/codeMirrorSetup"; import { lightTheme, darkTheme } from "~/utilities/codeMirrorTheme"; +import { CopyTextButton } from "./CopyTextButton"; +import { OpenInNewWindow } from "./OpenInWindow"; +import { Body } from "./Primitives/Body"; import { useTheme } from "./ThemeProvider"; export type JsonPreviewProps = { @@ -89,9 +92,25 @@ export function JsonPreview({ json, highlightPath }: JsonPreviewProps) { view.dispatch(transactionSpec); }, [view, highlighting, jsonMapped, highlightPath]); + const [hovering, setHovering] = useState(false); + return ( -
+
setHovering(true)} + onMouseLeave={() => setHovering(false)} + >
+
+ +
); } diff --git a/app/components/Preview/PreviewBox.tsx b/app/components/Preview/PreviewBox.tsx index 6991d51..f8dd02e 100644 --- a/app/components/Preview/PreviewBox.tsx +++ b/app/components/Preview/PreviewBox.tsx @@ -13,7 +13,7 @@ export function PreviewBox({ link, className, children }: PreviewBoxProps) { Preview diff --git a/app/components/Preview/Types/PreviewJson.tsx b/app/components/Preview/Types/PreviewJson.tsx index 5647531..bdf5ff9 100644 --- a/app/components/Preview/Types/PreviewJson.tsx +++ b/app/components/Preview/Types/PreviewJson.tsx @@ -20,7 +20,7 @@ export function PreviewJson({ preview }: { preview: PreviewJson }) { return (
setHovering(true)} onMouseLeave={() => setHovering(false)} > @@ -32,11 +32,11 @@ export function PreviewJson({ preview }: { preview: PreviewJson }) { > Open in tab