|
1 | 1 | <script lang="ts"> |
2 | 2 | import { ONE_SECOND } from "$lib/constants/date.constants"; |
3 | | - import ComponentHeader from "$lib/docs/ComponentHeader.svelte"; |
| 3 | + import ComponentPage from "$lib/docs/ComponentPage.svelte"; |
| 4 | + import ComponentPageCard from "$lib/docs/ComponentPageCard.svelte"; |
| 5 | + import ComponentPageFeature from "$lib/docs/ComponentPageFeature.svelte"; |
4 | 6 | import ChatWindow from "$lib/modules/chat/ChatWindow.svelte"; |
5 | 7 |
|
6 | 8 | const users = [ |
|
14 | 16 | name: "Obi-Wan Kenobi", |
15 | 17 | avatarUrl: |
16 | 18 | "https://img.icons8.com/external-flat-icons-inmotus-design/40/external-Obi-Wan-star-wars-flat-icons-inmotus-design.png" |
| 19 | + }, |
| 20 | + { |
| 21 | + id: "3", |
| 22 | + name: "Yoda", |
| 23 | + avatarUrl: "https://img.icons8.com/color/40/yoda.png" |
17 | 24 | } |
18 | 25 | ]; |
19 | 26 |
|
20 | 27 | const messages = [ |
21 | 28 | { |
22 | 29 | id: "1", |
23 | | - text: "It was said that you would, destroy the Sith, not join them.", |
| 30 | + text: "It was said that you would destroy the Sith, not join them", |
24 | 31 | senderId: "2", |
25 | 32 | createdAt: Date.now() - 1000 * 60 * 9 + ONE_SECOND * 5 |
26 | 33 | }, |
|
48 | 55 | senderId: "1", |
49 | 56 | createdAt: Date.now() - 1000 * 60 * 5 + ONE_SECOND * 10 |
50 | 57 | }, |
| 58 | + { |
| 59 | + id: "6", |
| 60 | + text: "Great humor you have, young padawan", |
| 61 | + senderId: "3", |
| 62 | + createdAt: Date.now() - 1000 * 60 * 4 + ONE_SECOND * 20 |
| 63 | + } |
| 64 | + ]; |
| 65 | +
|
| 66 | + const longMessages = $state([ |
| 67 | + ...messages, |
51 | 68 | { |
52 | 69 | id: "6", |
53 | 70 | text: "Bubba to the bang bang boogie, boobie to the boogie - To the rhythm of the boogie the beat. Now, what you hear is not a test I'm rappin' to the beat - And me, the groove, and my friends are gonna try to move your feet - See, I am Wonder Mike, and I'd like to say hello - To the black, to the white, the red and the brown- The purple and yellow, but first, I gotta - Bang bang, the boogie to the boogie -- Say up jump the boogie to the bang bang boogie -Let's rock, you don't stop - Rock the rhythm that'll make your body rock - Well so far you've heard my voice but I brought two friends along - And the next on the mic is my man Hank - C'mon, Hank, sing that song, check it out - Well, I'm Imp the Dimp, the ladies' pimp - The women fight for my delight - But I'm the grandmaster with the three MCs - That shock the house for the young ladies - And when you come inside, into the front - You do the Freak, Spank, and do the Bump", |
54 | 71 | senderId: "1", |
55 | 72 | createdAt: Date.now() |
56 | 73 | } |
| 74 | + ]); |
| 75 | +
|
| 76 | + const props = [ |
| 77 | + { |
| 78 | + name: "messages", |
| 79 | + type: "Array<ChatMessage>", |
| 80 | + default: "[]", |
| 81 | + description: "Array of messages to display" |
| 82 | + }, |
| 83 | + { |
| 84 | + name: "users", |
| 85 | + type: "Array<ChatUser>", |
| 86 | + default: "[]", |
| 87 | + description: "Array of users to display avatars" |
| 88 | + }, |
| 89 | + { |
| 90 | + name: "meId", |
| 91 | + type: "String", |
| 92 | + default: "", |
| 93 | + description: "Id of the user who is currently logged in and therefor shown on the left" |
| 94 | + }, |
| 95 | + { |
| 96 | + name: "showAvatars", |
| 97 | + type: '"never" | "always" | "change"', |
| 98 | + default: '"always"', |
| 99 | + description: "When to show avatars" |
| 100 | + } |
57 | 101 | ]; |
58 | 102 | </script> |
59 | 103 |
|
60 | | -<ComponentHeader title="Chat Window"></ComponentHeader> |
| 104 | +<ComponentPage |
| 105 | + title="Message Thread" |
| 106 | + description="Shows a thread window as known from various messengers" |
| 107 | + {demoComponent} |
| 108 | + {features} |
| 109 | + {props} |
| 110 | +></ComponentPage> |
| 111 | + |
| 112 | +{#snippet demoComponent()} |
| 113 | + <ChatWindow meId="1" {users} {messages}></ChatWindow> |
| 114 | +{/snippet} |
| 115 | + |
| 116 | +{#snippet features()} |
| 117 | + <ComponentPageFeature title="Avatars"> |
| 118 | + <div class="flex flex-row gap-4 justify-center items-stretch"> |
| 119 | + <div class="flex flex-col items-center grow"> |
| 120 | + <div class="text-lg font-mono">always</div> |
| 121 | + <ComponentPageCard> |
| 122 | + <ChatWindow meId="1" {users} {messages} showAvatars="always"></ChatWindow> |
| 123 | + </ComponentPageCard> |
| 124 | + </div> |
| 125 | + <div class="flex flex-col items-center grow"> |
| 126 | + <div class="text-lg font-mono">change</div> |
| 127 | + <ComponentPageCard> |
| 128 | + <ChatWindow meId="1" {users} {messages} showAvatars="change"></ChatWindow> |
| 129 | + </ComponentPageCard> |
| 130 | + </div> |
| 131 | + <div class="flex flex-col items-center grow"> |
| 132 | + <div class="text-lg font-mono">never</div> |
| 133 | + <ComponentPageCard> |
| 134 | + <ChatWindow meId="1" {users} {messages} showAvatars="never"></ChatWindow> |
| 135 | + </ComponentPageCard> |
| 136 | + </div> |
| 137 | + </div> |
| 138 | + </ComponentPageFeature> |
61 | 139 |
|
62 | | -<div class="mockup-phone"> |
63 | | - <div class="camera"></div> |
64 | | - <div class="display"> |
65 | | - <div class="artboard phone-1 h-full pt-6"> |
66 | | - <ChatWindow meId="1" {users} {messages}></ChatWindow> |
| 140 | + <ComponentPageFeature title="Auto Scroll"> |
| 141 | + <div class="flex flex-row gap-4 justify-center items-center"> |
| 142 | + <div class="mockup-phone"> |
| 143 | + <div class="camera"></div> |
| 144 | + <div class="display"> |
| 145 | + <div class="artboard artboard-demo phone-1 p-1 pt-8"> |
| 146 | + <ChatWindow meId="1" {users} messages={longMessages} showAvatars="always"></ChatWindow> |
| 147 | + </div> |
| 148 | + </div> |
| 149 | + </div> |
| 150 | + <div class="grow flex flex-row justify-center"> |
| 151 | + <button |
| 152 | + class="btn btn-primary btn-lg" |
| 153 | + onclick={() => { |
| 154 | + longMessages.push({ |
| 155 | + id: longMessages.length + 100 + "", |
| 156 | + text: "Lunch anyone?", |
| 157 | + senderId: "2", |
| 158 | + createdAt: Date.now() |
| 159 | + }); |
| 160 | + }} |
| 161 | + > |
| 162 | + Add new Message |
| 163 | + </button> |
| 164 | + </div> |
67 | 165 | </div> |
68 | | - </div> |
69 | | -</div> |
| 166 | + </ComponentPageFeature> |
| 167 | +{/snippet} |
0 commit comments