Dropdown featured posts
A bar whose menus open company links beside the latest blog posts.
Last updated
---
/**
* Dropdown featured posts: A bar whose menus open company links beside the latest blog posts.
*
* @block header-navigation
* @order 8
*/
import { ArrowRight, Flag, Folder, MessageCircle, Orbit, Users } from '@lucide/astro'
import Navbar from '@/components/apogee/Navbar/Navbar.astro'
import NavLink from '@/components/apogee/NavLink/NavLink.astro'
import NavDropdown from '@/components/apogee/NavDropdown/NavDropdown.astro'
import Link from '@/components/apogee/Link/Link.astro'
import Button from '@/components/apogee/Button/Button.astro'
import FeaturedIcon from '@/components/apogee/FeaturedIcon/FeaturedIcon.astro'
import Badge from '@/components/apogee/Badge/Badge.astro'
import Image from '@/components/apogee/Image/Image.astro'
import type { Action } from '@/components/apogee/sections/_shared/spine.ts'
import type { NavGroup, NavigationContent } from '@/components/apogee/sections/_shared/navigation.ts'
const icons = [Flag, MessageCircle, Users, Folder]
// A menu's first group is the link list, its second the blog posts.
const groups: NavGroup[] = [
{ heading: 'Company', items: [
{ label: 'About us', href: '#', description: 'Our team and what we are working towards.' },
{ label: 'Press', href: '#', description: 'News, press releases and press resources.' },
{ label: 'Careers', href: '#', description: 'We are always looking for talented people. Join our remote team.', badge: "We're hiring" },
{ label: 'Legal', href: '#', description: 'Company details, licensing, terms and privacy.' },
] },
{ heading: 'Latest blog posts', items: [
{ label: 'Auto layout explained', href: '#', description: 'How flexible layouts save hours on every screen.', media: { src: 'https://picsum.photos/seed/apogee-nav-1/288/176', alt: '' } },
{ label: 'Ways to level up your product design', href: '#', description: 'Small habits that make a big difference over a year.', media: { src: 'https://picsum.photos/seed/apogee-nav-2/288/176', alt: '' } },
{ label: 'Synthesise data with affinity diagrams', href: '#', description: 'Turn a wall of notes into findings your team trusts.', media: { src: 'https://picsum.photos/seed/apogee-nav-3/288/176', alt: '' } },
] },
]
/** @composable */
interface Props extends NavigationContent {
/** The bar's fill: the page, a grey band or the brand colour. */
background?: 'page' | 'neutral-faded' | 'primary' | undefined
/** `dark` sets the bar in the dark theme on a light page. */
theme?: 'dark' | undefined
/** The link under the blog posts. @category content */
postsAction?: Action | null
}
const {
brand = 'Example',
links = [
{ label: 'Products', groups },
{ label: 'Services', groups },
{ label: 'Pricing', href: '#' },
{ label: 'Resources', groups },
{ label: 'About', href: '#' },
],
primaryAction = { label: 'Sign up', href: '#' },
secondaryAction = { label: 'Log in', href: '#' },
postsAction = { label: 'All blog posts', href: '#' },
background,
theme,
} = Astro.props
---
<Navbar background={background} data-theme={theme}>
<Link slot="brand" href="/" color="inherit" underline="none" class="inline-flex items-center gap-2 text-lg font-semibold"><FeaturedIcon theme="solid" color="primary" size="small"><Orbit /></FeaturedIcon>{brand}</Link>
{links.map((l) => {
if (!('groups' in l)) return <NavLink href={l.href}>{l.label}</NavLink>
const [list, posts] = l.groups
return (
<NavDropdown label={l.label} width="48rem">
<div class="grid md:grid-cols-[minmax(0,1fr)_minmax(0,1.2fr)]">
{list && <div class="flex flex-col gap-2 p-3">{list.heading && <p class="px-3 text-sm font-semibold text-primary">{list.heading}</p>}<ul class="list-none p-0 flex flex-col gap-0.5">
{list.items.map((i, n) => {
const Icon = icons[n % icons.length]!
return (
<li>
<Link href={i.href} color="inherit" underline="none" class="flex gap-3 rounded-lg p-3 transition-colors hover:bg-neutral-faded">
<Icon class="mt-0.5 size-5 shrink-0 text-primary" aria-hidden="true" />
<span class="flex flex-col gap-1">
<span class="flex flex-wrap items-center gap-2 font-semibold">{i.label}{i.badge && <Badge size="small" color={i.badge === 'New' ? 'neutral' : 'positive'} variant="faded">{i.badge}</Badge>}</span>
{i.description && <span class="line-clamp-2 text-sm text-neutral-faded">{i.description}</span>}
</span>
</Link>
</li>
)})}
</ul></div>}
{posts && <div class="flex flex-col gap-2 bg-neutral-faded p-3">
{posts.heading && <p class="px-3 text-sm font-semibold text-primary">{posts.heading}</p>}
<ul class="list-none p-0 flex flex-col gap-1">
{posts.items.map((p) => (
<li>
<Link href={p.href} color="inherit" underline="none" class="flex gap-4 rounded-lg p-2 transition-colors hover:bg-neutral-faded">
{p.media && <Image src={p.media.src} alt={p.media.alt} width={288} height={176} fit="cover" radius="md" class="h-[5.5rem] w-36 shrink-0" />}
<span class="flex flex-col gap-1">
<span class="line-clamp-2 font-semibold">{p.label}</span>
{p.description && <span class="line-clamp-2 text-sm text-neutral-faded">{p.description}</span>}
</span>
</Link>
</li>
))}
</ul>
{postsAction && <Link href={postsAction.href} class="mx-3 inline-flex items-center gap-1.5 text-sm font-semibold">{postsAction.label}<ArrowRight class="size-4 rtl:-scale-x-100" aria-hidden="true" /></Link>}
</div>}
</div>
</NavDropdown>
)
})}
{secondaryAction && <Button slot="actions" href={secondaryAction.href} variant="outline" color="neutral" size="small">{secondaryAction.label}</Button>}
{primaryAction && <Button slot="actions" href={primaryAction.href} size="small">{primaryAction.label}</Button>}
</Navbar>
Show codeHide code
---
/**
* Dropdown featured posts: A bar whose menus open company links beside the latest blog posts.
*
* @block header-navigation
* @order 8
*/
import { ArrowRight, Flag, Folder, MessageCircle, Orbit, Users } from '@lucide/astro'
import Navbar from '@/components/apogee/Navbar/Navbar.astro'
import NavLink from '@/components/apogee/NavLink/NavLink.astro'
import NavDropdown from '@/components/apogee/NavDropdown/NavDropdown.astro'
import Link from '@/components/apogee/Link/Link.astro'
import Button from '@/components/apogee/Button/Button.astro'
import FeaturedIcon from '@/components/apogee/FeaturedIcon/FeaturedIcon.astro'
import Badge from '@/components/apogee/Badge/Badge.astro'
import Image from '@/components/apogee/Image/Image.astro'
import type { Action } from '@/components/apogee/sections/_shared/spine.ts'
import type { NavGroup, NavigationContent } from '@/components/apogee/sections/_shared/navigation.ts'
const icons = [Flag, MessageCircle, Users, Folder]
// A menu's first group is the link list, its second the blog posts.
const groups: NavGroup[] = [
{ heading: 'Company', items: [
{ label: 'About us', href: '#', description: 'Our team and what we are working towards.' },
{ label: 'Press', href: '#', description: 'News, press releases and press resources.' },
{ label: 'Careers', href: '#', description: 'We are always looking for talented people. Join our remote team.', badge: "We're hiring" },
{ label: 'Legal', href: '#', description: 'Company details, licensing, terms and privacy.' },
] },
{ heading: 'Latest blog posts', items: [
{ label: 'Auto layout explained', href: '#', description: 'How flexible layouts save hours on every screen.', media: { src: 'https://picsum.photos/seed/apogee-nav-1/288/176', alt: '' } },
{ label: 'Ways to level up your product design', href: '#', description: 'Small habits that make a big difference over a year.', media: { src: 'https://picsum.photos/seed/apogee-nav-2/288/176', alt: '' } },
{ label: 'Synthesise data with affinity diagrams', href: '#', description: 'Turn a wall of notes into findings your team trusts.', media: { src: 'https://picsum.photos/seed/apogee-nav-3/288/176', alt: '' } },
] },
]
/** @composable */
interface Props extends NavigationContent {
/** The bar's fill: the page, a grey band or the brand colour. */
background?: 'page' | 'neutral-faded' | 'primary' | undefined
/** `dark` sets the bar in the dark theme on a light page. */
theme?: 'dark' | undefined
/** The link under the blog posts. @category content */
postsAction?: Action | null
}
const {
brand = 'Example',
links = [
{ label: 'Products', groups },
{ label: 'Services', groups },
{ label: 'Pricing', href: '#' },
{ label: 'Resources', groups },
{ label: 'About', href: '#' },
],
primaryAction = { label: 'Sign up', href: '#' },
secondaryAction = { label: 'Log in', href: '#' },
postsAction = { label: 'All blog posts', href: '#' },
background,
theme,
} = Astro.props
---
<Navbar background={background} data-theme={theme}>
<Link slot="brand" href="/" color="inherit" underline="none" class="inline-flex items-center gap-2 text-lg font-semibold"><FeaturedIcon theme="solid" color="primary" size="small"><Orbit /></FeaturedIcon>{brand}</Link>
{links.map((l) => {
if (!('groups' in l)) return <NavLink href={l.href}>{l.label}</NavLink>
const [list, posts] = l.groups
return (
<NavDropdown label={l.label} width="48rem">
<div class="grid md:grid-cols-[minmax(0,1fr)_minmax(0,1.2fr)]">
{list && <div class="flex flex-col gap-2 p-3">{list.heading && <p class="px-3 text-sm font-semibold text-primary">{list.heading}</p>}<ul class="list-none p-0 flex flex-col gap-0.5">
{list.items.map((i, n) => {
const Icon = icons[n % icons.length]!
return (
<li>
<Link href={i.href} color="inherit" underline="none" class="flex gap-3 rounded-lg p-3 transition-colors hover:bg-neutral-faded">
<Icon class="mt-0.5 size-5 shrink-0 text-primary" aria-hidden="true" />
<span class="flex flex-col gap-1">
<span class="flex flex-wrap items-center gap-2 font-semibold">{i.label}{i.badge && <Badge size="small" color={i.badge === 'New' ? 'neutral' : 'positive'} variant="faded">{i.badge}</Badge>}</span>
{i.description && <span class="line-clamp-2 text-sm text-neutral-faded">{i.description}</span>}
</span>
</Link>
</li>
)})}
</ul></div>}
{posts && <div class="flex flex-col gap-2 bg-neutral-faded p-3">
{posts.heading && <p class="px-3 text-sm font-semibold text-primary">{posts.heading}</p>}
<ul class="list-none p-0 flex flex-col gap-1">
{posts.items.map((p) => (
<li>
<Link href={p.href} color="inherit" underline="none" class="flex gap-4 rounded-lg p-2 transition-colors hover:bg-neutral-faded">
{p.media && <Image src={p.media.src} alt={p.media.alt} width={288} height={176} fit="cover" radius="md" class="h-[5.5rem] w-36 shrink-0" />}
<span class="flex flex-col gap-1">
<span class="line-clamp-2 font-semibold">{p.label}</span>
{p.description && <span class="line-clamp-2 text-sm text-neutral-faded">{p.description}</span>}
</span>
</Link>
</li>
))}
</ul>
{postsAction && <Link href={postsAction.href} class="mx-3 inline-flex items-center gap-1.5 text-sm font-semibold">{postsAction.label}<ArrowRight class="size-4 rtl:-scale-x-100" aria-hidden="true" /></Link>}
</div>}
</div>
</NavDropdown>
)
})}
{secondaryAction && <Button slot="actions" href={secondaryAction.href} variant="outline" color="neutral" size="small">{secondaryAction.label}</Button>}
{primaryAction && <Button slot="actions" href={primaryAction.href} size="small">{primaryAction.label}</Button>}
</Navbar>Add
npx @ava-ui/apogee add header-navigation/dropdown-featured-posts
This copies the block to src/components/apogee/blocks/header-navigation/ with everything it uses: Badge, Button, FeaturedIcon, Image, Link, NavDropdown, NavLink, Navbar. Every piece of copy is a prop, with the sample copy as its default. Pass yours, or null to hide a part; see copy is props.
Accessibility
- Each menu is a button with a native popover: Esc or a click outside closes it and focus returns to the button. On phones the menus are rows that expand inside the menu. No JS is needed for either.
- Photos that only decorate have an empty
alt; give yours one when it carries meaning.
Related
NavbarA responsive site header that collapses its links into a mobile panel below the md breakpoint.
NavDropdownA Navbar item that opens a panel of links; a popover under the button or across the header on desktop, a row that expands in the phone menu.
NavLinkA navigation link that auto-detects and styles the current route, with prefix matching, external links and a collapsible NavGroup.