2024-04-20 23:19:23 +02:00
# @design.estate/dees-element
2020-11-25 13:43:39 +00:00
2026-01-27 13:57:49 +00:00
A 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.
## Issue Reporting and Security
2024-04-20 23:19:23 +02:00
2026-01-27 13:57:49 +00:00
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/ ](https://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/ ](https://code.foss.global/ ) account to submit Pull Requests directly.
## Install
2024-04-20 23:19:23 +02:00
```bash
npm install @design .estate/dees-element
2026-01-27 13:57:49 +00:00
# or
pnpm install @design .estate/dees-element
2024-04-20 23:19:23 +02:00
```
2026-01-27 13:57:49 +00:00
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` ).
2020-11-25 13:43:39 +00:00
## Usage
2026-01-27 13:57:49 +00:00
Everything you need is exported from the main entry point:
2024-04-20 23:19:23 +02:00
```typescript
2026-01-27 13:57:49 +00:00
import {
DeesElement,
customElement,
property,
state,
html,
css,
cssManager,
directives,
} from '@design .estate/dees-element';
2024-04-20 23:19:23 +02:00
```
2026-01-27 13:57:49 +00:00
### 🧱 Creating a Custom Element
2024-04-20 23:19:23 +02:00
2026-01-27 13:57:49 +00:00
Extend `DeesElement` and apply the `@customElement` decorator:
2024-04-20 23:19:23 +02:00
```typescript
2026-01-27 13:57:49 +00:00
import { DeesElement, customElement, html, css, cssManager } from '@design .estate/dees-element';
@customElement ('my-button')
class MyButton extends DeesElement {
2024-04-20 23:19:23 +02:00
static styles = [
2026-01-27 13:57:49 +00:00
cssManager.defaultStyles,
2024-04-20 23:19:23 +02:00
css`
2026-01-27 13:57:49 +00:00
.btn {
padding: 8px 16px;
border-radius: 4px;
background: ${cssManager.bdTheme('#0060df ', '#3a8fff ')};
color: ${cssManager.bdTheme('#fff ', '#fff ')};
border: none;
cursor: pointer;
2024-04-20 23:19:23 +02:00
}
`,
];
render() {
2026-01-27 13:57:49 +00:00
return html`<button class="btn"><slot></slot></button>` ;
2024-04-20 23:19:23 +02:00
}
}
```
2026-01-27 13:57:49 +00:00
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.
2024-04-20 23:19:23 +02:00
2026-01-27 13:57:49 +00:00
### 🎨 Theme Management with `cssManager`
2024-04-20 23:19:23 +02:00
2026-01-27 13:57:49 +00:00
The singleton `cssManager` is the central hub for theming and responsive layout:
2024-04-20 23:19:23 +02:00
2026-01-27 13:57:49 +00:00
| 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:
2024-04-20 23:19:23 +02:00
2026-01-27 13:57:49 +00:00
```typescript
@customElement ('my-card')
class MyCard extends DeesElement {
2024-04-20 23:19:23 +02:00
static styles = [
cssManager.defaultStyles,
css`
:host {
display: block;
2026-01-27 13:57:49 +00:00
padding: 16px;
background: ${cssManager.bdTheme('#ffffff ', '#1e1e1e ')};
color: ${cssManager.bdTheme('#111 ', '#eee ')};
border-radius: 8px;
2024-04-20 23:19:23 +02:00
}
`,
2026-01-27 13:57:49 +00:00
cssManager.cssForPhone(css`
:host { padding: 8px; }
`),
2024-04-20 23:19:23 +02:00
];
render() {
2026-01-27 13:57:49 +00:00
return html`<slot></slot>` ;
2024-04-20 23:19:23 +02:00
}
}
```
2026-01-27 13:57:49 +00:00
### ⚡ Reactive Properties & State
2024-04-20 23:19:23 +02:00
2026-01-27 13:57:49 +00:00
Use the standard Lit decorators, re-exported for convenience:
2024-04-20 23:19:23 +02:00
```typescript
2026-01-27 13:57:49 +00:00
import { DeesElement, customElement, property, state, html } from '@design .estate/dees-element';
@customElement ('my-counter')
class MyCounter extends DeesElement {
@property ({ type: String })
accessor label = 'Count';
2024-04-20 23:19:23 +02:00
2026-01-27 13:57:49 +00:00
@state ()
accessor count = 0;
2024-04-20 23:19:23 +02:00
render() {
return html`
2026-01-27 13:57:49 +00:00
<button @click =${() => this.count++}>
${this.label}: ${this.count}
</button>
2024-04-20 23:19:23 +02:00
`;
}
2026-01-27 13:57:49 +00:00
}
```
> **Note:** This library uses the TC39 standard decorators with the `accessor` keyword for decorated class properties.
### 🔄 Theme Change Callbacks
`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');
}
2024-04-20 23:19:23 +02:00
2026-01-27 13:57:49 +00:00
render() {
return html`<p>Current theme: ${this.goBright ? 'bright' : 'dark'}</p>` ;
2024-04-20 23:19:23 +02:00
}
}
```
2026-01-27 13:57:49 +00:00
### 🚀 Lifecycle Helpers
2024-04-20 23:19:23 +02:00
2026-01-27 13:57:49 +00:00
`DeesElement` adds lifecycle utilities on top of LitElement:
2024-04-20 23:19:23 +02:00
```typescript
2026-01-27 13:57:49 +00:00
@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!');
});
2024-04-20 23:19:23 +02:00
2026-01-27 13:57:49 +00:00
// Runs when the element is disconnected — perfect for cleanup
this.registerGarbageFunction(() => {
console.log('Widget removed');
2024-04-20 23:19:23 +02:00
});
}
render() {
2026-01-27 13:57:49 +00:00
return html`<p>Hello World</p>` ;
2024-04-20 23:19:23 +02:00
}
}
```
2026-01-27 13:57:49 +00:00
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
```
### 📡 Directives
The `directives` namespace includes powerful template helpers, accessible via `directives.*` :
#### `resolve` — Render a Promise
2024-04-20 23:19:23 +02:00
2026-01-27 13:57:49 +00:00
```typescript
import { html, directives } from '@design .estate/dees-element';
render() {
return html`${directives.resolve(this.fetchData())}` ;
}
```
2024-04-20 23:19:23 +02:00
2026-01-27 13:57:49 +00:00
#### `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`<span>${directives.subscribe(this.count$)}</span>` ;
}
```
#### `subscribeWithTemplate` — Observable + template transform
```typescript
render() {
return html`
${directives.subscribeWithTemplate(
this.items$,
(items) => html`<ul>${items.map(i => html` <li>${i}</li>`)}</ul>`
)}
`;
}
```
#### 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
### 📦 Full Export Reference
| 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 |
2024-04-20 23:19:23 +02:00
## License and Legal Information
2026-01-27 13:57:49 +00:00
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE ](./LICENSE ) file.
2024-04-20 23:19:23 +02:00
**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.
### Trademarks
2026-01-27 13:57:49 +00:00
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.
2020-11-25 13:43:39 +00:00
2024-04-20 23:19:23 +02:00
### Company Information
2020-11-25 13:43:39 +00:00
2026-01-27 13:57:49 +00:00
Task Venture Capital GmbH
Registered at District Court Bremen HRB 35230 HB, Germany
2020-11-25 13:43:39 +00:00
2026-01-27 13:57:49 +00:00
For any legal inquiries or further information, please contact us via email at hello@task .vc.
2020-11-25 13:43:39 +00:00
2024-04-20 23:19:23 +02:00
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.