Messagebar - 图1

Messagebar Vue Component

Messagebar Vue component represents Framework7’s Messagebar component.

Messagebar Components

There are following components included:

  • f7-messagebar - main messagebar element
  • f7-messagebar-sheet - messagebar sheet element
  • f7-messagebar-sheet-image - messagebar sheet image item
  • f7-messagebar-sheet-item - messagebar sheet item
  • f7-messagebar-attachments - messagebar attachments element
  • f7-messagebar-attachment - single messagebar attachment element

Messagebar - 图2

Messagebar Properties

PropTypeDefaultDescription
<f7-messagebar> properties
initbooleantrueInitializes Messagebar
namestringTextarea “name” attribute
textarea-idstring
number
Textarea “id” attribute
placeholderstringMessageTextarea placeholder text
valuestring
number
Textarea value
readonlybooleanfalseSets “readonly” textarea attribute
disabledbooleanfalseSets “disbled” textarea attribute
send-linkstringEnables Send link and specifies its text. This property will be ignored in case you use send-link slot
max-heightnumberDefines resizeable textarea max height
resizableboleantrueEnables resizeable textarea
sheet-visiblebooleanfalseMakes messagebar sheet visible/active
attachments-visiblebooleanfalseMakes messagebar attachments visible/active
resize-pagebooleantrueWhen enabled, it will resize messages page when messagebar textarea size changed
<f7-messagebar-sheet-image> properties
imagestringSheet image URL
checkedbooleanfalseIndicates whether this sheet image-item is checked or not
<f7-messagebar-attachment> properties
imagestringAttachment image URL
deletablebooleantrueDefines whether the attachment is deletable or not. In case of deletable the additional delete button will be rendered

Messagebar Methods

<f7-messagebar> methods
.clear()Clear textarea and update/reset its size
.setValue(newValue)Set messagebar textarea value/text
.getValue()Return messagebar textarea value
.resize()Force Messagebar to resize messages page depending on messagebar height/size
.focus()Focus messagebar textarea
.blur()Remove focus from messagebar textarea

Messagebar Events

EventArgumentsDescription
<f7-messagebar> events
change(event)Event will be triggered when “change” event occurs on messagebar textarea element
input(event)Event will be triggered when “input” event occurs on messagebar textarea element
focus(event)Event will be triggered when “focus” event occurs on messagebar textarea element
blur(event)Event will be triggered when “blur” event occurs on messagebar textarea element
submit
send
(value, clear)Event will be triggered when user clicks on messagebar “send link”
<f7-messagebar-sheet-image> events
change(event)Event will be triggered on sheet item checkbox change
<f7-messagebar-attachment> events
attachment:click(event)Event will be triggered on attachment click
attachment:delete(event)Event will be triggered on attachment delete button click

Messagebar Slots

Messagebar Vue component has additional slots for custom elements:

  • default - element will be inserted in the end of <div class="toolbar-inner">. element
  • before-area - element will be inserted right before textarea. Messagebar attachments go here
  • after-area - element will be inserted right after textarea
  • send-link - element will be inserted inside of send link
  • before-inner - element will be inserted right before <div class="toolbar-inner">. element
  • after-inner - element will be inserted right after <div class="toolbar-inner">. element. Messagebar sheet goes here
  • inner-start - element will be inserted in the beginning of <div class="toolbar-inner">. element
  • inner-end - element will be inserted in the end of <div class="toolbar-inner">. element. Same as default slot
  1. <f7-messagebar placeholder="Message" @submit="onSubmit">
  2. <div slot="before-inner">Before inner</div>
  3. <div slot="after-inner">After inner</div>
  4. <div slot="before-area">Before textarea</div>
  5. <div slot="after-area">After textarea</div>
  6. <f7-icon ios="f7:arrow_up_fill" aurora="f7:arrow_up_fill" md="material:send" slot="send-link"></f7-icon>
  7. <div>Default slot</div>
  8. </f7-messagebar>

Renders to:

  1. <div class="toolbar messagebar">
  2. <div>Before inner</div>
  3. <div class="toolbar-inner">
  4. <div class="messagebar-area">
  5. <div>Before textarea</div>
  6. <textarea placeholder="Message"></textarea>
  7. <div>After textarea</div>
  8. </div>
  9. <a href="#" class="link"><i class="icon f7-icons">arrow_up_fill</i></a>
  10. <div>Default slot</div>
  11. </div>
  12. <div>After inner</div>
  13. </div>

Access To Messagebar Instance

If you use automatic initalization to init Messagebar (with init:true prop) and need to use its Methods and Properties you can access its initialized instance by accessing .f7Messagebar component’s property.

Examples

