Connect, collaborate, and grow with a community of TypeScript developers
prettier copy to clipboard dialog
Nikita Krupinaa814079bbcd
diff --git a/src/components/challenge/description-panel.tsx b/src/components/challenge/description-panel.tsxindex 2ae64794..9897a000 100644--- a/src/components/challenge/description-panel.tsx+++ b/src/components/challenge/description-panel.tsx@@ -67,7 +67,6 @@ export function DescriptionPanel({ challenge }: Props) {<TabsTrigger value="solutions">Solutions</TabsTrigger></TabsList><TabsContent value="description" className="mt-0">-<div className="h-full p-5"><TypographyH3 className="mb-2 font-medium">{challenge.name}</TypographyH3><div className="mb-6 flex items-center gap-6">@@ -148,21 +147,21 @@ export function DescriptionPanel({ challenge }: Props) {<DialogContent className="w-[200px]"><DialogHeader><DialogTitle>Share this challenege</DialogTitle>- <div className="py-4">+ <div className="pt-4"><ShareForm /></div></DialogHeader></DialogContent></Dialog></div>- <div className="prose-invert prose-h3:text-xl leading-8">+ <div className="prose-invert leading-8 prose-h3:text-xl">{/* @ts-ignore */}<ReactMarkdownremarkPlugins={[remarkGfm]}components={{p: ({ ...props }) => <p className="mb-4" {...props} />,code({ inline, className, children, ...props }) {- console.log(children)+ console.log(children);const match = /language-(\w+)/.exec(className || '');return !inline && match ? (<SyntaxHighlighter@@ -175,7 +174,7 @@ export function DescriptionPanel({ challenge }: Props) {{String(children).replace(/\n$/, '')}</SyntaxHighlighter>) : (- <code className="rounded-md p-1 bg-neutral-200 dark:bg-black font-mono">+ <code className="rounded-md bg-neutral-200 p-1 font-mono dark:bg-black">{children}</code>);diff --git a/src/components/challenge/share-form.tsx b/src/components/challenge/share-form.tsxindex 43347ca5..d567c91d 100644--- a/src/components/challenge/share-form.tsx+++ b/src/components/challenge/share-form.tsx@@ -1,21 +1,32 @@'use client';-import { Button } from '../ui/button';export function ShareForm() {const url = window.location.href;+ const copyButton = document.getElementById('copy-button') as HTMLButtonElement;const copyToClipboard = async (): Promise<void> => {if (navigator.clipboard) {- await navigator.clipboard.writeText(url);+ try {+ await navigator.clipboard.writeText(url);+ copyButton.textContent = 'Copied!';+ copyButton.classList.add('bg-green-500');+ } catch {+ copyButton.textContent = 'Failed to copy';+ copyButton.classList.add('bg-green-500');+ }}};return (<div><p>Copy this challenge url to share with your friends!</p>- <Button className="block ml-auto mt-4" onClick={() => void copyToClipboard}>+ <button+ id="copy-button"+ className="ml-auto mt-4 block rounded-lg px-3 py-2 text-black duration-300 hover:scale-110 hover:rounded-2xl hover:duration-300 active:scale-95 active:rounded-md active:duration-75 dark:bg-white"+ onClick={() => void copyToClipboard}+ >Copy to Clipboard- </Button>+ </button></div>);}diff --git a/src/components/ui/button.tsx b/src/components/ui/button.tsxindex b387d6fb..2bfcb1e8 100644--- a/src/components/ui/button.tsx+++ b/src/components/ui/button.tsx@@ -1,35 +1,32 @@-import * as React from "react";-import { Slot } from "@radix-ui/react-slot";-import { cva, type VariantProps } from "class-variance-authority";+import * as React from 'react';+import { Slot } from '@radix-ui/react-slot';+import { cva, type VariantProps } from 'class-variance-authority';-import { cn } from "~/utils/cn";+import { cn } from '~/utils/cn';const buttonVariants = cva(- "inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:opacity-50 disabled:pointer-events-none ring-offset-background",+ 'inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:opacity-50 disabled:pointer-events-none ring-offset-background',{variants: {variant: {- default: "bg-primary text-primary-foreground hover:bg-primary/90",- destructive:- "bg-destructive text-destructive-foreground hover:bg-destructive/90",- outline:- "border border-input hover:bg-accent hover:text-accent-foreground",- secondary:- "bg-secondary text-secondary-foreground hover:bg-secondary/80",- ghost: "hover:bg-accent hover:text-accent-foreground",- link: "underline-offset-4 hover:underline text-primary",+ default: 'bg-primary text-primary-foreground hover:bg-primary/90',+ destructive: 'bg-destructive text-destructive-foreground hover:bg-destructive/90',+ outline: 'border border-input hover:bg-accent hover:text-accent-foreground',+ secondary: 'bg-secondary text-secondary-foreground hover:bg-secondary/80',+ ghost: 'hover:bg-accent hover:text-accent-foreground',+ link: 'underline-offset-4 hover:underline text-primary',},size: {- default: "h-10 py-2 px-4",- sm: "h-9 px-3 rounded-md",- lg: "h-11 px-8 rounded-md",+ default: 'h-10 py-2 px-4',+ sm: 'h-9 px-3 rounded-md',+ lg: 'h-11 px-8 rounded-md',},},defaultVariants: {- variant: "default",- size: "default",+ variant: 'default',+ size: 'default',},- }+ },);export interface ButtonProps@@ -40,16 +37,12 @@ export interface ButtonPropsconst Button = React.forwardRef<HTMLButtonElement, ButtonProps>(({ className, variant, size, asChild = false, ...props }, ref) => {- const Comp = asChild ? Slot : "button";+ const Comp = asChild ? Slot : 'button';return (- <Comp- className={cn(buttonVariants({ variant, size, className }))}- ref={ref}- {...props}- />+ <Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} />);- }+ },);-Button.displayName = "Button";+Button.displayName = 'Button';export { Button, buttonVariants };diff --git a/src/components/ui/dialog.tsx b/src/components/ui/dialog.tsxindex bb387f5a..9b58fa96 100644--- a/src/components/ui/dialog.tsx+++ b/src/components/ui/dialog.tsx@@ -39,7 +39,7 @@ const DialogContent = React.forwardRef<<DialogPrimitive.Contentref={ref}className={cn(- 'fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg md:w-full',+ 'fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-3xl md:w-full',className,)}{...props}