Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1,933 changes: 1,933 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

246 changes: 51 additions & 195 deletions src/components/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,219 +1,75 @@
'use client';

import { useState, useRef, useEffect } from 'react';
import { IconMenu2, IconChevronDown, IconWorld, IconX } from '@tabler/icons-react';
import { assetUrl } from '../utils/basePath';
import { useCallback, useState } from 'react';
import HeaderContent from '@/components/homeHeader/HeaderContent';
import { colors, spacing, typography } from '@policyengine/design-system/tokens';

const NAV_ITEMS = [
{ label: 'Research', href: 'https://policyengine.org/us/research' },
{ label: 'Model', href: 'https://policyengine.org/us/model' },
{ label: 'API', href: 'https://policyengine.org/us/api' },
// Inline useDisclosure (drop-in from app-v2 src/hooks/useDisclosure.ts)
function useDisclosure(initialState = false) {
const [opened, setOpened] = useState(initialState);
const open = useCallback(() => setOpened(true), []);
const close = useCallback(() => setOpened(false), []);
const toggle = useCallback(() => setOpened((prev) => !prev), []);
return [opened, { open, close, toggle }];
}

const navItems = [
{
label: 'Research',
href: 'https://policyengine.org/us/research',
hasDropdown: false,
},
{
label: 'Model',
href: 'https://policyengine.org/us/model',
hasDropdown: false,
},
{
label: 'API',
href: 'https://policyengine.org/us/api',
hasDropdown: false,
},
{
label: 'About',
hasDropdown: true,
items: [
dropdownItems: [
{ label: 'Team', href: 'https://policyengine.org/us/team' },
{ label: 'Supporters', href: 'https://policyengine.org/us/supporters' },
],
},
{ label: 'Donate', href: 'https://policyengine.org/us/donate' },
];

const COUNTRIES = [
{ id: 'us', label: 'United States' },
{ id: 'uk', label: 'United Kingdom' },
{
label: 'Donate',
href: 'https://policyengine.org/us/donate',
hasDropdown: false,
},
];

const linkStyle = {
color: '#fff',
fontWeight: 500,
fontSize: '18px',
textDecoration: 'none',
fontFamily: "'Inter', sans-serif",
};

export default function Header() {
const [aboutOpen, setAboutOpen] = useState(false);
const [countryOpen, setCountryOpen] = useState(false);
const [mobileOpen, setMobileOpen] = useState(false);
const aboutRef = useRef(null);
const countryRef = useRef(null);

useEffect(() => {
function handleClick(e) {
if (aboutRef.current && !aboutRef.current.contains(e.target)) setAboutOpen(false);
if (countryRef.current && !countryRef.current.contains(e.target)) setCountryOpen(false);
}
document.addEventListener('mousedown', handleClick);
return () => document.removeEventListener('mousedown', handleClick);
}, []);
const [opened, { open, close }] = useDisclosure(false);

return (
<header
<div
style={{
position: 'sticky',
top: 0,
padding: '8px 24px',
height: '58px',
backgroundColor: '#2C7A7B',
borderBottom: '0.5px solid #94A3B8',
boxShadow: '0px 2px 4px -1px rgba(16,24,40,0.05), 0px 4px 6px -1px rgba(16,24,40,0.1)',
padding: `${spacing.sm} ${spacing['2xl']}`,
height: spacing.layout.header,
background: `linear-gradient(to right, ${colors.primary[800]}, ${colors.primary[600]})`,
borderBottom: `0.5px solid ${colors.primary[700]}`,
boxShadow: `0px 2px 4px -1px ${colors.shadow.light}, 0px 4px 6px -1px ${colors.shadow.medium}`,
zIndex: 1000,
fontFamily: "'Inter', sans-serif",
fontFamily: typography.fontFamily.primary,
opacity: opened ? 0 : 1,
transition: 'opacity 0.1s ease',
width: '100%',
boxSizing: 'border-box',
}}
>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', height: '100%' }}>
<div style={{ display: 'flex', alignItems: 'center' }}>
<a href="https://policyengine.org/us" style={{ display: 'flex', alignItems: 'center', marginRight: '12px' }}>
<img
src={assetUrl('/assets/logos/policyengine/white.svg')}
alt="PolicyEngine"
style={{ height: '24px', width: 'auto' }}
/>
</a>
<nav style={{ display: 'flex', alignItems: 'center', gap: '24px' }} className="hidden lg:flex">
{NAV_ITEMS.map((item) =>
item.hasDropdown ? (
<div key={item.label} ref={aboutRef} style={{ position: 'relative' }}>
<button
onClick={() => setAboutOpen(!aboutOpen)}
style={{
...linkStyle,
background: 'transparent',
border: 'none',
cursor: 'pointer',
padding: 0,
display: 'flex',
alignItems: 'center',
gap: '4px',
}}
>
{item.label}
<IconChevronDown size={18} color="white" />
</button>
{aboutOpen && (
<div style={{
position: 'absolute', top: '100%', left: 0, marginTop: '4px',
width: '200px', background: '#fff', borderRadius: '8px',
boxShadow: '0 10px 15px -3px rgba(0,0,0,0.1)',
border: '1px solid #E2E8F0', padding: '4px 0', zIndex: 1001,
}}>
{item.items.map((sub) => (
<a key={sub.label} href={sub.href} style={{
display: 'block', padding: '8px 16px', fontSize: '14px',
color: '#101828', textDecoration: 'none', fontFamily: "'Inter', sans-serif",
}}>
{sub.label}
</a>
))}
</div>
)}
</div>
) : (
<a key={item.label} href={item.href} style={linkStyle}>{item.label}</a>
),
)}
</nav>
</div>

<div className="hidden lg:flex" style={{ alignItems: 'center' }}>
<div ref={countryRef} style={{ position: 'relative' }}>
<button
onClick={() => setCountryOpen(!countryOpen)}
style={{ background: 'transparent', border: 'none', cursor: 'pointer', padding: 0, lineHeight: 1 }}
aria-label="Country selector"
>
<IconWorld size={18} color="white" />
</button>
{countryOpen && (
<div style={{
position: 'absolute', top: '100%', right: 0, marginTop: '4px',
width: '200px', background: '#fff', borderRadius: '8px',
boxShadow: '0 10px 15px -3px rgba(0,0,0,0.1)',
border: '1px solid #E2E8F0', padding: '4px 0', zIndex: 1001,
}}>
{COUNTRIES.map((c) => (
<a key={c.id} href={`https://policyengine.org/${c.id}`} style={{
display: 'block', padding: '8px 16px', fontSize: '14px',
color: '#101828', textDecoration: 'none', fontFamily: "'Inter', sans-serif",
fontWeight: c.id === 'us' ? 700 : 400,
}}>
{c.label}
</a>
))}
</div>
)}
</div>
</div>

<div className="flex lg:hidden" style={{ alignItems: 'center', gap: '12px' }}>
<button
onClick={() => setCountryOpen(!countryOpen)}
style={{ background: 'transparent', border: 'none', cursor: 'pointer', padding: 0, lineHeight: 1 }}
aria-label="Country selector"
>
<IconWorld size={18} color="white" />
</button>
<button
onClick={() => setMobileOpen(!mobileOpen)}
style={{ background: 'transparent', border: 'none', cursor: 'pointer', padding: '4px' }}
aria-label="Toggle navigation"
>
<IconMenu2 size={24} color="white" />
</button>
</div>
</div>

{mobileOpen && (
<>
<div
style={{ position: 'fixed', inset: 0, backgroundColor: 'rgba(0,0,0,0.4)', zIndex: 1001 }}
onClick={() => setMobileOpen(false)}
/>
<div style={{
position: 'fixed', top: 0, right: 0, width: '300px', height: '100vh',
backgroundColor: '#2C7A7B', zIndex: 1002, padding: '16px 24px',
fontFamily: "'Inter', sans-serif",
}}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '24px' }}>
<span style={{ color: '#fff', fontWeight: 700, fontSize: '16px' }}>Menu</span>
<button
onClick={() => setMobileOpen(false)}
style={{ background: 'transparent', border: 'none', cursor: 'pointer' }}
aria-label="Close menu"
>
<IconX size={24} color="white" />
</button>
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: '16px' }}>
{NAV_ITEMS.map((item) =>
item.hasDropdown ? (
<div key={item.label}>
<span style={{ color: '#fff', fontWeight: 500, fontSize: '14px', display: 'block', marginBottom: '4px' }}>
{item.label}
</span>
<div style={{ display: 'flex', flexDirection: 'column', gap: '4px', paddingLeft: '12px' }}>
{item.items.map((sub) => (
<a key={sub.label} href={sub.href} style={{ color: '#fff', textDecoration: 'none', fontSize: '14px' }}>
{sub.label}
</a>
))}
</div>
</div>
) : (
<a key={item.label} href={item.href} style={{
color: '#fff', textDecoration: 'none', fontWeight: 500, fontSize: '14px', display: 'block',
}}>
{item.label}
</a>
),
)}
</div>
</div>
</>
)}
</header>
<HeaderContent
opened={opened}
onOpen={open}
onClose={close}
navItems={navItems}
/>
</div>
);
}
Loading