Skip to content

Commit

Permalink
refactor: Update dependencies for @radix-ui/react-dialog and @radix-u…
Browse files Browse the repository at this point in the history
…i/react-label
  • Loading branch information
emapeire committed May 15, 2024
1 parent 83597f1 commit 08fbb73
Show file tree
Hide file tree
Showing 7 changed files with 322 additions and 15 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
},
"dependencies": {
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-tooltip": "^1.0.7",
"@vercel/analytics": "^1.2.2",
Expand Down
65 changes: 65 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions src/components/contact-dialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Copy } from 'lucide-react'

import { Button } from '@/components/ui/button'
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger
} from '@/components/ui/dialog'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'

export function ContactDialog() {
return (
<Dialog>
<DialogTrigger asChild>
<Button
variant='ghost'
size={null}
className='font-semibold py-2 md:px-4 px-2'
>
Contact
</Button>
</DialogTrigger>
<DialogContent className='sm:max-w-md'>
<DialogHeader>
<DialogTitle>Share link</DialogTitle>
<DialogDescription>
Anyone who has this link will be able to view this.
</DialogDescription>
</DialogHeader>
<div className='flex items-center space-x-2'>
<div className='grid flex-1 gap-2'>
<Label htmlFor='link' className='sr-only'>
Link
</Label>
<Input
id='link'
defaultValue='https://ui.shadcn.com/docs/installation'
readOnly
/>
</div>
<Button type='submit' size='sm' className='px-3'>
<span className='sr-only'>Copy</span>
<Copy className='h-4 w-4' />
</Button>
</div>
<DialogFooter className='sm:justify-start'>
<DialogClose asChild>
<Button type='button' variant='secondary'>
Close
</Button>
</DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
35 changes: 20 additions & 15 deletions src/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import { usePathname } from 'next/navigation'
import { Link } from 'next-view-transitions'
import { ContactDialog } from './contact-dialog'
import { ModeToggle } from './mode-toggle'
import clsx from 'clsx'
import { links } from '@/constants'
import { Button } from './ui/button'

export function Header() {
const pathname = usePathname()
Expand All @@ -14,22 +16,25 @@ export function Header() {
<div className='flex items-center justify-between w-full md:max-w-3xl mx-4'>
<nav className='flex justify-center items-center'>
{links.map((link) => (
<Link
key={link.label}
aria-label={link.label}
href={link.url}
className={clsx(
'relative block me-2 transition-colors ease-in-out py-2 md:px-4 px-2 rounded-md text-sm font-semibold text-neutral-800 dark:text-neutral-100',
{
'bg-neutral-100 dark:bg-neutral-800': pathname === link.url,
'hover:bg-neutral-100 dark:hover:bg-neutral-800':
pathname !== link.url
}
)}
>
{link.title}
</Link>
<Button asChild variant='ghost' size={null} key={link.label}>
<Link
key={link.label}
aria-label={link.label}
href={link.url}
className={clsx(
'relative block me-2 py-2 md:px-4 px-2 font-semibold',
{
'bg-neutral-100 dark:bg-neutral-800': pathname === link.url,
'hover:bg-neutral-100 dark:hover:bg-neutral-800':
pathname !== link.url
}
)}
>
{link.title}
</Link>
</Button>
))}
<ContactDialog />
</nav>
<div className='flex items-center'>
<ModeToggle />
Expand Down
122 changes: 122 additions & 0 deletions src/components/ui/dialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
'use client'

import * as React from 'react'
import * as DialogPrimitive from '@radix-ui/react-dialog'
import { X } from 'lucide-react'

import { cn } from '@/lib/utils'

const Dialog = DialogPrimitive.Root

const DialogTrigger = DialogPrimitive.Trigger

const DialogPortal = DialogPrimitive.Portal

const DialogClose = DialogPrimitive.Close

const DialogOverlay = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Overlay
ref={ref}
className={cn(
'fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
className
)}
{...props}
/>
))
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName

const DialogContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Content
ref={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',
className
)}
{...props}
>
{children}
<DialogPrimitive.Close className='absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground'>
<X className='h-4 w-4' />
<span className='sr-only'>Close</span>
</DialogPrimitive.Close>
</DialogPrimitive.Content>
</DialogPortal>
))
DialogContent.displayName = DialogPrimitive.Content.displayName

const DialogHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
'flex flex-col space-y-1.5 text-center sm:text-left',
className
)}
{...props}
/>
)
DialogHeader.displayName = 'DialogHeader'

const DialogFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
'flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2',
className
)}
{...props}
/>
)
DialogFooter.displayName = 'DialogFooter'

const DialogTitle = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Title
ref={ref}
className={cn(
'text-lg font-semibold leading-none tracking-tight',
className
)}
{...props}
/>
))
DialogTitle.displayName = DialogPrimitive.Title.displayName

const DialogDescription = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Description
ref={ref}
className={cn('text-sm text-muted-foreground', className)}
{...props}
/>
))
DialogDescription.displayName = DialogPrimitive.Description.displayName

export {
Dialog,
DialogPortal,
DialogOverlay,
DialogClose,
DialogTrigger,
DialogContent,
DialogHeader,
DialogFooter,
DialogTitle,
DialogDescription
}
25 changes: 25 additions & 0 deletions src/components/ui/input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as React from "react"

import { cn } from "@/lib/utils"

export interface InputProps
extends React.InputHTMLAttributes<HTMLInputElement> {}

const Input = React.forwardRef<HTMLInputElement, InputProps>(
({ className, type, ...props }, ref) => {
return (
<input
type={type}
className={cn(
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
className
)}
ref={ref}
{...props}
/>
)
}
)
Input.displayName = "Input"

export { Input }
Loading

0 comments on commit 08fbb73

Please sign in to comment.