🔥 看看我們的新專案 t0ggles - 您終極的專案管理工具! 🔥

訊息欄 Svelte 組件

訊息欄是與訊息一起使用的工具列

訊息欄組件

包含以下組件

  • 訊息欄

訊息欄屬性

名稱類型預設值描述
顏色物件
colors.bgIos字串'bg-white dark:bg-black'
colors.bgMaterial字串'bg-md-light-surface dark:bg-md-dark-surface'
colors.borderIos字串'border-[#c8c8cd] dark:border-white dark:border-opacity-30'
colors.inputBgIos字串'bg-transparent'
colors.inputBgMd字串'bg-md-light-surface-2 dark:bg-md-dark-surface-variant'
colors.placeholderIos字串'dark:placeholder-white dark:placeholder-opacity-40'
colors.placeholderMd字串'placeholder-md-light-on-surface-variant dark:placeholder-md-dark-on-surface-variant'
colors.toolbarIconIos字串'fill-primary dark:fill-md-dark-primary'
colors.toolbarIconMd字串'fill-black'
停用布林值未定義

設定 "disabled" textarea 屬性

id字串

訊息欄 id 屬性

左邊字串

訊息欄 "左邊" 區域的內容

leftClass字串

其他左邊樣式

名稱字串

訊息欄名稱

外框布林值false

呈現外側細線 (邊框)。如果未指定,則會為 iOS 主題啟用

佔位符字串 | 數字'訊息'

訊息欄佔位符

右邊字串

訊息欄 "右邊" 區域的內容

rightClass字串

其他右邊樣式

大小字串 | 數字

textarea 原生 "size" 屬性的值

樣式CSSProperties

其他訊息欄類別

textareaId字串

Textarea "id" 屬性

任何

訊息欄值

onChange函式(e)

change 事件處理器

onInput函式(e)

input 事件處理器

訊息欄插槽

名稱描述
左邊

訊息欄 "左邊" 區域的內容

右邊

訊息欄 "右邊" 區域的內容

範例

Messages.svelte
<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'}
<Message
key={index}
type={message.type}
name={message.name}
text={message.text}
>
<img
slot="avatar"
alt="avatar"
class="w-8 h-8 rounded-full"
src={message.avatar}
/>
</Message>
{:else}
<Message
key={index}
type={message.type}
name={message.name}
text={message.text}
/>
{/if}
{/each}
</Messages>
<Messagebar
placeholder="Message"
value={messageText}
onInput={onMessageTextChange}
>
<Link toolbar iconOnly slot="left">
<Icon>
<CameraFill slot="ios" class="w-7 h-7" />
<MdCameraAlt
slot="material"
class="w-6 h-6 fill-black dark:fill-md-dark-on-surface"
/>
</Icon>
</Link>
<Link
toolbar
slot="right"
onClick={() => (isClickable ? handleSendClick() : undefined)}
style="opacity: {inputOpacity}; cursor: {isClickable
? 'pointer'
: 'default'}"
>
<Icon>
<ArrowUpCircleFill slot="ios" class="w-7 h-7" />
<MdSend
slot="material"
class="w-6 h-6 fill-black dark:fill-md-dark-on-surface"
/>
</Icon>
</Link>
</Messagebar>
</Page>
程式碼授權於 MIT.
2022 © Konsta UI by nolimits4web.