ttabs is a layout system that allows users to create resizable and rearrangeable interfaces with tiles and tabs.
You create an instance of ttabs, register your components (can be any Svelte component), create a layout, and add instances of your components to tabs and columns.
npm install ttabs-svelte
import { Ttabs, TtabsRoot } from 'ttabs-svelte';
// Create a ttabs instance
const ttabs = new Ttabs({
theme: darkTheme // Optional: specify a theme
});
// In your Svelte component
<div class="container">
<TtabsRoot {ttabs} />
</div>
TtabsRoot is the container component that renders your layout and manages the root grid.
// The rootGridId is automatically managed by TtabsRoot
const rowId = ttabs.addRow(ttabs.getRootGridId());
const columnId = ttabs.addColumn(rowId);
const panelId = ttabs.addPanel(columnId);
const tabId = ttabs.addTab(panelId, 'My Tab');
// Split panels
ttabs.splitPanel(tabId, panelId, 'right'); // directions: 'top', 'right', 'bottom', 'left'
// Register components
import MyComponent from './MyComponent.svelte';
ttabs.registerComponent('my-component', MyComponent, { defaultProp: 'value' });
// Add component to a tab
ttabs.setComponent(tabId, 'my-component', { prop1: 'value1' });
// Add component directly to a column (without a panel)
ttabs.addColumnComponent(columnId, 'my-component', { prop1: 'value1' });
// Create a new tab in the active panel
const newTabId = ttabs.createNewTabInActivePanel('New Tab');
// Close a tab
ttabs.closeTab(tabId);
// Set a tab as active
ttabs.setActiveTab(tabId);
// Move tab between panels
ttabs.moveTab(tabId, targetPanelId);
import { LocalStorageAdapter } from 'ttabs-svelte';
// Create storage adapter
const storage = new LocalStorageAdapter('my-app-layout');
// Load saved state
const savedData = storage.load();
const ttabs = new Ttabs({
tiles: savedData?.tiles,
focusedTab: savedData?.focusedTab
});
// Save changes
const unsubscribe = ttabs.subscribe(state => storage.save(state));
// Cleanup when component is destroyed
onDestroy(() => unsubscribe());
TileGrid -> TileRow[] -> TileColumn[] -> TileContent | TilePanel | TileGrid
TilePanel -> TileTab[] -> TileContnet
Each level follows strict containment rules:
$state
, $effect
) for state management