| 1 |
--- |
| 2 |
id: Page |
| 3 |
section: components |
| 4 |
cssPrefix: pf-v6-c-page |
| 5 |
propComponents: |
| 6 |
['Page', 'PageSidebar', 'PageSidebarBody', 'PageSection', 'PageGroup', 'PageBreadcrumb', 'PageToggleButton'] |
| 7 |
--- |
| 8 |
|
| 9 |
import { useState, useLayoutEffect, useRef } from 'react'; |
| 10 |
import RhUiMenuBarsIcon from '@patternfly/react-icons/dist/js/icons/rh-ui-menu-bars-icon'; |
| 11 |
import pageSectionWidthLimitMaxWidth from '@patternfly/react-tokens/dist/esm/c_page_section_m_limit_width_MaxWidth'; |
| 12 |
|
| 13 |
## Examples |
| 14 |
|
| 15 |
### Basic page components |
| 16 |
|
| 17 |
A page will typically contain the following components: |
| 18 |
|
| 19 |
- A `<Page>` with a `masthead` prop that often contains a [masthead](/components/masthead) component |
| 20 |
|
| 21 |
The `<MastheadMain>` component includes the smaller area that typically contains the `<MastheadToggle>` and a `<MastheadLogo>`. `<MastheadContent>` represents the main portion of the masthead, and will typically contain a `<Toolbar>` or other menu-like components, like a `<Dropdown>`. |
| 22 |
|
| 23 |
- Mastheads contain a `<MastheadMain>` component, which includes the `<MastheadToggle>`, a `<MastheadLogo>`, and the page's toolbar (via `<MastheadContent>`.) The `<MastheadToggle>` component contains a `<PageToggleButton>`, and the `<MastheadLogo>` component contains a `<MastheadBrand>`. |
| 24 |
- 1 or more `<PageSidebarBody>` components inside `<PageSidebar>` for vertical navigation or other sidebar content |
| 25 |
- 1 or more `<PageSection>` components |
| 26 |
|
| 27 |
### Vertical navigation |
| 28 |
|
| 29 |
To add a vertical sidebar to a `<Page>`, pass a `<PageSidebar>` component into the `sidebar` property. To render navigation in the sidebar, pass a `<PageSidebarBody>` component to `<PageSidebar>`. |
| 30 |
|
| 31 |
The `isSidebarOpen` property helps facilitate the opening and closing of the sidebar and should be 'true' when the sidebar is visible. |
| 32 |
|
| 33 |
```ts file="./PageVerticalNav.tsx" |
| 34 |
|
| 35 |
``` |
| 36 |
|
| 37 |
### Multiple sidebar body |
| 38 |
|
| 39 |
You can have multiple `<PageSidebarBody>` components inside the `<PageSidebar>` for more customization. You can modify the `<PageSidebarBody>` further by passing the following properties: |
| 40 |
|
| 41 |
- `usePageInsets` will modify the component's insets to match page insets |
| 42 |
- `isFilled={true}` will cause the component to grow to fill the available vertical space |
| 43 |
- `isFilled={false}` will cause the component to **not** grow to fill the available vertical space |
| 44 |
|
| 45 |
By default, the last `<PageSidebarBody>` will grow to fill the available vertical space. This can be changed by passing `isFilled={false}` as demonstrated in the following example. |
| 46 |
|
| 47 |
```ts file="./PageMultipleSidebarBody.tsx" |
| 48 |
|
| 49 |
``` |
| 50 |
|
| 51 |
### Horizontal navigation |
| 52 |
|
| 53 |
To add horizontal navigation to the top of a `<Page>`, add the navigation inside of a `<ToolbarItem>` in the `<Toolbar>` that is passed to the `<MastheadContent>` of the `<Masthead>`. |
| 54 |
|
| 55 |
```ts file="./PageHorizontalNav.tsx" |
| 56 |
|
| 57 |
``` |
| 58 |
|
| 59 |
### Uncontrolled navigation |
| 60 |
|
| 61 |
When the `isManagedSidebar` property is true, it manages the sidebar open/close state, removing the need to pass both `isSidebarOpen` into the `<PageSidebar>` and `onSidebarToggle` into the `<PageToggleButton>`. |
| 62 |
|
| 63 |
```ts file="./PageUncontrolledNav.tsx" |
| 64 |
|
| 65 |
``` |
| 66 |
|
| 67 |
### Filled page sections |
| 68 |
|
| 69 |
By default, page sections will not expand to fill in the available vertical space in a page. |
| 70 |
|
| 71 |
To change this default behavior, pass `isContentFilled` to the `<Page>` component and `isFilled={true}` to any child `<PageSection>` or `<PageGroup>` component that you want to fill the space. If multiple components are set to fill, then the available space will be split equally between them. |
| 72 |
|
| 73 |
```ts file="./PageWithOrWithoutFill.tsx" |
| 74 |
|
| 75 |
``` |
| 76 |
|
| 77 |
### Main section padding |
| 78 |
|
| 79 |
To adjust the padding of a `<PageSection>`, you can pass in different values to the `padding` property. These values should be aligned to a specific breakpoint: 'default', 'sm', 'md', 'lg', 'xl', and '2xl'. Each breakpoint passed into the property should be given a value of either ‘padding’ or ‘noPadding’. |
| 80 |
|
| 81 |
As the page's viewport width increases, breakpoints inherit the padding behavior of the previous breakpoint. For example, padding that is set on 'lg' also applies to 'xl' and '2xl'. |
| 82 |
|
| 83 |
To remove padding entirely, pass 'noPadding' to the `default` breakpoint. For example, the second section in this example passes in `padding={{ default: 'noPadding' }}`. Since no specific breakpoints are mentioned, every breakpoint will have 'noPadding'. |
| 84 |
|
| 85 |
To add padding at specific breakpoints, pass in "padding" at those breakpoints. For example, the third section in this example passes in `padding={{ default: 'noPadding', md: 'padding' }}`. At 'md', 'lg', 'xl', and '2xl' breakpoints, the default value will be overwritten, and padding will be added. |
| 86 |
|
| 87 |
To remove padding at specific breakpoints, pass in 'noPadding' at those breakpoints. For example, the fourth section in this example passes in `padding={{ md: 'noPadding' }}`, which means that 'md', 'lg' 'xl', and '2xl' breakpoints will have `noPadding`. |
| 88 |
|
| 89 |
```ts file="./PageMainSectionPadding.tsx" |
| 90 |
|
| 91 |
``` |
| 92 |
|
| 93 |
### Main section variations |
| 94 |
|
| 95 |
This example shows all types of page sections. |
| 96 |
|
| 97 |
```ts file="./PageMainSectionVariations.tsx" |
| 98 |
|
| 99 |
``` |
| 100 |
|
| 101 |
### Group section |
| 102 |
|
| 103 |
To group page content sections, add 1 or more `<PageGroup>` components to a `<Page>`. |
| 104 |
|
| 105 |
The following example adds a group containing `<PageBreadcrumb>` and `<PageSection>` components. |
| 106 |
|
| 107 |
To add additional components and information to a group, you may use the following properties: |
| 108 |
|
| 109 |
- To indicate that a breadcrumb should be in a group, use `isBreadcrumbGrouped`. |
| 110 |
- To indicate that horizontal sub navigation should be in a group, use `isHorizontalSubnavGrouped`. |
| 111 |
- To specify additional group content, use `additionalGroupedContent`. |
| 112 |
|
| 113 |
```ts file="./PageGroupSection.tsx" |
| 114 |
|
| 115 |
``` |
| 116 |
|
| 117 |
### Centered section |
| 118 |
|
| 119 |
By default, a page section spans the width of the page. To reduce the width of a section, use the `isWidthLimited` property. To center align width-limited page sections, use the `isCenterAligned` property. When the main content area of a page is wider than the value of a centered, width-limited page section's `--pf-v6-c-page--section--m-limit-width--MaxWidth` custom property, the section will automatically be centered. |
| 120 |
|
| 121 |
The content in this example is placed in a card to better illustrate how the section behaves when it is centered, but a card is not required to center a page section. |
| 122 |
|
| 123 |
```ts file="./PageCenteredSection.tsx" |
| 124 |
|
| 125 |
``` |
| 126 |
|
| 127 |
### Plain sections and groups |
| 128 |
|
| 129 |
To remove the default background color from a page section or group, use the `isPlain` property on `<PageSection>` or `<PageGroup>` components. |
| 130 |
|
| 131 |
```ts file="./PagePlainSections.tsx" |
| 132 |
|
| 133 |
``` |
| 134 |
|
| 135 |
### Dynamic sticky section |
| 136 |
|
| 137 |
A page section may be made sticky with separate control of its sticky positioning and stuck styling using the `stickyBase` and `isStickyStuck` properties. The `stickyBase` property accepts a value of `"top"` or `"bottom"` and applies the base sticky positioning in the given direction. The `isStickyStuck` property applies visual "stuck" styling such as a background, box shadow, and border, and should be toggled based on the scroll position of the scroll parent container. |
| 138 |
|
| 139 |
In this example, a scroll event listener on the scroll parent container toggles `isStickyStuck` when `scrollTop > 0`, so the stuck styling appears only when the content is scrolled. |
| 140 |
|
| 141 |
```ts file="./PageDynamicStickySection.tsx" |
| 142 |
|
| 143 |
``` |