generated from cloudoperators/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): adds HeaderContainer component (#607)
* feat(ui): adds HeaderContainer component * fix(ui): corrections afer review * Update .changeset/giant-news-flash.md Co-authored-by: Guoda <[email protected]> * Update packages/ui-components/src/components/AppShell/AppShell.component.tsx Co-authored-by: Guoda <[email protected]> * Update packages/ui-components/src/components/AppShell/AppShell.component.tsx Co-authored-by: Guoda <[email protected]> * fix(ui): fixes based on Guodas review commentary * fix(ui): code and logic improvements. Thankfully provided by Wowa --------- Co-authored-by: Guoda <[email protected]> Co-authored-by: Wowa Barsukov <[email protected]>
- Loading branch information
1 parent
ea90738
commit 385ebcf
Showing
8 changed files
with
164 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
"@cloudoperators/juno-ui-components": patch | ||
--- | ||
|
||
Created HeaderContainer component to make PageHeader and TopNavigation sticky when scrolling the content. AppShell is also affected by this change. |
This file contains 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 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
44 changes: 44 additions & 0 deletions
44
packages/ui-components/src/components/HeaderContainer/HeaderContainer.component.tsx
This file contains 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,44 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Juno contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from "react" | ||
|
||
const headerContainerStyles = ` | ||
jn-flex | ||
jn-flex-col | ||
jn-sticky | ||
jn-top-0 | ||
jn-z-50 | ||
jn-shadow-lg | ||
jn-bg-theme-global-bg | ||
` | ||
|
||
export const HeaderContainer: React.FC<HeaderContainerProps> = ({ | ||
fullWidth = false, | ||
className = "", | ||
children = null, | ||
...props | ||
}) => { | ||
return ( | ||
<div | ||
className={` | ||
juno-header-container | ||
${!fullWidth ? "jn-w-full 2xl:jn-container 2xl:jn-mx-auto" : ""} | ||
${headerContainerStyles} | ||
${className}`} | ||
{...props} | ||
> | ||
{children} | ||
</div> | ||
) | ||
} | ||
|
||
export interface HeaderContainerProps extends React.HTMLAttributes<HTMLDivElement> { | ||
/** Whether the page/view content will stretch over the full width of the viewport or not. Default is `false`. */ | ||
fullWidth?: boolean | ||
/** Add custom class name */ | ||
className?: string | ||
children?: React.ReactNode | ||
} |
38 changes: 38 additions & 0 deletions
38
packages/ui-components/src/components/HeaderContainer/HeaderContainer.stories.tsx
This file contains 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,38 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Juno contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from "react" | ||
|
||
import { HeaderContainer, HeaderContainerProps } from "./index" | ||
|
||
export default { | ||
title: "Internal/HeaderContainer", | ||
component: HeaderContainer, | ||
argTypes: { | ||
children: { | ||
control: false, | ||
table: { | ||
type: { summary: "ReactNode" }, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
const Template = (args: HeaderContainerProps) => <HeaderContainer {...args}>Header content</HeaderContainer> | ||
|
||
export const Main = { | ||
render: Template, | ||
|
||
parameters: { | ||
docs: { | ||
description: { | ||
story: | ||
"Only needed if you want to create the framework of your application manually. In most cases, it is better to use the AppShell component instead. The header container includes <PageHeader> and <TopNavigation>. When scrolling the page, the component sticks to the top and above the content.", | ||
}, | ||
}, | ||
}, | ||
|
||
args: {}, | ||
} |
34 changes: 34 additions & 0 deletions
34
packages/ui-components/src/components/HeaderContainer/HeaderContainer.test.tsx
This file contains 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,34 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Juno contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import * as React from "react" | ||
import { render, screen } from "@testing-library/react" | ||
import { HeaderContainer } from "./index" | ||
|
||
describe("HeaderContainer", () => { | ||
test("renders a header container", () => { | ||
render(<HeaderContainer data-testid="my-header-container" />) | ||
expect(screen.getByTestId("my-header-container")).toBeInTheDocument() | ||
expect(screen.getByTestId("my-header-container")).toHaveClass("juno-header-container") | ||
}) | ||
|
||
test("renders a header container which has sticky class", () => { | ||
render(<HeaderContainer data-testid="my-header-container" />) | ||
expect(screen.getByTestId("my-header-container")).toBeInTheDocument() | ||
expect(screen.getByTestId("my-header-container")).toHaveClass("jn-sticky") | ||
}) | ||
|
||
test("renders a custom className as passed", () => { | ||
render(<HeaderContainer className="my-class" data-testid="my-header-container" />) | ||
expect(screen.getByTestId("my-header-container")).toBeInTheDocument() | ||
expect(screen.getByTestId("my-header-container")).toHaveClass("my-class") | ||
}) | ||
|
||
test("renders all props", () => { | ||
render(<HeaderContainer data-lolol="some-prop" data-testid="my-header-container" />) | ||
expect(screen.getByTestId("my-header-container")).toBeInTheDocument() | ||
expect(screen.getByTestId("my-header-container")).toHaveAttribute("data-lolol", "some-prop") | ||
}) | ||
}) |
6 changes: 6 additions & 0 deletions
6
packages/ui-components/src/components/HeaderContainer/index.ts
This file contains 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,6 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Juno contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export { HeaderContainer, type HeaderContainerProps } from "./HeaderContainer.component" |
This file contains 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