Skip to content

Commit

Permalink
finishing touches
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte committed Jan 10, 2024
1 parent 2a04b68 commit 5aa4fe0
Show file tree
Hide file tree
Showing 6 changed files with 451 additions and 3 deletions.
3 changes: 2 additions & 1 deletion apps/www/src/lib/registry/default/example/cards/all.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import CardsCalendar from "./calendar.svelte";
import CardsDataTable from "./data-table.svelte";
import CardsTeamMembers from "./team-members.svelte";
import CardsChat from "./chat.svelte";
</script>

<div
Expand All @@ -33,7 +34,7 @@
<CardsPaymentMethod />
</div>
<div class="space-y-4 xl:space-y-4">
<!-- <CardsChat /> -->
<CardsChat />
<CardsCreateAccount />
<div class="hidden xl:block">
<CardsReportIssue />
Expand Down
222 changes: 222 additions & 0 deletions apps/www/src/lib/registry/default/example/cards/chat.svelte
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>
1 change: 1 addition & 0 deletions apps/www/src/lib/registry/default/example/cards/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export { default as CardsReportIssue } from "./report-issue.svelte";
export { default as CardsShare } from "./share.svelte";
export { default as CardsStats } from "./stats.svelte";
export { default as CardsDefault } from "./all.svelte";
export { default as CardsChat } from "./chat.svelte";
5 changes: 3 additions & 2 deletions apps/www/src/lib/registry/new-york/example/cards/all.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
CardsReportIssue,
CardsShare,
CardsStats,
CardsTeamMembers
CardsTeamMembers,
CardsChat
} from ".";
</script>

Expand All @@ -35,7 +36,7 @@
<CardsPaymentMethod />
</div>
<div class="space-y-4 xl:space-y-4">
<!-- <CardsChat /> -->
<CardsChat />
<CardsCreateAccount />
<div class="hidden xl:block">
<CardsReportIssue />
Expand Down
Loading

0 comments on commit 5aa4fe0

Please sign in to comment.