-
Notifications
You must be signed in to change notification settings - Fork 22
Page header component #16
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
Narinder788
wants to merge
19
commits into
Redback-Operations:main
Choose a base branch
from
Narinder788:page-header
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
19 commits
Select commit
Hold shift + click to select a range
a3a74f3
NEW: create page header component
Narinder788 4f641e3
NEW: create page header style component
Narinder788 312fdb3
NEW: create page header story component
Narinder788 878f5e8
NEW: create page header component test
Narinder788 d7832a6
ADD: add logo and menu items array as props
Narinder788 b228f89
UPDATE: integrate the styles of page header
Narinder788 ad3ca7e
FIX: fix all linting issues for page header component file
Narinder788 251f560
Merge branch 'main' into page-header
Narinder788 37c48b5
ADD: install react router dom for page header navlinks
Narinder788 960172c
Update TemplateName.test.tsx
Narinder788 416e4f7
FIX: import issues in page header test file
Narinder788 96ad4db
UPDATE: remove redundant code and comments
Narinder788 2ef0968
FIX: change the PageHeader colour according to theme
Narinder788 6eb8bcc
Merge branch 'main' into page-header
Narinder788 33f8e56
Merge branch 'main' into page-header
Narinder788 df74e50
Merge branch 'main' into page-header
Narinder788 48ab6fd
Merge branch 'main' into page-header
doubleedesign e815843
Merge branch 'main' into page-header
Narinder788 d75cf5d
Merge branch 'main' into page-header
ben-AI-cybersec 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,39 @@ | ||
import { PageHeader } from './PageHeader'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
const meta = { | ||
title: 'Components/PageHeader', | ||
component: PageHeader, | ||
} satisfies Meta<typeof PageHeader>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
const defaultProps = { | ||
|
||
}; | ||
|
||
const disableControls = { | ||
parameters: { | ||
controls: { | ||
disable: true | ||
}, | ||
actions: { | ||
disable: true | ||
}, | ||
} | ||
}; | ||
|
||
export const Demo: Story = { | ||
args: { | ||
...defaultProps | ||
}, | ||
tags: ['excludeFromSidebar'] | ||
}; | ||
|
||
export const Default: Story = { | ||
args: { | ||
...defaultProps | ||
}, | ||
...disableControls | ||
}; |
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,56 @@ | ||
import styled from 'styled-components'; | ||
import { ThemeElementSize, ThemeColor } from '../../types'; | ||
import { readableColor, shade } from 'polished'; | ||
|
||
type StyledPageHeaderProps = { | ||
$size: ThemeElementSize; | ||
$color: ThemeColor; | ||
}; | ||
|
||
export const StyledPageHeader = styled.header<StyledPageHeaderProps>` | ||
.header-container { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
width: 100%; | ||
max-width: ${props => (props.$size === 'sm' ? '600px' : '1200px')}; | ||
height: ${props => props.$size === 'sm' ? props.theme.spacing.xl : props.theme.spacing.xxl}; | ||
padding: ${props => props.$size === 'sm' ? props.theme.spacing.sm : props.theme.spacing.md}; | ||
margin: 0 auto; | ||
background-color: ${props => props.theme.colors[props.$color]}; | ||
color: ${props => readableColor(props.theme.colors[props.$color])}; | ||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
.logo-container { | ||
flex-shrink: 0; | ||
} | ||
|
||
.logo { | ||
height: 100%; | ||
max-height: ${props => props.$size === 'sm' ? props.theme.spacing.sm : props.theme.spacing.lg}; | ||
width: auto; | ||
} | ||
|
||
.menu-container { | ||
display: flex; | ||
gap: ${props => props.$size === 'sm' ? props.theme.spacing.sm : props.theme.spacing.md}; | ||
} | ||
|
||
.menu-item { | ||
all: unset; | ||
font-size: ${props => props.$size === 'sm' ? props.theme.fontSizes.sm : props.theme.fontSizes.md}; | ||
padding: ${props => props.$size === 'sm' ? props.theme.spacing.xs : props.theme.spacing.sm}; | ||
cursor: pointer; | ||
transition: color 150ms ease-in-out, background-color 150ms ease-in-out; | ||
text-decoration: none; | ||
} | ||
|
||
.menu-item:hover { | ||
background-color: ${props => shade(0.15, props.theme.colors.primary)}; | ||
} | ||
|
||
.menu-item.active { | ||
font-weight: ${props => props.theme.fontWeights.bold}; | ||
} | ||
`; |
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,13 @@ | ||
import { screen } from '@testing-library/react'; | ||
import { renderWithDeps } from '../../../jest.utils'; | ||
import { PageHeader } from './PageHeader'; | ||
|
||
describe('<PageHeader />', () => { | ||
it('renders', () => { | ||
renderWithDeps(<PageHeader logo={''} menuItems={[]} />); | ||
|
||
const pageHeader = screen.getByTestId('PageHeader'); | ||
|
||
expect(pageHeader).toBeInTheDocument(); | ||
}); | ||
}); |
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,48 @@ | ||
import { FC } from 'react'; | ||
import { NavLink } from 'react-router-dom'; | ||
import { StyledPageHeader } from './PageHeader.style'; | ||
import { ThemeElementSize, ThemeColor } from '../../types'; | ||
|
||
type MenuItem = { | ||
label: string; | ||
path: string; | ||
}; | ||
|
||
type PageHeaderProps = { | ||
logo: string; // URL or path to the logo image | ||
menuItems: MenuItem[]; // Array of menu items | ||
size?: ThemeElementSize; // Optional size prop, if needed | ||
color?: ThemeColor; | ||
}; | ||
|
||
export const PageHeader: FC<PageHeaderProps> = ({ | ||
logo = 'Path/to/logo.png', | ||
menuItems = [], | ||
size = 'lg', | ||
color = 'primary', | ||
}: PageHeaderProps) => { | ||
return ( | ||
<StyledPageHeader data-testid="PageHeader" $size={size} $color={color}> | ||
<div className="header-container"> | ||
<div className="logo-container"> | ||
<img src={logo} alt="Logo" className="logo" /> | ||
</div> | ||
<nav className="menu-container"> | ||
{menuItems.length > 0 ? ( | ||
menuItems.map((item, index) => ( | ||
<NavLink | ||
key={index} | ||
to={item.path} | ||
className={({ isActive }) => (isActive ? 'menu-item active' : 'menu-item')} | ||
> | ||
{item.label} | ||
</NavLink> | ||
)) | ||
) : ( | ||
<p>No menu items available</p> | ||
)} | ||
</nav> | ||
</div> | ||
</StyledPageHeader> | ||
); | ||
}; |
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
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.
Uh oh!
There was an error while loading. Please reload this page.