+ "content": "\"use client\";\n\nimport * as Sortable from \"@/registry/default/ui/sortable\";\nimport * as React from \"react\";\n\ninterface Trick {\n id: string;\n title: string;\n description: string;\n}\n\nexport default function SortableDynamicOverlayDemo() {\n const [tricks, setTricks] = React.useState<Trick[]>([\n {\n id: \"1\",\n title: \"The 900\",\n description: \"The 900 is a trick where you spin 900 degrees in the air.\",\n },\n {\n id: \"2\",\n title: \"Indy Backflip\",\n description:\n \"The Indy Backflip is a trick where you backflip in the air.\",\n },\n {\n id: \"3\",\n title: \"Pizza Guy\",\n description: \"The Pizza Guy is a trick where you flip the pizza guy.\",\n },\n {\n id: \"4\",\n title: \"Rocket Air\",\n description: \"The Rocket Air is a trick where you rocket air.\",\n },\n {\n id: \"5\",\n title: \"Kickflip Backflip\",\n description:\n \"The Kickflip Backflip is a trick where you kickflip backflip.\",\n },\n {\n id: \"6\",\n title: \"FS 540\",\n description: \"The FS 540 is a trick where you fs 540.\",\n },\n ]);\n\n return (\n <Sortable.Root\n value={tricks}\n onValueChange={setTricks}\n getItemValue={(item) => item.id}\n orientation=\"mixed\"\n >\n <Sortable.Content className=\"grid auto-rows-fr grid-cols-3 gap-2.5\">\n {tricks.map((trick) => (\n <TrickCard key={trick.id} trick={trick} asHandle />\n ))}\n </Sortable.Content>\n <Sortable.Overlay>\n {(activeItem) => {\n const trick = tricks.find((trick) => trick.id === activeItem.value);\n\n if (!trick) return null;\n\n return <TrickCard trick={trick} />;\n }}\n </Sortable.Overlay>\n </Sortable.Root>\n );\n}\n\ninterface TrickCardProps\n extends Omit<React.ComponentPropsWithoutRef<typeof Sortable.Item>, \"value\"> {\n trick: Trick;\n}\n\nfunction TrickCard({ trick, ...props }: TrickCardProps) {\n return (\n <Sortable.Item key={trick.id} value={trick.id} asChild {...props}>\n <div className=\"flex flex-col gap-1 rounded-md border bg-zinc-100 p-4 text-foreground shadow dark:bg-zinc-900\">\n <div className=\"font-medium text-sm leading-tight sm:text-base\">\n {trick.title}\n </div>\n <span className=\"line-clamp-2 hidden text-muted-foreground text-sm sm:inline-block\">\n {trick.description}\n </span>\n </div>\n </Sortable.Item>\n );\n}\n",
0 commit comments