stack/packages/stack-ui/src/components/copy-button.tsx
Zai Shi 5d7aab44c1
Better dashboard onboarding process (#604)
<img width="719" alt="image"
src="https://github.com/user-attachments/assets/1a9d10a9-a571-4c61-9702-4cfb4d2efa1c"
/>


<!--

Make sure you've read the CONTRIBUTING.md guidelines:
https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md

-->

<!-- ELLIPSIS_HIDDEN -->


----

> [!IMPORTANT]
> Enhances dashboard onboarding with a new setup page, refactors metrics
components, and improves UI components and code organization.
> 
>   - **Behavior**:
> - Introduces `SetupPage` in `setup-page.tsx` for onboarding, with
framework selection and key generation.
> - Replaces `OnboardingDialog` with `SetupPage` for a more interactive
onboarding experience.
> - `PageClient` in `page-client.tsx` now toggles between `SetupPage`
and `MetricsPage` based on user count.
>   - **UI Components**:
> - Adds `CodeBlock` component in `code-block.tsx` for displaying code
snippets with syntax highlighting.
> - Enhances `EnvKeys` in `env-keys.tsx` to support downloading keys and
displaying them in tabs.
> - Introduces `InlineCode` component in `inline-code.tsx` for inline
code styling.
>   - **Refactoring**:
> - Moves metrics-related components to `(overview)/(metrics)`
directory.
> - Renames and reorganizes files for better structure, e.g.,
`globe.tsx` and `line-chart.tsx`.
> - Updates `SidebarLayout` and `PageLayout` for improved layout
handling.
>   - **Dependencies**:
> - Adds `react-syntax-highlighter` and its types to `package.json` for
code highlighting.
>   - **Misc**:
>     - Updates `theme.tsx` to improve theme watching logic.
> - Fixes minor issues and improves code readability across several
files.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=stack-auth%2Fstack-auth&utm_source=github&utm_medium=referral)<sup>
for 194d1ef8da. You can
[customize](https://app.ellipsis.dev/stack-auth/settings/summaries) this
summary. It will automatically update as commits are pushed.</sup>


<!-- ELLIPSIS_HIDDEN -->

---------

Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
2025-06-06 10:51:08 +02:00

37 lines
992 B
TypeScript

"use client";
import { forwardRefIfNeeded } from "@stackframe/stack-shared/dist/utils/react";
import { Copy } from "lucide-react";
import React from "react";
import { Button, cn, useToast } from "..";
const CopyButton = forwardRefIfNeeded<
React.ElementRef<typeof Button>,
React.ComponentProps<typeof Button> & { content: string }
>((props, ref) => {
const { toast } = useToast();
return (
<Button
variant="secondary"
{...props}
className={cn("h-6 w-6 p-1", props.className)}
ref={ref}
onClick={async (...args) => {
await props.onClick?.(...args);
try {
await navigator.clipboard.writeText(props.content);
toast({ description: 'Copied to clipboard!', variant: 'success' });
} catch (e) {
toast({ description: 'Failed to copy to clipboard', variant: 'destructive' });
}
}}
>
<Copy />
</Button>
);
});
CopyButton.displayName = "CopyButton";
export { CopyButton };