Skip to content

Commit 9475cc6

Browse files
committed
refactor: QChatMessage to render function
1 parent 06b7dd5 commit 9475cc6

File tree

6 files changed

+119
-86
lines changed

6 files changed

+119
-86
lines changed

src/components/alert/QAlert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default {
3838
side.push(
3939
h('img', {
4040
staticClass: 'avatar',
41-
domProps: { src: this.avatar }
41+
attrs: { src: this.avatar }
4242
})
4343
)
4444
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
export default {
2+
name: 'QChatMessage',
3+
props: {
4+
sent: Boolean,
5+
label: String,
6+
bgColor: String,
7+
textColor: String,
8+
name: String,
9+
avatar: String,
10+
text: Array,
11+
stamp: String,
12+
size: String
13+
},
14+
computed: {
15+
textClass () {
16+
if (this.textColor) {
17+
return `text-${this.textColor}`
18+
}
19+
},
20+
messageClass () {
21+
if (this.bgColor) {
22+
return `text-${this.bgColor}`
23+
}
24+
},
25+
sizeClass () {
26+
if (this.size) {
27+
return `col-${this.size}`
28+
}
29+
},
30+
classes () {
31+
return {
32+
'q-message-sent': this.sent,
33+
'q-message-received': !this.sent
34+
}
35+
}
36+
},
37+
methods: {
38+
__getText (h) {
39+
return this.text.map((msg, index) => h('div', {
40+
staticClass: 'q-message-text',
41+
'class': this.messageClass
42+
}, [
43+
h('span', {
44+
staticClass: 'q-message-text-content',
45+
'class': this.textClass
46+
}, [
47+
h('div', { domProps: { innerHTML: msg } }),
48+
this.stamp
49+
? h('div', {
50+
staticClass: 'q-message-stamp',
51+
domProps: { innerHTML: this.stamp }
52+
})
53+
: null
54+
])
55+
]))
56+
},
57+
__getMessage (h) {
58+
return h('div', {
59+
staticClass: 'q-message-text',
60+
'class': this.messageClass
61+
}, [
62+
h('span', {
63+
staticClass: 'q-message-text-content',
64+
'class': this.textClass
65+
}, [
66+
this.$slots.default,
67+
this.stamp
68+
? h('div', {
69+
staticClass: 'q-message-stamp',
70+
domProps: { innerHTML: this.stamp }
71+
})
72+
: null
73+
])
74+
])
75+
}
76+
},
77+
render (h) {
78+
return h('div', {
79+
staticClass: 'q-message',
80+
'class': this.classes
81+
}, [
82+
this.label
83+
? h('div', {
84+
staticClass: 'q-message-label text-center',
85+
domProps: { innerHTML: this.label }
86+
})
87+
: null,
88+
89+
h('div', {
90+
staticClass: 'q-message-container row items-end no-wrap'
91+
}, [
92+
this.$slots.avatar || (
93+
this.avatar
94+
? h('img', {
95+
staticClass: 'q-message-avatar',
96+
attrs: { src: this.avatar }
97+
})
98+
: null
99+
),
100+
101+
h('div', { 'class': this.sizeClass }, [
102+
this.name
103+
? h('div', {
104+
staticClass: 'q-message-name',
105+
domProps: { innerHTML: this.name }
106+
})
107+
: null,
108+
109+
this.text ? this.__getText(h) : null,
110+
this.$slots.default ? this.__getMessage(h) : null
111+
])
112+
])
113+
])
114+
}
115+
}

src/components/chat/QChatMessage.vue

Lines changed: 0 additions & 82 deletions
This file was deleted.

src/components/chip/QChip.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default {
7777
}, [
7878
this.icon
7979
? h(QIcon, { staticClass: 'q-chip-icon', props: { name: this.icon } })
80-
: (this.avatar ? h('img', { domProps: { src: this.avatar } }) : null)
80+
: (this.avatar ? h('img', { attrs: { src: this.avatar } }) : null)
8181
])
8282
: null,
8383

src/components/parallax/QParallax.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export default {
9191
}, [
9292
h('img', {
9393
ref: 'img',
94-
domProps: {
94+
attrs: {
9595
src: this.src
9696
},
9797
'class': { ready: this.imageHasBeenLoaded },

src/components/tree/QTree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ export default {
388388
return h('img', {
389389
staticClass: `q-tree-img q-mr-sm`,
390390
'class': { avatar: node.avatar },
391-
domProps: { src: node.img || node.avatar }
391+
attrs: { src: node.img || node.avatar }
392392
})
393393
}
394394
},

0 commit comments

Comments
 (0)