Tiny. Typed. Transparent.
No virtual DOM. No reactivity. No hidden magic.
Just components with explicit, direct DOM control.
TComponent is a zero-dependency TypeScript component system designed for developers who want full control over how their UI works.
on* attributes. Supports both synchronous and asynchronous functions.onerror method.id attributes are automatically replaced with UUIDs to prevent global DOM collisions, while remaining easily accessible via this.getById().for, aria-labelledby, and aria-controls automatically resolve to the newly generated UUIDs, maintaining accessibility.static uses property..destroy() to safely remove the component from the DOM and automatically unbind all event listeners. The cleanup process automatically cascades to all nested child components, preventing memory leaks.npm install @haiix/tcomponent
import TComponent from '@haiix/tcomponent';
class CounterApp extends TComponent<HTMLElement> {
static template = /* HTML */ `
<section class="counter-app">
<h1 id="count-display">0</h1>
<!-- Attributes beginning with "on" bind events to component methods -->
<button onclick="handleIncrement">Increment</button>
</section>
`;
// Access internal elements or sub-components.
// Passing a class as the second argument provides automatic typing and runtime safety.
countDisplay = this.getById('count-display', HTMLHeadingElement);
// State is managed explicitly by the developer, not by the framework
count = 0;
handleIncrement(event: MouseEvent) {
this.count++;
// Explicit, non-reactive DOM manipulation
this.countDisplay.textContent = this.count.toString();
}
// Errors thrown in events (sync or async) propagate and are caught here
onerror(error: unknown) {
console.error('An error occurred:', error);
}
}
// 1. Instantiate the component
const app = new CounterApp();
// 2. Mount to the DOM
document.body.appendChild(app.element);
// To destroy the component safely (which removes it from the DOM and clears event listeners):
// app.destroy();
Since TComponent uses standard template literals for HTML, you can improve your Developer Experience (DX) by prefixing your templates with the /* HTML */ comment.
static template = /* HTML */ `
<div>Hello World</div>
`;
/* HTML */ comment and will format the inner string as HTML.TComponent is designed to be simple, but it provides useful features for complex applications. See the detailed documentation below:
https://haiix.github.io/TComponent/modules.html