Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input element #24

Merged
merged 29 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b42b249
Accessibility improvements
anezthes Feb 8, 2021
0e21663
Update lumo-message-list-ltr.png
anezthes Feb 8, 2021
5a936c8
Updated screenshots
anezthes Feb 8, 2021
2139248
Accessibility and theme update
anezthes Feb 8, 2021
91dab9f
Update vaadin-message-styles.js
anezthes Feb 8, 2021
c020c00
Initial commit
anezthes Feb 8, 2021
e8f8b33
Theme improvements
anezthes Feb 8, 2021
7395774
Update vaadin-message-input.js
anezthes Feb 9, 2021
ba2a70e
Update vaadin-message-input.js
anezthes Feb 9, 2021
f0afdc1
Update vaadin-message-input.js
anezthes Feb 9, 2021
01c3389
Update vaadin-message-list.js
anezthes Feb 9, 2021
f9bc1ca
Role tweaks
anezthes Feb 9, 2021
bb8824d
Updated screenshots
anezthes Feb 9, 2021
9f42b6b
Merge branch 'master' into input-element
anezthes Feb 10, 2021
6433840
Update lumo-message-list-ltr.png
anezthes Feb 10, 2021
275d4fe
Updated screenshots
anezthes Feb 10, 2021
f1b7fde
Merge branch 'master' into input-element
anezthes Feb 10, 2021
766c9a9
Fix version number.
Feb 12, 2021
0890804
Remove ` copy` from vaadin-message-input.d copy.ts
Feb 12, 2021
e693e02
Merge branch 'master' into input-element
Peppe Feb 12, 2021
a3ba66a
define `messageList.items` programmatically
Feb 12, 2021
a956012
Add message-input.html to screenshot tests
Feb 12, 2021
06198dc
Add documentation to message-input
Feb 12, 2021
28a6f7d
Add unit test for message-input
Feb 12, 2021
a4230f8
Apply suggestions from code review
Peppe Feb 15, 2021
4aaf667
User vaadin-text-field 2.8 instead of 3.0
Feb 15, 2021
50c18fa
Rearrange getters, remove dead api doc
Feb 15, 2021
9950619
Add text-field styles
Feb 15, 2021
345677e
Remove comment in type definition
Feb 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@
"dependencies": {
"@polymer/polymer": "^3.0.0",
"@vaadin/vaadin-avatar": "^1.0.3",
"@vaadin/vaadin-button": "^2.4.0",
"@vaadin/vaadin-element-mixin": "^2.4.1",
"@vaadin/vaadin-lumo-styles": "^1.6.1",
"@vaadin/vaadin-material-styles": "^1.3.2",
"@vaadin/vaadin-text-field": "^3.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use ^2.8.0 if you want the component to be compatible with Vaadin 14.x

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

"@vaadin/vaadin-themable-mixin": "^1.6.1"
},
"devDependencies": {
Expand Down
16 changes: 16 additions & 0 deletions src/vaadin-message-input.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';

import { ElementMixin } from '@vaadin/vaadin-element-mixin/vaadin-element-mixin.js';

/**
* `<vaadin-message-input>` is a Web Component ...
*/
Peppe marked this conversation as resolved.
Show resolved Hide resolved
declare class MessageInputElement extends ThemableMixin(ElementMixin(HTMLElement)) {}

declare global {
interface HTMLElementTagNameMap {
'vaadin-message-input': MessageInputElement;
}
}

export { MessageInputElement };
64 changes: 64 additions & 0 deletions src/vaadin-message-input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
Peppe marked this conversation as resolved.
Show resolved Hide resolved
* @license
* Copyright (c) 2021 Vaadin Ltd.
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
import { ElementMixin } from '@vaadin/vaadin-element-mixin/vaadin-element-mixin.js';
import '@vaadin/vaadin-button/src/vaadin-button.js';
import '@vaadin/vaadin-text-field/src/vaadin-text-area.js';
/**
* `<vaadin-message-input>` is a Web Component ...
*/
Peppe marked this conversation as resolved.
Show resolved Hide resolved
class MessageInputElement extends ElementMixin(ThemableMixin(PolymerElement)) {
static get template() {
return html`
<style>
:host {
align-items: flex-start;
box-sizing: border-box;
display: flex;
max-height: 50vh;
overflow: hidden;
}
vaadin-text-area {
align-self: stretch;
flex-grow: 1;
padding: 0;
}
vaadin-button {
flex-shrink: 0;
margin: 0;
}
</style>
<vaadin-text-area placeholder="Message"></vaadin-text-area>
Peppe marked this conversation as resolved.
Show resolved Hide resolved
<vaadin-button theme="primary contained">Send</vaadin-button>
Peppe marked this conversation as resolved.
Show resolved Hide resolved
pekam marked this conversation as resolved.
Show resolved Hide resolved
`;
}

ready() {
super.ready();

// Set aria-label to provide an accessible name for the labelless input
const textarea = this.shadowRoot.querySelector('vaadin-text-area').inputElement;
pekam marked this conversation as resolved.
Show resolved Hide resolved
textarea.setAttribute('aria-label', 'Message');
Peppe marked this conversation as resolved.
Show resolved Hide resolved
textarea.removeAttribute('aria-labelledby');

// Set initial height to one row
textarea.setAttribute('rows', 1);
textarea.style.minHeight = '0';
}

static get is() {
return 'vaadin-message-input';
}

static get version() {
return '1.0.0-alpha1';
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please place these getters after static get template and before ready method.
That's the convention that we follow in other components.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


customElements.define(MessageInputElement.is, MessageInputElement);

export { MessageInputElement };
4 changes: 3 additions & 1 deletion test/visual/default.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>

<head lang="en">
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Message tests</title>
<script>
Expand Down Expand Up @@ -39,3 +40,4 @@
})();
</script>
</body>
</html>
Peppe marked this conversation as resolved.
Show resolved Hide resolved
57 changes: 57 additions & 0 deletions test/visual/message-input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
Peppe marked this conversation as resolved.
Show resolved Hide resolved

<html lang="en">

<head>
<meta charset="UTF-8" />
<title>Message tests</title>
<script>
window.polymerSkipLoadingFontRoboto = true;
</script>
<style>
html {
--vaadin-user-color-1: blue;
--vaadin-user-color-2: green;
}
</style>
</head>

<body>
<div id="tests" style="padding: 10px">
<vaadin-message-list></vaadin-message-list>
<vaadin-message-input></vaadin-message-input>
Peppe marked this conversation as resolved.
Show resolved Hide resolved
</div>

<script type="module">
(async () => {
const theme = window.location.search.replace(/.*theme=(\w+).*/, '$1') || 'lumo';

await import('../../theme/' + theme + '/vaadin-message-list.js');
await import('../../theme/' + theme + '/vaadin-message-input.js');

window.requestAnimationFrame(() => {
const messageList = document.querySelector('vaadin-message-list');
messageList.items = [
{
text: 'Hello list',
time: 'yesterday',
userName: 'Matt Mambo',
userAbbr: 'MM',
userColorIndex: 1
},
{
text: 'Another message',
time: 'right now',
userName: 'Linsey Listy',
userAbbr: 'LL',
userColorIndex: 2,
userImg: '/test/visual/avatars/avatar.jpg'
}
];
document.getElementById('tests').dataset.ready = true;
});
})();
</script>
</body>

</html>
Peppe marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 3 additions & 1 deletion test/visual/message-list.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>

<head lang="en">
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Message tests</title>
<script>
Expand Down Expand Up @@ -49,3 +50,4 @@
})();
</script>
</body>
</html>
25 changes: 25 additions & 0 deletions theme/lumo/vaadin-message-input-styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
import '@vaadin/vaadin-lumo-styles/color.js';
import '@vaadin/vaadin-lumo-styles/sizing.js';
import '@vaadin/vaadin-lumo-styles/spacing.js';
import '@vaadin/vaadin-lumo-styles/style.js';
Comment on lines +2 to +5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have some convention that should all of these be imported always or only those that you refer to in the same file? Spacing seems to be the only one in use below.

