@haxtheweb/create
Version:
CLI for all things HAX the web
83 lines (75 loc) • 1.83 kB
JavaScript
/**
* Copyright <%= year %> <%= author %>
* @license Apache-2.0, see LICENSE for full text.
*/
import { LitElement, html, css } from "lit";
import { DDDSuper } from "@haxtheweb/d-d-d/d-d-d.js";
import { I18NMixin } from "@haxtheweb/i18n-manager/lib/I18NMixin.js";
/**
* `<%= name %>`
*
* @demo index.html
* @element <%= name %>
*/
export class <%= className %> extends DDDSuper(I18NMixin(LitElement)) {
static get tag() {
return "<%= name %>";
}
constructor() {
super();
this.title = "";
this.t = this.t || {};
this.t = {
...this.t,
title: "Title",
};
this.registerLocalization({
context: this,
localesPath:
new URL("./locales/<%= name %>.ar.json", import.meta.url).href +
"/../",
});
}
// Lit reactive properties
static get properties() {
return {
...super.properties,
title: { type: String },
};
}
// Lit scoped styles
static get styles() {
return [super.styles,
css`
:host {
display: block;
color: var(--ddd-theme-primary);
background-color: var(--ddd-theme-accent);
font-family: var(--ddd-font-navigation);
}
.wrapper {
margin: var(--ddd-spacing-2);
padding: var(--ddd-spacing-4);
}
h3 span {
font-size: var(--<%= name %>-label-font-size, var(--ddd-font-size-s));
}
`];
}
// Lit render the HTML
render() {
return html`
<div class="wrapper">
<h3><span>${this.t.title}:</span> ${this.title}</h3>
<slot></slot>
</div>`;
}
/**
* haxProperties integration via file reference
*/
static get haxProperties() {
return new URL(`./lib/${this.tag}.haxProperties.json`, import.meta.url)
.href;
}
}
globalThis.customElements.define(<%= className %>.tag, <%= className %>);