Complete Phase 1: React modernization foundation
- Initialize Vite + React 19 + TypeScript project - Configure Tailwind CSS v4 with design tokens - Add Button component (13 tests) - Add Card component (11 tests) - Add Container component (9 tests) - Add Header component with glassmorphism (17 tests) - Add Footer component (13 tests) - Add MobileNav with slide-out menu (19 tests) - Update App.tsx with layout preview 82 tests passing Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
104
src/App.tsx
Normal file
104
src/App.tsx
Normal file
@ -0,0 +1,104 @@
|
||||
import { Header, Footer, Container } from './components/layout'
|
||||
import { Button } from './components/ui/Button'
|
||||
import { Card } from './components/ui/Card'
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className="min-h-screen flex flex-col">
|
||||
<Header />
|
||||
|
||||
{/* Main content with top padding for fixed header */}
|
||||
<main className="flex-1 pt-20">
|
||||
{/* Hero Section Placeholder */}
|
||||
<section id="home" className="py-20 bg-gradient-to-br from-bg-primary to-bg-secondary">
|
||||
<Container>
|
||||
<div className="text-center max-w-3xl mx-auto">
|
||||
<h1 className="text-5xl md:text-6xl font-bold text-text-primary mb-6">
|
||||
Building <span className="text-primary">Digital</span> Experiences
|
||||
</h1>
|
||||
<p className="text-xl text-text-secondary mb-8">
|
||||
Custom software solutions that transform your business ideas into reality.
|
||||
</p>
|
||||
<div className="flex flex-wrap justify-center gap-4">
|
||||
<Button variant="primary" size="lg">
|
||||
Get Started
|
||||
</Button>
|
||||
<Button variant="secondary" size="lg">
|
||||
Learn More
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Container>
|
||||
</section>
|
||||
|
||||
{/* Services Section Placeholder */}
|
||||
<section id="services" className="py-20">
|
||||
<Container>
|
||||
<h2 className="text-3xl md:text-4xl font-bold text-center text-text-primary mb-12">
|
||||
Our Services
|
||||
</h2>
|
||||
<div className="grid md:grid-cols-3 gap-6">
|
||||
<Card variant="default" padding="lg">
|
||||
<h3 className="text-xl font-semibold text-text-primary mb-3">
|
||||
Web Development
|
||||
</h3>
|
||||
<p className="text-text-secondary">
|
||||
Modern, responsive websites built with the latest technologies.
|
||||
</p>
|
||||
</Card>
|
||||
<Card variant="elevated" padding="lg">
|
||||
<h3 className="text-xl font-semibold text-text-primary mb-3">
|
||||
Mobile Apps
|
||||
</h3>
|
||||
<p className="text-text-secondary">
|
||||
Native and cross-platform mobile applications.
|
||||
</p>
|
||||
</Card>
|
||||
<Card variant="outlined" padding="lg">
|
||||
<h3 className="text-xl font-semibold text-text-primary mb-3">
|
||||
Cloud Solutions
|
||||
</h3>
|
||||
<p className="text-text-secondary">
|
||||
Scalable infrastructure and cloud architecture.
|
||||
</p>
|
||||
</Card>
|
||||
</div>
|
||||
</Container>
|
||||
</section>
|
||||
|
||||
{/* Process Section Placeholder */}
|
||||
<section id="process" className="py-20 bg-bg-secondary">
|
||||
<Container>
|
||||
<h2 className="text-3xl md:text-4xl font-bold text-center text-text-primary mb-12">
|
||||
Our Process
|
||||
</h2>
|
||||
<p className="text-center text-text-secondary max-w-2xl mx-auto">
|
||||
Phase 2 will add the animated workflow carousel here.
|
||||
</p>
|
||||
</Container>
|
||||
</section>
|
||||
|
||||
{/* Contact Section Placeholder */}
|
||||
<section id="contact" className="py-20">
|
||||
<Container>
|
||||
<h2 className="text-3xl md:text-4xl font-bold text-center text-text-primary mb-12">
|
||||
Get In Touch
|
||||
</h2>
|
||||
<div className="max-w-md mx-auto text-center">
|
||||
<p className="text-text-secondary mb-8">
|
||||
Ready to start your project? Contact us today.
|
||||
</p>
|
||||
<Button variant="primary" size="lg">
|
||||
Contact Us
|
||||
</Button>
|
||||
</div>
|
||||
</Container>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<Footer />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
1
src/assets/react.svg
Normal file
1
src/assets/react.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
80
src/components/layout/Container.test.tsx
Normal file
80
src/components/layout/Container.test.tsx
Normal file
@ -0,0 +1,80 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { Container } from './Container'
|
||||
|
||||
describe('Container', () => {
|
||||
it('renders children correctly', () => {
|
||||
render(<Container>Test Content</Container>)
|
||||
expect(screen.getByText('Test Content')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('applies max-width class', () => {
|
||||
render(<Container data-testid="container">Content</Container>)
|
||||
const container = screen.getByTestId('container')
|
||||
expect(container).toHaveClass('max-w-7xl')
|
||||
})
|
||||
|
||||
it('applies padding classes', () => {
|
||||
render(<Container data-testid="container">Content</Container>)
|
||||
const container = screen.getByTestId('container')
|
||||
expect(container).toHaveClass('px-4')
|
||||
expect(container).toHaveClass('md:px-8')
|
||||
})
|
||||
|
||||
it('applies auto margin for centering', () => {
|
||||
render(<Container data-testid="container">Content</Container>)
|
||||
const container = screen.getByTestId('container')
|
||||
expect(container).toHaveClass('mx-auto')
|
||||
})
|
||||
|
||||
it('renders as div by default', () => {
|
||||
render(<Container data-testid="container">Content</Container>)
|
||||
const container = screen.getByTestId('container')
|
||||
expect(container.tagName).toBe('DIV')
|
||||
})
|
||||
|
||||
it('renders as section when as="section"', () => {
|
||||
render(
|
||||
<Container as="section" data-testid="container">
|
||||
Content
|
||||
</Container>
|
||||
)
|
||||
const container = screen.getByTestId('container')
|
||||
expect(container.tagName).toBe('SECTION')
|
||||
})
|
||||
|
||||
it('renders as article when as="article"', () => {
|
||||
render(
|
||||
<Container as="article" data-testid="container">
|
||||
Content
|
||||
</Container>
|
||||
)
|
||||
const container = screen.getByTestId('container')
|
||||
expect(container.tagName).toBe('ARTICLE')
|
||||
})
|
||||
|
||||
it('renders as main when as="main"', () => {
|
||||
render(
|
||||
<Container as="main" data-testid="container">
|
||||
Content
|
||||
</Container>
|
||||
)
|
||||
const container = screen.getByTestId('container')
|
||||
expect(container.tagName).toBe('MAIN')
|
||||
})
|
||||
|
||||
it('merges custom className', () => {
|
||||
render(
|
||||
<Container className="bg-blue-500 mt-4" data-testid="container">
|
||||
Content
|
||||
</Container>
|
||||
)
|
||||
const container = screen.getByTestId('container')
|
||||
expect(container).toHaveClass('max-w-7xl')
|
||||
expect(container).toHaveClass('mx-auto')
|
||||
expect(container).toHaveClass('px-4')
|
||||
expect(container).toHaveClass('md:px-8')
|
||||
expect(container).toHaveClass('bg-blue-500')
|
||||
expect(container).toHaveClass('mt-4')
|
||||
})
|
||||
})
|
||||
28
src/components/layout/Container.tsx
Normal file
28
src/components/layout/Container.tsx
Normal file
@ -0,0 +1,28 @@
|
||||
import { cn } from '../../lib/utils'
|
||||
|
||||
interface ContainerProps {
|
||||
/** Container content */
|
||||
children: React.ReactNode
|
||||
/** Additional CSS classes */
|
||||
className?: string
|
||||
/** HTML element to render as */
|
||||
as?: 'div' | 'section' | 'article' | 'main'
|
||||
/** Test ID for testing */
|
||||
'data-testid'?: string
|
||||
}
|
||||
|
||||
export function Container({
|
||||
children,
|
||||
className,
|
||||
as: Component = 'div',
|
||||
'data-testid': testId,
|
||||
}: ContainerProps) {
|
||||
return (
|
||||
<Component
|
||||
className={cn('max-w-7xl mx-auto px-4 md:px-8', className)}
|
||||
data-testid={testId}
|
||||
>
|
||||
{children}
|
||||
</Component>
|
||||
)
|
||||
}
|
||||
121
src/components/layout/Footer.test.tsx
Normal file
121
src/components/layout/Footer.test.tsx
Normal file
@ -0,0 +1,121 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||
import { Footer } from './Footer'
|
||||
|
||||
describe('Footer', () => {
|
||||
// Mock the current year for consistent testing
|
||||
const mockYear = 2026
|
||||
let originalDate: DateConstructor
|
||||
|
||||
beforeEach(() => {
|
||||
originalDate = global.Date
|
||||
vi.useFakeTimers()
|
||||
vi.setSystemTime(new Date(mockYear, 0, 1))
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers()
|
||||
global.Date = originalDate
|
||||
})
|
||||
|
||||
describe('Logo', () => {
|
||||
it('renders logo correctly', () => {
|
||||
render(<Footer />)
|
||||
expect(screen.getByText('Maverick')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('logo has correct styling', () => {
|
||||
render(<Footer />)
|
||||
const logo = screen.getByText('Maverick').closest('a')
|
||||
expect(logo).toHaveClass('text-white')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Navigation Links', () => {
|
||||
it('renders default navigation links', () => {
|
||||
render(<Footer />)
|
||||
|
||||
expect(screen.getByRole('link', { name: 'Home' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('link', { name: 'Services' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('link', { name: 'Contact' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders custom links when provided', () => {
|
||||
const customLinks = [
|
||||
{ label: 'About', href: '#about' },
|
||||
{ label: 'Portfolio', href: '#portfolio' },
|
||||
]
|
||||
|
||||
render(<Footer links={customLinks} />)
|
||||
|
||||
expect(screen.getByRole('link', { name: 'About' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('link', { name: 'Portfolio' })).toBeInTheDocument()
|
||||
expect(screen.queryByRole('link', { name: 'Home' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('links have correct href attributes', () => {
|
||||
render(<Footer />)
|
||||
|
||||
expect(screen.getByRole('link', { name: 'Home' })).toHaveAttribute('href', '#home')
|
||||
expect(screen.getByRole('link', { name: 'Services' })).toHaveAttribute('href', '#services')
|
||||
expect(screen.getByRole('link', { name: 'Contact' })).toHaveAttribute('href', '#contact')
|
||||
})
|
||||
|
||||
it('links are accessible with proper roles', () => {
|
||||
render(<Footer />)
|
||||
|
||||
const nav = screen.getByRole('navigation', { name: /footer/i })
|
||||
expect(nav).toBeInTheDocument()
|
||||
|
||||
const links = screen.getAllByRole('link')
|
||||
// Logo link + 3 nav links
|
||||
expect(links.length).toBeGreaterThanOrEqual(3)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Copyright', () => {
|
||||
it('renders copyright with current year', () => {
|
||||
render(<Footer />)
|
||||
expect(screen.getByText(new RegExp(`${mockYear}`))).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('includes company name in copyright', () => {
|
||||
render(<Footer />)
|
||||
expect(screen.getByText(/Maverick Applications/i)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('includes "All rights reserved" text', () => {
|
||||
render(<Footer />)
|
||||
expect(screen.getByText(/All rights reserved/i)).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Styling', () => {
|
||||
it('applies dark background', () => {
|
||||
render(<Footer />)
|
||||
const footer = screen.getByRole('contentinfo')
|
||||
expect(footer).toHaveClass('bg-text-primary')
|
||||
})
|
||||
|
||||
it('has proper footer role', () => {
|
||||
render(<Footer />)
|
||||
expect(screen.getByRole('contentinfo')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('applies white text color', () => {
|
||||
render(<Footer />)
|
||||
const footer = screen.getByRole('contentinfo')
|
||||
expect(footer).toHaveClass('text-white')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Responsive Layout', () => {
|
||||
it('uses flex container with wrap', () => {
|
||||
render(<Footer />)
|
||||
// The inner container should have flex and flex-wrap classes
|
||||
const footer = screen.getByRole('contentinfo')
|
||||
const innerContainer = footer.querySelector('[class*="flex"]')
|
||||
expect(innerContainer).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
63
src/components/layout/Footer.tsx
Normal file
63
src/components/layout/Footer.tsx
Normal file
@ -0,0 +1,63 @@
|
||||
import { Diamond } from 'lucide-react'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { Container } from './Container'
|
||||
|
||||
interface FooterLink {
|
||||
label: string
|
||||
href: string
|
||||
}
|
||||
|
||||
interface FooterProps {
|
||||
links?: FooterLink[]
|
||||
}
|
||||
|
||||
const defaultLinks: FooterLink[] = [
|
||||
{ label: 'Home', href: '#home' },
|
||||
{ label: 'Services', href: '#services' },
|
||||
{ label: 'Contact', href: '#contact' },
|
||||
]
|
||||
|
||||
export function Footer({ links = defaultLinks }: FooterProps) {
|
||||
const currentYear = new Date().getFullYear()
|
||||
|
||||
return (
|
||||
<footer className="bg-text-primary text-white py-8">
|
||||
<Container>
|
||||
<div className="flex flex-wrap items-center justify-between gap-4">
|
||||
{/* Logo */}
|
||||
<a
|
||||
href="#home"
|
||||
className="flex items-center gap-2 text-xl font-bold text-white"
|
||||
>
|
||||
<Diamond className="h-5 w-5 text-accent" />
|
||||
<span>Maverick</span>
|
||||
</a>
|
||||
|
||||
{/* Navigation */}
|
||||
<nav aria-label="Footer navigation">
|
||||
<ul className="flex flex-wrap items-center gap-6">
|
||||
{links.map((link) => (
|
||||
<li key={link.href}>
|
||||
<a
|
||||
href={link.href}
|
||||
className={cn(
|
||||
'text-white/80 transition-colors duration-200',
|
||||
'hover:text-white'
|
||||
)}
|
||||
>
|
||||
{link.label}
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
{/* Copyright */}
|
||||
<p className="w-full text-center text-sm text-white/60 mt-4 md:w-auto md:mt-0">
|
||||
© {currentYear} Maverick Applications. All rights reserved.
|
||||
</p>
|
||||
</div>
|
||||
</Container>
|
||||
</footer>
|
||||
)
|
||||
}
|
||||
200
src/components/layout/Header.test.tsx
Normal file
200
src/components/layout/Header.test.tsx
Normal file
@ -0,0 +1,200 @@
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||
import { Header } from './Header'
|
||||
|
||||
const mockScrollTo = vi.fn()
|
||||
|
||||
describe('Header', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
// Reset scroll position
|
||||
Object.defineProperty(window, 'scrollY', { value: 0, writable: true })
|
||||
// Mock scrollIntoView
|
||||
Element.prototype.scrollIntoView = mockScrollTo
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
document.body.style.overflow = ''
|
||||
})
|
||||
|
||||
describe('Logo', () => {
|
||||
it('renders logo correctly', () => {
|
||||
render(<Header />)
|
||||
expect(screen.getByText('Maverick')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('logo links to home', () => {
|
||||
render(<Header />)
|
||||
const logo = screen.getByRole('link', { name: /maverick/i })
|
||||
expect(logo).toHaveAttribute('href', '#home')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Navigation Links', () => {
|
||||
it('renders default navigation links', () => {
|
||||
render(<Header />)
|
||||
|
||||
expect(screen.getByRole('link', { name: 'Home' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('link', { name: 'Services' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('link', { name: 'Process' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('link', { name: 'Contact' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders custom navigation links when provided', () => {
|
||||
const customLinks = [
|
||||
{ label: 'About', href: '#about' },
|
||||
{ label: 'Portfolio', href: '#portfolio' },
|
||||
]
|
||||
|
||||
render(<Header links={customLinks} />)
|
||||
|
||||
expect(screen.getByRole('link', { name: 'About' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('link', { name: 'Portfolio' })).toBeInTheDocument()
|
||||
expect(screen.queryByRole('link', { name: 'Home' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('links have correct href attributes', () => {
|
||||
render(<Header />)
|
||||
|
||||
expect(screen.getByRole('link', { name: 'Home' })).toHaveAttribute('href', '#home')
|
||||
expect(screen.getByRole('link', { name: 'Services' })).toHaveAttribute('href', '#services')
|
||||
expect(screen.getByRole('link', { name: 'Process' })).toHaveAttribute('href', '#process')
|
||||
expect(screen.getByRole('link', { name: 'Contact' })).toHaveAttribute('href', '#contact')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Styling', () => {
|
||||
it('applies fixed positioning', () => {
|
||||
render(<Header />)
|
||||
const header = screen.getByRole('banner')
|
||||
expect(header).toHaveClass('fixed')
|
||||
expect(header).toHaveClass('top-0')
|
||||
expect(header).toHaveClass('left-0')
|
||||
expect(header).toHaveClass('right-0')
|
||||
})
|
||||
|
||||
it('applies glassmorphism styles', () => {
|
||||
render(<Header />)
|
||||
const header = screen.getByRole('banner')
|
||||
expect(header).toHaveClass('backdrop-blur-md')
|
||||
})
|
||||
|
||||
it('has appropriate z-index', () => {
|
||||
render(<Header />)
|
||||
const header = screen.getByRole('banner')
|
||||
expect(header).toHaveClass('z-50')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Scroll Behavior', () => {
|
||||
it('applies scrolled styles after 100px scroll', () => {
|
||||
render(<Header />)
|
||||
const header = screen.getByRole('banner')
|
||||
|
||||
// Initially not scrolled
|
||||
expect(header).not.toHaveClass('shadow-md')
|
||||
|
||||
// Simulate scroll past 100px
|
||||
Object.defineProperty(window, 'scrollY', { value: 150, writable: true })
|
||||
fireEvent.scroll(window)
|
||||
|
||||
expect(header).toHaveClass('shadow-md')
|
||||
})
|
||||
|
||||
it('removes scrolled styles when scrolled back up', () => {
|
||||
render(<Header />)
|
||||
const header = screen.getByRole('banner')
|
||||
|
||||
// Scroll down
|
||||
Object.defineProperty(window, 'scrollY', { value: 150, writable: true })
|
||||
fireEvent.scroll(window)
|
||||
expect(header).toHaveClass('shadow-md')
|
||||
|
||||
// Scroll back up
|
||||
Object.defineProperty(window, 'scrollY', { value: 50, writable: true })
|
||||
fireEvent.scroll(window)
|
||||
expect(header).not.toHaveClass('shadow-md')
|
||||
})
|
||||
|
||||
it('handles smooth scroll on link click', async () => {
|
||||
const user = userEvent.setup()
|
||||
|
||||
// Create a target element
|
||||
const targetElement = document.createElement('div')
|
||||
targetElement.id = 'services'
|
||||
document.body.appendChild(targetElement)
|
||||
|
||||
render(<Header />)
|
||||
|
||||
await user.click(screen.getByRole('link', { name: 'Services' }))
|
||||
|
||||
expect(mockScrollTo).toHaveBeenCalledWith({
|
||||
behavior: 'smooth',
|
||||
block: 'start',
|
||||
})
|
||||
|
||||
// Cleanup
|
||||
document.body.removeChild(targetElement)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Mobile Navigation', () => {
|
||||
it('renders mobile menu button', () => {
|
||||
render(<Header />)
|
||||
expect(screen.getByRole('button', { name: /toggle menu/i })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('opens mobile menu when hamburger is clicked', async () => {
|
||||
const user = userEvent.setup()
|
||||
|
||||
render(<Header />)
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /toggle menu/i }))
|
||||
|
||||
// Mobile nav should be visible
|
||||
expect(screen.getByRole('navigation', { name: /mobile/i })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('closes mobile menu when close button is clicked', async () => {
|
||||
const user = userEvent.setup()
|
||||
|
||||
render(<Header />)
|
||||
|
||||
// Open menu
|
||||
await user.click(screen.getByRole('button', { name: /toggle menu/i }))
|
||||
expect(screen.getByRole('navigation', { name: /mobile/i })).toBeInTheDocument()
|
||||
|
||||
// Close menu
|
||||
await user.click(screen.getByRole('button', { name: /close menu/i }))
|
||||
expect(screen.queryByRole('navigation', { name: /mobile/i })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('mobile menu has same links as desktop nav', async () => {
|
||||
const user = userEvent.setup()
|
||||
|
||||
render(<Header />)
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /toggle menu/i }))
|
||||
|
||||
const mobileNav = screen.getByRole('navigation', { name: /mobile/i })
|
||||
|
||||
expect(mobileNav.querySelector('a[href="#home"]')).toBeInTheDocument()
|
||||
expect(mobileNav.querySelector('a[href="#services"]')).toBeInTheDocument()
|
||||
expect(mobileNav.querySelector('a[href="#process"]')).toBeInTheDocument()
|
||||
expect(mobileNav.querySelector('a[href="#contact"]')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Accessibility', () => {
|
||||
it('has a proper banner role', () => {
|
||||
render(<Header />)
|
||||
expect(screen.getByRole('banner')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('desktop navigation has navigation role', () => {
|
||||
render(<Header />)
|
||||
expect(screen.getByRole('navigation', { name: /main/i })).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
112
src/components/layout/Header.tsx
Normal file
112
src/components/layout/Header.tsx
Normal file
@ -0,0 +1,112 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { Diamond } from 'lucide-react'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { MobileNav } from './MobileNav'
|
||||
import { Container } from './Container'
|
||||
|
||||
interface NavLink {
|
||||
label: string
|
||||
href: string
|
||||
}
|
||||
|
||||
interface HeaderProps {
|
||||
links?: NavLink[]
|
||||
}
|
||||
|
||||
const defaultLinks: NavLink[] = [
|
||||
{ label: 'Home', href: '#home' },
|
||||
{ label: 'Services', href: '#services' },
|
||||
{ label: 'Process', href: '#process' },
|
||||
{ label: 'Contact', href: '#contact' },
|
||||
]
|
||||
|
||||
export function Header({ links = defaultLinks }: HeaderProps) {
|
||||
const [isScrolled, setIsScrolled] = useState(false)
|
||||
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false)
|
||||
|
||||
// Handle scroll detection
|
||||
useEffect(() => {
|
||||
const handleScroll = () => {
|
||||
setIsScrolled(window.scrollY > 100)
|
||||
}
|
||||
|
||||
window.addEventListener('scroll', handleScroll)
|
||||
return () => window.removeEventListener('scroll', handleScroll)
|
||||
}, [])
|
||||
|
||||
// Handle smooth scroll to section
|
||||
const handleLinkClick = (e: React.MouseEvent<HTMLAnchorElement>, href: string) => {
|
||||
e.preventDefault()
|
||||
const targetId = href.replace('#', '')
|
||||
const targetElement = document.getElementById(targetId)
|
||||
|
||||
if (targetElement) {
|
||||
targetElement.scrollIntoView({
|
||||
behavior: 'smooth',
|
||||
block: 'start',
|
||||
})
|
||||
}
|
||||
|
||||
// Close mobile menu if open
|
||||
setIsMobileMenuOpen(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<header
|
||||
className={cn(
|
||||
'fixed top-0 left-0 right-0 z-50',
|
||||
'bg-white/95 backdrop-blur-md',
|
||||
'border-b border-border',
|
||||
'transition-all duration-300',
|
||||
isScrolled && 'shadow-md bg-white'
|
||||
)}
|
||||
>
|
||||
<Container>
|
||||
<div className="flex items-center justify-between py-4">
|
||||
{/* Logo */}
|
||||
<a
|
||||
href="#home"
|
||||
onClick={(e) => handleLinkClick(e, '#home')}
|
||||
className="flex items-center gap-2 text-xl font-bold text-primary"
|
||||
>
|
||||
<Diamond className="h-5 w-5 text-accent" />
|
||||
<span>Maverick</span>
|
||||
</a>
|
||||
|
||||
{/* Desktop Navigation */}
|
||||
<nav aria-label="Main navigation" className="hidden md:block">
|
||||
<ul className="flex items-center gap-8">
|
||||
{links.map((link) => (
|
||||
<li key={link.href}>
|
||||
<a
|
||||
href={link.href}
|
||||
onClick={(e) => handleLinkClick(e, link.href)}
|
||||
className={cn(
|
||||
'relative font-medium text-text-secondary',
|
||||
'transition-colors duration-200 hover:text-primary',
|
||||
'after:absolute after:bottom-0 after:left-0 after:h-0.5',
|
||||
'after:w-0 after:bg-primary after:transition-all after:duration-200',
|
||||
'hover:after:w-full'
|
||||
)}
|
||||
>
|
||||
{link.label}
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
{/* Mobile Navigation */}
|
||||
<div className="md:hidden">
|
||||
<MobileNav
|
||||
links={links}
|
||||
isOpen={isMobileMenuOpen}
|
||||
onClose={() => setIsMobileMenuOpen(false)}
|
||||
onToggle={() => setIsMobileMenuOpen((prev) => !prev)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Container>
|
||||
</header>
|
||||
)
|
||||
}
|
||||
188
src/components/layout/MobileNav.test.tsx
Normal file
188
src/components/layout/MobileNav.test.tsx
Normal file
@ -0,0 +1,188 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||
import { MobileNav, HamburgerButton } from './MobileNav'
|
||||
|
||||
const mockLinks = [
|
||||
{ label: 'Home', href: '#home' },
|
||||
{ label: 'Services', href: '#services' },
|
||||
{ label: 'Contact', href: '#contact' },
|
||||
]
|
||||
|
||||
describe('HamburgerButton', () => {
|
||||
it('renders three lines when closed', () => {
|
||||
render(<HamburgerButton isOpen={false} onClick={vi.fn()} />)
|
||||
const button = screen.getByRole('button', { name: /toggle menu/i })
|
||||
const lines = button.querySelectorAll('span')
|
||||
expect(lines).toHaveLength(3)
|
||||
})
|
||||
|
||||
it('renders as X when open', () => {
|
||||
render(<HamburgerButton isOpen={true} onClick={vi.fn()} />)
|
||||
const button = screen.getByRole('button', { name: /toggle menu/i })
|
||||
// When open, lines should have rotation transforms applied
|
||||
const lines = button.querySelectorAll('span')
|
||||
expect(lines).toHaveLength(3)
|
||||
// Middle line should be hidden (opacity-0)
|
||||
expect(lines[1]).toHaveClass('opacity-0')
|
||||
})
|
||||
|
||||
it('calls onClick when clicked', async () => {
|
||||
const handleClick = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
|
||||
render(<HamburgerButton isOpen={false} onClick={handleClick} />)
|
||||
await user.click(screen.getByRole('button', { name: /toggle menu/i }))
|
||||
|
||||
expect(handleClick).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('has correct accessible name', () => {
|
||||
render(<HamburgerButton isOpen={false} onClick={vi.fn()} />)
|
||||
expect(screen.getByRole('button', { name: /toggle menu/i })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('indicates expanded state for accessibility', () => {
|
||||
const { rerender } = render(<HamburgerButton isOpen={false} onClick={vi.fn()} />)
|
||||
expect(screen.getByRole('button')).toHaveAttribute('aria-expanded', 'false')
|
||||
|
||||
rerender(<HamburgerButton isOpen={true} onClick={vi.fn()} />)
|
||||
expect(screen.getByRole('button')).toHaveAttribute('aria-expanded', 'true')
|
||||
})
|
||||
})
|
||||
|
||||
describe('MobileNav', () => {
|
||||
const defaultProps = {
|
||||
links: mockLinks,
|
||||
isOpen: false,
|
||||
onClose: vi.fn(),
|
||||
onToggle: vi.fn(),
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
// Ensure body scroll is restored
|
||||
document.body.style.overflow = ''
|
||||
})
|
||||
|
||||
it('renders hamburger button', () => {
|
||||
render(<MobileNav {...defaultProps} />)
|
||||
expect(screen.getByRole('button', { name: /toggle menu/i })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hamburger button calls onToggle when clicked', async () => {
|
||||
const onToggle = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
|
||||
render(<MobileNav {...defaultProps} onToggle={onToggle} />)
|
||||
await user.click(screen.getByRole('button', { name: /toggle menu/i }))
|
||||
|
||||
expect(onToggle).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('menu is hidden when isOpen is false', () => {
|
||||
render(<MobileNav {...defaultProps} isOpen={false} />)
|
||||
// Menu should not be in the document when closed
|
||||
expect(screen.queryByRole('navigation')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('menu is visible when isOpen is true', () => {
|
||||
render(<MobileNav {...defaultProps} isOpen={true} />)
|
||||
expect(screen.getByRole('navigation')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders all navigation links', () => {
|
||||
render(<MobileNav {...defaultProps} isOpen={true} />)
|
||||
|
||||
mockLinks.forEach((link) => {
|
||||
expect(screen.getByRole('link', { name: link.label })).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('navigation links have correct href attributes', () => {
|
||||
render(<MobileNav {...defaultProps} isOpen={true} />)
|
||||
|
||||
mockLinks.forEach((link) => {
|
||||
expect(screen.getByRole('link', { name: link.label })).toHaveAttribute('href', link.href)
|
||||
})
|
||||
})
|
||||
|
||||
it('calls onClose when link is clicked', async () => {
|
||||
const onClose = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
|
||||
render(<MobileNav {...defaultProps} isOpen={true} onClose={onClose} />)
|
||||
await user.click(screen.getByRole('link', { name: 'Home' }))
|
||||
|
||||
expect(onClose).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('calls onClose when overlay is clicked', async () => {
|
||||
const onClose = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
|
||||
render(<MobileNav {...defaultProps} isOpen={true} onClose={onClose} />)
|
||||
|
||||
// Click on overlay (background)
|
||||
const overlay = screen.getByTestId('mobile-nav-overlay')
|
||||
await user.click(overlay)
|
||||
|
||||
expect(onClose).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('does not call onClose when menu panel is clicked', async () => {
|
||||
const onClose = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
|
||||
render(<MobileNav {...defaultProps} isOpen={true} onClose={onClose} />)
|
||||
|
||||
// Click on menu panel (not overlay)
|
||||
const panel = screen.getByRole('navigation')
|
||||
await user.click(panel)
|
||||
|
||||
expect(onClose).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('locks body scroll when menu is open', () => {
|
||||
const { rerender } = render(<MobileNav {...defaultProps} isOpen={false} />)
|
||||
expect(document.body.style.overflow).toBe('')
|
||||
|
||||
rerender(<MobileNav {...defaultProps} isOpen={true} />)
|
||||
expect(document.body.style.overflow).toBe('hidden')
|
||||
})
|
||||
|
||||
it('restores body scroll when menu is closed', () => {
|
||||
const { rerender } = render(<MobileNav {...defaultProps} isOpen={true} />)
|
||||
expect(document.body.style.overflow).toBe('hidden')
|
||||
|
||||
rerender(<MobileNav {...defaultProps} isOpen={false} />)
|
||||
expect(document.body.style.overflow).toBe('')
|
||||
})
|
||||
|
||||
it('restores body scroll on unmount', () => {
|
||||
const { unmount } = render(<MobileNav {...defaultProps} isOpen={true} />)
|
||||
expect(document.body.style.overflow).toBe('hidden')
|
||||
|
||||
unmount()
|
||||
expect(document.body.style.overflow).toBe('')
|
||||
})
|
||||
|
||||
it('renders close button inside menu', () => {
|
||||
render(<MobileNav {...defaultProps} isOpen={true} />)
|
||||
// There should be a close button in the menu panel
|
||||
expect(screen.getByRole('button', { name: /close menu/i })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('close button calls onClose when clicked', async () => {
|
||||
const onClose = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
|
||||
render(<MobileNav {...defaultProps} isOpen={true} onClose={onClose} />)
|
||||
await user.click(screen.getByRole('button', { name: /close menu/i }))
|
||||
|
||||
expect(onClose).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
146
src/components/layout/MobileNav.tsx
Normal file
146
src/components/layout/MobileNav.tsx
Normal file
@ -0,0 +1,146 @@
|
||||
import { useEffect } from 'react'
|
||||
import { motion, AnimatePresence } from 'framer-motion'
|
||||
import { X } from 'lucide-react'
|
||||
import { cn } from '../../lib/utils'
|
||||
|
||||
interface NavLink {
|
||||
label: string
|
||||
href: string
|
||||
}
|
||||
|
||||
interface HamburgerButtonProps {
|
||||
isOpen: boolean
|
||||
onClick: () => void
|
||||
className?: string
|
||||
}
|
||||
|
||||
interface MobileNavProps {
|
||||
links: NavLink[]
|
||||
isOpen: boolean
|
||||
onClose: () => void
|
||||
onToggle: () => void
|
||||
}
|
||||
|
||||
export function HamburgerButton({ isOpen, onClick, className }: HamburgerButtonProps) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
aria-label="Toggle menu"
|
||||
aria-expanded={isOpen}
|
||||
className={cn(
|
||||
'relative flex h-6 w-6 flex-col items-center justify-center gap-1.5',
|
||||
'focus:outline-none focus-visible:ring-2 focus-visible:ring-primary',
|
||||
className
|
||||
)}
|
||||
>
|
||||
<span
|
||||
className={cn(
|
||||
'block h-0.5 w-6 bg-current transition-all duration-300',
|
||||
isOpen && 'translate-y-2 rotate-45'
|
||||
)}
|
||||
/>
|
||||
<span
|
||||
className={cn(
|
||||
'block h-0.5 w-6 bg-current transition-all duration-300',
|
||||
isOpen && 'opacity-0'
|
||||
)}
|
||||
/>
|
||||
<span
|
||||
className={cn(
|
||||
'block h-0.5 w-6 bg-current transition-all duration-300',
|
||||
isOpen && '-translate-y-2 -rotate-45'
|
||||
)}
|
||||
/>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
export function MobileNav({ links, isOpen, onClose, onToggle }: MobileNavProps) {
|
||||
// Lock body scroll when menu is open
|
||||
useEffect(() => {
|
||||
if (isOpen) {
|
||||
document.body.style.overflow = 'hidden'
|
||||
} else {
|
||||
document.body.style.overflow = ''
|
||||
}
|
||||
|
||||
return () => {
|
||||
document.body.style.overflow = ''
|
||||
}
|
||||
}, [isOpen])
|
||||
|
||||
return (
|
||||
<>
|
||||
<HamburgerButton isOpen={isOpen} onClick={onToggle} />
|
||||
|
||||
<AnimatePresence>
|
||||
{isOpen && (
|
||||
<>
|
||||
{/* Overlay */}
|
||||
<motion.div
|
||||
data-testid="mobile-nav-overlay"
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={{ opacity: 0 }}
|
||||
transition={{ duration: 0.2 }}
|
||||
className="fixed inset-0 z-40 bg-black/50"
|
||||
onClick={onClose}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
|
||||
{/* Menu Panel */}
|
||||
<motion.nav
|
||||
aria-label="Mobile navigation"
|
||||
initial={{ x: '100%' }}
|
||||
animate={{ x: 0 }}
|
||||
exit={{ x: '100%' }}
|
||||
transition={{ type: 'tween', duration: 0.3, ease: 'easeInOut' }}
|
||||
className={cn(
|
||||
'fixed right-0 top-0 z-50 h-full w-[80vw] max-w-[300px]',
|
||||
'bg-white shadow-[-4px_0_16px_rgba(0,0,0,0.1)]'
|
||||
)}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{/* Close button */}
|
||||
<div className="flex justify-end p-4">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
aria-label="Close menu"
|
||||
className={cn(
|
||||
'flex h-10 w-10 items-center justify-center rounded-full',
|
||||
'text-text-secondary hover:bg-gray-100',
|
||||
'focus:outline-none focus-visible:ring-2 focus-visible:ring-primary'
|
||||
)}
|
||||
>
|
||||
<X className="h-6 w-6" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Navigation links */}
|
||||
<ul className="flex flex-col px-4">
|
||||
{links.map((link) => (
|
||||
<li key={link.href}>
|
||||
<a
|
||||
href={link.href}
|
||||
onClick={onClose}
|
||||
className={cn(
|
||||
'block py-4 text-xl font-medium',
|
||||
'text-text-secondary hover:text-primary',
|
||||
'border-b border-gray-100 last:border-b-0',
|
||||
'transition-colors duration-200'
|
||||
)}
|
||||
>
|
||||
{link.label}
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</motion.nav>
|
||||
</>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
</>
|
||||
)
|
||||
}
|
||||
4
src/components/layout/index.ts
Normal file
4
src/components/layout/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export { Container } from './Container'
|
||||
export { Footer } from './Footer'
|
||||
export { Header } from './Header'
|
||||
export { MobileNav, HamburgerButton } from './MobileNav'
|
||||
148
src/components/ui/Button.test.tsx
Normal file
148
src/components/ui/Button.test.tsx
Normal file
@ -0,0 +1,148 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { Button } from './Button'
|
||||
|
||||
describe('Button', () => {
|
||||
it('renders children correctly', () => {
|
||||
render(<Button variant="primary">Click me</Button>)
|
||||
expect(screen.getByText('Click me')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('applies primary variant styles by default', () => {
|
||||
render(<Button variant="primary">Primary</Button>)
|
||||
const button = screen.getByRole('button')
|
||||
expect(button).toHaveClass('bg-primary')
|
||||
expect(button).toHaveClass('text-white')
|
||||
})
|
||||
|
||||
it('applies secondary variant styles', () => {
|
||||
render(<Button variant="secondary">Secondary</Button>)
|
||||
const button = screen.getByRole('button')
|
||||
expect(button).toHaveClass('border-primary')
|
||||
expect(button).toHaveClass('text-primary')
|
||||
expect(button).toHaveClass('bg-transparent')
|
||||
})
|
||||
|
||||
it('applies ghost variant styles', () => {
|
||||
render(<Button variant="ghost">Ghost</Button>)
|
||||
const button = screen.getByRole('button')
|
||||
expect(button).toHaveClass('bg-transparent')
|
||||
expect(button).toHaveClass('text-primary')
|
||||
})
|
||||
|
||||
it('renders as anchor when href is provided', () => {
|
||||
render(
|
||||
<Button variant="primary" href="https://example.com">
|
||||
Link
|
||||
</Button>
|
||||
)
|
||||
const link = screen.getByRole('link')
|
||||
expect(link).toBeInTheDocument()
|
||||
expect(link).toHaveAttribute('href', 'https://example.com')
|
||||
})
|
||||
|
||||
it('renders as button when href is not provided', () => {
|
||||
render(<Button variant="primary">Button</Button>)
|
||||
expect(screen.getByRole('button')).toBeInTheDocument()
|
||||
expect(screen.queryByRole('link')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('calls onClick when clicked', async () => {
|
||||
const handleClick = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
|
||||
render(
|
||||
<Button variant="primary" onClick={handleClick}>
|
||||
Click me
|
||||
</Button>
|
||||
)
|
||||
|
||||
await user.click(screen.getByRole('button'))
|
||||
expect(handleClick).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('does not call onClick when disabled', async () => {
|
||||
const handleClick = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
|
||||
render(
|
||||
<Button variant="primary" onClick={handleClick} disabled>
|
||||
Click me
|
||||
</Button>
|
||||
)
|
||||
|
||||
await user.click(screen.getByRole('button'))
|
||||
expect(handleClick).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('applies disabled styles when disabled', () => {
|
||||
render(
|
||||
<Button variant="primary" disabled>
|
||||
Disabled
|
||||
</Button>
|
||||
)
|
||||
const button = screen.getByRole('button')
|
||||
expect(button).toBeDisabled()
|
||||
expect(button).toHaveClass('opacity-50')
|
||||
expect(button).toHaveClass('cursor-not-allowed')
|
||||
})
|
||||
|
||||
it('applies size classes correctly', () => {
|
||||
const { rerender } = render(
|
||||
<Button variant="primary" size="sm">
|
||||
Small
|
||||
</Button>
|
||||
)
|
||||
expect(screen.getByRole('button')).toHaveClass('py-2', 'px-4', 'text-sm')
|
||||
|
||||
rerender(
|
||||
<Button variant="primary" size="md">
|
||||
Medium
|
||||
</Button>
|
||||
)
|
||||
expect(screen.getByRole('button')).toHaveClass('py-3', 'px-6', 'text-base')
|
||||
|
||||
rerender(
|
||||
<Button variant="primary" size="lg">
|
||||
Large
|
||||
</Button>
|
||||
)
|
||||
expect(screen.getByRole('button')).toHaveClass('py-4', 'px-8', 'text-lg')
|
||||
})
|
||||
|
||||
it('defaults to md size when not specified', () => {
|
||||
render(<Button variant="primary">Default Size</Button>)
|
||||
const button = screen.getByRole('button')
|
||||
expect(button).toHaveClass('py-3', 'px-6', 'text-base')
|
||||
})
|
||||
|
||||
it('merges custom className', () => {
|
||||
render(
|
||||
<Button variant="primary" className="custom-class">
|
||||
Custom
|
||||
</Button>
|
||||
)
|
||||
const button = screen.getByRole('button')
|
||||
expect(button).toHaveClass('custom-class')
|
||||
})
|
||||
|
||||
it('applies correct button type attribute', () => {
|
||||
const { rerender } = render(
|
||||
<Button variant="primary" type="submit">
|
||||
Submit
|
||||
</Button>
|
||||
)
|
||||
expect(screen.getByRole('button')).toHaveAttribute('type', 'submit')
|
||||
|
||||
rerender(
|
||||
<Button variant="primary" type="reset">
|
||||
Reset
|
||||
</Button>
|
||||
)
|
||||
expect(screen.getByRole('button')).toHaveAttribute('type', 'reset')
|
||||
|
||||
rerender(<Button variant="primary">Default</Button>)
|
||||
expect(screen.getByRole('button')).toHaveAttribute('type', 'button')
|
||||
})
|
||||
})
|
||||
74
src/components/ui/Button.tsx
Normal file
74
src/components/ui/Button.tsx
Normal file
@ -0,0 +1,74 @@
|
||||
import { cn } from '../../lib/utils'
|
||||
|
||||
interface ButtonProps {
|
||||
/** Visual style variant */
|
||||
variant: 'primary' | 'secondary' | 'ghost'
|
||||
/** Size variant */
|
||||
size?: 'sm' | 'md' | 'lg'
|
||||
/** Button content */
|
||||
children: React.ReactNode
|
||||
/** If provided, renders as an anchor tag */
|
||||
href?: string
|
||||
/** Click handler (for button behavior) */
|
||||
onClick?: () => void
|
||||
/** Disabled state */
|
||||
disabled?: boolean
|
||||
/** Additional CSS classes */
|
||||
className?: string
|
||||
/** Button type attribute */
|
||||
type?: 'button' | 'submit' | 'reset'
|
||||
}
|
||||
|
||||
const variantStyles = {
|
||||
primary: 'bg-primary text-white shadow-[0_4px_14px_0_rgba(37,99,235,0.39)] hover:bg-primary-dark hover:-translate-y-0.5 hover:shadow-[0_6px_20px_0_rgba(37,99,235,0.5)]',
|
||||
secondary: 'bg-transparent border-2 border-primary text-primary hover:bg-primary hover:text-white',
|
||||
ghost: 'bg-transparent text-primary hover:underline',
|
||||
}
|
||||
|
||||
const sizeStyles = {
|
||||
sm: 'py-2 px-4 text-sm',
|
||||
md: 'py-3 px-6 text-base',
|
||||
lg: 'py-4 px-8 text-lg',
|
||||
}
|
||||
|
||||
export function Button({
|
||||
variant,
|
||||
size = 'md',
|
||||
children,
|
||||
href,
|
||||
onClick,
|
||||
disabled = false,
|
||||
className,
|
||||
type = 'button',
|
||||
}: ButtonProps) {
|
||||
const baseStyles = 'inline-flex items-center justify-center font-semibold rounded-lg transition-all duration-300'
|
||||
|
||||
const disabledStyles = disabled ? 'opacity-50 cursor-not-allowed' : ''
|
||||
|
||||
const combinedClassName = cn(
|
||||
baseStyles,
|
||||
variantStyles[variant],
|
||||
sizeStyles[size],
|
||||
disabledStyles,
|
||||
className
|
||||
)
|
||||
|
||||
if (href) {
|
||||
return (
|
||||
<a href={href} className={combinedClassName}>
|
||||
{children}
|
||||
</a>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
type={type}
|
||||
onClick={onClick}
|
||||
disabled={disabled}
|
||||
className={combinedClassName}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
162
src/components/ui/Card.test.tsx
Normal file
162
src/components/ui/Card.test.tsx
Normal file
@ -0,0 +1,162 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { Card } from './Card';
|
||||
|
||||
describe('Card', () => {
|
||||
it('renders children correctly', () => {
|
||||
render(
|
||||
<Card>
|
||||
<p>Test content</p>
|
||||
</Card>
|
||||
);
|
||||
|
||||
expect(screen.getByText('Test content')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('applies base styles', () => {
|
||||
render(
|
||||
<Card data-testid="card">
|
||||
<p>Content</p>
|
||||
</Card>
|
||||
);
|
||||
|
||||
const card = screen.getByTestId('card');
|
||||
// Base styles: white bg, border, rounded-2xl, p-8, shadow-md
|
||||
expect(card).toHaveClass('bg-white');
|
||||
expect(card).toHaveClass('border');
|
||||
expect(card).toHaveClass('border-border');
|
||||
expect(card).toHaveClass('rounded-2xl');
|
||||
expect(card).toHaveClass('p-8');
|
||||
expect(card).toHaveClass('shadow-md');
|
||||
});
|
||||
|
||||
it('applies hover classes when hover prop is true', () => {
|
||||
render(
|
||||
<Card hover data-testid="card">
|
||||
<p>Hoverable card</p>
|
||||
</Card>
|
||||
);
|
||||
|
||||
const card = screen.getByTestId('card');
|
||||
// Hover state should add hover transform and shadow classes
|
||||
expect(card).toHaveClass('hover:-translate-y-1.5');
|
||||
expect(card).toHaveClass('hover:shadow-xl');
|
||||
});
|
||||
|
||||
it('does not apply hover classes when hover prop is false', () => {
|
||||
render(
|
||||
<Card hover={false} data-testid="card">
|
||||
<p>Non-hoverable card</p>
|
||||
</Card>
|
||||
);
|
||||
|
||||
const card = screen.getByTestId('card');
|
||||
expect(card).not.toHaveClass('hover:-translate-y-1.5');
|
||||
expect(card).not.toHaveClass('hover:shadow-xl');
|
||||
});
|
||||
|
||||
it('renders gradient border when gradientBorder is true', () => {
|
||||
render(
|
||||
<Card gradientBorder data-testid="card">
|
||||
<p>Card with gradient border</p>
|
||||
</Card>
|
||||
);
|
||||
|
||||
const card = screen.getByTestId('card');
|
||||
// Should have relative positioning for the pseudo-element
|
||||
expect(card).toHaveClass('relative');
|
||||
expect(card).toHaveClass('overflow-hidden');
|
||||
// The gradient border is implemented via a before pseudo-element
|
||||
// We check for the class that enables the gradient border styling
|
||||
expect(card).toHaveClass('before:absolute');
|
||||
expect(card).toHaveClass('before:inset-x-0');
|
||||
expect(card).toHaveClass('before:top-0');
|
||||
expect(card).toHaveClass('before:h-1');
|
||||
expect(card).toHaveClass('before:bg-gradient-to-r');
|
||||
expect(card).toHaveClass('before:from-primary');
|
||||
expect(card).toHaveClass('before:to-accent');
|
||||
});
|
||||
|
||||
it('does not render gradient border when gradientBorder is false', () => {
|
||||
render(
|
||||
<Card gradientBorder={false} data-testid="card">
|
||||
<p>Card without gradient border</p>
|
||||
</Card>
|
||||
);
|
||||
|
||||
const card = screen.getByTestId('card');
|
||||
expect(card).not.toHaveClass('before:absolute');
|
||||
expect(card).not.toHaveClass('before:bg-gradient-to-r');
|
||||
});
|
||||
|
||||
it('merges custom className', () => {
|
||||
render(
|
||||
<Card className="custom-class another-class" data-testid="card">
|
||||
<p>Card with custom classes</p>
|
||||
</Card>
|
||||
);
|
||||
|
||||
const card = screen.getByTestId('card');
|
||||
// Should have custom classes merged with base classes
|
||||
expect(card).toHaveClass('custom-class');
|
||||
expect(card).toHaveClass('another-class');
|
||||
// Should still have base classes
|
||||
expect(card).toHaveClass('bg-white');
|
||||
expect(card).toHaveClass('rounded-2xl');
|
||||
});
|
||||
|
||||
it('calls onClick when clicked', async () => {
|
||||
const handleClick = vi.fn();
|
||||
const user = userEvent.setup();
|
||||
|
||||
render(
|
||||
<Card onClick={handleClick} data-testid="card">
|
||||
<p>Clickable card</p>
|
||||
</Card>
|
||||
);
|
||||
|
||||
const card = screen.getByTestId('card');
|
||||
await user.click(card);
|
||||
|
||||
expect(handleClick).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('has correct transition styles', () => {
|
||||
render(
|
||||
<Card data-testid="card">
|
||||
<p>Card with transitions</p>
|
||||
</Card>
|
||||
);
|
||||
|
||||
const card = screen.getByTestId('card');
|
||||
// Should have transition classes for smooth animations
|
||||
expect(card).toHaveClass('transition-all');
|
||||
expect(card).toHaveClass('duration-300');
|
||||
expect(card).toHaveClass('ease-in-out');
|
||||
});
|
||||
|
||||
it('applies cursor-pointer when onClick is provided', () => {
|
||||
const handleClick = vi.fn();
|
||||
|
||||
render(
|
||||
<Card onClick={handleClick} data-testid="card">
|
||||
<p>Clickable card</p>
|
||||
</Card>
|
||||
);
|
||||
|
||||
const card = screen.getByTestId('card');
|
||||
expect(card).toHaveClass('cursor-pointer');
|
||||
});
|
||||
|
||||
it('does not apply cursor-pointer when onClick is not provided', () => {
|
||||
render(
|
||||
<Card data-testid="card">
|
||||
<p>Non-clickable card</p>
|
||||
</Card>
|
||||
);
|
||||
|
||||
const card = screen.getByTestId('card');
|
||||
expect(card).not.toHaveClass('cursor-pointer');
|
||||
});
|
||||
});
|
||||
45
src/components/ui/Card.tsx
Normal file
45
src/components/ui/Card.tsx
Normal file
@ -0,0 +1,45 @@
|
||||
import { cn } from '../../lib/utils'
|
||||
|
||||
interface CardProps {
|
||||
/** Card content */
|
||||
children: React.ReactNode
|
||||
/** Additional CSS classes */
|
||||
className?: string
|
||||
/** Enable hover lift effect */
|
||||
hover?: boolean
|
||||
/** Show gradient top border */
|
||||
gradientBorder?: boolean
|
||||
/** Click handler */
|
||||
onClick?: () => void
|
||||
/** Test ID for testing */
|
||||
'data-testid'?: string
|
||||
}
|
||||
|
||||
export function Card({
|
||||
children,
|
||||
className,
|
||||
hover = false,
|
||||
gradientBorder = false,
|
||||
onClick,
|
||||
'data-testid': testId,
|
||||
}: CardProps) {
|
||||
const baseStyles = 'bg-white border border-border rounded-2xl p-8 shadow-md transition-all duration-300 ease-in-out'
|
||||
|
||||
const hoverStyles = hover ? 'hover:-translate-y-1.5 hover:shadow-xl' : ''
|
||||
|
||||
const gradientBorderStyles = gradientBorder
|
||||
? 'relative overflow-hidden before:absolute before:inset-x-0 before:top-0 before:h-1 before:bg-gradient-to-r before:from-primary before:to-accent'
|
||||
: ''
|
||||
|
||||
const clickableStyles = onClick ? 'cursor-pointer' : ''
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(baseStyles, hoverStyles, gradientBorderStyles, clickableStyles, className)}
|
||||
onClick={onClick}
|
||||
data-testid={testId}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
2
src/components/ui/index.ts
Normal file
2
src/components/ui/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export { Button } from './Button'
|
||||
export { Card } from './Card'
|
||||
6
src/lib/utils.ts
Normal file
6
src/lib/utils.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { clsx, type ClassValue } from 'clsx'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
10
src/main.tsx
Normal file
10
src/main.tsx
Normal file
@ -0,0 +1,10 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './styles/index.css'
|
||||
import App from './App.tsx'
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
||||
76
src/styles/index.css
Normal file
76
src/styles/index.css
Normal file
@ -0,0 +1,76 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
/* Design Tokens - Tailwind v4 CSS-first configuration */
|
||||
@theme {
|
||||
/* Colors */
|
||||
--color-primary: #2563eb;
|
||||
--color-primary-dark: #1d4ed8;
|
||||
--color-primary-light: #3b82f6;
|
||||
--color-accent: #f59e0b;
|
||||
--color-secondary: #64748b;
|
||||
--color-text-primary: #1e293b;
|
||||
--color-text-secondary: #64748b;
|
||||
--color-bg-primary: #ffffff;
|
||||
--color-bg-secondary: #f8fafc;
|
||||
--color-border: #e2e8f0;
|
||||
|
||||
/* Font family */
|
||||
--font-sans: 'Inter', system-ui, -apple-system, sans-serif;
|
||||
|
||||
/* Custom animations */
|
||||
--animate-fade-in-up: fade-in-up 0.6s ease-out;
|
||||
--animate-slide-in: slide-in 0.5s ease-out;
|
||||
--animate-count-up: count-up 2s ease-out;
|
||||
|
||||
/* Keyframes */
|
||||
@keyframes fade-in-up {
|
||||
0% {
|
||||
opacity: 0;
|
||||
transform: translateY(30px);
|
||||
}
|
||||
100% {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes slide-in {
|
||||
0% {
|
||||
opacity: 0;
|
||||
transform: translateX(-20px);
|
||||
}
|
||||
100% {
|
||||
opacity: 1;
|
||||
transform: translateX(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes count-up {
|
||||
0% {
|
||||
opacity: 0;
|
||||
}
|
||||
100% {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Base styles */
|
||||
@layer base {
|
||||
html {
|
||||
scroll-behavior: smooth;
|
||||
}
|
||||
body {
|
||||
@apply antialiased text-text-primary;
|
||||
}
|
||||
}
|
||||
|
||||
/* Component styles */
|
||||
@layer components {
|
||||
.gradient-text {
|
||||
@apply bg-gradient-to-r from-slate-900 to-primary bg-clip-text text-transparent;
|
||||
}
|
||||
.glassmorphism {
|
||||
@apply bg-white/95 backdrop-blur-md;
|
||||
}
|
||||
}
|
||||
1
src/test/setup.ts
Normal file
1
src/test/setup.ts
Normal file
@ -0,0 +1 @@
|
||||
import '@testing-library/jest-dom'
|
||||
41
src/types/index.ts
Normal file
41
src/types/index.ts
Normal file
@ -0,0 +1,41 @@
|
||||
// Navigation types
|
||||
export interface NavLink {
|
||||
label: string
|
||||
href: string
|
||||
}
|
||||
|
||||
// Service types
|
||||
export interface Service {
|
||||
id: string
|
||||
title: string
|
||||
description: string
|
||||
icon: string
|
||||
features: string[]
|
||||
}
|
||||
|
||||
// Workflow types
|
||||
export interface WorkflowStep {
|
||||
id: number
|
||||
title: string
|
||||
description: string
|
||||
icon: string
|
||||
}
|
||||
|
||||
// Stats types
|
||||
export interface Stat {
|
||||
value: number
|
||||
label: string
|
||||
suffix?: string
|
||||
}
|
||||
|
||||
// Contact types
|
||||
export interface ContactMethod {
|
||||
icon: string
|
||||
title: string
|
||||
value: string
|
||||
href?: string
|
||||
}
|
||||
|
||||
// Component prop types
|
||||
export type Size = 'sm' | 'md' | 'lg'
|
||||
export type Variant = 'primary' | 'secondary' | 'ghost'
|
||||
Reference in New Issue
Block a user