import '@vaadin/vaadin-button/theme/lumo/vaadin-button-styles.js';
import '@vaadin/vaadin-text-field/theme/lumo/vaadin-text-area-styles.js';

registerStyles(
'vaadin-message-input',
css`
:host {
padding: var(--lumo-space-s) var(--lumo-space-m);
}

vaadin-text-area {
margin: 0 var(--lumo-space-s) 0 0;
}

:host([dir='rtl']) vaadin-text-area {
margin: 0 0 0 var(--lumo-space-s);
}
`,
{ moduleId: 'lumo-message-input' }
);
2 changes: 2 additions & 0 deletions theme/lumo/vaadin-message-input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './vaadin-message-input-styles.js';
import '../../src/vaadin-message-input.js';
10 changes: 9 additions & 1 deletion theme/lumo/vaadin-message-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import '@vaadin/vaadin-lumo-styles/sizing.js';
import '@vaadin/vaadin-lumo-styles/spacing.js';
import '@vaadin/vaadin-lumo-styles/style.js';
import '@vaadin/vaadin-lumo-styles/typography.js';
import '@vaadin/vaadin-avatar/theme/lumo/vaadin-avatar.js';
import '@vaadin/vaadin-avatar/theme/lumo/vaadin-avatar-styles.js';

registerStyles(
'vaadin-message',
Expand Down Expand Up @@ -35,11 +35,19 @@ registerStyles(
margin-right: var(--lumo-space-s);
}

[part='name']:empty {
margin-right: 0;
}

:host([dir='rtl']) [part='name'] {
margin-left: var(--lumo-space-s);
margin-right: 0;
}

:host([dir='rtl']) [part='name']:empty {
margin-left: 0;
}

[part='time'] {
color: var(--lumo-secondary-text-color);
font-size: var(--lumo-font-size-s);
Expand Down
23 changes: 23 additions & 0 deletions theme/material/vaadin-message-input-styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
import '@vaadin/vaadin-material-styles/color.js';
import '@vaadin/vaadin-material-styles/typography.js';
import '@vaadin/vaadin-button/theme/material/vaadin-button-styles.js';
import '@vaadin/vaadin-text-field/theme/material/vaadin-text-area-styles.js';

registerStyles(
'vaadin-message-input',
css`
:host {
padding: 0.5em 1em;
}

vaadin-text-area {
margin: 0 0.5em 0 0;
}

:host([dir='rtl']) vaadin-text-area {
margin: 0 0 0 0.5em;
}
`,
{ moduleId: 'material-message-input' }
);
2 changes: 2 additions & 0 deletions theme/material/vaadin-message-input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './vaadin-message-input-styles.js';
import '../../src/vaadin-message-input.js';
1 change: 1 addition & 0 deletions vaadin-message-input.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src/vaadin-message-input.js';
2 changes: 2 additions & 0 deletions vaadin-message-input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './theme/lumo/vaadin-message-input.js';
export * from './src/vaadin-message-input.js';