AppShell
Responsive shell for your application with header, navbar, aside and footer
Import
Source
Docs
Package
Examples
This page includes only documentation. Since all associated AppShell
components have fixed
position, it is not possible to include demos on this page.
Usage
AppShell
is a layout component. It can be used to implement a common Header – Navbar – Footer – Aside
layout pattern. All AppShell
components have position: fixed
style – they are not scrolled with
the page.
Basic AppShell example with header and navbar. Navbar is hidden on mobile by default and toggled with the burger button.
AppShell components
AppShell
– root component, it is required to wrap all other components, used to configure layout propertiesAppShell.Header
– header section rendered at the top of the page, has fixed position, its height and collapsed state are controlled by the AppShellheader
propAppShell.Navbar
– navbar section rendered at the left side of the page, has fixed position, its width and collapsed state are controlled by the AppShellnavbar
propAppShell.Aside
– aside section rendered at the right side of the page, has fixed position, its width and collapsed state are controlled by the AppShellaside
propAppShell.Footer
– footer section rendered at the bottom of the page, has fixed position, its height and collapsed state are controlled by the AppShellfooter
propAppShell.Main
– main section rendered at the center of the page, has static position, all other sections are offset by its paddingAppShell.Section
– utility component that can be used to render group of content insideAppShell.Navbar
andAppShell.Aside
, can be used to create areas with custom scrollbars
Configuration
AppShell
component accepts, header
, footer
, navbar
and aside
props to configure
corresponding sections. It is required to set these props if you want to use corresponding
components. For example, if you want to use AppShell.Header
component, you need to set header
prop on the AppShell
component.
header
and footer
configuration objects are the same and have the following properties:
navbar
and aside
configuration objects are the same as well and have the following properties:
layout prop
layout
prop controls how AppShell.Header
/AppShell.Footer
and AppShell.Navbar
/AppShell.Aside
are positioned relative to each other. It accepts alt
and default
values:
alt
–AppShell.Navbar
/AppShell.Aside
height is equal to viewport height,AppShell.Header
/AppShell.Footer
width is equal to viewport width -AppShell.Navbar
andAppShell.Aside
width (example)default
–AppShell.Navbar
/AppShell.Aside
height is equal to viewport height -AppShell.Header
/AppShell.Footer
height,AppShell.Header
/AppShell.Footer
width is equal to viewport width (example)
Height configuration
height
property in header
and footer
configuration objects works the following way:
- If you pass a number, the value will be converted to rem and used as height at all viewport sizes.
- To change height based on viewport width, use object with breakpoints as keys and height as values. It works the same way as style props.
Examples:
Width configuration
width
property in navbar
and aside
configuration objects works the following way:
- If you pass a number, the value will be converted to rem and used as
width when the viewport is larger than
breakpoint
. - To change width based on viewport width, use object with breakpoints as keys and width as
values. It works the same way as style props.
Note that width is always 100% when the viewport is smaller than
breakpoint
.
Examples:
padding prop
padding
prop controls the padding of the AppShell.Main
component. It is important to use it
instead of setting padding on the AppShell.Main
directly because padding of the AppShell.Main
is
also used to offset AppShell.Header
, AppShell.Navbar
, AppShell.Aside
and AppShell.Footer
components.
padding
prop works the same way as style props and
accepts numbers, strings and objects with breakpoints as keys and padding as values. You can
reference theme.spacing
values or use any valid CSS values.
Header offset configuration
header
prop has offset
property which allows removing AppShell.Header
offset from AppShell.Main
component.
It is useful when you want to collapse AppShell.Header
based on the scroll position. For example, you can use
use-headroom hook to collapse header when user scrolls down and expand it when user scrolls up (example).
Collapsed navbar/aside configuration
navbar
and aside
props have collapsed
property. The property accepts an object
{ mobile: boolean; desktop: boolean }
which allows to configure collapsed state
depending on the viewport width.
Example with separate collapsed state for mobile and desktop:
withBorder prop
withBorder
prop is available on AppShell
and associated sections: AppShell.Header
, AppShell.Navbar
, AppShell.Aside
and AppShell.Footer
.
By default, withBorder
prop is true
– all components have a border on the side that is adjacent to the AppShell.Main
component.
For example, AppShell.Header
is located at the top of the page – it has a border on the bottom side,
AppShell.Navbar
is located on the left side of the page – it has a border on the right side.
To remove the border from all components, set withBorder={false}
on the AppShell
:
To remove the border from a specific component, set withBorder={false}
on that component:
zIndex prop
zIndex
prop is available on AppShell
and associated sections: AppShell.Header
, AppShell.Navbar
, AppShell.Aside
and AppShell.Footer
.
By default, all sections z-index
is 200
.
To change z-index
of all sections, set zIndex
prop on the AppShell
:
To change z-index
of a specific section, set zIndex
prop on that section:
Control transitions
Set transitionDuration
and transitionTimingFunction
props on the AppShell
to control transitions:
disabled prop
Set disabled
prop on the AppShell
to prevent all sections except AppShell.Main
from rendering.
It is useful when you want to hide the shell on some pages of your application.
AppShell.Section component
AppShell.Section
component can be used to create scrollable areas inside AppShell.Navbar
and AppShell.Aside
.
Root elements of AppShell.Navbar
and AppShell.Aside
are flexbox containers with flex-direction: column
,
AppShell.Section
with grow
attribute will take all available space and will be scrollable if component={ScrollArea}
is set.
In the following example:
- First and last sections (header and footer) will take as much space as they need to render
children
- Second section will take all available space and will be scrollable if content height exceeds available space
Semantic elements
AppShell.Header
root element isheader
AppShell.Navbar
root element isnav
AppShell.Aside
root element isaside
AppShell.Footer
root element isfooter
AppShell.Main
root element ismain
– !important: do not usemain
element insideAppShell.Main
component