A library for creating custom elements extending the lit element class with additional functionalities.
npm install @design.estate/dees-elementA powerful custom element base class that extends Lit's LitElement with integrated theming, responsive CSS utilities, RxJS-powered directives, and DOM tooling — so you can build web components that look great and stay reactive out of the box.
For reporting bugs, issues, or security vulnerabilities, please visit community.foss.global/. This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a code.foss.global/ account to submit Pull Requests directly.
``bash`
npm install @design.estate/dees-elementor
pnpm install @design.estate/dees-element
This package ships as ESM and is written in TypeScript. Make sure your project targets ES2022+ with a modern module resolution strategy (e.g. NodeNext).
Everything you need is exported from the main entry point:
`typescript`
import {
DeesElement,
customElement,
property,
state,
html,
css,
cssManager,
directives,
} from '@design.estate/dees-element';
Extend DeesElement and apply the @customElement decorator:
`typescript
import { DeesElement, customElement, html, css, cssManager } from '@design.estate/dees-element';
@customElement('my-button')
class MyButton extends DeesElement {
static styles = [
cssManager.defaultStyles,
css
.btn {
padding: 8px 16px;
border-radius: 4px;
background: ${cssManager.bdTheme('#0060df', '#3a8fff')};
color: ${cssManager.bdTheme('#fff', '#fff')};
border: none;
cursor: pointer;
}
,
];
render() {
return html;`
}
}
That single bdTheme() call generates a CSS variable that automatically flips between the bright and dark values when the user's theme changes — no manual toggling needed.
The singleton cssManager is the central hub for theming and responsive layout:
| Method | Purpose |
|---|---|
| cssManager.defaultStyles | Base styles for consistent element rendering |cssManager.bdTheme(bright, dark)
| | Returns a CSSResult that auto-switches between bright/dark values |cssManager.cssForDesktop(css)
| | Media-query wrapper for desktop breakpoints |cssManager.cssForNotebook(css)
| | Media-query wrapper for notebook breakpoints |cssManager.cssForTablet(css)
| | Media-query wrapper for tablet breakpoints |cssManager.cssForPhablet(css)
| | Media-query wrapper for phablet breakpoints |cssManager.cssForPhone(css)
| | Media-query wrapper for phone breakpoints |cssManager.cssGridColumns(cols, gap)
| | Generates CSS grid column widths |
Example — responsive + themed styles:
`typescript
@customElement('my-card')
class MyCard extends DeesElement {
static styles = [
cssManager.defaultStyles,
css
:host {
display: block;
padding: 16px;
background: ${cssManager.bdTheme('#ffffff', '#1e1e1e')};
color: ${cssManager.bdTheme('#111', '#eee')};
border-radius: 8px;
}
,
cssManager.cssForPhone(css
:host { padding: 8px; }
),
];
render() {
return html;`
}
}
Use the standard Lit decorators, re-exported for convenience:
`typescript
import { DeesElement, customElement, property, state, html } from '@design.estate/dees-element';
@customElement('my-counter')
class MyCounter extends DeesElement {
@property({ type: String })
accessor label = 'Count';
@state()
accessor count = 0;
render() {
return html
;`
}
}
> Note: This library uses the TC39 standard decorators with the accessor keyword for decorated class properties.
DeesElement tracks the current theme via the goBright property and exposes an optional themeChanged callback:
`typescript
@customElement('theme-aware')
class ThemeAware extends DeesElement {
protected themeChanged(goBright: boolean) {
console.log(goBright ? 'Switched to bright' : 'Switched to dark');
}
render() {
return html
Current theme: ${this.goBright ? 'bright' : 'dark'}
;
}
}
`$3
DeesElement adds lifecycle utilities on top of LitElement:`typescript
@customElement('my-widget')
class MyWidget extends DeesElement {
constructor() {
super(); // Runs once after the element is connected to the DOM
this.registerStartupFunction(async () => {
console.log('Widget connected!');
});
// Runs when the element is disconnected — perfect for cleanup
this.registerGarbageFunction(() => {
console.log('Widget removed');
});
}
render() {
return html
Hello World
;
}
}
`Additionally,
this.elementDomReady is a promise that resolves after firstUpdated, which is handy when you need to wait for the initial render:`typescript
await this.elementDomReady;
// The element's shadow DOM is now fully rendered
`$3
The
directives namespace includes powerful template helpers, accessible via directives.*:####
resolve — Render a Promise`typescript
import { html, directives } from '@design.estate/dees-element';render() {
return html
${directives.resolve(this.fetchData())};
}
`####
resolveExec — Resolve a lazy async function`typescript
render() {
return html${directives.resolveExec(() => this.loadContent())};
}
`####
subscribe — Render an RxJS Observable`typescript
import { html, directives } from '@design.estate/dees-element';render() {
return html
${directives.subscribe(this.count$)};
}
`####
subscribeWithTemplate — Observable + template transform`typescript
render() {
return html${items.map(i => html
)};
}
`#### Re-exported Lit directives
The directives namespace also re-exports these commonly used Lit directives:
-
until — render a placeholder while a promise resolves
- asyncAppend — append values from an async iterable
- keyed — force re-creation of a template when a key changes
- repeat — efficiently render lists with identity tracking$3
| Export | Description |
|---|---|
|
DeesElement | Base class for custom elements |
| CssManager | CSS/theme management class |
| cssManager | Singleton CssManager instance |
| customElement | Class decorator to register elements |
| property | Reactive property decorator |
| state | Internal state decorator |
| query, queryAll, queryAsync | Shadow DOM query decorators |
| html | Lit html template tag |
| css | Lit css template tag |
| unsafeCSS | Create CSSResult from a string |
| unsafeHTML | Render raw HTML in templates |
| render | Lit render function |
| static / unsafeStatic | Static html template helpers |
| domtools | DOM tooling utilities |
| directives | All directives (resolve, subscribe, etc.) |
| rxjs` (type) | RxJS type re-export |This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the LICENSE file.
Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
Task Venture Capital GmbH
Registered at District Court Bremen HRB 35230 HB, Germany
For any legal inquiries or further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.