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

Auto define vpu-auth in the bundle

We only want to export it in the package entry point and not
the generated bundle.
parent 48a198cd
No related branches found
No related tags found
No related merge requests found
import {LanguageSelect} from './vpu-language-select.js'; import {LanguageSelect} from './language-select.js';
export {LanguageSelect}; export {LanguageSelect};
\ No newline at end of file
import {html, css, LitElement} from 'lit-element';
import {i18n} from './i18n.js';
import * as commonStyles from 'vpu-common/styles';
/**
* Emits a vpu-language-changed event where event.detail.lang is the new selected language
*/
export class LanguageSelect extends LitElement {
constructor() {
super();
this._lang = 'de';
this.languages = ['de', 'en'];
this.onExternalChange = this.onExternalChange.bind(this);
// for the i18next scanner
i18n.t('de');
i18n.t('de-action');
i18n.t('en');
i18n.t('en-action');
}
_getNextLanguage(lang) {
var index = this.languages.indexOf(lang);
var next = this.languages[index + 1];
if (typeof next === 'undefined')
next = this.languages[0];
return next;
}
_getPreviousLanguage(lang) {
var index = this.languages.indexOf(lang);
var prev = this.languages[index - 1];
if (typeof prev === 'undefined')
prev = this.languages[this.languages.length - 1];
return prev;
}
static get properties() {
return {
lang: {type: String},
next: {type: String},
languages: {type: Array},
};
}
set lang(value) {
const oldValue = this.lang;
const oldNext = this.next;
this._lang = value;
this.requestUpdate('lang', oldValue);
this.requestUpdate('next', oldNext);
if (oldValue !== value) {
const event = new CustomEvent("vpu-language-changed", {
bubbles: true,
composed: true,
detail: {'lang': value}
});
this.dispatchEvent(event);
// Unlike other cases we use the next language for the translations so that
// users not knowing the current language can understand it.
// In case of more than two this doesn't make that much sense, but for now..
i18n.changeLanguage(this.next);
}
}
get lang() {
return this._lang;
}
set next(value) {
this.lang = this._getPreviousLanguage(value);
}
get next() {
return this._getNextLanguage(this.lang);
}
static get styles() {
// language=css
return css`
${commonStyles.getThemeCSS()}
:host {
display: inline-block;
}
a:hover {
background-color: var(--vpu-dark);
color: var(--vpu-light);
transition: none;
}
a {
padding: 0.3em;
display: inline-block;
text-decoration: none;
transition: background-color 0.15s, color 0.15s;
color: var(--vpu-dark);
border-radius: var(--vpu-border-radius);
}
`;
}
onExternalChange(e) {
this.lang = e.detail.lang
}
connectedCallback() {
super.connectedCallback();
window.addEventListener('vpu-language-changed', this.onExternalChange);
}
disconnectedCallback() {
document.removeEventListener('vpu-language-changed', this.onExternalChange);
super.disconnectedCallback();
}
onClick(e) {
e.preventDefault();
this.lang = this.next;
}
render() {
var linkTitle = i18n.t(this.next + '-action');
return html`
<a href="#" title="${linkTitle}" @click=${this.onClick}>${this.next.toUpperCase()}</a>
`;
}
}
\ No newline at end of file
import {html, LitElement} from 'lit-element'; import {html, LitElement} from 'lit-element';
import {LanguageSelect} from './vpu-language-select.js'; import {LanguageSelect} from './language-select.js';
import * as commonUtils from 'vpu-common/utils'; import * as commonUtils from 'vpu-common/utils';
import { ScopedElementsMixin } from '@open-wc/scoped-elements'; import { ScopedElementsMixin } from '@open-wc/scoped-elements';
......
import {html, css, LitElement} from 'lit-element'; import * as commonUtils from 'vpu-common/utils';
import {i18n} from './i18n.js'; import {LanguageSelect} from './language-select.js';
import * as commonStyles from 'vpu-common/styles';
/** commonUtils.defineCustomElement('vpu-language-select', LanguageSelect);
* Emits a vpu-language-changed event where event.detail.lang is the new selected language
*/
export class LanguageSelect extends LitElement {
constructor() {
super();
this._lang = 'de';
this.languages = ['de', 'en'];
this.onExternalChange = this.onExternalChange.bind(this);
// for the i18next scanner
i18n.t('de');
i18n.t('de-action');
i18n.t('en');
i18n.t('en-action');
}
_getNextLanguage(lang) {
var index = this.languages.indexOf(lang);
var next = this.languages[index + 1];
if (typeof next === 'undefined')
next = this.languages[0];
return next;
}
_getPreviousLanguage(lang) {
var index = this.languages.indexOf(lang);
var prev = this.languages[index - 1];
if (typeof prev === 'undefined')
prev = this.languages[this.languages.length - 1];
return prev;
}
static get properties() {
return {
lang: {type: String},
next: {type: String},
languages: {type: Array},
};
}
set lang(value) {
const oldValue = this.lang;
const oldNext = this.next;
this._lang = value;
this.requestUpdate('lang', oldValue);
this.requestUpdate('next', oldNext);
if (oldValue !== value) {
const event = new CustomEvent("vpu-language-changed", {
bubbles: true,
composed: true,
detail: {'lang': value}
});
this.dispatchEvent(event);
// Unlike other cases we use the next language for the translations so that
// users not knowing the current language can understand it.
// In case of more than two this doesn't make that much sense, but for now..
i18n.changeLanguage(this.next);
}
}
get lang() {
return this._lang;
}
set next(value) {
this.lang = this._getPreviousLanguage(value);
}
get next() {
return this._getNextLanguage(this.lang);
}
static get styles() {
// language=css
return css`
${commonStyles.getThemeCSS()}
:host {
display: inline-block;
}
a:hover {
background-color: var(--vpu-dark);
color: var(--vpu-light);
transition: none;
}
a {
padding: 0.3em;
display: inline-block;
text-decoration: none;
transition: background-color 0.15s, color 0.15s;
color: var(--vpu-dark);
border-radius: var(--vpu-border-radius);
}
`;
}
onExternalChange(e) {
this.lang = e.detail.lang
}
connectedCallback() {
super.connectedCallback();
window.addEventListener('vpu-language-changed', this.onExternalChange);
}
disconnectedCallback() {
document.removeEventListener('vpu-language-changed', this.onExternalChange);
super.disconnectedCallback();
}
onClick(e) {
e.preventDefault();
this.lang = this.next;
}
render() {
var linkTitle = i18n.t(this.next + '-action');
return html`
<a href="#" title="${linkTitle}" @click=${this.onClick}>${this.next.toUpperCase()}</a>
`;
}
}
\ No newline at end of file
import {LanguageSelect} from '../src/vpu-language-select.js'; import '../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 = [];
......
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