-
-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
451 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
222 changes: 222 additions & 0 deletions
222
apps/www/src/lib/registry/default/example/cards/chat.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
<script lang="ts"> | ||
import { Check, Send, Plus } from "lucide-svelte"; | ||
import { cn } from "$lib/utils"; | ||
import * as Avatar from "@/registry/default/ui/avatar"; | ||
import * as Card from "@/registry/default/ui/card"; | ||
import * as Command from "@/registry/default/ui/command"; | ||
import * as Dialog from "@/registry/default/ui/dialog"; | ||
import * as Tooltip from "@/registry/default/ui/tooltip"; | ||
import { Button } from "@/registry/default/ui/button"; | ||
import { Input } from "@/registry/default/ui/input"; | ||
const users = [ | ||
{ | ||
name: "Olivia Martin", | ||
email: "[email protected]", | ||
avatar: "/avatars/01.png" | ||
}, | ||
{ | ||
name: "Isabella Nguyen", | ||
email: "[email protected]", | ||
avatar: "/avatars/03.png" | ||
}, | ||
{ | ||
name: "Emma Wilson", | ||
email: "[email protected]", | ||
avatar: "/avatars/05.png" | ||
}, | ||
{ | ||
name: "Jackson Lee", | ||
email: "[email protected]", | ||
avatar: "/avatars/02.png" | ||
}, | ||
{ | ||
name: "William Kim", | ||
email: "[email protected]", | ||
avatar: "/avatars/04.png" | ||
} | ||
] as const; | ||
type User = (typeof users)[number]; | ||
let open = false; | ||
let selectedUsers: User[] = []; | ||
let messages = [ | ||
{ | ||
role: "agent", | ||
content: "Hi, how can I help you today?" | ||
}, | ||
{ | ||
role: "user", | ||
content: "Hey, I'm having trouble with my account." | ||
}, | ||
{ | ||
role: "agent", | ||
content: "What seems to be the problem?" | ||
}, | ||
{ | ||
role: "user", | ||
content: "I can't log in." | ||
} | ||
]; | ||
let input = ""; | ||
$: inputLength = input.trim().length; | ||
</script> | ||
|
||
<Card.Root> | ||
<Card.Header class="flex flex-row items-center"> | ||
<div class="flex items-center space-x-4"> | ||
<Avatar.Root> | ||
<Avatar.Image src="/avatars/01.png" alt="Image" /> | ||
<Avatar.Fallback>OM</Avatar.Fallback> | ||
</Avatar.Root> | ||
<div> | ||
<p class="text-sm font-medium leading-none">Sofia Davis</p> | ||
<p class="text-sm text-muted-foreground">[email protected]</p> | ||
</div> | ||
</div> | ||
<Tooltip.Root openDelay={0}> | ||
<Tooltip.Trigger asChild> | ||
<Button | ||
size="icon" | ||
variant="outline" | ||
class="ml-auto rounded-full" | ||
on:click={() => (open = true)} | ||
> | ||
<Plus class="h-4 w-4" /> | ||
<span class="sr-only">New message</span> | ||
</Button> | ||
</Tooltip.Trigger> | ||
<Tooltip.Content sideOffset={10}>New message</Tooltip.Content> | ||
</Tooltip.Root> | ||
</Card.Header> | ||
<Card.Content> | ||
<div class="space-y-4"> | ||
{#each messages as message} | ||
<div | ||
class={cn( | ||
"flex w-max max-w-[75%] flex-col gap-2 rounded-lg px-3 py-2 text-sm", | ||
message.role === "user" | ||
? "ml-auto bg-primary text-primary-foreground" | ||
: "bg-muted" | ||
)} | ||
> | ||
{message.content} | ||
</div> | ||
{/each} | ||
</div> | ||
</Card.Content> | ||
<Card.Footer> | ||
<form | ||
on:submit={(event) => { | ||
event.preventDefault(); | ||
if (inputLength === 0) return; | ||
messages = [ | ||
...messages, | ||
{ | ||
role: "user", | ||
content: input | ||
} | ||
]; | ||
input = ""; | ||
}} | ||
class="flex w-full items-center space-x-2" | ||
> | ||
<Input | ||
id="message" | ||
placeholder="Type your message..." | ||
class="flex-1" | ||
autocomplete="off" | ||
bind:value={input} | ||
/> | ||
<Button type="submit" size="icon" disabled={inputLength === 0}> | ||
<Send class="h-4 w-4" /> | ||
<span class="sr-only">Send</span> | ||
</Button> | ||
</form> | ||
</Card.Footer> | ||
</Card.Root> | ||
<Dialog.Root bind:open> | ||
<Dialog.Content class="gap-0 p-0 outline-none"> | ||
<Dialog.Header class="px-4 pb-4 pt-5"> | ||
<Dialog.Title>New message</Dialog.Title> | ||
<Dialog.Description> | ||
Invite a user to this thread. This will create a new group | ||
message. | ||
</Dialog.Description> | ||
</Dialog.Header> | ||
<Command.Root | ||
class="overflow-hidden rounded-t-none border-t bg-transparent" | ||
> | ||
<Command.Input placeholder="Search user..." /> | ||
<Command.List> | ||
<Command.Empty>No users found.</Command.Empty> | ||
<Command.Group class="p-2"> | ||
{#each users as user} | ||
<Command.Item | ||
class="flex items-center px-2" | ||
onSelect={() => { | ||
if (selectedUsers.includes(user)) { | ||
selectedUsers = selectedUsers.filter( | ||
(selectedUser) => selectedUser !== user | ||
); | ||
} else { | ||
selectedUsers = [...users].filter((u) => | ||
[...selectedUsers, user].includes(u) | ||
); | ||
} | ||
}} | ||
> | ||
<Avatar.Root> | ||
<Avatar.Image src={user.avatar} alt="Image" /> | ||
<Avatar.Fallback>{user.name[0]}</Avatar.Fallback | ||
> | ||
</Avatar.Root> | ||
<div class="ml-2"> | ||
<p class="text-sm font-medium leading-none"> | ||
{user.name} | ||
</p> | ||
<p class="text-sm text-muted-foreground"> | ||
{user.email} | ||
</p> | ||
</div> | ||
{#if selectedUsers.includes(user)} | ||
<Check | ||
class="ml-auto flex h-5 w-5 text-primary" | ||
/> | ||
{/if} | ||
</Command.Item> | ||
{/each} | ||
</Command.Group> | ||
</Command.List> | ||
</Command.Root> | ||
<Dialog.Footer | ||
class="flex items-center border-t p-4 sm:justify-between" | ||
> | ||
{#if selectedUsers.length} | ||
<div class="flex -space-x-2 overflow-hidden"> | ||
{#each selectedUsers as user} | ||
<Avatar.Root | ||
class="inline-block border-2 border-background" | ||
> | ||
<Avatar.Image src={user.avatar} /> | ||
<Avatar.Fallback>{user.name[0]}</Avatar.Fallback> | ||
</Avatar.Root> | ||
{/each} | ||
</div> | ||
{:else} | ||
<p class="text-sm text-muted-foreground"> | ||
Select users to add to this thread. | ||
</p> | ||
{/if} | ||
<Button | ||
disabled={selectedUsers.length < 2} | ||
on:click={() => (open = false)} | ||
> | ||
Continue | ||
</Button> | ||
</Dialog.Footer> | ||
</Dialog.Content> | ||
</Dialog.Root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.