@alwith/module-tabs
v0.6.1
Published
A shared tab system for pages, tools and documents. The core has no React, DOM, filesystem or native-host dependency. React rendering uses the published shadcn Vega primitives.
Readme
@alwith/module-tabs
A shared tab system for pages, tools and documents. The core has no React, DOM, filesystem or native-host dependency. React rendering uses the published shadcn Vega primitives.
Entry points
@alwith/module-tabs/core:createTabController,createTabStateand presentation contracts.@alwith/module-tabs/react:TabStripandTabActionButton.@alwith/module-tabs/styles.css: complete scoped styles. No editor stylesheet is required.
Applications provide the usual semantic theme tokens (--background, --foreground, --muted, --muted-foreground, --accent, --border, --ring, --sidebar-foreground, --radius-md). --chrome-hover-background can override the toolbar hover overlay. Include the package's dist files in Tailwind's source scanning when consuming the shared Vega primitives.
Plain pages
import { createTabController } from "@alwith/module-tabs/core"
import { TabStrip } from "@alwith/module-tabs/react"
import "@alwith/module-tabs/styles.css"
const controller = createTabController({
initial: {
tabs: [{ id: "home", title: "Home", transient: false, dirty: false, closable: false }],
activeId: "home",
},
beforeClose: async (tab) => await confirmPageClose(tab.id),
})
<TabStrip
controller={controller}
prefix="pages"
labels={labels}
newTabAction={{ label: "New page", onInvoke: createPage }}
renderIcon={renderPageIcon}
renderContextMenu={renderPageMenu}
trailing={<PageActions />}
onError={reportError}
/>Dispose an owned controller when its host is destroyed. Keep the controller stable across renders. prefix must be unique per mounted strip; the host connects panels using ${prefix}-panel-${id} and ${prefix}-tab-${id}. The labels contract includes the strip label (newTab) and the common close commands. A host may supply a preformatted shortcutLabel for the new-tab tooltip; shortcut registration remains host-owned.
beforeClose resolves false to cancel. Duplicate concurrent closes share one promise. A cancelled close stops a batch. Closing a tab returns to its opener if still present, otherwise its neighbor, and does not steal a later selection. createTabState provides the same ordered selection and close coordinator to document adapters without copying document state.
Interaction and layout
Tabs range from 90 to 240 CSS pixels, separated by 4 pixels. Only tabs scroll. A new-tab action follows the tabs and docks before trailing actions when needed; its separator uses a 16-pixel gap. Titles fade before visible close controls and never use ellipses. Pointer reordering includes edge scrolling, RTL and cancellation. Keyboard navigation, middle-click close, preview retention, reduced motion and continuous-close geometry are built in.
The strip renders where mounted and does not own application panels, filesystem operations, persistence, global shortcuts or window controls. File integration is provided separately by @alwith/module-editor/tabs.
Validation
Run bun run build and bun run test. Unit tests include a non-file page consumer. Browser geometry and integration checks run in the consuming application against locally packed packages before release.
