Skip to content

Commit e57a6af

Browse files
committed
Update to latest version of @shadcn/ui dialogs
1 parent 656ab2f commit e57a6af

File tree

6 files changed

+201
-182
lines changed

6 files changed

+201
-182
lines changed

webview-ui/package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/components/history/DeleteTaskDialog.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import React from "react"
1+
import { useCallback } from "react"
2+
import { AlertDialogProps } from "@radix-ui/react-alert-dialog"
3+
4+
import { vscode } from "@/utils/vscode"
25
import {
36
AlertDialog,
47
AlertDialogAction,
@@ -8,24 +11,23 @@ import {
811
AlertDialogFooter,
912
AlertDialogHeader,
1013
AlertDialogTitle,
11-
} from "@/components/ui/alert-dialog"
12-
import { Button } from "@/components/ui"
13-
import { vscode } from "@/utils/vscode"
14+
Button,
15+
} from "@/components/ui"
1416

15-
interface DeleteTaskDialogProps {
17+
interface DeleteTaskDialogProps extends AlertDialogProps {
1618
taskId: string
17-
open: boolean
18-
onOpenChange: (open: boolean) => void
1919
}
2020

21-
export const DeleteTaskDialog = ({ taskId, open, onOpenChange }: DeleteTaskDialogProps) => {
22-
const handleDelete = () => {
21+
export const DeleteTaskDialog = ({ taskId, ...props }: DeleteTaskDialogProps) => {
22+
const { onOpenChange } = props
23+
24+
const onDelete = useCallback(() => {
2325
vscode.postMessage({ type: "deleteTaskWithId", text: taskId })
24-
onOpenChange(false)
25-
}
26+
onOpenChange?.(false)
27+
}, [taskId, onOpenChange])
2628

2729
return (
28-
<AlertDialog open={open} onOpenChange={onOpenChange}>
30+
<AlertDialog {...props}>
2931
<AlertDialogContent>
3032
<AlertDialogHeader>
3133
<AlertDialogTitle>Delete Task</AlertDialogTitle>
@@ -38,7 +40,7 @@ export const DeleteTaskDialog = ({ taskId, open, onOpenChange }: DeleteTaskDialo
3840
<Button variant="secondary">Cancel</Button>
3941
</AlertDialogCancel>
4042
<AlertDialogAction asChild>
41-
<Button variant="destructive" onClick={handleDelete}>
43+
<Button variant="destructive" onClick={onDelete}>
4244
Delete
4345
</Button>
4446
</AlertDialogAction>

webview-ui/src/components/history/HistoryView.tsx

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { memo, useMemo, useState, useEffect } from "react"
2-
import { DeleteTaskDialog } from "./DeleteTaskDialog"
32
import { Fzf } from "fzf"
43
import prettyBytes from "pretty-bytes"
54
import { Virtuoso } from "react-virtuoso"
@@ -11,6 +10,7 @@ import { formatLargeNumber } from "../../utils/format"
1110
import { highlightFzfMatch } from "../../utils/highlight"
1211
import { useCopyToClipboard } from "../../utils/clipboard"
1312
import { Button } from "../ui"
13+
import { DeleteTaskDialog } from "./DeleteTaskDialog"
1414

1515
type HistoryViewProps = {
1616
onDone: () => void
@@ -34,31 +34,14 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
3434
}
3535
}, [searchQuery, sortOption, lastNonRelevantSort])
3636

37-
const handleHistorySelect = (id: string) => {
38-
vscode.postMessage({ type: "showTaskWithId", text: id })
39-
}
37+
const handleHistorySelect = (id: string) => vscode.postMessage({ type: "showTaskWithId", text: id })
4038

41-
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false)
39+
const [isConfirmDeleteTask, setIsConfirmDeleteTask] = useState(false)
4240
const [taskToDelete, setTaskToDelete] = useState<string | null>(null)
4341

4442
const handleDeleteHistoryItem = (id: string) => {
4543
setTaskToDelete(id)
46-
setDeleteDialogOpen(true)
47-
}
48-
49-
const formatDate = (timestamp: number) => {
50-
const date = new Date(timestamp)
51-
return date
52-
?.toLocaleString("en-US", {
53-
month: "long",
54-
day: "numeric",
55-
hour: "numeric",
56-
minute: "2-digit",
57-
hour12: true,
58-
})
59-
.replace(", ", " ")
60-
.replace(" at", ",")
61-
.toUpperCase()
44+
setIsConfirmDeleteTask(true)
6245
}
6346

6447
const presentableTasks = useMemo(() => {
@@ -406,9 +389,10 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
406389
{taskToDelete && (
407390
<DeleteTaskDialog
408391
taskId={taskToDelete}
409-
open={deleteDialogOpen}
392+
open={isConfirmDeleteTask}
410393
onOpenChange={(open) => {
411-
setDeleteDialogOpen(open)
394+
setIsConfirmDeleteTask(open)
395+
412396
if (!open) {
413397
setTaskToDelete(null)
414398
}
@@ -443,4 +427,19 @@ const ExportButton = ({ itemId }: { itemId: string }) => (
443427
</Button>
444428
)
445429

430+
const formatDate = (timestamp: number) => {
431+
const date = new Date(timestamp)
432+
return date
433+
?.toLocaleString("en-US", {
434+
month: "long",
435+
day: "numeric",
436+
hour: "numeric",
437+
minute: "2-digit",
438+
hour12: true,
439+
})
440+
.replace(", ", " ")
441+
.replace(" at", ",")
442+
.toUpperCase()
443+
}
444+
446445
export default memo(HistoryView)

webview-ui/src/components/ui/alert-dialog.tsx

Lines changed: 77 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -4,94 +4,97 @@ import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog"
44
import { cn } from "@/lib/utils"
55
import { buttonVariants } from "@/components/ui/button"
66

7-
const AlertDialog = AlertDialogPrimitive.Root
8-
9-
const AlertDialogTrigger = AlertDialogPrimitive.Trigger
7+
function AlertDialog({ ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Root>) {
8+
return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />
9+
}
1010

11-
const AlertDialogPortal = AlertDialogPrimitive.Portal
11+
function AlertDialogTrigger({ ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>) {
12+
return <AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />
13+
}
1214

13-
const AlertDialogOverlay = React.forwardRef<
14-
React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
15-
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
16-
>(({ className, ...props }, ref) => (
17-
<AlertDialogPrimitive.Overlay
18-
className={cn(
19-
"fixed inset-0 z-50 bg-black/50 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
20-
className,
21-
)}
22-
{...props}
23-
ref={ref}
24-
/>
25-
))
26-
AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName
15+
function AlertDialogPortal({ ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Portal>) {
16+
return <AlertDialogPrimitive.Portal data-slot="alert-dialog-portal" {...props} />
17+
}
2718

28-
const AlertDialogContent = React.forwardRef<
29-
React.ElementRef<typeof AlertDialogPrimitive.Content>,
30-
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>
31-
>(({ className, ...props }, ref) => (
32-
<AlertDialogPortal>
33-
<AlertDialogOverlay />
34-
<AlertDialogPrimitive.Content
35-
ref={ref}
19+
function AlertDialogOverlay({ className, ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>) {
20+
return (
21+
<AlertDialogPrimitive.Overlay
22+
data-slot="alert-dialog-overlay"
3623
className={cn(
37-
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-vscode-editor-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%] rounded-lg",
24+
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/80",
3825
className,
3926
)}
4027
{...props}
4128
/>
42-
</AlertDialogPortal>
43-
))
44-
AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName
29+
)
30+
}
4531

46-
const AlertDialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
47-
<div className={cn("flex flex-col space-y-2 text-left", className)} {...props} />
48-
)
49-
AlertDialogHeader.displayName = "AlertDialogHeader"
32+
function AlertDialogContent({ className, ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Content>) {
33+
return (
34+
<AlertDialogPortal>
35+
<AlertDialogOverlay />
36+
<AlertDialogPrimitive.Content
37+
data-slot="alert-dialog-content"
38+
className={cn(
39+
"bg-background 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 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",
40+
className,
41+
)}
42+
{...props}
43+
/>
44+
</AlertDialogPortal>
45+
)
46+
}
5047

51-
const AlertDialogFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
52-
<div className={cn("flex flex-row justify-end space-x-2", className)} {...props} />
53-
)
54-
AlertDialogFooter.displayName = "AlertDialogFooter"
48+
function AlertDialogHeader({ className, ...props }: React.ComponentProps<"div">) {
49+
return (
50+
<div
51+
data-slot="alert-dialog-header"
52+
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
53+
{...props}
54+
/>
55+
)
56+
}
5557

56-
const AlertDialogTitle = React.forwardRef<
57-
React.ElementRef<typeof AlertDialogPrimitive.Title>,
58-
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>
59-
>(({ className, ...props }, ref) => (
60-
<AlertDialogPrimitive.Title ref={ref} className={cn("text-lg font-semibold", className)} {...props} />
61-
))
62-
AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName
58+
function AlertDialogFooter({ className, ...props }: React.ComponentProps<"div">) {
59+
return (
60+
<div
61+
data-slot="alert-dialog-footer"
62+
className={cn("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", className)}
63+
{...props}
64+
/>
65+
)
66+
}
67+
68+
function AlertDialogTitle({ className, ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Title>) {
69+
return (
70+
<AlertDialogPrimitive.Title
71+
data-slot="alert-dialog-title"
72+
className={cn("text-lg font-semibold", className)}
73+
{...props}
74+
/>
75+
)
76+
}
6377

64-
const AlertDialogDescription = React.forwardRef<
65-
React.ElementRef<typeof AlertDialogPrimitive.Description>,
66-
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>
67-
>(({ className, ...props }, ref) => (
68-
<AlertDialogPrimitive.Description
69-
ref={ref}
70-
className={cn("text-base text-muted-foreground", className)}
71-
{...props}
72-
/>
73-
))
74-
AlertDialogDescription.displayName = AlertDialogPrimitive.Description.displayName
78+
function AlertDialogDescription({
79+
className,
80+
...props
81+
}: React.ComponentProps<typeof AlertDialogPrimitive.Description>) {
82+
return (
83+
<AlertDialogPrimitive.Description
84+
data-slot="alert-dialog-description"
85+
className={cn("text-muted-foreground text-sm", className)}
86+
{...props}
87+
/>
88+
)
89+
}
7590

76-
const AlertDialogAction = React.forwardRef<
77-
React.ElementRef<typeof AlertDialogPrimitive.Action>,
78-
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>
79-
>(({ className, ...props }, ref) => (
80-
<AlertDialogPrimitive.Action ref={ref} className={cn(buttonVariants(), className)} {...props} />
81-
))
82-
AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName
91+
function AlertDialogAction({ className, ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Action>) {
92+
return <AlertDialogPrimitive.Action className={cn(buttonVariants(), className)} {...props} />
93+
}
8394

84-
const AlertDialogCancel = React.forwardRef<
85-
React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
86-
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>
87-
>(({ className, ...props }, ref) => (
88-
<AlertDialogPrimitive.Cancel
89-
ref={ref}
90-
className={cn(buttonVariants({ variant: "secondary" }), "mt-0", className)}
91-
{...props}
92-
/>
93-
))
94-
AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName
95+
function AlertDialogCancel({ className, ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Cancel>) {
96+
return <AlertDialogPrimitive.Cancel className={cn(buttonVariants({ variant: "outline" }), className)} {...props} />
97+
}
9598

9699
export {
97100
AlertDialog,

0 commit comments

Comments
 (0)