UNPKG

@atlaskit/navigation-system

Version:

Page layout and navigation components for Atlassian apps.

436 lines (292 loc) • 21.8 kB
--- title: Layout description: Layout components define a page’s structure and the areas for navigation and content. order: 1 --- import Image from '@atlaskit/image'; import layoutExampleLight from './images/layout-example-light.png'; import layoutExampleDark from './images/layout-example-dark.png'; import layoutExampleSideNavLight from './images/layout-example-sideNav-light.png'; import layoutExampleSideNavDark from './images/layout-example-sideNav-dark.png'; import layoutExampleTopNav1Light from './images/layout-example-topNav-1-light.png'; import layoutExampleTopNav1Dark from './images/layout-example-topNav-1-dark.png'; import { CustomSkipLinkExample } from '../../examples/constellation/layout/custom-skip-links'; import { LayoutCompositionExample } from '../../examples/constellation/layout/layout-composition'; import { PanelOpenCloseExample } from '../../examples/constellation/layout/panel-open-close'; import { WidthPersistenceExample } from '../../examples/constellation/layout/width-persistence'; import { ExpandSideNavButtonExample } from '../../examples/constellation/layout/expand-side-nav'; import { ToggleSideNavKeyboardShortcutExample } from '../../examples/constellation/layout/toggle-side-nav-keyboard-shortcut'; The full page layout with all areas rendered has the structure depicted below. <Image src={layoutExampleLight} srcDark={layoutExampleDark} alt="Example of the navigation system layout areas" /> When composing your page layout ensure that: - The `Root` element wraps your entire view. - `Banner`, `TopNav`, `SideNav`, `Main`, and `ChatPanel` are rendered as immediate children of `Root`. - To include a panel, render `PanelLayout` inside `Main`. This example shows how to arrange the layout areas. Supply your app’s content and control whether panel and chat panel are open through the example’s props. Explore the [interactive example](https://atlaskit.stg.atlassian.com/examples/navigation/global-top-navigation/self-hiding-chat) to try resizing and responsive behavior. <Example Component={LayoutCompositionExample} appearance="source-only" isCodeSandboxDisabled /> ## Layout areas These are the distinct areas in the layout. These components are designed to contain other components and content. The tables below show the width settings supplied by the layout components. Apps can override default, minimum, and maximum widths where supported. See the [code tab](/components/navigation-system/layout/code) for the available props. ### Banner Use the banner area to render a [banner](/components/banner) component. It will always display at the top of the screen. ### Top nav Use the top nav area to render [top nav items](/components/navigation-system/top-nav-items). - It will display at the top of the screen, below the banner if one is present. Its default height is 56px. Use the `height` prop to override it. - Use the [top nav slots](#top-nav-slots) to position actions within top nav. - The top nav is responsive, with the top nav items changing according to the container width. Opening chat panel reduces the space available to top nav. #### Top nav slots The top nav has three layout components that you must use to position top nav items within the top nav flexbox. - `TopNavStart`: Area for left-aligned items. - `TopNavMiddle`: Area for center-aligned items. - `TopNavEnd`: Area for right-aligned items. <Image src={layoutExampleTopNav1Light} srcDark={layoutExampleTopNav1Dark} alt="Example of the top nav slots" /> #### Top nav custom theming See the [custom theming](/components/navigation-system/layout/custom-theming) tab. ### Side nav Use the side nav area to render [side nav items](https://atlaskit.atlassian.com/packages/navigation/side-nav-items). - It will display along the leading edge of the screen. - Use the [side nav slots](#side-nav-slots) to position content within the side nav. - The side nav is collapsible and expandable, resizable, and responsive. | Breakpoint | Viewport size | Default width | Minimum width | Maximum width | Layout mode | | ---------- | ----------------- | ------------- | ------------- | ------------------------------------------------------------------------------- | ---------------------------------------------------------- | | `xxs`–`s` | 320–1,023px | 320px | 240px | The larger of its default width or 90% of the screen width minus the chat panel | Collapsed; opens as overlay | | `m`–`xl` | 1,024px and above | 320px | 240px | No fixed maximum; limited by the minimum widths of the other open inline areas | Inline. In the collapsed state, opens as a flyout on hover | #### Side nav slots The side nav has three layout components that you can use to position components within the side nav flexbox. - `SideNavHeader`: The top part of the side nav. - `SideNavBody`: The middle part of the side nav. It acts as a scroll container. It will grow to take up the available space. This is used to push the footer to the bottom of the side nav. - `SideNavFooter`: The bottom part of the side nav. Note: make sure to render `SideNavBody` to ensure that the footer is positioned at the bottom of the side nav, simulating a sticky footer. <Image src={layoutExampleSideNavLight} srcDark={layoutExampleSideNavDark} alt="Example of the side nav slots" /> #### Side nav collapse and expand The side nav can collapse and expand based on user input or programmatically through hooks. ##### Toggle button The side nav can collapse and expand using the `SideNavToggleButton` from top nav items or the keyboard shortcut. ##### Keyboard shortcut The keyboard shortcut `Ctrl+[` is enabled globally through the `isSideNavShortcutEnabled` on `Root`. It’s disabled by default. When enabled, use `canToggleWithShortcut` on `SideNav` to check individual keypresses and conditionally disable the shortcut for app-specific requirements. ##### Programmatic control There are two hooks available for programmatically toggling the side nav. - `useExpandSideNav` - `useToggleSideNav` These hooks need to be used by components that are rendered as a child of [Root](#root), as they require the internal React context that it provides. **useExpandSideNav** Returns a function that will expand the side nav. This can be useful for ensuring the side nav is expanded before displaying an onboarding spotlight, for example. If the side nav is already expanded, it will simply no-op. <Example Component={ExpandSideNavButtonExample} appearance="source-only" /> <br /> **useToggleSideNav** Returns a function that will toggle the side nav. This is useful for toggling the side nav based on a keyboard shortcut. <Example Component={ToggleSideNavKeyboardShortcutExample} appearance="source-only" /> #### Side nav flyout - At viewport widths of 1,024px and above (`m`, `l`, and `xl` breakpoints), hovering over `SideNavToggleButton` when side nav is collapsed opens it as an overlay. - Moving the pointer away closes it. - If supported ADS layering components, such as popups or dropdown menus, are open within side nav, the flyout stays open until those components close. - The side nav flyout is animated on supported browsers. In Firefox, it expands and collapses without animation. #### Side nav resizing Render `SideNavPanelSplitter` inside `SideNav` to make the side nav resizable. Double-clicking the splitter collapses the side nav. #### Side nav responsive At viewport widths of 1,023px and below (`xxs`, `xs`, and `s` breakpoints), side nav automatically collapses. Users can open it as an overlay using the toggle button or keyboard shortcut, if enabled. ### Main Use the main area for the [page header](/components/page-header) and page content. It will expand to fill available space. | Breakpoint | Viewport size | Default width | Minimum width | Maximum width | Layout mode | | ---------- | ------------------ | --------------------- | ------------- | ------------------------------------------------------------------------------ | ----------- | | `xxs`–`xl` | All viewport sizes | Fills remaining space | 320px\* | No fixed maximum; limited by the minimum widths of the other open inline areas | Inline | \*When panel overlays main and side nav is inline, main must be at least 32px wider than panel’s minimum width, without going below its own minimum width. ### Panel Use the panel area to render a [panel](/components/panel/examples) component. - It will display alongside the main content, opposite the side nav. - To include a panel, render `PanelLayout` inside `Main`. - The panel can be opened, closed, and resized, and is responsive. | Breakpoint | Viewport size | Default width | Minimum width | Maximum width | Layout mode | | ---------- | ----------------- | ------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | | `xxs`–`s` | 320–1,023px | 320px | 320px | Inline: no fixed maximum; limited by the minimum widths of the other open inline areas. Overlay: the larger of its default width or 90% of main’s width | Inline, unless space doesn’t allow, in which case it will display as an overlay | | `m`–`l` | 1,024–1,767px | 400px | 320px | Same as above | Same as above | | `xl` | 1,768px and above | 500px | 320px | Same as above | Same as above | #### Panel opening and closing See [panel loading methods](/components/panel/examples#loading-methods) for how to open a panel. Use `isPanelOpen` on `PanelLayout` to control whether the panel is open. Keep `PanelLayout` mounted when closed so that resized widths are retained. In this example, your app supplies the panel content and manages whether it is open. Opening the panel moves focus to its close button. Using the close button returns focus to the button that opened the panel. If you use the [panel loading methods](/components/panel/examples#loading-methods) to load content, use `LayoutWithPanel` in place of `PanelLayout`. <Example Component={PanelOpenCloseExample} appearance="source-only" isCodeSandboxDisabled /> #### Panel resizing `PanelLayout` includes its own resize control. You don’t need to add a `PanelSplitter`. #### Panel responsive The panel becomes an overlay when the open layout areas can no longer fit side by side at their minimum widths. It overlays main before chat panel becomes an overlay. See [responsive behavior](#responsive-behavior) for how available space determines these transitions. ### Chat panel Use the chat panel area to render Rovo Chat. - It will display along the trailing edge of the screen, alongside top nav and main, below the banner if one is present. - Chat panel can be opened, closed, and resized, and is responsive. | Breakpoint | Viewport size | Default width | Minimum width | Maximum width | Layout mode | | ---------- | ----------------- | ------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | | `xxs`–`s` | 320–1,023px | 320px | 320px | Inline: no fixed maximum; limited by the minimum widths of the other open inline areas. Overlay: the larger of its default width or 90% of the screen width | Inline, unless space doesn’t allow, in which case it will display as an overlay | | `m`–`xl` | 1,024px and above | 400px | 320px | Same as above | Same as above | #### Chat panel opening and closing Apps manage when chat panel opens and closes. Wire up Rovo Chat triggers, such as Ask Rovo in top nav, to open chat panel. Ensure the close button within Rovo Chat closes chat panel. See the [Ask Rovo example](/components/navigation-system/top-nav-items/examples#ask-rovo) for opening and closing chat panel, showing and hiding Ask Rovo, and moving focus. Pass the same close handler to your chat’s close action and `ChatPanel.onClose`. This keeps your app’s open state updated when opening side nav closes a chat panel overlay. #### Chat panel resizing Render a `PanelSplitter` inside `ChatPanel` to make chat panel resizable. #### Chat panel responsive Chat panel becomes an overlay when main and chat panel can no longer fit side by side at their minimum widths. It overlays the rest of the app, including panel. See [responsive behavior](#responsive-behavior) for how available space determines these transitions. ## Layout and data connections Layout manages how areas share space. Apps supply the content and connect data and actions between areas. | Content connection | Guidance | | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | Main content and panel content | The app supplies panel content and handles selections and edits using its state, callbacks, and data APIs. Layout doesn’t synchronize content between main and panel. | | Main content and Rovo Chat | The app’s Rovo integration provides context and supported actions. Rendering Rovo Chat inside `ChatPanel` doesn’t establish this integration. | | Panel content and Rovo Chat | Opening or focusing a panel doesn’t automatically make its content available to Rovo Chat as context or for editing. This depends on the app’s Rovo integration, rather than layout. | ## User resizing Side nav, panel, and chat panel are resizable. Main isn’t directly resizable; it fills the remaining space. ### Resize controls - Side nav: Render `SideNavPanelSplitter` inside `SideNav`. - Panel: `PanelLayout` includes its own resize control. - Chat panel: Render `PanelSplitter` inside `ChatPanel`. Users resize an area by dragging its resize handle. Resizing never triggers an overlay. Resizing side nav, panel, or chat panel closes any open layer components, such as popups, dropdowns, selects, and tooltips. ### How areas share space when inline Dragging an inline area wider makes other areas narrower. With all areas open inline: - Side nav: Dragging side nav wider makes main narrower first, then panel, then chat panel. - Panel: Dragging panel wider makes main narrower first, then side nav. - Chat panel: Dragging chat panel wider makes main narrower first, then panel, then side nav. Each affected area reaches its minimum width before the next area becomes narrower. Resizing stops when all affected areas reach their minimum widths. Dragging an area narrower gives space to main. With all areas open inline: - Side nav: Dragging side nav narrower makes main wider. Resizing stops when side nav reaches its minimum width. - Panel: Dragging panel narrower makes main wider. Once panel reaches its minimum width, continuing to drag pushes chat panel narrower, giving more space to main. Resizing stops when chat panel reaches its minimum width. - Chat panel: Dragging chat panel narrower makes main wider. Resizing stops when chat panel reaches its minimum width. ### Width limits Areas can be resized within their minimum and maximum widths. The tables in each layout area section describe these limits, including differences between inline and overlay modes. Resizing a panel overlay follows different rules from resizing an inline panel. When panel overlays main beside an inline side nav, the layout maintains a 32px gap between their resize handles. Dragging the panel overlay wider makes side nav narrower once that gap reaches 32px. The drag stops when side nav reaches its minimum width. When a side nav overlay covers the panel’s resize handle, the covered handle is hidden and disabled. ### Width persistence Each resizable area remembers its user-selected width after it’s closed and reopened. If available space requires a narrower width, the layout temporarily makes the area narrower. As space becomes available again, the area becomes wider toward its user-selected width. Only the area whose resize handle was dragged receives a new user-selected width. Areas that resize as a result retain their own width preferences. To remember widths across page refreshes, write the `finalWidth` from the `onResizeEnd` callback to persistent storage, such as `localStorage` or your app’s user-preferences store. Store each area’s width separately. When the page loads, read the stored value and pass it to that area’s default width prop before the component mounts. If no saved width exists, the default value will be used. Use the `onResizeEnd` callback on the component for each area: - Side nav: `SideNavPanelSplitter`. - Panel: `PanelLayout`. - Chat panel: `PanelSplitter` inside `ChatPanel`. The example saves one width per area and restores it through `defaultWidth` or `defaultPanelWidth`. Missing or invalid saved values, or unavailable storage, leave the component defaults in place. For apps rendered only in the browser, call `readSavedWidths()` before mounting the layout and pass the result as `savedWidths`. For server-rendered apps, supply the same initial width values on the server and client. Read browser storage outside rendering. With chat panel layout enabled, panel remembers separate widths for inline and overlay modes. This example saves only the last resized panel width and uses it as the initial default when the layout mounts again. <Example Component={WidthPersistenceExample} appearance="source-only" isCodeSandboxDisabled /> ## Responsive behavior The layout uses the viewport width and the widths of the open areas to determine their sizes and whether they fit inline (side by side). Opening or closing an area also changes the space available. ### Breakpoint changes - Panel and chat panel: Default widths vary by viewport breakpoint. See the width tables in the [panel](#panel) and [chat panel](#chat-panel) sections. - Side nav: At viewport widths of 1,023px and below (`xxs`, `xs`, and `s` breakpoints), side nav automatically collapses. Users can open it as an overlay. ### When areas fit inline Side nav, panel, and chat panel will use either their default widths, or the width that the user has resized them to, given there is enough space. Main fills the remaining space. If the open areas don’t fit at their default or user-chosen widths, the layout makes areas narrower in this order: 1. Main 2. Panel 3. Chat panel 4. Side nav Each area reaches its minimum width before the next area becomes narrower. These narrower widths are temporary. The layout uses the user’s chosen width, or the default width, whenever there’s enough space. ### When areas do not fit inline If the open areas can’t fit side by side at their minimum widths, panel overlays main first. If main and chat panel still don’t fit, chat panel overlays the rest of the app, including panel. Panel and chat panel become overlays based on the minimum widths of the open areas, rather than fixed viewport breakpoints. Changing minimum widths changes when an overlay is needed. ### Overlay interactions - A side nav overlay can appear above a panel overlay. - When side nav and chat panel both use overlays, only one can be open at a time. Opening one closes the other. Closing one doesn’t reopen the other. ## Skip links Skip links let keyboard users jump directly to layout areas without tabbing through the preceding content. `Root` automatically provides skip-link navigation as the first tab stop in the layout, allowing keyboard users to move directly to a layout area. Layout components register their links automatically. ### Custom skip links Use `useSkipLink` to register custom skip links where appropriate. The `useSkipLink` hook accepts an optional third argument to manually specify the index of the skip link in the list. You can also optionally use the `useSkipLinkId` hook to retrieve a unique ID for use for your skip link. <Example Component={CustomSkipLinkExample} appearance="source-only" />