@aglyn/shared-ui-next
v1.0.0-beta.177
Published
React components and hooks that depend on Next.js: a two-column tab hub whose active tab lives in the URL, a route-based section rail, a `next/image` wrapper with a shimmer placeholder, and a page title provider. The Aglyn console and the console pages th
Readme
@aglyn/shared-ui-next
React components and hooks that depend on Next.js: a two-column tab hub whose active tab lives in the URL, a route-based section rail, a next/image wrapper with a shimmer placeholder, and a page title provider. The Aglyn console and the console pages that plugins ship are built with it. It assumes the App Router (next/navigation).
Beta. Published from the Aglyn monorepo under the
betadist-tag; APIs can change between beta releases.
Install
npm install @aglyn/shared-ui-next@betaPeer dependencies: react, next, @mui/material and @mui/lab (the tab components use TabContext, TabList and TabPanel from @mui/lab).
What's in it
From the root entry:
HubTabs— a navigation card with vertical tabs on the left and the active panel on the right, collapsing to horizontal tabs on small screens. Takestabs: { id, label, content }[], an optionalnavHeader, andlazyto defer mounting a panel until it is first opened. The active tab is mirrored into the?tab=query parameter, so a tab can be linked to and survives back and forward. Panels stay mounted once shown.HubSections— the same rail, choosing a section by route instead of by panel. Takessections: { href, label, visible?, locked? }[]and renderschildren(the current route's page) beside the rail. Use it when each section should be its own code-split route.useActiveSection(sections)— the section the current pathname is inside, matched by longesthrefprefix on a path-separator boundary, ornull. Useful for a breadcrumb that must agree with the rail.Image—next/imagewrapped as an Emotion styled component, with an animated SVG shimmer as the blur placeholder.widthandheightdefault to 100; passdisableShimmerto turn the placeholder off.NextPageTitleProvider,NextPageTitle,useNextPageTitle,useNextPageTitleContext— compose a document title from parts and render it throughnext/head.PageDecoratedand theNextPageWithLayouttypes — render a page inside the layout the page itself declares.
By subpath:
@aglyn/shared-ui-next/hooks/use-tab-param—useTabParam({ ids, param?, fallback?, onChange? })returns{ tab, onTabChange }, the URL-backed tab stateHubTabsis built on.onTabChangeis a drop-in for a Material UITabList'sonChange.
Usage
'use client'
import { HubTabs } from '@aglyn/shared-ui-next'
export function SettingsHub() {
return (
<HubTabs
navHeader="Settings"
tabs={[
{ id: 'general', label: 'General', content: <p>General settings</p> },
{ id: 'members', label: 'Members', content: <p>Members</p> },
]}
/>
)
}/settings?tab=members opens the second tab.
How it fits
A shared UI package. It depends on @aglyn/shared-ui-jsx, @aglyn/shared-ui-theme, @aglyn/shared-data-enums, @aglyn/shared-util-dom and @aglyn/shared-util-tools; the feature plugins depend on it for their console pages. Shared packages are generic: they import only other shared packages and hold no plugin's domain.
License
Apache-2.0. Source: https://github.com/aglyn/aglyn/tree/main/libs/shared/ui/next