You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/04/13 16:55:59 UTC

[GitHub] [airflow] bbovenzi commented on a diff in pull request #22988: Add a clipboard button to grid details

bbovenzi commented on code in PR #22988:
URL: https://github.com/apache/airflow/pull/22988#discussion_r849701867


##########
airflow/www/static/js/tree/Clipboard.jsx:
##########
@@ -0,0 +1,64 @@
+import React from 'react';
+import {
+  Box,
+  Button,
+  IconButton,
+  Tooltip,
+  useClipboard,
+  forwardRef,
+} from '@chakra-ui/react';
+import { FiCopy } from 'react-icons/fi';
+
+import { useContainerRef } from './context/containerRef';
+
+export const ClipboardButton = forwardRef(
+  (
+    {
+      value,
+      variant = 'outline',
+      iconOnly = false,
+      label = 'copy',
+      title = 'Copy',
+      'aria-label': ariaLabel = 'Copy',
+      ...rest
+    },
+    ref,
+  ) => {
+    const { hasCopied, onCopy } = useClipboard(value);
+    const containerRef = useContainerRef();
+
+    const commonProps = {
+      onClick: onCopy,
+      variant,
+      title,
+      ref,
+      ...rest,
+    };
+
+    return (
+      <Tooltip
+        label="Copied"
+        isOpen={hasCopied}
+        isDisabled={!hasCopied}
+        closeDelay={500}
+        placement="top"
+        portalProps={{ containerRef }}
+      >
+        {iconOnly ? (
+          <IconButton icon={<FiCopy />} aria-label={ariaLabel} {...commonProps} />
+        ) : (
+          <Button leftIcon={<FiCopy />} {...commonProps}>
+            {label}
+          </Button>
+        )}
+      </Tooltip>
+    );
+  },
+);
+
+export const ClipboardText = ({ value }) => (
+  <Box as="span">
+    {value}
+    <ClipboardButton value={value} iconOnly variant="ghost" size="xs" fontSize="lg" ml={1} />
+  </Box>

Review Comment:
   Good idea! Fixed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org