{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scroll-area6",
  "title": "Scroll area",
  "description": "Scroll area built with shadcn/ui.",
  "dependencies": [
    "class-variance-authority@0",
    "date-fns",
    "lucide-react@0",
    "radix-ui"
  ],
  "registryDependencies": [
    "avatar",
    "button",
    "input",
    "scroll-area"
  ],
  "files": [
    {
      "path": "contents/components/scroll-area/6/index.tsx",
      "content": "\"use client\";\n\nimport { useState, useEffect, useRef } from \"react\";\nimport { ScrollArea } from \"@/components/ui/scroll-area\";\nimport { Avatar, AvatarFallback, AvatarImage } from \"@/components/ui/avatar\";\nimport { Bubble, BubbleContent } from \"@/components/ui/bubble\";\nimport { Input } from \"@/components/ui/input\";\nimport { Button } from \"@/components/ui/button\";\nimport { cn } from \"@/lib/utils\";\nimport { SendIcon } from \"lucide-react\";\nimport { format, parseISO } from \"date-fns\";\n\nconst initialMessages = [\n  {\n    id: 1,\n    sender: \"Sarah Miller\",\n    avatar: \"https://i.pravatar.cc/150?img=2\",\n    message: \"Hey! Are we still on for the meeting tomorrow?\",\n    timestamp: \"2024-01-15T09:15:00\",\n    isOwn: false,\n  },\n  {\n    id: 2,\n    sender: \"You\",\n    avatar: \"https://i.pravatar.cc/150?img=1\",\n    message: \"Yes, absolutely! 2 PM works for me.\",\n    timestamp: \"2024-01-15T09:18:00\",\n    isOwn: true,\n  },\n  {\n    id: 3,\n    sender: \"Sarah Miller\",\n    avatar: \"https://i.pravatar.cc/150?img=2\",\n    message: \"Perfect! I'll send the agenda later today.\",\n    timestamp: \"2024-01-15T09:20:00\",\n    isOwn: false,\n  },\n  {\n    id: 4,\n    sender: \"Mike Johnson\",\n    avatar: \"https://i.pravatar.cc/150?img=3\",\n    message: \"Can I join the meeting as well?\",\n    timestamp: \"2024-01-15T10:30:00\",\n    isOwn: false,\n  },\n  {\n    id: 5,\n    sender: \"You\",\n    avatar: \"https://i.pravatar.cc/150?img=1\",\n    message: \"Of course! The more the merrier.\",\n    timestamp: \"2024-01-15T10:32:00\",\n    isOwn: true,\n  },\n  {\n    id: 6,\n    sender: \"Emma Wilson\",\n    avatar: \"https://i.pravatar.cc/150?img=4\",\n    message: \"I've prepared the presentation slides. Should I share them now?\",\n    timestamp: \"2024-01-15T11:45:00\",\n    isOwn: false,\n  },\n  {\n    id: 7,\n    sender: \"You\",\n    avatar: \"https://i.pravatar.cc/150?img=1\",\n    message: \"Yes please, that would be great!\",\n    timestamp: \"2024-01-15T11:47:00\",\n    isOwn: true,\n  },\n  {\n    id: 8,\n    sender: \"David Brown\",\n    avatar: \"https://i.pravatar.cc/150?img=5\",\n    message: \"Just reviewed the slides. They look excellent!\",\n    timestamp: \"2024-01-15T14:20:00\",\n    isOwn: false,\n  },\n  {\n    id: 9,\n    sender: \"Sarah Miller\",\n    avatar: \"https://i.pravatar.cc/150?img=2\",\n    message: \"Thanks everyone for the quick responses. See you all tomorrow!\",\n    timestamp: \"2024-01-15T15:00:00\",\n    isOwn: false,\n  },\n  {\n    id: 10,\n    sender: \"You\",\n    avatar: \"https://i.pravatar.cc/150?img=1\",\n    message: \"Looking forward to it!\",\n    timestamp: \"2024-01-15T15:02:00\",\n    isOwn: true,\n  },\n];\n\nfunction formatMessageTime(timestamp: string): string {\n  const date = parseISO(timestamp);\n  return format(date, \"h:mm a\");\n}\n\nexport default function Example() {\n  const [messages, setMessages] = useState(initialMessages);\n  const [message, setMessage] = useState(\"\");\n  const scrollAreaRef = useRef<HTMLDivElement>(null);\n\n  useEffect(() => {\n    const scrollToBottom = () => {\n      if (scrollAreaRef.current) {\n        const viewport = scrollAreaRef.current.querySelector(\n          '[data-slot=\"scroll-area-viewport\"]'\n        ) as HTMLElement;\n        if (viewport) {\n          viewport.scrollTop = viewport.scrollHeight;\n        }\n      }\n    };\n\n    scrollToBottom();\n    const timeout = setTimeout(scrollToBottom, 100);\n    return () => clearTimeout(timeout);\n  }, [messages]);\n\n  const handleSend = () => {\n    if (!message.trim()) {\n      return;\n    }\n\n    setMessages((prev) => [\n      ...prev,\n      {\n        id: prev.length + 1,\n        sender: \"You\",\n        avatar: \"https://i.pravatar.cc/150?img=1\",\n        message: message.trim(),\n        timestamp: new Date().toISOString(),\n        isOwn: true,\n      },\n    ]);\n    setMessage(\"\");\n  };\n\n  const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n    if (e.key === \"Enter\" && !e.shiftKey) {\n      e.preventDefault();\n      handleSend();\n    }\n  };\n\n  return (\n    <div className=\"bg-muted/30 relative flex h-[500px] w-full max-w-sm flex-col overflow-hidden rounded-lg border\">\n      <div className=\"relative min-h-0 flex-1\">\n        <div ref={scrollAreaRef} className=\"h-full\">\n          <ScrollArea className=\"h-full\">\n            <div className=\"space-y-4 p-4\">\n              {messages.map((msg) => (\n                <div\n                  key={msg.id}\n                  className={cn(\"flex gap-3\", msg.isOwn && \"flex-row-reverse\")}\n                >\n                  <Avatar className=\"shrink-0\">\n                    <AvatarImage src={msg.avatar} alt={msg.sender} />\n                    <AvatarFallback>\n                      {msg.sender === \"You\"\n                        ? \"Y\"\n                        : msg.sender\n                            .split(\" \")\n                            .map((n) => n[0])\n                            .join(\"\")}\n                    </AvatarFallback>\n                  </Avatar>\n                  <Bubble\n                    align={msg.isOwn ? \"end\" : \"start\"}\n                    className=\"max-w-[75%]\"\n                    variant={msg.isOwn ? \"default\" : \"outline\"}\n                  >\n                    <div\n                      className={cn(\n                        \"flex items-center gap-2\",\n                        msg.isOwn && \"flex-row-reverse self-end\"\n                      )}\n                    >\n                      <span className=\"text-foreground text-xs font-medium\">\n                        {msg.sender}\n                      </span>\n                      <span className=\"text-muted-foreground text-xs\">\n                        {formatMessageTime(msg.timestamp)}\n                      </span>\n                    </div>\n                    <BubbleContent>{msg.message}</BubbleContent>\n                  </Bubble>\n                </div>\n              ))}\n            </div>\n          </ScrollArea>\n        </div>\n        <div className=\"from-muted/30 pointer-events-none absolute right-0 bottom-0 left-0 z-10 h-12 bg-linear-to-t to-transparent\" />\n      </div>\n      <div className=\"bg-background relative z-20 shrink-0 border-t p-3\">\n        <div className=\"flex gap-2\">\n          <Input\n            placeholder=\"Type a message...\"\n            value={message}\n            onChange={(e) => setMessage(e.target.value)}\n            onKeyDown={handleKeyDown}\n            className=\"flex-1\"\n          />\n          <Button onClick={handleSend} size=\"icon\" disabled={!message.trim()}>\n            <SendIcon />\n          </Button>\n        </div>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/scroll-area6.tsx"
    },
    {
      "path": "components/ui/bubble.tsx",
      "content": "import * as React from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport { Slot } from \"radix-ui\"\n\nimport { cn } from \"@/lib/utils\"\n\nfunction BubbleGroup({ className, ...props }: React.ComponentProps<\"div\">) {\n  return (\n    <div\n      data-slot=\"bubble-group\"\n      className={cn(\"flex min-w-0 flex-col gap-2\", className)}\n      {...props}\n    />\n  )\n}\n\nconst bubbleVariants = cva(\n  \"group/bubble relative flex w-fit max-w-[80%] min-w-0 flex-col gap-1 group-data-[align=end]/message:self-end data-[align=end]:self-end data-[variant=ghost]:max-w-full\",\n  {\n    variants: {\n      variant: {\n        default:\n          \"*:data-[slot=bubble-content]:bg-primary *:data-[slot=bubble-content]:text-primary-foreground [&>[data-slot=bubble-content]:is(button,a):hover]:bg-primary/80\",\n        secondary:\n          \"*:data-[slot=bubble-content]:bg-secondary *:data-[slot=bubble-content]:text-secondary-foreground [&>[data-slot=bubble-content]:is(button,a):hover]:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)]\",\n        muted:\n          \"*:data-[slot=bubble-content]:bg-muted [&>[data-slot=bubble-content]:is(button,a):hover]:bg-[color-mix(in_oklch,var(--muted),var(--foreground)_5%)]\",\n        tinted:\n          \"*:data-[slot=bubble-content]:bg-[oklch(from_var(--primary)_0.93_calc(c*0.4)_h)] *:data-[slot=bubble-content]:text-foreground dark:*:data-[slot=bubble-content]:bg-[oklch(from_var(--primary)_0.3_calc(c*0.4)_h)] [&>[data-slot=bubble-content]:is(button,a):hover]:bg-[oklch(from_var(--primary)_0.88_calc(c*0.5)_h)] dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-[oklch(from_var(--primary)_0.35_calc(c*0.5)_h)]\",\n        outline:\n          \"*:data-[slot=bubble-content]:border-border *:data-[slot=bubble-content]:bg-background [&>[data-slot=bubble-content]:is(button,a):hover]:bg-muted [&>[data-slot=bubble-content]:is(button,a):hover]:text-foreground dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-input/30\",\n        ghost:\n          \"border-none *:data-[slot=bubble-content]:rounded-none *:data-[slot=bubble-content]:bg-transparent *:data-[slot=bubble-content]:p-0 [&>[data-slot=bubble-content]:is(button,a):hover]:bg-muted [&>[data-slot=bubble-content]:is(button,a):hover]:text-foreground dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-muted/50\",\n        destructive:\n          \"*:data-[slot=bubble-content]:bg-destructive/10 *:data-[slot=bubble-content]:text-destructive dark:*:data-[slot=bubble-content]:bg-destructive/20 [&>[data-slot=bubble-content]:is(button,a):hover]:bg-destructive/20 dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-destructive/30\",\n      },\n    },\n    defaultVariants: {\n      variant: \"default\",\n    },\n  }\n)\n\nfunction Bubble({\n  variant = \"default\",\n  align = \"start\",\n  className,\n  ...props\n}: React.ComponentProps<\"div\"> &\n  VariantProps<typeof bubbleVariants> & {\n    align?: \"start\" | \"end\"\n  }) {\n  return (\n    <div\n      data-slot=\"bubble\"\n      data-variant={variant}\n      data-align={align}\n      className={cn(bubbleVariants({ variant }), className)}\n      {...props}\n    />\n  )\n}\n\nfunction BubbleContent({\n  asChild = false,\n  className,\n  ...props\n}: React.ComponentProps<\"div\"> & {\n  asChild?: boolean\n}) {\n  const Comp = asChild ? Slot.Root : \"div\"\n\n  return (\n    <Comp\n      data-slot=\"bubble-content\"\n      className={cn(\n        \"w-fit max-w-full min-w-0 overflow-hidden rounded-3xl border border-transparent px-3.5 py-2.5 text-sm leading-relaxed wrap-break-word group-data-[align=end]/bubble:self-end [button]:text-left [button,a]:transition-colors [button,a]:outline-none [button,a]:focus-visible:border-ring [button,a]:focus-visible:ring-3 [button,a]:focus-visible:ring-ring/30\",\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\nconst bubbleReactionsVariants = cva(\n  \"absolute z-10 flex w-fit shrink-0 items-center justify-center gap-1 rounded-full bg-muted px-1.5 py-0.5 text-sm ring-3 ring-card has-[button]:p-0\",\n  {\n    variants: {\n      side: {\n        top: \"top-0 -translate-y-3/4\",\n        bottom: \"bottom-0 translate-y-3/4\",\n      },\n      align: {\n        start: \"left-3\",\n        end: \"right-3\",\n      },\n    },\n    defaultVariants: {\n      side: \"bottom\",\n      align: \"end\",\n    },\n  }\n)\n\nfunction BubbleReactions({\n  side = \"bottom\",\n  align = \"end\",\n  className,\n  ...props\n}: React.ComponentProps<\"div\"> & {\n  align?: \"start\" | \"end\"\n  side?: \"top\" | \"bottom\"\n}) {\n  return (\n    <div\n      data-slot=\"bubble-reactions\"\n      data-align={align}\n      data-side={side}\n      className={cn(bubbleReactionsVariants({ side, align }), className)}\n      {...props}\n    />\n  )\n}\n\nexport { BubbleGroup, Bubble, BubbleContent, BubbleReactions }\n",
      "type": "registry:ui",
      "target": "components/ui/bubble.tsx"
    }
  ],
  "type": "registry:component"
}