The parts of the layout are described on their own pages: CdsHeader, CdsDrawer, CdsMain, CdsPage, CdsFooter and CdsToolbar. You can assemble the frame with the mouse and copy the ready code in the layout builder.
Anatomy
CdsLayout is the root element of the application. The parts of the layout go inside it: the header, the drawers, CdsMain with CdsPage and the footer. The order in the template does not matter — the layout calculates the positions itself.
Variations
The view scheme
The view prop describes the layout with three strings: top, middle, bottom. The letters are the parts of the layout: h — the header, f — the footer, l and r — the left and the right drawer, p — the page. The corner letters of the top and the bottom string settle the argument over the corners: hhh gives the whole width to the header, lhh gives the top left corner to the drawer.
An uppercase letter gives the part position: fixed: HHH lpr fff nails the header to the window, hhh LPR fff nails both drawers. The default value is hhh lpr fff.
Container mode
By default the layout takes the whole page and controls its scrolling. The container prop locks it inside its parent: the layout gets its own scroll area, and the header and the footer keep their places inside it. This is a handy way to show the application in a preview, to embed it into somebody else's page or to build a working area of a fixed height.
Events
The layout watches its scroll area and shares what it sees: @scroll gives the position, the direction and the turning point, @resize gives the new sizes, @scroll-height gives the height of the content. The floating header and footer are built on these events, but you can use them for your own logic too — to load the next page of a list, for example.
Guidelines
Scenarios
Application shell
The typical set: a header with CdsToolbar, permanent navigation in CdsDrawer, CdsMain → CdsPage with the content and a footer. A button in the header toggles minified — the drawer shrinks to icons and gives the width to the content, and on hover it expands back.
A header that hides on scroll
On long lists the space is worth more than the navigation. The reveal prop of the header and the footer hides them when scrolling down and brings them back when scrolling up; reveal-offset sets the zone near the top of the list where the header stays in place.
Working area with filters
The lhh lpr fff scheme gives the top left corner to the navigation — it starts from the very top, and the header takes the remaining width. The right drawer with temporary slides over the content on a button click and closes on a click on the overlay, so it takes no place in the layout.
API
Props
| Name | Type | Default | Description |
|---|---|---|---|
container | boolean | undefined | false | Container mode: the layout scrolls inside itself instead of scrolling the page. |
theme | string | undefined | — | Component theme |
view | string | undefined | 'hhh lpr fff' | Layout scheme of three strings: top (header), middle (left-page-right), bottom (footer). For example 'hhh lpr fff'. |
Events
| Name | Type | Description |
|---|---|---|
resize | [contentRect: Pick<DOMRectReadOnly, "width" | "height">] | The size of the layout area has changed. |
scroll | [info: ScrollObserver] | The layout area has been scrolled. |
scrollHeight | [height: number] | The height of the scrollable content has changed. |
Slots
| Name | Type | Description |
|---|---|---|
default | any | Content of the layout: CdsHeader, CdsDrawer, CdsMain, CdsFooter. |
Exposed
| Name | Type | Description |
|---|---|---|
animate | () => void | Turns on the rebuild animation of the layout for the duration of the next size update. |
containerHeight | number | Height of the content area without the header and the footer, in pixels. |
footer | LayoutPart | Size and offset of the layout footer. |
header | LayoutPart | Size and offset of the layout header. |
height | number | Full height of the layout in pixels. |
instances | Record<string, unknown> | Components registered in the layout by their identifiers — the header, the footer, the drawers, the content. |
isContainer | boolean | Whether the layout is limited in width by a container (container) instead of stretching across the whole screen. |
left | LayoutPart | Size and offset of the left drawer of the layout. |
right | LayoutPart | Size and offset of the right drawer of the layout. |
rootRef | HTMLElement | undefined | Ref to the root DOM element of the layout. |
rows | { top: string[]; middle: string[]; bottom: string[]; } | Identifiers of the components distributed across the rows of the layout: top, middle and bottom. |
scroll | ScrollObserver | Scroll state of the layout: position, direction and delta. |
scrollbarWidth | number | Width of the system scrollbar in pixels — taken into account when the scroll is locked. |
totalWidth | number | Full width of the layout in pixels. |
update | (part: "left" | "right" | "footer" | "header", prop: keyof LayoutPart, value: number | boolean) => void | Updates the size, the offset or the space reservation for a part of the layout. |