Skip to content

Commit 3ae875e

Browse files
committed
feat: update sortable again
1 parent e7dee0f commit 3ae875e

2 files changed

Lines changed: 29 additions & 19 deletions

File tree

src/app/_components/mixed-sorting-demo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function MixedSortingDemo() {
3737
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 md:grid-cols-4">
3838
{specialTricks.map((item) => (
3939
<SortableItem key={item.id} value={item.id} asTrigger asChild>
40-
<Card className="flex aspect-video cursor-auto items-center justify-center rounded-md bg-accent hover:bg-accent/80">
40+
<Card className="flex aspect-video items-center justify-center rounded-md bg-accent hover:bg-accent/80">
4141
<CardHeader className="items-center">
4242
<CardTitle>{item.name}</CardTitle>
4343
<CardDescription>{item.points} points</CardDescription>

src/components/ui/sortable.tsx

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -191,22 +191,28 @@ interface SortableOverlayProps
191191
activeId?: UniqueIdentifier | null
192192
}
193193

194-
function SortableOverlay({
195-
activeId,
196-
dropAnimation = dropAnimationOpts,
197-
children,
198-
...props
199-
}: SortableOverlayProps) {
200-
return (
201-
<DragOverlay dropAnimation={dropAnimation} {...props}>
202-
{activeId ? (
203-
<SortableItem value={activeId} asChild>
204-
{children}
205-
</SortableItem>
206-
) : null}
207-
</DragOverlay>
208-
)
209-
}
194+
const SortableOverlay = React.forwardRef<HTMLDivElement, SortableOverlayProps>(
195+
(
196+
{ activeId, dropAnimation = dropAnimationOpts, children, ...props },
197+
ref
198+
) => {
199+
return (
200+
<DragOverlay dropAnimation={dropAnimation} {...props}>
201+
{activeId ? (
202+
<SortableItem
203+
ref={ref}
204+
value={activeId}
205+
className="cursor-grabbing"
206+
asChild
207+
>
208+
{children}
209+
</SortableItem>
210+
) : null}
211+
</DragOverlay>
212+
)
213+
}
214+
)
215+
SortableOverlay.displayName = "SortableOverlay"
210216

211217
interface SortableItemContextProps {
212218
attributes: React.HTMLAttributes<HTMLElement>
@@ -273,7 +279,7 @@ const SortableItem = React.forwardRef<HTMLDivElement, SortableItemProps>(
273279
[attributes, listeners, isDragging]
274280
)
275281
const style: React.CSSProperties = {
276-
opacity: isDragging ? 0.4 : undefined,
282+
opacity: isDragging ? 0.5 : 1,
277283
transform: CSS.Translate.toString(transform),
278284
transition,
279285
}
@@ -284,7 +290,11 @@ const SortableItem = React.forwardRef<HTMLDivElement, SortableItemProps>(
284290
<SortableItemContext.Provider value={context}>
285291
<Comp
286292
data-state={isDragging ? "dragging" : undefined}
287-
className={cn("data-[state=dragging]:cursor-grabbing", className)}
293+
className={cn(
294+
"data-[state=dragging]:cursor-grabbing",
295+
{ "cursor-grab": !isDragging && asTrigger },
296+
className
297+
)}
288298
ref={composeRefs(ref, setNodeRef as React.Ref<HTMLDivElement>)}
289299
style={style}
290300
{...(asTrigger ? attributes : {})}

0 commit comments

Comments
 (0)