-
Notifications
You must be signed in to change notification settings - Fork 392
feat(Page): Add PageHeader component #12632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rebeccaalpert
wants to merge
2
commits into
patternfly:main
Choose a base branch
from
rebeccaalpert:pageheader
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import styles from '@patternfly/react-styles/css/components/Page/page'; | ||
| import { css } from '@patternfly/react-styles'; | ||
|
|
||
| export interface PageHeaderProps extends React.HTMLProps<HTMLElement> { | ||
| /** Content rendered inside the page header. This should be custom header content, rather than the PatternFly Masthead. */ | ||
| children?: React.ReactNode; | ||
| /** Additional classes added to the page header */ | ||
| className?: string; | ||
| /** Sets the base component to render. Defaults to div */ | ||
| component?: keyof React.JSX.IntrinsicElements; | ||
| } | ||
|
|
||
| export const PageHeader: React.FunctionComponent<PageHeaderProps> = ({ | ||
| className, | ||
| children, | ||
| component = 'div', | ||
| ...props | ||
| }: PageHeaderProps) => { | ||
| const Component = component as any; | ||
|
|
||
| return ( | ||
| <Component {...props} className={css(styles.pageHeader, className)}> | ||
|
Check failure on line 22 in packages/react-core/src/components/Page/PageHeader.tsx
|
||
| {children} | ||
| </Component> | ||
| ); | ||
| }; | ||
|
|
||
| PageHeader.displayName = 'PageHeader'; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/react-core/src/components/Page/__tests__/PageHeader.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import styles from '@patternfly/react-styles/css/components/Page/page'; | ||
| import { PageHeader } from '../PageHeader'; | ||
|
|
||
| test('Renders children', () => { | ||
| render(<PageHeader>Header content</PageHeader>); | ||
| expect(screen.getByText('Header content')).toBeVisible(); | ||
| }); | ||
|
|
||
| test(`Renders with class ${styles.pageHeader} by default`, () => { | ||
| render(<PageHeader>Header content</PageHeader>); | ||
| expect(screen.getByText('Header content')).toHaveClass(styles.pageHeader); | ||
| }); | ||
|
|
||
| test('Renders as a div by default', () => { | ||
| render(<PageHeader>Header content</PageHeader>); | ||
| expect(screen.getByText('Header content').tagName).toBe('DIV'); | ||
| }); | ||
|
|
||
| test('Renders as a custom component when component is passed', () => { | ||
| render(<PageHeader component="header">Header content</PageHeader>); | ||
| expect(screen.getByText('Header content').tagName).toBe('HEADER'); | ||
| }); | ||
|
|
||
| test('Renders with custom classes when className is passed', () => { | ||
| render(<PageHeader className="custom-class">Header content</PageHeader>); | ||
| expect(screen.getByText('Header content')).toHaveClass('custom-class'); | ||
| }); | ||
|
|
||
| test('Renders with spread props', () => { | ||
| render(<PageHeader id="custom-id">Header content</PageHeader>); | ||
| expect(screen.getByText('Header content')).toHaveAttribute('id', 'custom-id'); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/react-core/src/components/Page/examples/PageHeaderContent.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { | ||
| Page, | ||
| PageHeader, | ||
| Masthead, | ||
| MastheadMain, | ||
| MastheadBrand, | ||
| MastheadLogo, | ||
| MastheadContent, | ||
| PageSection, | ||
| Toolbar, | ||
| ToolbarContent, | ||
| ToolbarItem | ||
| } from '@patternfly/react-core'; | ||
|
|
||
| export const PageHeaderContent: React.FunctionComponent = () => { | ||
| const headerToolbar = ( | ||
| <Toolbar id="page-header-content-toolbar"> | ||
| <ToolbarContent> | ||
| <ToolbarItem>header-tools</ToolbarItem> | ||
| </ToolbarContent> | ||
| </Toolbar> | ||
| ); | ||
|
|
||
| const pageHeader = ( | ||
| <PageHeader> | ||
| <Masthead> | ||
| <MastheadMain> | ||
| <MastheadBrand> | ||
| <MastheadLogo href="https://patternfly.org" target="_blank"> | ||
| Logo | ||
| </MastheadLogo> | ||
| </MastheadBrand> | ||
| </MastheadMain> | ||
| <MastheadContent>{headerToolbar}</MastheadContent> | ||
| </Masthead> | ||
| </PageHeader> | ||
| ); | ||
|
|
||
| return ( | ||
| <Page masthead={pageHeader}> | ||
| <PageSection aria-labelledby="section-1"> | ||
| <h2 id="section-1">Page header example section 1</h2> | ||
| </PageSection> | ||
| <PageSection variant="secondary" aria-labelledby="section-2"> | ||
| <h2 id="section-2">Page header example section 2 with secondary variant styling</h2> | ||
| </PageSection> | ||
| <PageSection aria-labelledby="section-3"> | ||
| <h2 id="section-3">Page header example section 3</h2> | ||
| </PageSection> | ||
| </Page> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: patternfly/patternfly-react
Length of output: 13285
🏁 Script executed:
Repository: patternfly/patternfly-react
Length of output: 26274
Forward the
refto the rendered element.PageHeaderPropsacceptsref, but React 18 does not pass refs to thisReact.FunctionComponent.PageHeadertherefore renders without attaching the ref, soref.currentremains unset. Wrap the component withReact.forwardRefand pass the ref toComponent. Add a test for the rendered element.🤖 Prompt for AI Agents