訊息組件將協助您在應用程式中視覺化評論和訊息系統。
包含以下組件
訊息
訊息
MessagesTitle
名稱 | 類型 | 預設 | 描述 |
---|
名稱 | 類型 | 預設 | 描述 |
---|---|---|---|
avatar | 字串 | 訊息使用者的頭像 URL | |
colors | 物件 | ||
colors.bubbleReceivedIos | 字串 | 'bg-[#e5e5ea] dark:bg-[#252525]' | |
colors.bubbleReceivedMd | 字串 | 'dark:bg-md-dark-surface-variant bg-[#e5e5ea]' | |
colors.bubbleSentIos | 字串 | 'bg-primary' | |
colors.bubbleSentMd | 字串 | 'bg-md-light-primary dark:bg-md-dark-primary dark:text-md-dark-on-primary' | |
colors.messageNameIos | 字串 | 'text-black text-opacity-45 dark:text-white dark:text-opacity-45' | |
colors.messageNameMd | 字串 | 'text-md-light-on-surface-variant dark:text-md-dark-on-surface-variant' | |
colors.messageSent | 字串 | 'text-white' | |
footer | 字串 | 訊息頁尾的內容 | |
header | 字串 | 訊息頁首的內容 | |
id | 字串 | 訊息 id 屬性 | |
name | 字串 | 訊息名稱 | |
text | 字串 | 訊息文字 | |
textFooter | 字串 | 訊息頁尾文字 | |
textHeader | 字串 | 訊息頁首文字 | |
type | 字串 | 'sent' |
|
onClick | function(e) | 訊息點擊處理常式 |
名稱 | 描述 |
---|---|
avatar | 訊息使用者的頭像 URL |
footer | 訊息頁尾的內容 |
header | 訊息頁首的內容 |
text | 訊息文字 |
名稱 | 類型 | 預設 | 描述 |
---|---|---|---|
colors | 物件 | ||
colors.titleMd | 字串 | 'text-md-light-on-surface-variant dark:text-md-dark-on-surface-variant' |
<script>import {Page,Navbar,NavbarBackLink,Messagebar,Messages,Message,MessagesTitle,Icon,Link,} from 'konsta/svelte';import { onMount, afterUpdate } from 'svelte';import { CameraFill, ArrowUpCircleFill } from 'framework7-icons/svelte';import MdCameraAlt from '../components/MdCameraAlt.svelte';import MdSend from '../components/MdSend.svelte';let messageText = '';let isClickable;let inputOpacity = 0.3;const onMessageTextChange = (e) => {messageText = e.target.value;isClickable = messageText.trim().length > 0;inputOpacity = messageText ? 1 : 0.3;};let messagesData = [{type: 'sent',text: 'Hi, Kate',},{type: 'sent',text: 'How are you?',},{name: 'Kate',type: 'received',text: 'Hi, I am good!',avatar: 'https://cdn.framework7.io/placeholder/people-100x100-9.jpg',},{name: 'Blue Ninja',type: 'received',text: 'Hi there, I am also fine, thanks! And how are you?',avatar: 'https://cdn.framework7.io/placeholder/people-100x100-7.jpg',},{type: 'sent',text: 'Hey, Blue Ninja! Glad to see you ;)',},{type: 'sent',text: 'How do you feel about going to the movies today?',},{name: 'Kate',type: 'received',text: ' Oh, great idea!',avatar: 'https://cdn.framework7.io/placeholder/people-100x100-9.jpg',},{name: 'Kate',type: 'received',text: ' What cinema are we going to?',avatar: 'https://cdn.framework7.io/placeholder/people-100x100-9.jpg',},{name: 'Blue Ninja',type: 'received',text: 'Great. And what movie?',avatar: 'https://cdn.framework7.io/placeholder/people-100x100-7.jpg',},{name: 'Blue Ninja',type: 'received',text: 'What time?',avatar: 'https://cdn.framework7.io/placeholder/people-100x100-7.jpg',},];let shouldScrollMessages = false;const scrollToBottom = (animate = true) => {const pageEl = document.querySelector('.messages-page');pageEl.scrollTo({top: pageEl.scrollHeight - pageEl.offsetHeight,behavior: animate ? 'smooth' : 'auto',});};onMount(() => {scrollToBottom(false);});afterUpdate(() => {if (shouldScrollMessages) {scrollToBottom();shouldScrollMessages = false;}});const handleSendClick = () => {const text = messageText.replace(//g, '<br>').trim();const type = 'sent';if (text.length) {const messageToSend = { text, type };messagesData = [...messagesData, messageToSend];messageText = '';inputOpacity = 0.3;shouldScrollMessages = true;}};const dateFormatter = new Intl.DateTimeFormat('en-US', {weekday: 'long',month: 'short',day: 'numeric',});const timeFormatter = new Intl.DateTimeFormat('en-US', {hour12: false,hour: '2-digit',minute: '2-digit',});const currentDate = new Date();const currentDay = dateFormatter.format(currentDate);const currentTime = timeFormatter.format(currentDate);</script><Page class="ios:bg-white ios:dark:bg-black messages-page"><Navbar title="Messages" /><Messages><MessagesTitle><b>{currentDay}</b> , {currentTime}</MessagesTitle>{#each messagesData as message, index (index)}{#if message.type === 'received'}<Messagekey={index}type={message.type}name={message.name}text={message.text}><imgslot="avatar"alt="avatar"class="w-8 h-8 rounded-full"src={message.avatar}/></Message>{:else}<Messagekey={index}type={message.type}name={message.name}text={message.text}/>{/if}{/each}</Messages><Messagebarplaceholder="Message"value={messageText}onInput={onMessageTextChange}><Link toolbar iconOnly slot="left"><Icon><CameraFill slot="ios" class="w-7 h-7" /><MdCameraAltslot="material"class="w-6 h-6 fill-black dark:fill-md-dark-on-surface"/></Icon></Link><Linktoolbarslot="right"onClick={() => (isClickable ? handleSendClick() : undefined)}style="opacity: {inputOpacity}; cursor: {isClickable? 'pointer': 'default'}"><Icon><ArrowUpCircleFill slot="ios" class="w-7 h-7" /><MdSendslot="material"class="w-6 h-6 fill-black dark:fill-md-dark-on-surface"/></Icon></Link></Messagebar></Page>