Skip to content
Snippets Groups Projects
Commit 48a198cd authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Port to scoped elements

The demo now registers our web components lazily with a unique name
so that two different apps using the same underlying web compontens
don't clash.

This also disables auto registering and leaves that to the user.
parent 30c47a7d
No related branches found
No related tags found
No related merge requests found
{ {
"name": "vpu-language-select", "name": "vpu-language-select",
"version": "1.0.0", "version": "1.0.0",
"main": "src/vpu-language-select.js", "main": "src/index.js",
"devDependencies": { "devDependencies": {
"karma": "^5.0.1", "karma": "^5.0.1",
"karma-chai": "^0.1.0", "karma-chai": "^0.1.0",
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
"vpu-common": "file:./vendor/common" "vpu-common": "file:./vendor/common"
}, },
"dependencies": { "dependencies": {
"@open-wc/scoped-elements": "^1.0.8",
"lit-element": "^2.2.1" "lit-element": "^2.2.1"
}, },
"scripts": { "scripts": {
......
import {LanguageSelect} from './vpu-language-select.js';
export {LanguageSelect};
\ No newline at end of file
import {html, LitElement, css} from 'lit-element'; import {html, LitElement} from 'lit-element';
import './vpu-language-select.js'; import {LanguageSelect} from './vpu-language-select.js';
import * as commonUtils from 'vpu-common/utils'; import * as commonUtils from 'vpu-common/utils';
import { ScopedElementsMixin } from '@open-wc/scoped-elements';
class LanguageSelectDisplay extends LitElement { class LanguageSelectDisplay extends LitElement {
...@@ -35,14 +37,19 @@ class LanguageSelectDisplay extends LitElement { ...@@ -35,14 +37,19 @@ class LanguageSelectDisplay extends LitElement {
} }
} }
commonUtils.defineCustomElement('vpu-language-select-display', LanguageSelectDisplay); class LanguageSelectDemo extends ScopedElementsMixin(LitElement) {
class LanguageSelectDemo extends LitElement {
constructor() { constructor() {
super(); super();
} }
static get scopedElements() {
return {
'vpu-language-select': LanguageSelect,
'vpu-language-select-display': LanguageSelectDisplay,
};
}
render() { render() {
return html` return html`
Select 1: <vpu-language-select></vpu-language-select> Select 1: <vpu-language-select></vpu-language-select>
......
import {html, css, LitElement} from 'lit-element'; import {html, css, LitElement} from 'lit-element';
import {i18n} from './i18n.js'; import {i18n} from './i18n.js';
import * as commonUtils from 'vpu-common/utils';
import * as commonStyles from 'vpu-common/styles'; import * as commonStyles from 'vpu-common/styles';
/** /**
* Emits a vpu-language-changed event where event.detail.lang is the new selected language * Emits a vpu-language-changed event where event.detail.lang is the new selected language
*/ */
class LanguageSelect extends LitElement { export class LanguageSelect extends LitElement {
constructor() { constructor() {
super(); super();
...@@ -131,6 +130,4 @@ class LanguageSelect extends LitElement { ...@@ -131,6 +130,4 @@ class LanguageSelect extends LitElement {
<a href="#" title="${linkTitle}" @click=${this.onClick}>${this.next.toUpperCase()}</a> <a href="#" title="${linkTitle}" @click=${this.onClick}>${this.next.toUpperCase()}</a>
`; `;
} }
} }
\ No newline at end of file
commonUtils.defineCustomElement('vpu-language-select', LanguageSelect);
import '../src/vpu-language-select.js'; import {LanguageSelect} from '../src/vpu-language-select.js';
import * as commonUtils from 'vpu-common/utils';
import '../src/demo.js'; import '../src/demo.js';
commonUtils.defineCustomElement('vpu-language-select', LanguageSelect);
describe('vpu-language-select basics', () => { describe('vpu-language-select basics', () => {
let node; let node;
let events = []; let events = [];
......
common @ 0f626c7a
Subproject commit 894bf3f1f7d8d2d2746c98bc24ff6a3fb82618b8 Subproject commit 0f626c7a2051ec37606242d46f42d9790b6f0bcc
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment