Draggable
blok/draggableFreeComponent
Drag and drop components using @dnd-kit/react. Includes draggable, droppable, and sortable functionality with hooks.
Install it
npx shadcn@latest add https://blok.sitecore.com/r/draggable.jsonSource
1"use client";23import { cn } from "@/lib/utils";4import { type UniqueIdentifier, useDraggable } from "@dnd-kit/core";5import { CSS } from "@dnd-kit/utilities";6import type * as React from "react";7import { useDndMounted } from "./dnd-context";89export interface DraggableProps10 extends Omit<React.HTMLAttributes<HTMLDivElement>, "id"> {11 /** Unique identifier for this draggable item */12 id: UniqueIdentifier;13 /** Whether dragging is disabled */14 disabled?: boolean;15 /** Optional data to pass along with drag events */16 data?: Record<string, unknown>;17 /** Element type to render (default: div) */18 as?: React.ElementType;19 children: React.ReactNode;20}2122function DraggableInner({23 id,24 disabled = false,25 data,26 children,27 className,28 as: Component = "div",29 ...props30}: DraggableProps) {31 const { attributes, listeners, setNodeRef, transform, isDragging } =32 useDraggable({33 id,34 disabled,35 data,36 });3738 const style: React.CSSProperties = {39 transform: CSS.Translate.toString(transform),40 };4142 return (43 <Component44 ref={setNodeRef}45 style={style}46 data-draggable-id={id}47 data-dragging={isDragging}48 className={cn(49 isDragging && "opacity-50 z-50",50 !disabled && "cursor-grab",51 isDragging && "cursor-grabbing",52 disabled && "cursor-not-allowed opacity-60",53 className,54 )}55 {...listeners}56 {...attributes}57 {...props}58 >59 {children}60 </Component>61 );62}6364export function Draggable({65 children,66 className,67 as: Component = "div",68 id,69 disabled,70 data,71 ...props72}: DraggableProps) {73 const isMounted = useDndMounted();7475 // Render static version on server76 if (!isMounted) {77 return (78 <Component className={className} {...props}>79 {children}80 </Component>81 );82 }8384 return (85 <DraggableInner86 className={className}87 as={Component}88 id={id}89 disabled={disabled}90 data={data}91 {...props}92 >93 {children}94 </DraggableInner>95 );96}9798export interface DraggableHandleProps99 extends React.HTMLAttributes<HTMLDivElement> {100 children: React.ReactNode;101}102103/**104 * Use this component to create a drag handle within a Draggable.105 * Pass the listeners and attributes from useDraggable to this component.106 */107export function DraggableHandle({108 children,109 className,110 ...props111}: DraggableHandleProps) {112 return (113 <div114// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from blok
All 72 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | blok | Components | Free | 2 deps · 2 files | |
| Action baraction-bar | blok | Components | Free | 1 dep · 2 files | |
| Alertalert | blok | Components | Free | 2 deps · 2 files | |
| Alert dialogalert-dialog | blok | Components | Free | 2 deps | |
| Aspect ratioaspect-ratio | blok | Components | Free | 1 dep | |
| Avataravatar | blok | Components | Free | 1 dep | |
| Badgebadge | blok | Components | Free | 2 deps | |
| All componentsblok-components | blok | Components | Free | no deps |
