From b886e8eeec8a8b5a9781efa3bdebcd02aea5817e Mon Sep 17 00:00:00 2001 From: Gerard Clos Date: Thu, 26 Sep 2024 18:45:27 +0200 Subject: [PATCH] minor: abstract copy button --- .../_components/WorkspaceApiKeys/index.tsx | 15 +++++++++++---- packages/web-ui/src/ds/atoms/CodeBlock/index.tsx | 4 ++-- .../CopyButton.tsx => CopyButton/index.tsx} | 14 +++++++++----- packages/web-ui/src/ds/atoms/Table/index.tsx | 6 ++++-- packages/web-ui/src/ds/atoms/index.ts | 1 + 5 files changed, 27 insertions(+), 13 deletions(-) rename packages/web-ui/src/ds/atoms/{CodeBlock/CopyButton.tsx => CopyButton/index.tsx} (57%) diff --git a/apps/web/src/app/(private)/settings/_components/WorkspaceApiKeys/index.tsx b/apps/web/src/app/(private)/settings/_components/WorkspaceApiKeys/index.tsx index a6be9933b..b09dbc767 100644 --- a/apps/web/src/app/(private)/settings/_components/WorkspaceApiKeys/index.tsx +++ b/apps/web/src/app/(private)/settings/_components/WorkspaceApiKeys/index.tsx @@ -2,6 +2,7 @@ import { Button, + CopyButton, Icon, Table, TableBody, @@ -34,7 +35,7 @@ export default function WorkspaceApiKeys() { {apiKeys.map((apiKey) => ( - + {apiKey.name || 'Unnamed API Key'} @@ -50,9 +51,15 @@ export default function WorkspaceApiKeys() { }) }} > - - {apiKey.token} - +
+ + {apiKey.token} + + +
} > diff --git a/packages/web-ui/src/ds/atoms/CodeBlock/index.tsx b/packages/web-ui/src/ds/atoms/CodeBlock/index.tsx index 9eb04f014..ad3da083d 100644 --- a/packages/web-ui/src/ds/atoms/CodeBlock/index.tsx +++ b/packages/web-ui/src/ds/atoms/CodeBlock/index.tsx @@ -3,7 +3,7 @@ import React from 'react' import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter' import { oneLight } from 'react-syntax-highlighter/dist/esm/styles/prism' -import { CopyButton } from './CopyButton' +import { CopyButton } from '../CopyButton' interface CodeBlockProps { language: string @@ -14,7 +14,7 @@ export function CodeBlock({ language, children }: CodeBlockProps) { return (
- +
& { content: string } -export function CopyButton({ content }: CopyButtonProps) { +export function CopyButton({ + content, + color = 'foregroundMuted', + ...rest +}: CopyButtonProps) { const { toast } = useToast() const handleCopy = () => { @@ -23,8 +27,8 @@ export function CopyButton({ content }: CopyButtonProps) { } return ( - ) } diff --git a/packages/web-ui/src/ds/atoms/Table/index.tsx b/packages/web-ui/src/ds/atoms/Table/index.tsx index d1727fea4..77152cc36 100644 --- a/packages/web-ui/src/ds/atoms/Table/index.tsx +++ b/packages/web-ui/src/ds/atoms/Table/index.tsx @@ -68,14 +68,16 @@ const TableRow = forwardRef< HTMLTableRowElement, HTMLAttributes & { verticalPadding?: boolean + hoverable?: boolean } ->(({ className, verticalPadding, ...props }, ref) => ( +>(({ className, verticalPadding, hoverable = true, ...props }, ref) => ( td]:py-4': verticalPadding, + 'hover:bg-muted/50': hoverable, }, className, )} diff --git a/packages/web-ui/src/ds/atoms/index.ts b/packages/web-ui/src/ds/atoms/index.ts index 3a2178fac..635370bdc 100644 --- a/packages/web-ui/src/ds/atoms/index.ts +++ b/packages/web-ui/src/ds/atoms/index.ts @@ -31,3 +31,4 @@ export * from './DropzoneInput' export * from './Charts' export * from './CircularProgress' export * from './CodeBlock' +export * from './CopyButton'