Skip to main content

tab

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://unpkg.com/xnew@5.0.x/dist/xnew.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
</head>

<body class="relative m-0 p-0 w-full h-screen overflow-hidden">
<div id="main" class="relative w-full h-full"></div>
<script>
xnew('#main', (self) => {
xnew.extend(xnew.TabFrame);
xnew.nest('<div class="p-2">')

xnew('<div class="flex">', () => {
xnew(TabButton, { name: 'Tab 1' });
xnew(TabButton, { name: 'Tab 2' });
xnew(TabButton, { name: 'Tab 3' });
});
xnew(Content1);
xnew(Content2);
xnew(Content3);
});

function TabButton(self, { name }) {
xnew.extend(xnew.TabButton);
xnew('<div class="m-2">', name);
}

function Content1(self) {
xnew.extend(xnew.TabContent);
xnew.nest('<div class="p-2 border rounded-lg bg-red-100">');
xnew('<p>', 'content 1');
}

function Content2(self) {
xnew.extend(xnew.TabContent);
xnew.nest('<div class="p-2 border rounded-lg bg-green-100">');
xnew('<p>', 'content 2');
}

function Content3(self) {
xnew.extend(xnew.TabContent);
xnew.nest('<div class="p-2 border rounded-lg bg-blue-100">');
xnew('<p>', 'content 3');
}
</script>
</body>

</html>