Here is how the full example of Messages page where it can be used together with Messages:

  1. <template>
  2. <f7-page>
  3. <f7-navbar title="Messages"></f7-navbar>
  4. <f7-messagebar
  5. :placeholder="placeholder"
  6. ref="messagebar"
  7. :attachments-visible="attachmentsVisible"
  8. :sheet-visible="sheetVisible"
  9. >
  10. <f7-link
  11. icon-ios="f7:camera_fill"
  12. icon-aurora="f7:camera_fill"
  13. icon-md="material:camera_alt"
  14. slot="inner-start"
  15. @click="sheetVisible = !sheetVisible"
  16. ></f7-link>
  17. <f7-link
  18. icon-ios="f7:arrow_up_fill"
  19. icon-aurora="f7:arrow_up_fill"
  20. icon-md="material:send"
  21. slot="inner-end"
  22. @click="sendMessage"
  23. ></f7-link>
  24. <f7-messagebar-attachments>
  25. <f7-messagebar-attachment
  26. v-for="(image, index) in attachments"
  27. :key="index"
  28. :image="image"
  29. @attachment:delete="deleteAttachment(image)"
  30. ></f7-messagebar-attachment>
  31. </f7-messagebar-attachments>
  32. <f7-messagebar-sheet>
  33. <f7-messagebar-sheet-image
  34. v-for="(image, index) in images"
  35. :key="index"
  36. :image="image"
  37. :checked="attachments.indexOf(image) >= 0"
  38. @change="handleAttachment"
  39. ></f7-messagebar-sheet-image>
  40. </f7-messagebar-sheet>
  41. </f7-messagebar>
  42. <f7-messages ref="messages">
  43. <f7-messages-title><b>Sunday, Feb 9,</b> 12:58</f7-messages-title>
  44. <f7-message
  45. v-for="(message, index) in messagesData"
  46. :key="index"
  47. :type="message.type"
  48. :image="message.image"
  49. :name="message.name"
  50. :avatar="message.avatar"
  51. :first="isFirstMessage(message, index)"
  52. :last="isLastMessage(message, index)"
  53. :tail="isTailMessage(message, index)"
  54. >
  55. <span slot="text" v-if="message.text" v-html="message.text"></span>
  56. </f7-message>
  57. <f7-message v-if="typingMessage"
  58. type="received"
  59. :typing="true"
  60. :first="true"
  61. :last="true"
  62. :tail="true"
  63. :header="`${typingMessage.name} is typing`"
  64. :avatar="typingMessage.avatar"
  65. ></f7-message>
  66. </f7-messages>
  67. </f7-page>
  68. </template>
  69. <script>
  70. export default {
  71. data() {
  72. return {
  73. attachments: [],
  74. sheetVisible: false,
  75. typingMessage: null,
  76. messagesData: [
  77. {
  78. type: 'sent',
  79. text: 'Hi, Kate',
  80. },
  81. {
  82. type: 'sent',
  83. text: 'How are you?',
  84. },
  85. {
  86. name: 'Kate',
  87. type: 'received',
  88. text: 'Hi, I am good!',
  89. avatar: 'https://cdn.framework7.io/placeholder/people-100x100-9.jpg',
  90. },
  91. {
  92. name: 'Blue Ninja',
  93. type: 'received',
  94. text: 'Hi there, I am also fine, thanks! And how are you?',
  95. avatar: 'https://cdn.framework7.io/placeholder/people-100x100-7.jpg',
  96. },
  97. {
  98. type: 'sent',
  99. text: 'Hey, Blue Ninja! Glad to see you ;)',
  100. },
  101. {
  102. type: 'sent',
  103. text: 'Hey, look, cutest kitten ever!',
  104. },
  105. {
  106. type: 'sent',
  107. image: 'https://cdn.framework7.io/placeholder/cats-200x260-4.jpg',
  108. },
  109. {
  110. name: 'Kate',
  111. type: 'received',
  112. text: 'Nice!',
  113. avatar: 'https://cdn.framework7.io/placeholder/people-100x100-9.jpg',
  114. },
  115. {
  116. name: 'Kate',
  117. type: 'received',
  118. text: 'Like it very much!',
  119. avatar: 'https://cdn.framework7.io/placeholder/people-100x100-9.jpg',
  120. },
  121. {
  122. name: 'Blue Ninja',
  123. type: 'received',
  124. text: 'Awesome!',
  125. avatar: 'https://cdn.framework7.io/placeholder/people-100x100-7.jpg',
  126. },
  127. ],
  128. images: [
  129. 'https://cdn.framework7.io/placeholder/cats-300x300-1.jpg',
  130. 'https://cdn.framework7.io/placeholder/cats-200x300-2.jpg',
  131. 'https://cdn.framework7.io/placeholder/cats-400x300-3.jpg',
  132. 'https://cdn.framework7.io/placeholder/cats-300x150-4.jpg',
  133. 'https://cdn.framework7.io/placeholder/cats-150x300-5.jpg',
  134. 'https://cdn.framework7.io/placeholder/cats-300x300-6.jpg',
  135. 'https://cdn.framework7.io/placeholder/cats-300x300-7.jpg',
  136. 'https://cdn.framework7.io/placeholder/cats-200x300-8.jpg',
  137. 'https://cdn.framework7.io/placeholder/cats-400x300-9.jpg',
  138. 'https://cdn.framework7.io/placeholder/cats-300x150-10.jpg',
  139. ],
  140. people: [
  141. {
  142. name: 'Kate Johnson',
  143. avatar: 'https://cdn.framework7.io/placeholder/people-100x100-9.jpg',
  144. },
  145. {
  146. name: 'Blue Ninja',
  147. avatar: 'https://cdn.framework7.io/placeholder/people-100x100-7.jpg',
  148. },
  149. ],
  150. answers: [
  151. 'Yes!',
  152. 'No',
  153. 'Hm...',
  154. 'I am not sure',
  155. 'And what about you?',
  156. 'May be ;)',
  157. 'Lorem ipsum dolor sit amet, consectetur',
  158. 'What?',
  159. 'Are you sure?',
  160. 'Of course',
  161. 'Need to think about it',
  162. 'Amazing!!!',
  163. ],
  164. responseInProgress: false,
  165. };
  166. },
  167. computed: {
  168. attachmentsVisible() {
  169. const self = this;
  170. return self.attachments.length > 0;
  171. },
  172. placeholder() {
  173. const self = this;
  174. return self.attachments.length > 0 ? 'Add comment or Send' : 'Message';
  175. },
  176. },
  177. mounted() {
  178. const self = this;
  179. self.$f7ready(() => {
  180. self.messagebar = self.$refs.messagebar.f7Messagebar;
  181. self.messages = self.$refs.messages.f7Messages;
  182. });
  183. },
  184. methods: {
  185. isFirstMessage(message, index) {
  186. const self = this;
  187. const previousMessage = self.messagesData[index - 1];
  188. if (message.isTitle) return false;
  189. if (!previousMessage || previousMessage.type !== message.type || previousMessage.name !== message.name) return true;
  190. return false;
  191. },
  192. isLastMessage(message, index) {
  193. const self = this;
  194. const nextMessage = self.messagesData[index + 1];
  195. if (message.isTitle) return false;
  196. if (!nextMessage || nextMessage.type !== message.type || nextMessage.name !== message.name) return true;
  197. return false;
  198. },
  199. isTailMessage(message, index) {
  200. const self = this;
  201. const nextMessage = self.messagesData[index + 1];
  202. if (message.isTitle) return false;
  203. if (!nextMessage || nextMessage.type !== message.type || nextMessage.name !== message.name) return true;
  204. return false;
  205. },
  206. deleteAttachment(image) {
  207. const self = this;
  208. const index = self.attachments.indexOf(image);
  209. self.attachments.splice(index, 1)[0]; // eslint-disable-line
  210. },
  211. handleAttachment(e) {
  212. const self = this;
  213. const index = self.$$(e.target).parents('label.checkbox').index();
  214. const image = self.images[index];
  215. if (e.target.checked) {
  216. // Add to attachments
  217. self.attachments.unshift(image);
  218. } else {
  219. // Remove from attachments
  220. self.attachments.splice(self.attachments.indexOf(image), 1);
  221. }
  222. },
  223. sendMessage() {
  224. const self = this;
  225. const text = self.messagebar.getValue().replace(/\n/g, '<br>').trim();
  226. const messagesToSend = [];
  227. self.attachments.forEach((attachment) => {
  228. messagesToSend.push({
  229. image: attachment,
  230. });
  231. });
  232. if (text.trim().length) {
  233. messagesToSend.push({
  234. text,
  235. });
  236. }
  237. if (messagesToSend.length === 0) {
  238. return;
  239. }
  240. // Reset attachments
  241. self.attachments = [];
  242. // Hide sheet
  243. self.sheetVisible = false;
  244. // Clear area
  245. self.messagebar.clear();
  246. // Focus area
  247. if (text.length) self.messagebar.focus();
  248. // Send message
  249. self.messagesData.push(...messagesToSend);
  250. // Mock response
  251. if (self.responseInProgress) return;
  252. self.responseInProgress = true;
  253. setTimeout(() => {
  254. const answer = self.answers[Math.floor(Math.random() * self.answers.length)];
  255. const person = self.people[Math.floor(Math.random() * self.people.length)];
  256. self.typingMessage = {
  257. name: person.name,
  258. avatar: person.avatar,
  259. };
  260. setTimeout(() => {
  261. self.messagesData.push({
  262. text: answer,
  263. type: 'received',
  264. name: person.name,
  265. avatar: person.avatar,
  266. });
  267. self.typingMessage = null;
  268. self.responseInProgress = false;
  269. }, 4000);
  270. }, 1000);
  271. },
  272. },
  273. };
  274. </script>

← Menu

Messages →