A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
add floating copy button to mo.ui.dataframe (#280)
Myles Scolnick78658bfb931f
diff --git a/frontend/src/plugins/impl/data-frames/DataFramePlugin.tsx b/frontend/src/plugins/impl/data-frames/DataFramePlugin.tsxindex c01e3e2d6a..9718f1f9a0 100644--- a/frontend/src/plugins/impl/data-frames/DataFramePlugin.tsx+++ b/frontend/src/plugins/impl/data-frames/DataFramePlugin.tsx@@ -131,7 +131,7 @@ export const DataFrameComponent = ({</TabsList><TabsContentvalue="transform"- className="mt-1 border-x border-t rounded-t"+ className="mt-1 border rounded-t overflow-hidden"><TransformPanelinitialValue={internalValue}@@ -147,7 +147,7 @@ export const DataFrameComponent = ({</TabsContent><TabsContentvalue="code"- className="mt-1 border-x border-t rounded-t overflow-hidden"+ className="mt-1 border rounded-t overflow-hidden"><CodePanel dataframeName={dataframeName} transforms={value} /></TabsContent>diff --git a/frontend/src/plugins/impl/data-frames/python/code-panel.tsx b/frontend/src/plugins/impl/data-frames/python/code-panel.tsxindex a4a2d75005..b425366cae 100644--- a/frontend/src/plugins/impl/data-frames/python/code-panel.tsx+++ b/frontend/src/plugins/impl/data-frames/python/code-panel.tsx@@ -2,8 +2,13 @@import React from "react";import { Transformations } from "../schema";import { python } from "@codemirror/lang-python";-import CodeMirror from "@uiw/react-codemirror";+import CodeMirror, { EditorView } from "@uiw/react-codemirror";import { pythonPrintTransforms } from "./python-print";+import { CopyIcon } from "lucide-react";+import { Button } from "@/components/ui/button";+import { Events } from "@/utils/events";+import { toast } from "@/components/ui/use-toast";+import { useThemeForPlugin } from "@/theme/useTheme";interface Props {dataframeName: string;@@ -23,16 +28,37 @@ export const CodePanel: React.FC<Props> = ({ transforms, dataframeName }) => {};const PythonCode = (props: { code: string }) => {+ const { theme } = useThemeForPlugin();return (- <div className="border-t border-x rounded-t overflow-hidden">+ <div className="relative min-h-[200px]">+ <FloatingCopyButton text={props.code} /><CodeMirrorminHeight="200px"+ className="cm"+ theme={theme === "dark" ? "dark" : "light"}height="100%"editable={true}- extensions={[python()]}+ extensions={[python(), EditorView.lineWrapping]}value={props.code}readOnly={true}/></div>);};++const FloatingCopyButton = (props: { text: string }) => {+ const copy = Events.stopPropagation(() => {+ navigator.clipboard.writeText(props.text);+ toast({ title: "Copied to clipboard" });+ });++ return (+ <Button+ onClick={copy}+ className="absolute top-0 right-0 m-2 z-10"+ variant="secondary"+ >+ <CopyIcon size={16} strokeWidth={1.5} />+ </Button>+ );+};