Advanced web components with YEH (Yai Event Hub) - Enterprise-grade tabs with efficient event delegation
Build deeply nested, event-heavy interfaces with constant-time listener delegation and zero manual lifecycle handling. Everything you need in one package.
@yaijs/core packagefile://, CDN, or bundler with zero build required<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@yaijs/core@latest/tabs/yai-tabs.css">
</head>
<body>
<div data-yai-tabs data-theme="default">
<nav data-controller>
<button data-tab-action="open" data-open="1">Tab 1</button>
<button data-tab-action="open" data-open="2">Tab 2</button>
</nav>
<div data-content>
<div data-tab="1">Content 1</div>
<div data-tab="2">Content 2</div>
</div>
</div>
<script type="module">
import { YaiTabs } from 'https://cdn.jsdelivr.net/npm/@yaijs/core@latest/dist/yai-bundle.js';
new YaiTabs();
</script>
</body>
</html>
npm install @yaijs/core
import { YaiTabs, YEH } from '@yaijs/core';
const tabs = new YaiTabs({
defaultBehavior: 'fade',
autoFocus: true
});
// Or extend YEH directly for custom event orchestration
class AppBus extends YEH {
constructor() {
super({ '#app': ['click', 'input', 'change'] });
}
}
.on().emit())| Complete YaiTabs Documentation → | Live Demo → |
data-url with abort controllerstabOpened, tabReady, eventClick, eventInput, etc.YaiTabs doubles as an application event hub. Add any event type and get automatic hooks:
const tabs = new YaiTabs({
events: {
setListener: {
'[data-yai-tabs]': ['click', 'keydown', 'input', 'change', 'submit']
}
}
});
// All events are automatically available as hooks
tabs.hook('eventClick', ({ event, target, container, action }) => {
console.log('Click action:', action); // Extracted from data-click
});
tabs.hook('eventInput', ({ event, target, container, action }) => {
console.log('Input action:', action); // Extracted from data-input
});
tabs.hook('tabOpened', ({ detail }) => {
console.log('Tab opened:', detail.id);
});
Multiple hooks per event:
tabs
.hook('tabOpened', (ctx) => trackAnalytics(ctx))
.hook('tabOpened', (ctx) => updateUI(ctx))
.hook('tabOpened', (ctx) => loadContent(ctx));
data-tab="1" or data-tab="2". And repeat the step in each pasted component. But set your expectations first, what’s your first thought? And share your final conclusion.License: MIT