Skip to content
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

Page header component #16

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"lucide-react": "^0.378.0",
"polished": "^4.3.1",
"react-icons": "^5.2.1",
"react-router-dom": "^6.26.1",
"styled-components": "^6.1.8"
},
"peerDependencies": {
Expand Down
39 changes: 39 additions & 0 deletions src/components/PageHeader/PageHeader.stories.ts
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 = {

Narinder788 marked this conversation as resolved.
Show resolved Hide resolved
};

const disableControls = {
parameters: {
controls: {
disable: true
},
actions: {
disable: true
},
}
};

export const Demo: Story = {
args: {
...defaultProps
},
tags: ['excludeFromSidebar']
};

export const Default: Story = {
args: {
...defaultProps
},
...disableControls
};
51 changes: 51 additions & 0 deletions src/components/PageHeader/PageHeader.style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import styled from 'styled-components';

export const StyledPageHeader = styled.header<{ size: 'small' | 'large' }>`
.header-container {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
max-width: ${props => (props.size === 'small' ? '600px' : '1200px')};
height: ${props => (props.size === 'small' ? '60px' : '100px')};
padding: ${props => (props.size === 'small' ? '0.5rem' : '1rem')};
margin: 0 auto;
background-color: #333; /* Background color for the header */
Narinder788 marked this conversation as resolved.
Show resolved Hide resolved
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* Optional shadow for header */
}

.logo-container {
flex-shrink: 0;
}

.logo {
height: 100%;
max-height: ${props => (props.size === 'small' ? '50px' : '80px')}; /* Adjust logo size */
width: auto;
}

.menu-container {
display: flex;
gap: ${props => (props.size === 'small' ? '0.5rem' : '1rem')}; /* Space between menu items */
}

.menu-item {
all: unset;
color: white; /* Text color for menu items */
Narinder788 marked this conversation as resolved.
Show resolved Hide resolved
font-size: ${props => (props.size === 'small' ? '0.8rem' : '1rem')}; /* Font size based on size prop */
padding: ${props => (props.size === 'small' ? '0.25rem 0.5rem' : '0.5rem 1rem')}; /* Padding around menu items */
cursor: pointer;
transition: color 150ms ease-in-out, background-color 150ms ease-in-out; /* Transition for hover effects */
text-decoration: none; /* Remove underline from links */
}

.menu-item:hover {
color: #ddd; /* Hover text color */
background-color: rgba(255, 255, 255, 0.1); /* Hover background color */
}

.menu-item.active {
color: #ffd700; /* Active link color */
font-weight: bold; /* Bold active link */
}
`;
13 changes: 13 additions & 0 deletions src/components/PageHeader/PageHeader.test.tsx
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();
});
});
45 changes: 45 additions & 0 deletions src/components/PageHeader/PageHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { FC } from 'react';
import { NavLink } from 'react-router-dom';
import { StyledPageHeader } from './PageHeader.style';

type MenuItem = {
label: string;
path: string;
};

type PageHeaderProps = {
logo: string; // URL or path to the logo image
menuItems: MenuItem[]; // Array of menu items
size?: 'small' | 'large'; // Optional size prop, if needed
};

export const PageHeader: FC<PageHeaderProps> = ({
logo = 'Path/to/logo.png',
menuItems = [],
size = 'large',
}: PageHeaderProps) => {
return (
<StyledPageHeader data-testid="PageHeader" size={size}>
<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>
);
};
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './components/Label/Label';
export * from './components/LinkButton/LinkButton';
export * from './components/Table/Table';
export * from './components/TruncatedText/TruncatedText';
export * from './components/PageHeader/PageHeader';
4 changes: 2 additions & 2 deletions templates/TemplateName.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { screen } from '@testing-library/react';
import { renderWithDeps } from '../../../jest.utils.tsx';
import TemplateName from './TemplateName';
import { renderWithDeps } from '../jest.utils';
import { TemplateName } from './TemplateName';

describe('<TemplateName />', () => {
it('renders', () => {
Expand Down
Loading