# Examples Common usage patterns for the `ZestResponsiveLayout` component. --- ## Table of Contents - [Basic Layout](#basic-layout) - [Custom Desktop Width](#custom-desktop-width) - [Mobile Breakpoint Configuration](#mobile-breakpoint-configuration) - [Animation Control](#animation-control) - [Desktop Overlay Configuration](#desktop-overlay-configuration) - [State Preservation with keepMounted](#state-preservation-with-keepmounted) - [Side Pane Stacking (Nested Views)](#side-pane-stacking-nested-views) - [Function Components with useSidePane](#function-components-with-usesidepane) - [Class Components with withSidePane HOC](#class-components-with-withsidepane-hoc) - [Class Components with SidePaneConsumer](#class-components-with-sidepaneconsumer) - [Deep Nesting and Data Preservation](#deep-nesting-and-data-preservation) - [Nesting with Form State Preservation](#nesting-with-form-state-preservation) - [Custom Styling](#custom-styling) --- ## Basic Layout A standard sidebar-and-content layout with automatic mobile responsiveness. ```tsx import { ZestResponsiveLayout } from 'jattac.libs.web.zest-responsive-layout'; import { useState } from 'react'; const BasicApp = () => { const [isOpen, setIsOpen] = useState(false); return (
  • Home
  • Profile
  • , onClose: () => setIsOpen(false) }} >

    Main content goes here.

    ); }; ``` On viewports narrower than the configured breakpoint (default 768px), the side pane renders as a full-screen overlay that slides in from the right edge. --- ## Custom Desktop Width ```tsx Fixed Width Sidebar }} >
    Dynamic Content
    ``` The `sidePaneWidth` prop accepts any valid CSS length value, including `"30%"`, `"400px"`, or `"20vw"`. --- ## Mobile Breakpoint Configuration ```tsx Responsive Menu }} >
    Content
    ``` Use this to switch the layout to mobile mode at a higher or lower viewport width. --- ## Animation Control ```tsx Sidebar }} >
    Content
    ``` Disable the bounce animation for applications that require a more restrained visual style or need to conform to accessibility guidelines regarding reduced motion. --- ## Desktop Overlay Configuration ```tsx Settings, onClose: () => handleClose() }} >
    Settings Dashboard
    ``` - `enableDesktopOverlay={false}` removes the dimming overlay, allowing the main content to remain fully interactive. - `closeOnDesktopOverlayClick={false}` prevents the side pane from closing when the overlay area is clicked; users must use the close button. --- ## State Preservation with keepMounted ```tsx , onClose: () => setIsOpen(false) }} >
    Main Content Area
    ``` When `keepMounted` is `true`, the side pane content remains in the DOM even while hidden. This is useful when the content includes forms, data grids, or other stateful components that would be expensive or disruptive to reinitialize on each open. --- ## Side Pane Stacking (Nested Views) **Important:** Do not nest `ZestResponsiveLayout` components or place side panes inside other side panes. Doing so produces a cramped and unusable interface. Instead, use the side pane stack API. The stack API allows an unlimited number of side panes to be pushed onto a stack. Only the topmost pane is visible at any time. When a pane is closed, the pane below it is revealed with its state fully preserved, including form inputs, scroll position, and all component state. ### Function Components with useSidePane The `useSidePane()` hook is the primary API for function components. It returns `openSidePane`, `closeSidePane`, `stackLength`, and `stack`. ```tsx import { ZestResponsiveLayout, SidePaneProvider, useSidePane, ISidePaneConfig } from 'jattac.libs.web.zest-responsive-layout'; import { useState } from 'react'; const ItemList = () => { const { openSidePane } = useSidePane(); const items = [ { id: 1, name: "Project Alpha" }, { id: 2, name: "Project Beta" } ]; return (
    {items.map(item => ( ))}
    ); }; const ItemDetail = ({ item }: { item: { id: number; name: string } }) => { const { openSidePane, stackLength } = useSidePane(); return (

    {item.name}

    Stack depth: {stackLength}

    ); }; const App = () => { const [isOpen, setIsOpen] = useState(false); return ( , onClose: () => setIsOpen(false) }} >
    ); }; ``` ### Class Components with withSidePane HOC Class components can use the `withSidePane` higher-order component, which injects `openSidePane`, `closeSidePane`, and `stackLength` as props. ```tsx import { ZestResponsiveLayout, SidePaneProvider, withSidePane, WithSidePaneProps, ISidePaneConfig } from 'jattac.libs.web.zest-responsive-layout'; import React from 'react'; interface ProjectListProps extends WithSidePaneProps {} class ProjectList extends React.Component { private items = [ { id: 1, name: "Project Alpha" }, { id: 2, name: "Project Beta" }, { id: 3, name: "Project Gamma" } ]; private handleView(item: { id: number; name: string }): void { this.props.openSidePane({ title: item.name, content: }); } render() { return (
    {this.items.map(item => ( ))}

    Current stack depth: {this.props.stackLength}

    ); } } // Wrap with the HOC to inject side pane context props const ProjectListWithSidePane = withSidePane(ProjectList); const App = () => { return ( }} >
    Main Content
    ); }; ``` ### Class Components with SidePaneConsumer An alternative for class components is the `SidePaneConsumer` render-prop component. This avoids the HOC wrapper and gives direct access to the full context value, including the raw stack array. ```tsx import { ZestResponsiveLayout, SidePaneProvider, SidePaneConsumer } from 'jattac.libs.web.zest-responsive-layout'; import React from 'react'; interface TaskListState { tasks: { id: number; title: string }[]; } class TaskList extends React.Component<{}, TaskListState> { constructor(props: {}) { super(props); this.state = { tasks: [ { id: 1, title: "Design review" }, { id: 2, title: "API integration" }, { id: 3, title: "Testing" } ] }; } render() { return ( {({ openSidePane, closeSidePane, stackLength, stack }) => (

    Tasks (stack depth: {stackLength})

      {this.state.tasks.map(task => (
    • {task.title}
    })}> View ))} {stackLength > 0 && ( )} )}
    ); } } const App = () => { return ( }} >
    Main Content
    ); }; ``` ### Deep Nesting and Data Preservation The stack API supports an arbitrary number of nested panes. Each level pushes a new entry onto the stack. When the user closes panes one by one, each previous pane is restored with its component state intact. The following example demonstrates four levels of nesting with form data preservation: ```tsx import { ZestResponsiveLayout, SidePaneProvider, useSidePane } from 'jattac.libs.web.zest-responsive-layout'; import { useState } from 'react'; // Level 1: Order list const OrderList = () => { const { openSidePane } = useSidePane(); return (

    Orders

    {[1001, 1002, 1003].map(id => (
    Order #{id}
    ))}
    ); }; // Level 2: Order detail with edit action const OrderDetail = ({ orderId }: { orderId: number }) => { const { openSidePane } = useSidePane(); return (

    Order #{orderId}

    Status: Pending

    Items: 3 line items

    ); }; // Level 3: Order edit form with line-item drill-in const OrderEdit = ({ orderId }: { orderId: number }) => { const [notes, setNotes] = useState(""); const { openSidePane } = useSidePane(); return (

    Edit Order #{orderId}