消息栏是与消息一起使用的一种工具栏
以下组件已包含在内
消息栏
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
颜色 | 对象 | ||
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" 文本区域属性 |
ID | 字符串 | 消息栏 ID 属性 | |
左 | 字符串 | 消息栏 "左" 区域的内容 | |
leftClass | 字符串 | 附加的左样式 | |
名称 | 字符串 | 消息栏名称 | |
轮廓 | 布尔值 | 错误 | 呈现外部发际线(边框)。如果未指定,将为 iOS 主题启用 |
占位符 | 字符串 | 号码 | '消息' | 消息栏占位符 |
右 | 字符串 | 消息栏 "右" 区域的内容 | |
rightClass | 字符串 | 附加的右样式 | |
尺寸 | 字符串 | 号码 | 文本区域的原生 "size" 属性的值 | |
样式 | CSSProperties | 附加的消息栏类 | |
textareaId | 字符串 | 文本区域 "id" 属性 | |
价值 | 任何 | 消息栏值 | |
onChange | 函数(e) |
| |
onInput | 函数(e) |
|
名称 | 描述 |
---|---|
左 | 消息栏 "左" 区域的内容 |
右 | 消息栏 "右" 区域的内容 |
<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>