-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Things that need to be configurable: TextArea aria-label Button label, icon and theme Fixes #16
- Loading branch information
Showing
19 changed files
with
256 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
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 for sending messages. | ||
* It consists of a text area that grows on along with the content, and a send button to send message. | ||
* | ||
* ```html | ||
* <vaadin-message-input></vaadin-message-input> | ||
* ``` | ||
* | ||
* @extends HTMLElement | ||
* @mixes ThemableMixin | ||
* @mixes ElementMixin | ||
*/ | ||
declare class MessageInputElement extends ThemableMixin(ElementMixin(HTMLElement)) {} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'vaadin-message-input': MessageInputElement; | ||
} | ||
} | ||
|
||
export { MessageInputElement }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* @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 for sending messages. | ||
* It consists of a text area that grows on along with the content, and a send button to send message. | ||
* | ||
* ```html | ||
* <vaadin-message-input></vaadin-message-input> | ||
* ``` | ||
* | ||
* @extends HTMLElement | ||
* @mixes ThemableMixin | ||
* @mixes ElementMixin | ||
*/ | ||
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> | ||
<vaadin-button theme="primary contained">Send</vaadin-button> | ||
`; | ||
} | ||
|
||
static get is() { | ||
return 'vaadin-message-input'; | ||
} | ||
|
||
static get version() { | ||
return '1.0.0-alpha1'; | ||
} | ||
|
||
ready() { | ||
super.ready(); | ||
|
||
// Set aria-label to provide an accessible name for the labelless input | ||
const textarea = this.shadowRoot.querySelector('vaadin-text-area').inputElement; | ||
textarea.setAttribute('aria-label', 'Message'); | ||
textarea.removeAttribute('aria-labelledby'); | ||
|
||
// Set initial height to one row | ||
textarea.setAttribute('rows', 1); | ||
textarea.style.minHeight = '0'; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rolfsmeds
|
||
} | ||
} | ||
|
||
customElements.define(MessageInputElement.is, MessageInputElement); | ||
|
||
export { MessageInputElement }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { expect } from '@esm-bundle/chai'; | ||
import { fixtureSync } from '@open-wc/testing-helpers'; | ||
import '../vaadin-message-input.js'; | ||
|
||
describe('message-input', () => { | ||
let messageInput; | ||
|
||
beforeEach(() => { | ||
messageInput = fixtureSync('<vaadin-message-input></vaadin-message-input>'); | ||
}); | ||
|
||
it('should have a valid version number', () => { | ||
expect(messageInput.constructor.version).to.match(/^(\d+\.)?(\d+\.)?(\d+)(-(alpha|beta)\d+)?$/); | ||
}); | ||
|
||
it('message should be initialized', () => { | ||
expect(messageInput.shadowRoot.querySelector('vaadin-text-area')).to.be.not.undefined; | ||
expect(messageInput.shadowRoot.querySelector('vaadin-button')).to.be.not.undefined; | ||
}); | ||
|
||
it('text area placeholder should be set', () => { | ||
expect(messageInput.shadowRoot.querySelector('vaadin-text-area').placeholder).to.be.equal('Message'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<!DOCTYPE html> | ||
|
||
<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> | ||
</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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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'; | ||
import '@vaadin/vaadin-button/theme/lumo/vaadin-button-styles.js'; | ||
import '@vaadin/vaadin-text-field/theme/lumo/vaadin-text-area-styles.js'; | ||
import '@vaadin/vaadin-text-field/theme/lumo/vaadin-text-field-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' } | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' } | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './src/vaadin-message-input.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
It’s a bit of a shame that we have to do it like this. Should be fixed in vaadin-text-area: https://github.com/vaadin/vaadin-text-field/issues/229