@vaadin/message-list 24.6.0-beta1 → 24.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +10 -9
- package/src/vaadin-lit-message-list.d.ts +1 -0
- package/src/vaadin-lit-message-list.js +53 -0
- package/src/vaadin-lit-message.d.ts +1 -0
- package/src/vaadin-lit-message.js +50 -0
- package/src/vaadin-message-list-mixin.d.ts +42 -0
- package/src/vaadin-message-list-mixin.js +149 -0
- package/src/vaadin-message-list.d.ts +3 -32
- package/src/vaadin-message-list.js +6 -141
- package/src/vaadin-message-mixin.d.ts +68 -0
- package/src/vaadin-message-mixin.js +119 -0
- package/src/vaadin-message-styles.d.ts +8 -0
- package/src/vaadin-message-styles.js +43 -0
- package/src/vaadin-message.d.ts +2 -57
- package/src/vaadin-message.js +7 -147
- package/theme/lumo/vaadin-lit-message-list.d.ts +2 -0
- package/theme/lumo/vaadin-lit-message-list.js +2 -0
- package/theme/lumo/vaadin-lit-message.d.ts +2 -0
- package/theme/lumo/vaadin-lit-message.js +2 -0
- package/theme/material/vaadin-lit-message-list.d.ts +2 -0
- package/theme/material/vaadin-lit-message-list.js +2 -0
- package/theme/material/vaadin-lit-message.d.ts +2 -0
- package/theme/material/vaadin-lit-message.js +2 -0
- package/vaadin-lit-message-list.d.ts +1 -0
- package/vaadin-lit-message-list.js +2 -0
- package/vaadin-lit-message.d.ts +1 -0
- package/vaadin-lit-message.js +2 -0
- package/web-types.json +2 -2
- package/web-types.lit.json +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/message-list",
|
|
3
|
-
"version": "24.6.0
|
|
3
|
+
"version": "24.6.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -37,17 +37,18 @@
|
|
|
37
37
|
"polymer"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
+
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
40
41
|
"@polymer/polymer": "^3.0.0",
|
|
41
|
-
"@vaadin/a11y-base": "24.6.0
|
|
42
|
-
"@vaadin/avatar": "24.6.0
|
|
43
|
-
"@vaadin/component-base": "24.6.0
|
|
44
|
-
"@vaadin/vaadin-lumo-styles": "24.6.0
|
|
45
|
-
"@vaadin/vaadin-material-styles": "24.6.0
|
|
46
|
-
"@vaadin/vaadin-themable-mixin": "24.6.0
|
|
42
|
+
"@vaadin/a11y-base": "~24.6.0",
|
|
43
|
+
"@vaadin/avatar": "~24.6.0",
|
|
44
|
+
"@vaadin/component-base": "~24.6.0",
|
|
45
|
+
"@vaadin/vaadin-lumo-styles": "~24.6.0",
|
|
46
|
+
"@vaadin/vaadin-material-styles": "~24.6.0",
|
|
47
|
+
"@vaadin/vaadin-themable-mixin": "~24.6.0",
|
|
47
48
|
"lit": "^3.0.0"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
|
-
"@vaadin/chai-plugins": "24.6.0
|
|
51
|
+
"@vaadin/chai-plugins": "~24.6.0",
|
|
51
52
|
"@vaadin/testing-helpers": "^1.0.0",
|
|
52
53
|
"sinon": "^18.0.0"
|
|
53
54
|
},
|
|
@@ -55,5 +56,5 @@
|
|
|
55
56
|
"web-types.json",
|
|
56
57
|
"web-types.lit.json"
|
|
57
58
|
],
|
|
58
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "c0b38aa981494d04fac64da35aa3890ad72551ea"
|
|
59
60
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './vaadin-message-list.js';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 - 2024 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import './vaadin-lit-message.js';
|
|
7
|
+
import { css, html, LitElement } from 'lit';
|
|
8
|
+
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
9
|
+
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
|
|
10
|
+
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
|
|
11
|
+
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
12
|
+
import { MessageListMixin } from './vaadin-message-list-mixin.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* LitElement based version of `<vaadin-message-list>` web component.
|
|
16
|
+
*
|
|
17
|
+
* ## Disclaimer
|
|
18
|
+
*
|
|
19
|
+
* This component is an experiment and not yet a part of Vaadin platform.
|
|
20
|
+
* There is no ETA regarding specific Vaadin version where it'll land.
|
|
21
|
+
* Feel free to try this code in your apps as per Apache 2.0 license.
|
|
22
|
+
*/
|
|
23
|
+
class MessageList extends MessageListMixin(ElementMixin(ThemableMixin(PolylitMixin(LitElement)))) {
|
|
24
|
+
static get is() {
|
|
25
|
+
return 'vaadin-message-list';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static get styles() {
|
|
29
|
+
return css`
|
|
30
|
+
:host {
|
|
31
|
+
display: block;
|
|
32
|
+
overflow: auto;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
:host([hidden]) {
|
|
36
|
+
display: none !important;
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** @protected */
|
|
42
|
+
render() {
|
|
43
|
+
return html`
|
|
44
|
+
<div part="list" role="list">
|
|
45
|
+
<slot></slot>
|
|
46
|
+
</div>
|
|
47
|
+
`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
defineCustomElement(MessageList);
|
|
52
|
+
|
|
53
|
+
export { MessageList };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './vaadin-message.js';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 - 2024 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import '@vaadin/avatar/src/vaadin-lit-avatar.js';
|
|
7
|
+
import { html, LitElement } from 'lit';
|
|
8
|
+
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
9
|
+
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
|
|
10
|
+
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
|
|
11
|
+
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
12
|
+
import { MessageMixin } from './vaadin-message-mixin.js';
|
|
13
|
+
import { messageStyles } from './vaadin-message-styles.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* LitElement based version of `<vaadin-message>` web component.
|
|
17
|
+
*
|
|
18
|
+
* ## Disclaimer
|
|
19
|
+
*
|
|
20
|
+
* This component is an experiment and not yet a part of Vaadin platform.
|
|
21
|
+
* There is no ETA regarding specific Vaadin version where it'll land.
|
|
22
|
+
* Feel free to try this code in your apps as per Apache 2.0 license.
|
|
23
|
+
*/
|
|
24
|
+
class Message extends MessageMixin(ElementMixin(ThemableMixin(PolylitMixin(LitElement)))) {
|
|
25
|
+
static get is() {
|
|
26
|
+
return 'vaadin-message';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static get styles() {
|
|
30
|
+
return messageStyles;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** @protected */
|
|
34
|
+
render() {
|
|
35
|
+
return html`
|
|
36
|
+
<slot name="avatar"></slot>
|
|
37
|
+
<div part="content">
|
|
38
|
+
<div part="header">
|
|
39
|
+
<span part="name">${this.userName}</span>
|
|
40
|
+
<span part="time">${this.time}</span>
|
|
41
|
+
</div>
|
|
42
|
+
<div part="message"><slot></slot></div>
|
|
43
|
+
</div>
|
|
44
|
+
`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
defineCustomElement(Message);
|
|
49
|
+
|
|
50
|
+
export { Message };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 - 2024 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import type { Constructor } from '@open-wc/dedupe-mixin';
|
|
7
|
+
import type { KeyboardDirectionMixinClass } from '@vaadin/a11y-base/src/keyboard-direction-mixin.js';
|
|
8
|
+
|
|
9
|
+
export interface MessageListItem {
|
|
10
|
+
text?: string;
|
|
11
|
+
time?: string;
|
|
12
|
+
userName?: string;
|
|
13
|
+
userAbbr?: string;
|
|
14
|
+
userImg?: string;
|
|
15
|
+
userColorIndex?: number;
|
|
16
|
+
theme?: string;
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export declare function MessageListMixin<T extends Constructor<HTMLElement>>(
|
|
21
|
+
base: T,
|
|
22
|
+
): Constructor<KeyboardDirectionMixinClass> & Constructor<MessageListMixinClass> & T;
|
|
23
|
+
|
|
24
|
+
export declare class MessageListMixinClass {
|
|
25
|
+
/**
|
|
26
|
+
* An array of objects which will be rendered as messages.
|
|
27
|
+
* The message objects can have the following properties:
|
|
28
|
+
* ```js
|
|
29
|
+
* Array<{
|
|
30
|
+
* text: string,
|
|
31
|
+
* time: string,
|
|
32
|
+
* userName: string,
|
|
33
|
+
* userAbbr: string,
|
|
34
|
+
* userImg: string,
|
|
35
|
+
* userColorIndex: number,
|
|
36
|
+
* className: string,
|
|
37
|
+
* theme: string
|
|
38
|
+
* }>
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
items: MessageListItem[] | null | undefined;
|
|
42
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 - 2024 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { html, render } from 'lit';
|
|
7
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
8
|
+
import { KeyboardDirectionMixin } from '@vaadin/a11y-base/src/keyboard-direction-mixin.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @polymerMixin
|
|
12
|
+
* @mixes KeyboardDirectionMixin
|
|
13
|
+
*/
|
|
14
|
+
export const MessageListMixin = (superClass) =>
|
|
15
|
+
class MessageListMixinClass extends KeyboardDirectionMixin(superClass) {
|
|
16
|
+
static get properties() {
|
|
17
|
+
return {
|
|
18
|
+
/**
|
|
19
|
+
* An array of objects which will be rendered as messages.
|
|
20
|
+
* The message objects can have the following properties:
|
|
21
|
+
* ```js
|
|
22
|
+
* Array<{
|
|
23
|
+
* text: string,
|
|
24
|
+
* time: string,
|
|
25
|
+
* userName: string,
|
|
26
|
+
* userAbbr: string,
|
|
27
|
+
* userImg: string,
|
|
28
|
+
* userColorIndex: number,
|
|
29
|
+
* className: string,
|
|
30
|
+
* theme: string
|
|
31
|
+
* }>
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
items: {
|
|
35
|
+
type: Array,
|
|
36
|
+
value: () => [],
|
|
37
|
+
observer: '_itemsChanged',
|
|
38
|
+
sync: true,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @protected */
|
|
44
|
+
get _messages() {
|
|
45
|
+
return [...this.querySelectorAll('vaadin-message')];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** @protected */
|
|
49
|
+
ready() {
|
|
50
|
+
super.ready();
|
|
51
|
+
|
|
52
|
+
// Make screen readers announce new messages
|
|
53
|
+
this.setAttribute('aria-relevant', 'additions');
|
|
54
|
+
this.setAttribute('role', 'log');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Override method inherited from `KeyboardDirectionMixin`
|
|
59
|
+
* to use the list of message elements as items.
|
|
60
|
+
*
|
|
61
|
+
* @return {Element[]}
|
|
62
|
+
* @protected
|
|
63
|
+
* @override
|
|
64
|
+
*/
|
|
65
|
+
_getItems() {
|
|
66
|
+
return this._messages;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** @private */
|
|
70
|
+
_itemsChanged(newVal, oldVal) {
|
|
71
|
+
const items = newVal || [];
|
|
72
|
+
const oldItems = oldVal || [];
|
|
73
|
+
|
|
74
|
+
if (items.length || oldItems.length) {
|
|
75
|
+
const focusedIndex = this._getIndexOfFocusableElement();
|
|
76
|
+
const closeToBottom = this.scrollHeight < this.clientHeight + this.scrollTop + 50;
|
|
77
|
+
|
|
78
|
+
this._renderMessages(items);
|
|
79
|
+
this._setTabIndexesByIndex(focusedIndex);
|
|
80
|
+
|
|
81
|
+
requestAnimationFrame(() => {
|
|
82
|
+
if (items.length > oldItems.length && closeToBottom) {
|
|
83
|
+
this._scrollToLastMessage();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** @private */
|
|
90
|
+
_renderMessages(items) {
|
|
91
|
+
render(
|
|
92
|
+
html`
|
|
93
|
+
${items.map(
|
|
94
|
+
(item) => html`
|
|
95
|
+
<vaadin-message
|
|
96
|
+
role="listitem"
|
|
97
|
+
.time="${item.time}"
|
|
98
|
+
.userAbbr="${item.userAbbr}"
|
|
99
|
+
.userName="${item.userName}"
|
|
100
|
+
.userImg="${item.userImg}"
|
|
101
|
+
.userColorIndex="${item.userColorIndex}"
|
|
102
|
+
theme="${ifDefined(item.theme)}"
|
|
103
|
+
class="${ifDefined(item.className)}"
|
|
104
|
+
@focusin="${this._onMessageFocusIn}"
|
|
105
|
+
>${item.text}<vaadin-avatar slot="avatar"></vaadin-avatar
|
|
106
|
+
></vaadin-message>
|
|
107
|
+
`,
|
|
108
|
+
)}
|
|
109
|
+
`,
|
|
110
|
+
this,
|
|
111
|
+
{ host: this },
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** @private */
|
|
116
|
+
_scrollToLastMessage() {
|
|
117
|
+
if (this.items.length > 0) {
|
|
118
|
+
this.scrollTop = this.scrollHeight - this.clientHeight;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** @private */
|
|
123
|
+
_onMessageFocusIn(e) {
|
|
124
|
+
const target = e.composedPath().find((node) => node instanceof customElements.get('vaadin-message'));
|
|
125
|
+
this._setTabIndexesByMessage(target);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @param {number} idx
|
|
130
|
+
* @protected
|
|
131
|
+
*/
|
|
132
|
+
_setTabIndexesByIndex(index) {
|
|
133
|
+
const message = this._messages[index] || this._messages[0];
|
|
134
|
+
this._setTabIndexesByMessage(message);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** @private */
|
|
138
|
+
_setTabIndexesByMessage(message) {
|
|
139
|
+
this._messages.forEach((e) => {
|
|
140
|
+
e.tabIndex = e === message ? 0 : -1;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** @private */
|
|
145
|
+
_getIndexOfFocusableElement() {
|
|
146
|
+
const index = this._messages.findIndex((e) => e.tabIndex === 0);
|
|
147
|
+
return index !== -1 ? index : 0;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
@@ -3,20 +3,11 @@
|
|
|
3
3
|
* Copyright (c) 2021 - 2024 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
-
import { KeyboardDirectionMixin } from '@vaadin/a11y-base/src/keyboard-direction-mixin.js';
|
|
7
6
|
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
|
|
8
7
|
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
8
|
+
import { MessageListMixin } from './vaadin-message-list-mixin.js';
|
|
9
9
|
|
|
10
|
-
export
|
|
11
|
-
text?: string;
|
|
12
|
-
time?: string;
|
|
13
|
-
userName?: string;
|
|
14
|
-
userAbbr?: string;
|
|
15
|
-
userImg?: string;
|
|
16
|
-
userColorIndex?: number;
|
|
17
|
-
theme?: string;
|
|
18
|
-
className?: string;
|
|
19
|
-
}
|
|
10
|
+
export { MessageListItem } from './vaadin-message-list-mixin.js';
|
|
20
11
|
|
|
21
12
|
/**
|
|
22
13
|
* `<vaadin-message-list>` is a Web Component for showing an ordered list of messages. The messages are rendered as <vaadin-message>
|
|
@@ -51,27 +42,7 @@ export interface MessageListItem {
|
|
|
51
42
|
*
|
|
52
43
|
* See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
|
|
53
44
|
*/
|
|
54
|
-
declare class MessageList extends
|
|
55
|
-
/**
|
|
56
|
-
* An array of objects which will be rendered as messages.
|
|
57
|
-
* The message objects can have the following properties:
|
|
58
|
-
* ```js
|
|
59
|
-
* Array<{
|
|
60
|
-
* text: string,
|
|
61
|
-
* time: string,
|
|
62
|
-
* userName: string,
|
|
63
|
-
* userAbbr: string,
|
|
64
|
-
* userImg: string,
|
|
65
|
-
* userColorIndex: number,
|
|
66
|
-
* className: string,
|
|
67
|
-
* theme: string
|
|
68
|
-
* }>
|
|
69
|
-
* ```
|
|
70
|
-
*
|
|
71
|
-
* @type {!Array<!MessageListItem>}
|
|
72
|
-
*/
|
|
73
|
-
items: MessageListItem[] | null | undefined;
|
|
74
|
-
}
|
|
45
|
+
declare class MessageList extends MessageListMixin(ThemableMixin(ElementMixin(HTMLElement))) {}
|
|
75
46
|
|
|
76
47
|
declare global {
|
|
77
48
|
interface HTMLElementTagNameMap {
|
|
@@ -3,14 +3,12 @@
|
|
|
3
3
|
* Copyright (c) 2021 - 2024 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
-
import
|
|
7
|
-
import { html,
|
|
8
|
-
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
9
|
-
import { KeyboardDirectionMixin } from '@vaadin/a11y-base/src/keyboard-direction-mixin.js';
|
|
6
|
+
import './vaadin-message.js';
|
|
7
|
+
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
10
8
|
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
11
9
|
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
|
|
12
10
|
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
13
|
-
import {
|
|
11
|
+
import { MessageListMixin } from './vaadin-message-list-mixin.js';
|
|
14
12
|
|
|
15
13
|
/**
|
|
16
14
|
* `<vaadin-message-list>` is a Web Component for showing an ordered list of messages. The messages are rendered as <vaadin-message>
|
|
@@ -49,41 +47,15 @@ import { Message } from './vaadin-message.js';
|
|
|
49
47
|
* @extends HTMLElement
|
|
50
48
|
* @mixes ThemableMixin
|
|
51
49
|
* @mixes ElementMixin
|
|
52
|
-
* @mixes
|
|
50
|
+
* @mixes MessageListMixin
|
|
53
51
|
*/
|
|
54
|
-
class MessageList extends
|
|
52
|
+
class MessageList extends MessageListMixin(ElementMixin(ThemableMixin(PolymerElement))) {
|
|
55
53
|
static get is() {
|
|
56
54
|
return 'vaadin-message-list';
|
|
57
55
|
}
|
|
58
56
|
|
|
59
|
-
static get properties() {
|
|
60
|
-
return {
|
|
61
|
-
/**
|
|
62
|
-
* An array of objects which will be rendered as messages.
|
|
63
|
-
* The message objects can have the following properties:
|
|
64
|
-
* ```js
|
|
65
|
-
* Array<{
|
|
66
|
-
* text: string,
|
|
67
|
-
* time: string,
|
|
68
|
-
* userName: string,
|
|
69
|
-
* userAbbr: string,
|
|
70
|
-
* userImg: string,
|
|
71
|
-
* userColorIndex: number,
|
|
72
|
-
* className: string,
|
|
73
|
-
* theme: string
|
|
74
|
-
* }>
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
items: {
|
|
78
|
-
type: Array,
|
|
79
|
-
value: () => [],
|
|
80
|
-
observer: '_itemsChanged',
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
57
|
static get template() {
|
|
86
|
-
return
|
|
58
|
+
return html`
|
|
87
59
|
<style>
|
|
88
60
|
:host {
|
|
89
61
|
display: block;
|
|
@@ -99,113 +71,6 @@ class MessageList extends KeyboardDirectionMixin(ElementMixin(ThemableMixin(Poly
|
|
|
99
71
|
</div>
|
|
100
72
|
`;
|
|
101
73
|
}
|
|
102
|
-
|
|
103
|
-
/** @protected */
|
|
104
|
-
get _messages() {
|
|
105
|
-
return [...this.querySelectorAll('vaadin-message')];
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/** @protected */
|
|
109
|
-
ready() {
|
|
110
|
-
super.ready();
|
|
111
|
-
|
|
112
|
-
// Make screen readers announce new messages
|
|
113
|
-
this.setAttribute('aria-relevant', 'additions');
|
|
114
|
-
this.setAttribute('role', 'log');
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Override method inherited from `KeyboardDirectionMixin`
|
|
119
|
-
* to use the list of message elements as items.
|
|
120
|
-
*
|
|
121
|
-
* @return {Element[]}
|
|
122
|
-
* @protected
|
|
123
|
-
* @override
|
|
124
|
-
*/
|
|
125
|
-
_getItems() {
|
|
126
|
-
return this._messages;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/** @private */
|
|
130
|
-
_itemsChanged(newVal, oldVal) {
|
|
131
|
-
const items = newVal || [];
|
|
132
|
-
const oldItems = oldVal || [];
|
|
133
|
-
|
|
134
|
-
if (items.length || oldItems.length) {
|
|
135
|
-
const focusedIndex = this._getIndexOfFocusableElement();
|
|
136
|
-
const closeToBottom = this.scrollHeight < this.clientHeight + this.scrollTop + 50;
|
|
137
|
-
|
|
138
|
-
this._renderMessages(items);
|
|
139
|
-
this._setTabIndexesByIndex(focusedIndex);
|
|
140
|
-
|
|
141
|
-
requestAnimationFrame(() => {
|
|
142
|
-
if (items.length > oldItems.length && closeToBottom) {
|
|
143
|
-
this._scrollToLastMessage();
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/** @private */
|
|
150
|
-
_renderMessages(items) {
|
|
151
|
-
render(
|
|
152
|
-
html`
|
|
153
|
-
${items.map(
|
|
154
|
-
(item) => html`
|
|
155
|
-
<vaadin-message
|
|
156
|
-
role="listitem"
|
|
157
|
-
.time="${item.time}"
|
|
158
|
-
.userAbbr="${item.userAbbr}"
|
|
159
|
-
.userName="${item.userName}"
|
|
160
|
-
.userImg="${item.userImg}"
|
|
161
|
-
.userColorIndex="${item.userColorIndex}"
|
|
162
|
-
theme="${ifDefined(item.theme)}"
|
|
163
|
-
class="${ifDefined(item.className)}"
|
|
164
|
-
@focusin="${this._onMessageFocusIn}"
|
|
165
|
-
>${item.text}<vaadin-avatar slot="avatar"></vaadin-avatar
|
|
166
|
-
></vaadin-message>
|
|
167
|
-
`,
|
|
168
|
-
)}
|
|
169
|
-
`,
|
|
170
|
-
this,
|
|
171
|
-
{ host: this },
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/** @private */
|
|
176
|
-
_scrollToLastMessage() {
|
|
177
|
-
if (this.items.length > 0) {
|
|
178
|
-
this.scrollTop = this.scrollHeight - this.clientHeight;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/** @private */
|
|
183
|
-
_onMessageFocusIn(e) {
|
|
184
|
-
const target = e.composedPath().find((node) => node instanceof Message);
|
|
185
|
-
this._setTabIndexesByMessage(target);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* @param {number} idx
|
|
190
|
-
* @protected
|
|
191
|
-
*/
|
|
192
|
-
_setTabIndexesByIndex(index) {
|
|
193
|
-
const message = this._messages[index] || this._messages[0];
|
|
194
|
-
this._setTabIndexesByMessage(message);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/** @private */
|
|
198
|
-
_setTabIndexesByMessage(message) {
|
|
199
|
-
this._messages.forEach((e) => {
|
|
200
|
-
e.tabIndex = e === message ? 0 : -1;
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/** @private */
|
|
205
|
-
_getIndexOfFocusableElement() {
|
|
206
|
-
const index = this._messages.findIndex((e) => e.tabIndex === 0);
|
|
207
|
-
return index !== -1 ? index : 0;
|
|
208
|
-
}
|
|
209
74
|
}
|
|
210
75
|
|
|
211
76
|
defineCustomElement(MessageList);
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 - 2024 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import type { Constructor } from '@open-wc/dedupe-mixin';
|
|
7
|
+
import type { FocusMixinClass } from '@vaadin/a11y-base/src/focus-mixin.js';
|
|
8
|
+
import type { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
|
|
9
|
+
|
|
10
|
+
export declare function MessageMixin<T extends Constructor<HTMLElement>>(
|
|
11
|
+
base: T,
|
|
12
|
+
): Constructor<ControllerMixinClass> & Constructor<FocusMixinClass> & Constructor<MessageMixinClass> & T;
|
|
13
|
+
|
|
14
|
+
export declare class MessageMixinClass {
|
|
15
|
+
/**
|
|
16
|
+
* Time of sending the message. It is rendered as-is to the part='time' slot,
|
|
17
|
+
* so the formatting is up to you.
|
|
18
|
+
*/
|
|
19
|
+
time: string | null | undefined;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The name of the user posting the message.
|
|
23
|
+
* It will be placed in the name part to indicate who has sent the message.
|
|
24
|
+
* It is also used as a tooltip for the avatar.
|
|
25
|
+
* Example: `message.userName = "Jessica Jacobs";`
|
|
26
|
+
* @attr {string} user-name
|
|
27
|
+
*/
|
|
28
|
+
userName: string | null | undefined;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The abbreviation of the user.
|
|
32
|
+
* The abbreviation will be passed on to avatar of the message.
|
|
33
|
+
* If the user does not have an avatar picture set with `userImg`, `userAbbr` will be shown in the avatar.
|
|
34
|
+
* Example: `message.userAbbr = "JJ";`
|
|
35
|
+
* @attr {string} user-abbr
|
|
36
|
+
*/
|
|
37
|
+
userAbbr: string | null | undefined;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* An URL for a user image.
|
|
41
|
+
* The image will be used in the avatar component to show who has sent the message.
|
|
42
|
+
* Example: `message.userImg = "/static/img/avatar.jpg";`
|
|
43
|
+
* @attr {string} user-img
|
|
44
|
+
*/
|
|
45
|
+
userImg: string | null | undefined;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A color index to be used to render the color of the avatar.
|
|
49
|
+
* With no `userColorIndex` set, the basic avatar color will be used.
|
|
50
|
+
* By setting a userColorIndex, the component will check if there exists a CSS variable defining the color, and uses it if there is one.
|
|
51
|
+
* If now CSS variable is found for the color index, the property for the color will not be set.
|
|
52
|
+
*
|
|
53
|
+
* Example:
|
|
54
|
+
* CSS:
|
|
55
|
+
* ```css
|
|
56
|
+
* html {
|
|
57
|
+
* --vaadin-user-color-1: red;
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* JavaScript:
|
|
62
|
+
* ```js
|
|
63
|
+
* message.userColorIndex = 1;
|
|
64
|
+
* ```
|
|
65
|
+
* @attr {number} user-color-index
|
|
66
|
+
*/
|
|
67
|
+
userColorIndex: number | null | undefined;
|
|
68
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 - 2024 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { FocusMixin } from '@vaadin/a11y-base/src/focus-mixin.js';
|
|
7
|
+
import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
|
|
8
|
+
import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @polymerMixin
|
|
12
|
+
* @mixes ControllerMixin
|
|
13
|
+
* @mixes FocusMixin
|
|
14
|
+
*/
|
|
15
|
+
export const MessageMixin = (superClass) =>
|
|
16
|
+
class MessageMixinClass extends FocusMixin(ControllerMixin(superClass)) {
|
|
17
|
+
static get properties() {
|
|
18
|
+
return {
|
|
19
|
+
/**
|
|
20
|
+
* Time of sending the message. It is rendered as-is to the part='time' slot,
|
|
21
|
+
* so the formatting is up to you.
|
|
22
|
+
*/
|
|
23
|
+
time: {
|
|
24
|
+
type: String,
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The name of the user posting the message.
|
|
29
|
+
* It will be placed in the name part to indicate who has sent the message.
|
|
30
|
+
* It is also used as a tooltip for the avatar.
|
|
31
|
+
* Example: `message.userName = "Jessica Jacobs";`
|
|
32
|
+
* @attr {string} user-name
|
|
33
|
+
*/
|
|
34
|
+
userName: {
|
|
35
|
+
type: String,
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The abbreviation of the user.
|
|
40
|
+
* The abbreviation will be passed on to avatar of the message.
|
|
41
|
+
* If the user does not have an avatar picture set with `userImg`, `userAbbr` will be shown in the avatar.
|
|
42
|
+
* Example: `message.userAbbr = "JJ";`
|
|
43
|
+
* @attr {string} user-abbr
|
|
44
|
+
*/
|
|
45
|
+
userAbbr: {
|
|
46
|
+
type: String,
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* An URL for a user image.
|
|
51
|
+
* The image will be used in the avatar component to show who has sent the message.
|
|
52
|
+
* Example: `message.userImg = "/static/img/avatar.jpg";`
|
|
53
|
+
* @attr {string} user-img
|
|
54
|
+
*/
|
|
55
|
+
userImg: {
|
|
56
|
+
type: String,
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A color index to be used to render the color of the avatar.
|
|
61
|
+
* With no `userColorIndex` set, the basic avatar color will be used.
|
|
62
|
+
* By setting a userColorIndex, the component will check if there exists a CSS variable defining the color, and uses it if there is one.
|
|
63
|
+
* If now CSS variable is found for the color index, the property for the color will not be set.
|
|
64
|
+
*
|
|
65
|
+
* Example:
|
|
66
|
+
* CSS:
|
|
67
|
+
* ```css
|
|
68
|
+
* html {
|
|
69
|
+
* --vaadin-user-color-1: red;
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* JavaScript:
|
|
74
|
+
* ```js
|
|
75
|
+
* message.userColorIndex = 1;
|
|
76
|
+
* ```
|
|
77
|
+
* @attr {number} user-color-index
|
|
78
|
+
*/
|
|
79
|
+
userColorIndex: {
|
|
80
|
+
type: Number,
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
/** @private */
|
|
84
|
+
_avatar: {
|
|
85
|
+
type: Object,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static get observers() {
|
|
91
|
+
return ['__avatarChanged(_avatar, userName, userAbbr, userImg, userColorIndex)'];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** @protected */
|
|
95
|
+
ready() {
|
|
96
|
+
super.ready();
|
|
97
|
+
|
|
98
|
+
this._avatarController = new SlotController(this, 'avatar', 'vaadin-avatar', {
|
|
99
|
+
initializer: (avatar) => {
|
|
100
|
+
avatar.setAttribute('tabindex', '-1');
|
|
101
|
+
avatar.setAttribute('aria-hidden', 'true');
|
|
102
|
+
this._avatar = avatar;
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
this.addController(this._avatarController);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** @private */
|
|
109
|
+
__avatarChanged(avatar, userName, userAbbr, userImg, userColorIndex) {
|
|
110
|
+
if (avatar) {
|
|
111
|
+
avatar.setProperties({
|
|
112
|
+
name: userName,
|
|
113
|
+
abbr: userAbbr,
|
|
114
|
+
img: userImg,
|
|
115
|
+
colorIndex: userColorIndex,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 - 2024 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { css } from 'lit';
|
|
7
|
+
|
|
8
|
+
export const messageStyles = css`
|
|
9
|
+
:host {
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-direction: row;
|
|
12
|
+
outline: none;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
:host([hidden]) {
|
|
16
|
+
display: none !important;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
[part='content'] {
|
|
20
|
+
display: flex;
|
|
21
|
+
flex-direction: column;
|
|
22
|
+
flex-grow: 1;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
[part='header'] {
|
|
26
|
+
align-items: baseline;
|
|
27
|
+
display: flex;
|
|
28
|
+
flex-flow: row wrap;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
[part='name'] {
|
|
32
|
+
font-weight: 500;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
[part='message'] {
|
|
36
|
+
white-space: pre-wrap;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
::slotted([slot='avatar']) {
|
|
40
|
+
--vaadin-avatar-outline-width: 0;
|
|
41
|
+
flex-shrink: 0;
|
|
42
|
+
}
|
|
43
|
+
`;
|
package/src/vaadin-message.d.ts
CHANGED
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
* Copyright (c) 2021 - 2024 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
-
import { FocusMixin } from '@vaadin/a11y-base/src/focus-mixin.js';
|
|
7
|
-
import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
|
|
8
6
|
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
|
|
9
7
|
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
8
|
+
import { MessageMixin } from './vaadin-message-mixin.js';
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* `<vaadin-message>` is a Web Component for showing a single message with an author, message and time.
|
|
@@ -37,61 +36,7 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
|
|
|
37
36
|
*
|
|
38
37
|
* See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
|
|
39
38
|
*/
|
|
40
|
-
declare class Message extends
|
|
41
|
-
/**
|
|
42
|
-
* Time of sending the message. It is rendered as-is to the part='time' slot,
|
|
43
|
-
* so the formatting is up to you.
|
|
44
|
-
*/
|
|
45
|
-
time: string | null | undefined;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* The name of the user posting the message.
|
|
49
|
-
* It will be placed in the name part to indicate who has sent the message.
|
|
50
|
-
* It is also used as a tooltip for the avatar.
|
|
51
|
-
* Example: `message.userName = "Jessica Jacobs";`
|
|
52
|
-
* @attr {string} user-name
|
|
53
|
-
*/
|
|
54
|
-
userName: string | null | undefined;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* The abbreviation of the user.
|
|
58
|
-
* The abbreviation will be passed on to avatar of the message.
|
|
59
|
-
* If the user does not have an avatar picture set with `userImg`, `userAbbr` will be shown in the avatar.
|
|
60
|
-
* Example: `message.userAbbr = "JJ";`
|
|
61
|
-
* @attr {string} user-abbr
|
|
62
|
-
*/
|
|
63
|
-
userAbbr: string | null | undefined;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* An URL for a user image.
|
|
67
|
-
* The image will be used in the avatar component to show who has sent the message.
|
|
68
|
-
* Example: `message.userImg = "/static/img/avatar.jpg";`
|
|
69
|
-
* @attr {string} user-img
|
|
70
|
-
*/
|
|
71
|
-
userImg: string | null | undefined;
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* A color index to be used to render the color of the avatar.
|
|
75
|
-
* With no `userColorIndex` set, the basic avatar color will be used.
|
|
76
|
-
* By setting a userColorIndex, the component will check if there exists a CSS variable defining the color, and uses it if there is one.
|
|
77
|
-
* If now CSS variable is found for the color index, the property for the color will not be set.
|
|
78
|
-
*
|
|
79
|
-
* Example:
|
|
80
|
-
* CSS:
|
|
81
|
-
* ```css
|
|
82
|
-
* html {
|
|
83
|
-
* --vaadin-user-color-1: red;
|
|
84
|
-
* }
|
|
85
|
-
* ```
|
|
86
|
-
*
|
|
87
|
-
* JavaScript:
|
|
88
|
-
* ```js
|
|
89
|
-
* message.userColorIndex = 1;
|
|
90
|
-
* ```
|
|
91
|
-
* @attr {number} user-color-index
|
|
92
|
-
*/
|
|
93
|
-
userColorIndex: number | null | undefined;
|
|
94
|
-
}
|
|
39
|
+
declare class Message extends MessageMixin(ThemableMixin(ElementMixin(HTMLElement))) {}
|
|
95
40
|
|
|
96
41
|
declare global {
|
|
97
42
|
interface HTMLElementTagNameMap {
|
package/src/vaadin-message.js
CHANGED
|
@@ -5,12 +5,13 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import '@vaadin/avatar/src/vaadin-avatar.js';
|
|
7
7
|
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
8
|
-
import { FocusMixin } from '@vaadin/a11y-base/src/focus-mixin.js';
|
|
9
|
-
import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
|
|
10
8
|
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
11
9
|
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
10
|
+
import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
11
|
+
import { MessageMixin } from './vaadin-message-mixin.js';
|
|
12
|
+
import { messageStyles } from './vaadin-message-styles.js';
|
|
13
|
+
|
|
14
|
+
registerStyles('vaadin-message', messageStyles, { moduleId: 'vaadin-message-styles' });
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* `<vaadin-message>` is a Web Component for showing a single message with an author, message and time.
|
|
@@ -43,124 +44,13 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
|
|
|
43
44
|
*
|
|
44
45
|
* @customElement
|
|
45
46
|
* @extends HTMLElement
|
|
46
|
-
* @mixes
|
|
47
|
-
* @mixes FocusMixin
|
|
47
|
+
* @mixes MessageMixin
|
|
48
48
|
* @mixes ThemableMixin
|
|
49
49
|
* @mixes ElementMixin
|
|
50
50
|
*/
|
|
51
|
-
class Message extends
|
|
52
|
-
static get properties() {
|
|
53
|
-
return {
|
|
54
|
-
/**
|
|
55
|
-
* Time of sending the message. It is rendered as-is to the part='time' slot,
|
|
56
|
-
* so the formatting is up to you.
|
|
57
|
-
*/
|
|
58
|
-
time: {
|
|
59
|
-
type: String,
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* The name of the user posting the message.
|
|
64
|
-
* It will be placed in the name part to indicate who has sent the message.
|
|
65
|
-
* It is also used as a tooltip for the avatar.
|
|
66
|
-
* Example: `message.userName = "Jessica Jacobs";`
|
|
67
|
-
* @attr {string} user-name
|
|
68
|
-
*/
|
|
69
|
-
userName: {
|
|
70
|
-
type: String,
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* The abbreviation of the user.
|
|
75
|
-
* The abbreviation will be passed on to avatar of the message.
|
|
76
|
-
* If the user does not have an avatar picture set with `userImg`, `userAbbr` will be shown in the avatar.
|
|
77
|
-
* Example: `message.userAbbr = "JJ";`
|
|
78
|
-
* @attr {string} user-abbr
|
|
79
|
-
*/
|
|
80
|
-
userAbbr: {
|
|
81
|
-
type: String,
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* An URL for a user image.
|
|
86
|
-
* The image will be used in the avatar component to show who has sent the message.
|
|
87
|
-
* Example: `message.userImg = "/static/img/avatar.jpg";`
|
|
88
|
-
* @attr {string} user-img
|
|
89
|
-
*/
|
|
90
|
-
userImg: {
|
|
91
|
-
type: String,
|
|
92
|
-
},
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* A color index to be used to render the color of the avatar.
|
|
96
|
-
* With no `userColorIndex` set, the basic avatar color will be used.
|
|
97
|
-
* By setting a userColorIndex, the component will check if there exists a CSS variable defining the color, and uses it if there is one.
|
|
98
|
-
* If now CSS variable is found for the color index, the property for the color will not be set.
|
|
99
|
-
*
|
|
100
|
-
* Example:
|
|
101
|
-
* CSS:
|
|
102
|
-
* ```css
|
|
103
|
-
* html {
|
|
104
|
-
* --vaadin-user-color-1: red;
|
|
105
|
-
* }
|
|
106
|
-
* ```
|
|
107
|
-
*
|
|
108
|
-
* JavaScript:
|
|
109
|
-
* ```js
|
|
110
|
-
* message.userColorIndex = 1;
|
|
111
|
-
* ```
|
|
112
|
-
* @attr {number} user-color-index
|
|
113
|
-
*/
|
|
114
|
-
userColorIndex: {
|
|
115
|
-
type: Number,
|
|
116
|
-
},
|
|
117
|
-
|
|
118
|
-
/** @private */
|
|
119
|
-
_avatar: {
|
|
120
|
-
ttype: Object,
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
51
|
+
class Message extends MessageMixin(ElementMixin(ThemableMixin(PolymerElement))) {
|
|
125
52
|
static get template() {
|
|
126
53
|
return html`
|
|
127
|
-
<style>
|
|
128
|
-
:host {
|
|
129
|
-
display: flex;
|
|
130
|
-
flex-direction: row;
|
|
131
|
-
outline: none;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
:host([hidden]) {
|
|
135
|
-
display: none !important;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
[part='content'] {
|
|
139
|
-
display: flex;
|
|
140
|
-
flex-direction: column;
|
|
141
|
-
flex-grow: 1;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
[part='header'] {
|
|
145
|
-
align-items: baseline;
|
|
146
|
-
display: flex;
|
|
147
|
-
flex-direction: row;
|
|
148
|
-
flex-wrap: wrap;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
[part='name'] {
|
|
152
|
-
font-weight: 500;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
[part='message'] {
|
|
156
|
-
white-space: pre-wrap;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
::slotted([slot='avatar']) {
|
|
160
|
-
--vaadin-avatar-outline-width: 0px;
|
|
161
|
-
flex-shrink: 0;
|
|
162
|
-
}
|
|
163
|
-
</style>
|
|
164
54
|
<slot name="avatar"></slot>
|
|
165
55
|
<div part="content">
|
|
166
56
|
<div part="header">
|
|
@@ -175,36 +65,6 @@ class Message extends FocusMixin(ElementMixin(ThemableMixin(ControllerMixin(Poly
|
|
|
175
65
|
static get is() {
|
|
176
66
|
return 'vaadin-message';
|
|
177
67
|
}
|
|
178
|
-
|
|
179
|
-
static get observers() {
|
|
180
|
-
return ['__avatarChanged(_avatar, userName, userAbbr, userImg, userColorIndex)'];
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/** @protected */
|
|
184
|
-
ready() {
|
|
185
|
-
super.ready();
|
|
186
|
-
|
|
187
|
-
this._avatarController = new SlotController(this, 'avatar', 'vaadin-avatar', {
|
|
188
|
-
initializer: (avatar) => {
|
|
189
|
-
avatar.setAttribute('tabindex', '-1');
|
|
190
|
-
avatar.setAttribute('aria-hidden', 'true');
|
|
191
|
-
this._avatar = avatar;
|
|
192
|
-
},
|
|
193
|
-
});
|
|
194
|
-
this.addController(this._avatarController);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/** @private */
|
|
198
|
-
__avatarChanged(avatar, userName, userAbbr, userImg, userColorIndex) {
|
|
199
|
-
if (avatar) {
|
|
200
|
-
avatar.setProperties({
|
|
201
|
-
name: userName,
|
|
202
|
-
abbr: userAbbr,
|
|
203
|
-
img: userImg,
|
|
204
|
-
colorIndex: userColorIndex,
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
68
|
}
|
|
209
69
|
|
|
210
70
|
defineCustomElement(Message);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/vaadin-message-list.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/vaadin-message.js';
|
package/web-types.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/web-types",
|
|
3
3
|
"name": "@vaadin/message-list",
|
|
4
|
-
"version": "24.6.0
|
|
4
|
+
"version": "24.6.0",
|
|
5
5
|
"description-markup": "markdown",
|
|
6
6
|
"contributions": {
|
|
7
7
|
"html": {
|
|
@@ -140,7 +140,7 @@
|
|
|
140
140
|
},
|
|
141
141
|
{
|
|
142
142
|
"name": "vaadin-message-list",
|
|
143
|
-
"description": "`<vaadin-message-list>` is a Web Component for showing an ordered list of messages. The messages are rendered as <vaadin-message>\n\n### Example\n\nTo create a new message list, add the component to the page:\n\n```html\n<vaadin-message-list></vaadin-message-list>\n```\n\nProvide the messages to the message list with the [`items`](https://cdn.vaadin.com/vaadin-web-components/24.6.0
|
|
143
|
+
"description": "`<vaadin-message-list>` is a Web Component for showing an ordered list of messages. The messages are rendered as <vaadin-message>\n\n### Example\n\nTo create a new message list, add the component to the page:\n\n```html\n<vaadin-message-list></vaadin-message-list>\n```\n\nProvide the messages to the message list with the [`items`](https://cdn.vaadin.com/vaadin-web-components/24.6.0/#/elements/vaadin-message-list#property-items) property.\n\n```js\ndocument.querySelector('vaadin-message-list').items = [\n { text: 'Hello list', time: 'yesterday', userName: 'Matt Mambo', userAbbr: 'MM', userColorIndex: 1 },\n { text: 'Another message', time: 'right now', userName: 'Linsey Listy', userAbbr: 'LL', userColorIndex: 2, userImg: '/static/img/avatar.jpg' }\n];\n```\n\n### Styling\n\nThe following shadow DOM parts are available for styling:\n\nPart name | Description\n----------|----------------\n`list` | The container wrapping messages.\n\nSee the [`<vaadin-message>`](https://cdn.vaadin.com/vaadin-web-components/24.6.0/#/elements/vaadin-message) documentation for the available\nstate attributes and stylable shadow parts of message elements.\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.",
|
|
144
144
|
"attributes": [
|
|
145
145
|
{
|
|
146
146
|
"name": "theme",
|
package/web-types.lit.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/web-types",
|
|
3
3
|
"name": "@vaadin/message-list",
|
|
4
|
-
"version": "24.6.0
|
|
4
|
+
"version": "24.6.0",
|
|
5
5
|
"description-markup": "markdown",
|
|
6
6
|
"framework": "lit",
|
|
7
7
|
"framework-config": {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
},
|
|
59
59
|
{
|
|
60
60
|
"name": "vaadin-message-list",
|
|
61
|
-
"description": "`<vaadin-message-list>` is a Web Component for showing an ordered list of messages. The messages are rendered as <vaadin-message>\n\n### Example\n\nTo create a new message list, add the component to the page:\n\n```html\n<vaadin-message-list></vaadin-message-list>\n```\n\nProvide the messages to the message list with the [`items`](https://cdn.vaadin.com/vaadin-web-components/24.6.0
|
|
61
|
+
"description": "`<vaadin-message-list>` is a Web Component for showing an ordered list of messages. The messages are rendered as <vaadin-message>\n\n### Example\n\nTo create a new message list, add the component to the page:\n\n```html\n<vaadin-message-list></vaadin-message-list>\n```\n\nProvide the messages to the message list with the [`items`](https://cdn.vaadin.com/vaadin-web-components/24.6.0/#/elements/vaadin-message-list#property-items) property.\n\n```js\ndocument.querySelector('vaadin-message-list').items = [\n { text: 'Hello list', time: 'yesterday', userName: 'Matt Mambo', userAbbr: 'MM', userColorIndex: 1 },\n { text: 'Another message', time: 'right now', userName: 'Linsey Listy', userAbbr: 'LL', userColorIndex: 2, userImg: '/static/img/avatar.jpg' }\n];\n```\n\n### Styling\n\nThe following shadow DOM parts are available for styling:\n\nPart name | Description\n----------|----------------\n`list` | The container wrapping messages.\n\nSee the [`<vaadin-message>`](https://cdn.vaadin.com/vaadin-web-components/24.6.0/#/elements/vaadin-message) documentation for the available\nstate attributes and stylable shadow parts of message elements.\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.",
|
|
62
62
|
"extension": true,
|
|
63
63
|
"attributes": [
|
|
64
64
|
{
|