@orderly.network/ui-scaffold
v2.10.0
Published
Scaffold is a powerful layout component that provides a complete application scaffolding structure, including top navigation bar, sidebar, main content area, bottom navigation, and footer. This component supports responsive layouts for both desktop and mo
Downloads
2,844
Keywords
Readme
Scaffold Component Integration Guide
Overview
Scaffold is a powerful layout component that provides a complete application scaffolding structure, including top navigation bar, sidebar, main content area, bottom navigation, and footer. This component supports responsive layouts for both desktop and mobile devices and offers rich customization options.
Installation and Import
import { Scaffold, type ScaffoldProps } from "@orderly.network/ui-scaffold";Basic Usage
import React from 'react';
import { Scaffold } from "@orderly.network/ui-scaffold";
const App = () => {
return (
<Scaffold>
<div>Your main content here</div>
</Scaffold>
);
};ScaffoldProps Properties Detailed
1. leftSidebar (Optional)
- Type:
React.ReactNode - Description: Custom left sidebar component. If provided, the layout will use this component instead of the default sidebar component
- Use Case: When you need to completely customize the sidebar style and functionality
<Scaffold
leftSidebar={<CustomSidebar />}
>
{children}
</Scaffold>2. leftSideProps (Optional)
- Type:
SideBarProps - Description: Configuration properties for the default sidebar component
- Main Properties:
title: Sidebar titleitems: Array of menu itemsopen: Whether the sidebar is expandedonOpenChange: Callback for expansion state changesonItemSelect: Callback for menu item selectioncurrent: Currently selected menu itemmaxWidth: Maximum width when expanded (default: 185px)minWidth: Minimum width when collapsed (default: 98px)
const sidebarMenus = [
{ name: "Dashboard", href: "/dashboard", icon: <DashboardIcon /> },
{ name: "Trading", href: "/trading", icon: <TradingIcon /> },
{ name: "Portfolio", href: "/portfolio", icon: <PortfolioIcon /> }
];
<Scaffold
leftSideProps={{
title: "Navigation",
items: sidebarMenus,
current: "/dashboard",
onItemSelect: (item) => console.log('Selected:', item),
maxWidth: 200,
minWidth: 80
}}
>
{children}
</Scaffold>3. topBar (Optional)
- Type:
React.ReactNode - Description: Custom top navigation bar component
- Use Case: When you need to completely customize the top navigation bar
<Scaffold
topBar={<CustomTopBar />}
>
{children}
</Scaffold>4. mainNavProps (Optional)
- Type:
MainNavWidgetProps - Description: Configuration properties for the default main navigation component
- Main Properties:
leading: Content on the left side of the navigation bartrailing: Content on the right side of the navigation barlogo: Brand logo configurationmainMenus: Array of main menu itemscampaigns: Campaign menu itemcampaignPosition: Campaign menu positioninitialMenu: Initial menu pathonItemClick: Menu item click callbackleftNav: Left navigation configuration for mobile drawer (only works on mobile)customLeftNav: Custom left navigation component to replace the default leftNavcustomRender: Function to customize the main navigation layout- Type:
(components: MainNavComponents) => ReactNode - Components:
title: Logo or title component (desktop & mobile)languageSwitcher: Language selection component (desktop & mobile)subAccount: Sub-account component (desktop & mobile)linkDevice: Device linking component (desktop & mobile)chainMenu: Chain selection menu (desktop & mobile)walletConnect: Wallet connection component (desktop & mobile)mainNav: Main navigation menu (desktop only)accountSummary: Account summary component (desktop only)leftNav: Left navigation component (mobile only)scanQRCode: QR code scanner component (mobile only)
- Type:
<Scaffold
mainNavProps={{
logo: {
src: "/logo.png",
alt: "Company Logo"
},
mainMenus: [
{ name: "Trade", href: "/trade" },
{ name: "Portfolio", href: "/portfolio" }
],
leading: <BrandSection />,
trailing: <UserActions />,
onItemClick: ({ href, name }) => {
console.log(`Navigating to ${href}`);
},
leftNav: {
menus: [
{ name: "Dashboard", href: "/dashboard", icon: <DashboardIcon /> },
{ name: "Trading", href: "/trading", icon: <TradingIcon /> },
{ name: "Portfolio", href: "/portfolio", icon: <PortfolioIcon /> }
],
leading: <CustomLeftNavHeader />,
twitterUrl: "https://twitter.com/yourhandle",
telegramUrl: "https://t.me/yourgroup",
discordUrl: "https://discord.gg/yourserver",
duneUrl: "https://dune.com/youranalytics",
feedbackUrl: "https://feedback.yoursite.com"
},
// Custom layout for main navigation
customRender: (components) => {
// Mobile layout
if (isMobile) {
return (
<Flex width="100%" justify="between">
<Flex gapX={2}>
{components.leftNav}
{components.title}
</Flex>
<Flex gapX={2}>
{components.languageSwitcher}
{components.scanQRCode}
{components.linkDevice}
{components.chainMenu}
{components.walletConnect}
</Flex>
</Flex>
);
}
// Desktop layout
return (
<Flex width="100%" justify="between">
<Flex gapX={2}>
{components.title}
{components.mainNav}
</Flex>
<Flex gapX={2}>
{components.accountSummary}
{components.linkDevice}
{components.languageSwitcher}
{components.subAccount}
{components.chainMenu}
{components.walletConnect}
</Flex>
</Flex>
);
}
}}
>
{children}
</Scaffold>5. leftNav Configuration (Optional)
leftNav is a configuration property within mainNavProps that controls the mobile slide-out navigation drawer. It only appears on mobile devices and provides a comprehensive menu system.
LeftNavProps Properties
- Type:
LeftNavProps - Description: Configuration for the mobile left navigation drawer
- Main Properties:
menus: Array of navigation menu items for the drawerleading: Custom content at the top of the drawer (below logo)twitterUrl: Twitter/X social media linktelegramUrl: Telegram community linkdiscordUrl: Discord community linkduneUrl: Dune Analytics linkfeedbackUrl: Feedback form link (optional - if not provided, feedback section will not be displayed)customLeftNav: Custom component to replace the default leftNav trigger
LeftNavItem Properties
Each menu item in the menus array supports:
name: Display name of the menu itemhref: Navigation URLtarget: Link target (e.g., "_blank" for new window). If provided, will usewindow.open()instead of router navigation (optional)icon: Icon component to display (optional)trailing: Additional content on the right side (optional)customRender: Custom render function for complete control over item appearance
Usage Example
<Scaffold
mainNavProps={{
leftNav: {
menus: [
{
name: "Dashboard",
href: "/dashboard",
icon: <DashboardIcon />
},
{
name: "Trading",
href: "/trading",
icon: <TradingIcon />,
trailing: <NotificationBadge />
},
{
name: "Portfolio",
href: "/portfolio",
icon: <PortfolioIcon />,
customRender: ({ name, href, isActive }) => (
<div className={`custom-menu-item ${isActive ? 'active' : ''}`}>
<PortfolioIcon />
<span>{name}</span>
<SpecialBadge />
</div>
)
},
{
name: "External Link",
href: "https://external-site.com",
target: "_blank",
icon: <ExternalLinkIcon />
}
],
leading: (
<div className="px-3 py-2">
<Text className="text-sm text-gray-500">Quick Actions</Text>
</div>
),
twitterUrl: "https://twitter.com/yourhandle",
telegramUrl: "https://t.me/yourgroup",
discordUrl: "https://discord.gg/yourserver",
duneUrl: "https://dune.com/youranalytics",
feedbackUrl: "https://feedback.yoursite.com"
}
}}
>
{children}
</Scaffold>Mobile Navigation Behavior
- Trigger: The leftNav appears as a hamburger menu icon on mobile devices
- Drawer: Slides out from the left side when triggered
- Content Structure:
- Logo at the top
- Leading content (if provided)
- Sub-account selector (if user is logged in with trading enabled)
- Menu items list (scrollable if needed)
- Social media links at the bottom
- Feedback link at the very bottom (only if
feedbackUrlis provided)
- Auto-close: The drawer automatically closes when a menu item is selected
- Navigation Behavior:
- Items with
targetproperty will open in new window/tab usingwindow.open() - Items without
targetwill use router navigation and close the drawer
- Items with
Advanced Customization
You can provide a completely custom left navigation trigger:
<Scaffold
mainNavProps={{
customLeftNav: <CustomHamburgerButton />,
leftNav: {
// ... leftNav configuration
}
}}
>
{children}
</Scaffold>6. bottomNavProps (Optional)
- Type:
BottomNavProps - Description: Mobile bottom navigation configuration (only displayed on mobile devices)
- Main Properties:
mainMenus: Array of bottom menu items
const bottomMenus = [
{
name: "Home",
href: "/home",
activeIcon: <HomeActiveIcon />,
inactiveIcon: <HomeInactiveIcon />
},
{
name: "Trade",
href: "/trade",
activeIcon: <TradeActiveIcon />,
inactiveIcon: <TradeInactiveIcon />
}
];
<Scaffold
bottomNavProps={{
mainMenus: bottomMenus,
}}
>
{children}
</Scaffold>7. footer (Optional)
- Type:
React.ReactNode - Description: Custom footer component
<Scaffold
footer={<CustomFooter />}
>
{children}
</Scaffold>8. footerProps (Optional)
- Type:
FooterProps - Description: Configuration properties for the default footer component
- Main Properties:
telegramUrl: Telegram linktwitterUrl: Twitter linkdiscordUrl: Discord linktrailing: Content on the right side of the footer
<Scaffold
footerProps={{
telegramUrl: "https://t.me/yourgroup",
twitterUrl: "https://twitter.com/yourhandle",
discordUrl: "https://discord.gg/yourserver",
trailing: <AdditionalFooterContent />
}}
>
{children}
</Scaffold>9. routerAdapter (Optional)
- Type:
RouterAdapter - Description: Router adapter for integrating with different routing libraries
- Main Properties:
onRouteChange: Route change handler functioncurrentPath: Current path
// React Router integration example
const routerAdapter = {
onRouteChange: (option) => {
if (option.target === '_blank') {
window.open(option.href, '_blank');
} else {
navigate(option.href);
}
},
currentPath: location.pathname
};
<Scaffold
routerAdapter={routerAdapter}
>
{children}
</Scaffold>10. classNames (Optional)
- Type: Style class name configuration object
- Description: Used to customize styles for various layout areas
- Configurable Areas:
root: Root container (topNavbar + container + footer)container: Main containercontent: Content areabody: Body area (leftSidebar + content)leftSidebar: Left sidebartopNavbar: Top navigation barfooter: Footer
<Scaffold
classNames={{
root: "custom-root-class",
container: "custom-container-class",
content: "custom-content-class",
body: "custom-body-class",
leftSidebar: "custom-sidebar-class",
topNavbar: "custom-navbar-class",
footer: "custom-footer-class"
}}
>
{children}
</Scaffold>Complete Usage Example
import React from 'react';
import { Scaffold } from "@orderly.network/ui-scaffold";
import { useNavigate, useLocation } from 'react-router-dom';
const App = () => {
const navigate = useNavigate();
const location = useLocation();
const sidebarMenus = [
{
name: "Dashboard",
href: "/dashboard",
icon: <DashboardIcon />
},
{
name: "Trading",
href: "/trading",
icon: <TradingIcon />
},
{
name: "Portfolio",
href: "/portfolio",
icon: <PortfolioIcon />
}
];
const bottomMenus = [
{
name: "Home",
href: "/home",
activeIcon: <HomeActiveIcon />,
inactiveIcon: <HomeInactiveIcon />
},
{
name: "Trade",
href: "/trade",
activeIcon: <TradeActiveIcon />,
inactiveIcon: <TradeInactiveIcon />
}
];
const routerAdapter = {
onRouteChange: (option) => {
if (option.target === '_blank') {
window.open(option.href, '_blank');
} else {
navigate(option.href);
}
},
currentPath: location.pathname
};
return (
<Scaffold
leftSideProps={{
title: "Navigation",
items: sidebarMenus,
current: location.pathname,
onItemSelect: (item) => {
if (item.href) {
navigate(item.href);
}
}
}}
mainNavProps={{
logo: {
src: "/logo.png",
alt: "Company Logo"
},
mainMenus: [
{ name: "Trade", href: "/trade" },
{ name: "Portfolio", href: "/portfolio" }
],
leading: <BrandSection />,
trailing: <UserActions />,
onItemClick: ({ href }) => navigate(href),
leftNav: {
menus: sidebarMenus, // Reuse the same menu items
twitterUrl: "https://twitter.com/yourhandle",
telegramUrl: "https://t.me/yourgroup",
discordUrl: "https://discord.gg/yourserver",
feedbackUrl: "https://feedback.yoursite.com"
}
}}
bottomNavProps={{
mainMenus: bottomMenus,
}}
footerProps={{
telegramUrl: "https://t.me/yourgroup",
twitterUrl: "https://twitter.com/yourhandle",
discordUrl: "https://discord.gg/yourserver"
}}
routerAdapter={routerAdapter}
classNames={{
content: "p-4",
leftSidebar: "border-r border-gray-200"
}}
>
<div className="min-h-screen">
{/* Your main application content */}
<h1>Welcome to your application</h1>
<p>This is the main content area.</p>
</div>
</Scaffold>
);
};
export default App;Responsive Behavior
The Scaffold component automatically detects device type and provides appropriate layouts:
- Desktop: Displays complete sidebar, top navigation bar, and footer
- Mobile: Hides sidebar, displays bottom navigation bar and left navigation drawer (leftNav), optimized for touch interaction
Mobile Navigation Features
- Left Navigation Drawer: Accessed via hamburger menu icon, provides slide-out menu with complete navigation options
- Bottom Navigation: Fixed bottom bar for quick access to main sections
- Responsive Top Bar: Adapts to show essential controls and navigation elements
Best Practices
- Router Integration: Always provide
routerAdapterto ensure navigation functionality works properly - Responsive Design: Provide
bottomNavPropsandleftNavconfiguration for optimal mobile experience - Style Customization: Use the
classNamesproperty for style customization instead of directly modifying component styles - Menu State Management: Ensure the
currentproperty is synchronized with actual route state - Performance Optimization: For large menu lists, consider using React.memo to optimize rendering performance
- Mobile Navigation: Configure
leftNavwith social media links and feedback URL to provide comprehensive mobile navigation experience
Important Notes
- The Scaffold component must be wrapped in
ScaffoldProviderto work properly (automatically handled internally) - Sidebar expand/collapse state is automatically saved to localStorage
- Mobile and desktop use different layout components to ensure good user experience on different devices
- The
leftNavdrawer is only available on mobile devices and provides a comprehensive navigation menu - All navigation callbacks should properly handle route navigation logic
Related Components
ScaffoldProvider: Provides Scaffold contextuseScaffoldContext: Hook to get Scaffold stateMobileScaffold: Mobile layout componentDesktopScaffold: Desktop layout componentSubAccountWidget: Sub-account selection component (exported from ui-scaffold)
