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
npm install @orderly.network/ui-scaffoldScaffold 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.
``typescript`
import { Scaffold, type ScaffoldProps } from "@orderly.network/ui-scaffold";
`typescript
import React from 'react';
import { Scaffold } from "@orderly.network/ui-scaffold";
const App = () => {
return (
Your main content here
);
};
`
- 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
`typescript`
>
{children}
- Type: SideBarPropstitle
- Description: Configuration properties for the default sidebar component
- Main Properties:
- : 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)
`typescript
const sidebarMenus = [
{ name: "Dashboard", href: "/dashboard", icon:
{ name: "Trading", href: "/trading", icon:
{ name: "Portfolio", href: "/portfolio", icon:
];
title: "Navigation",
items: sidebarMenus,
current: "/dashboard",
onItemSelect: (item) => console.log('Selected:', item),
maxWidth: 200,
minWidth: 80
}}
>
{children}
`
- Type: React.ReactNode
- Description: Custom top navigation bar component
- Use Case: When you need to completely customize the top navigation bar
`typescript`
>
{children}
- Type: MainNavWidgetPropsleading
- Description: Configuration properties for the default main navigation component
- Main Properties:
- : 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(components: MainNavComponents) => ReactNode
- Type: title
- Components:
- : 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)
`typescriptNavigating to ${href}
logo: {
src: "/logo.png",
alt: "Company Logo"
},
mainMenus: [
{ name: "Trade", href: "/trade" },
{ name: "Portfolio", href: "/portfolio" }
],
leading:
trailing:
onItemClick: ({ href, name }) => {
console.log();
},
leftNav: {
menus: [
{ name: "Dashboard", href: "/dashboard", icon:
{ name: "Trading", href: "/trading", icon:
{ name: "Portfolio", href: "/portfolio", icon:
],
leading:
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 (
{components.leftNav}
{components.title}
{components.languageSwitcher}
{components.scanQRCode}
{components.linkDevice}
{components.chainMenu}
{components.walletConnect}
);
}
// Desktop layout
return (
{components.title}
{components.mainNav}
{components.accountSummary}
{components.linkDevice}
{components.languageSwitcher}
{components.subAccount}
{components.chainMenu}
{components.walletConnect}
);
}
}}
>
{children}
`
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: LeftNavPropsmenus
- Description: Configuration for the mobile left navigation drawer
- Main Properties:
- : 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 use window.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
`typescript`
leftNav: {
menus: [
{
name: "Dashboard",
href: "/dashboard",
icon:
},
{
name: "Trading",
href: "/trading",
icon:
trailing:
},
{
name: "Portfolio",
href: "/portfolio",
icon:
customRender: ({ name, href, isActive }) => (
custom-menu-item ${isActive ? 'active' : ''}}>
{name}
)
},
{
name: "External Link",
href: "https://external-site.com",
target: "_blank",
icon:
}
],
leading: (
),
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}
#### 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:
1. Logo at the top
2. Leading content (if provided)
3. Sub-account selector (if user is logged in with trading enabled)
4. Menu items list (scrollable if needed)
5. Social media links at the bottom
6. Feedback link at the very bottom (only if feedbackUrl is provided)target
- Auto-close: The drawer automatically closes when a menu item is selected
- Navigation Behavior:
- Items with property will open in new window/tab using window.open()target
- Items without will use router navigation and close the drawer
#### Advanced Customization
You can provide a completely custom left navigation trigger:
`typescript`
customLeftNav:
leftNav: {
// ... leftNav configuration
}
}}
>
{children}
- Type: BottomNavPropsmainMenus
- Description: Mobile bottom navigation configuration (only displayed on mobile devices)
- Main Properties:
- : Array of bottom menu items
`typescript
const bottomMenus = [
{
name: "Home",
href: "/home",
activeIcon:
inactiveIcon:
},
{
name: "Trade",
href: "/trade",
activeIcon:
inactiveIcon:
}
];
mainMenus: bottomMenus,
}}
>
{children}
`
- Type: React.ReactNode
- Description: Custom footer component
`typescript`
>
{children}
- Type: FooterPropstelegramUrl
- Description: Configuration properties for the default footer component
- Main Properties:
- : Telegram linktwitterUrl
- : Twitter linkdiscordUrl
- : Discord linktrailing
- : Content on the right side of the footer
`typescript`
telegramUrl: "https://t.me/yourgroup",
twitterUrl: "https://twitter.com/yourhandle",
discordUrl: "https://discord.gg/yourserver",
trailing:
}}
>
{children}
- Type: RouterAdapteronRouteChange
- Description: Router adapter for integrating with different routing libraries
- Main Properties:
- : Route change handler functioncurrentPath
- : Current path
`typescript
// React Router integration example
const routerAdapter = {
onRouteChange: (option) => {
if (option.target === '_blank') {
window.open(option.href, '_blank');
} else {
navigate(option.href);
}
},
currentPath: location.pathname
};
>
{children}
`
- 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
`typescript`
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}
`typescript
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:
},
{
name: "Trading",
href: "/trading",
icon:
},
{
name: "Portfolio",
href: "/portfolio",
icon:
}
];
const bottomMenus = [
{
name: "Home",
href: "/home",
activeIcon:
inactiveIcon:
},
{
name: "Trade",
href: "/trade",
activeIcon:
inactiveIcon:
}
];
const routerAdapter = {
onRouteChange: (option) => {
if (option.target === '_blank') {
window.open(option.href, '_blank');
} else {
navigate(option.href);
}
},
currentPath: location.pathname
};
return (
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:
trailing:
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"
}}
>
This is the main content area.
export default App;
`
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
- 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
1. Router Integration: Always provide routerAdapter to ensure navigation functionality works properlybottomNavProps
2. Responsive Design: Provide and leftNav configuration for optimal mobile experienceclassNames
3. Style Customization: Use the property for style customization instead of directly modifying component stylescurrent
4. Menu State Management: Ensure the property is synchronized with actual route stateleftNav
5. Performance Optimization: For large menu lists, consider using React.memo to optimize rendering performance
6. Mobile Navigation: Configure with social media links and feedback URL to provide comprehensive mobile navigation experience
- The Scaffold component must be wrapped in ScaffoldProvider to work properly (automatically handled internally)leftNav
- 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 drawer is only available on mobile devices and provides a comprehensive navigation menu
- All navigation callbacks should properly handle route navigation logic
- ScaffoldProvider: Provides Scaffold contextuseScaffoldContext
- : Hook to get Scaffold stateMobileScaffold
- : Mobile layout componentDesktopScaffold
- : Desktop layout componentSubAccountWidget`: Sub-account selection component (exported from ui-scaffold)
-