New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@sofidevo/astro-dynamic-header

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sofidevo/astro-dynamic-header

A dynamic Astro header component that switches between floating and fullscreen styles

latest
Source
npmnpm
Version
2.0.2
Version published
Maintainers
1
Created
Source

@sofidevo/astro-dynamic-header

A dynamic, responsive header component for Astro projects that can switch between floating and fullscreen styles with multi-level dropdown navigation support.

[!WARNING] Breaking Changes: Version 2.0+ introduces a restructured configuration object. If you are upgrading from an older version, please review the Component Props and the Comprehensive Example to migrate your configuration.

Features

  • Dynamic Styles: Switch between floating and fullscreen header layouts
  • Fully Responsive: Mobile-first design with hamburger menu
  • Multi-level Dropdowns: Support for nested navigation menus
  • Slot Support: Customizable slots for desktop header and mobile panel content
  • TypeScript Support: Full type safety and IntelliSense
  • Customizable: Extensive customization options for colors, sizes, and behavior
  • Astro Optimized: Built specifically for Astro framework

Live demo

https://base-astro-psi.vercel.app/fullscreen-demo

Installation

 npm i @sofidevo/astro-dynamic-header

Required Dependencies

You need to add the Iconify CDN to the head of your project for the hamburger menu icons to work properly:

<script src="https://code.iconify.design/iconify-icon/3.0.0/iconify-icon.min.js"></script>

Add this to your main layout or in the <head> section of your Astro pages.

Quick Start

Basic Usage (Automatic Theme)

By default, the header uses preset="auto", which automatically detects the theme based on a .dark class on your root element (html or body).

---
import Header from '@sofidevo/astro-dynamic-header/Header';


const =  menuItems: [
    { link: '/about', text: 'About' },
  ]

---

<!-- Detects .dark class on root automatically -->
<Header navigation={{ menuItems }} />

Advanced Usage (Dual-Theme Customization)

You can provide custom colors for both light and dark modes simultaneously.


---
import Header from '@sofidevo/astro-dynamic-header/Header';
const navigation = {
  menuItems: [
    { link: '/about', text: 'About' },
  ]
};
const theme = {
  light: {
    accentColor: "#3e1c71",
    backgroundColor: "rgba(255, 255, 255, 0.8)"
  },
  dark: {
    accentColor: "#00ffff",
    backgroundColor: "rgba(20, 20, 20, 0.9)"
  }
};
---

<Header
  preset="auto"
  theme={theme}
  navigation={navigation}
/>

Component Props

Header Component

PropTypeDefaultDescription
headerType"floating" | "fullscreen""floating"Header layout style
preset"light" | "dark" | "auto""auto"Theme behavior. auto follows root class.
logoLogoConfig{}Logo configuration object
navigationNavConfig{}Navigation configuration object
themeDualThemeConfig{}Custom theme overrides for light/dark
classNamesCustomClassNames{}Custom class names for CSS Modules

Config Objects

DualThemeConfig

ProperyTypeDescription
lightThemeConfigStyles applied in light mode
darkThemeConfigStyles applied in dark mode

ThemeConfig

ProperyTypeDefault
backgroundColorstringPreset default
backgroundColorOpaquestringPreset default
backdropBlurstring"blur(20px)"
zIndexnumber10
textColorstringPreset default
accentColorstringPreset default

[!IMPORTANT] Transparency vs Solid Submenus: To ensure the best UI and avoid rendering bugs with backdrop-filter on nested elements, submenus and the mobile navigation panel are solid/opaque.

If you use a transparent backgroundColor (e.g., rgba), remember to also provide its solid counterpart in backgroundColorOpaque.

<Header theme={{
  light: {
    backgroundColor: "rgba(255, 255, 255, 0.7)", // Transparent header body
    backgroundColorOpaque: "#ffffff",            // Solid submenus
  }
}} />

CustomClassNames

The classNames prop allows you to inject custom CSS classes (such as Tailwind CSS utility classes) into specific high-level elements of the Header component. This provides a bridge between the component's internal styles and your project's global styling system.

PropertyTarget ElementPurpose & Common Use Cases
containerOuter div wrapping the headerPositioning & Layout: Use for top-0, z-50, fixed, or adjusting the max-width and mx-auto logic.
headerInner <header> elementAppearance: The best place for shadows (shadow-md), borders (border-b), or custom transition durations.
logo<a> tag surrounding the logoInteractions: Add hover states, custom focus rings, or adjust the flex alignment of the logo group.
logoText<span> tag containing the logo textTypography: Override font weights, apply text shadows, or use specific tracking/leading classes.
navdiv wrapping the desktop navigation itemsDesktop Layout: Adjust spacing between the logo and the menu, or add responsive visibility classes (hidden md:flex).
Advanced Usage Examples

Implementing a Premium Shadow & Border (Tailwind): Ideal for creating a modern "glass" effect with a subtle border and shadow that adapts to dark mode.

<Header 
  classNames={{ 
    header: "shadow-xl border-b border-black/5 dark:border-white/10 transition-all duration-500",
    container: "top-4 px-6"
  }} 
/>

Custom Typography for Logo & Nav Spacing: Perfect for matching the header with your brand's specific typography and layout requirements.

<Header 
  classNames={{ 
    logoText: "tracking-tighter font-black italic uppercase",
    nav: "ml-auto gap-8" /* Moves menu to the right and increases gap */
  }} 
/>

[!TIP] Since these classes are injected using Astro's class:list, you can also pass objects or arrays if you need conditional logic for your custom classes.

LogoConfig

PropertyTypeDescription
srcstringURL of the logo image
altstringAlternative text for the logo image
widthstringWidth of the logo (e.g., "50px", "5rem")
textstringText to display next to or instead of logo image
textSizestringFont size for the logo text
textColorstringColor for the logo text

NavConfig

PropertyTypeDescription
homeUrlstringURL for the home link (defaults to /)
menuItemsMenuItem[]Array of navigation menu items

MenuItem

PropertyTypeDescription
linkstringURL the menu item points to
textstringLabel text for the menu item
submenuSecondaryMenuItem[]Optional array of nested menu items

Slots Support

The Header component provides a flexible slot system that allows you to add additional content:

Available Slots

Slot NameLocationVisibilityDescription
actionsHeader & Mobile panelResponsive visibilityAdd action buttons (login, signup, etc.)

Example with Slots

---
import Header from '@sofidevo/astro-dynamic-header/Header';

const navigation = {
  menuItems: [{ link: '/about', text: 'About' }]
};
---

<Header navigation={navigation}>
  <div slot="actions">
    <button class="login-btn">Login</button>
  </div>
</Header>

Comprehensive Example

Below is a complete implementation example showcasing custom logo configuration, navigation with a home URL, and theme overrides.

---
import Header from '@sofidevo/astro-dynamic-header/Header';

const menuItems = [
  {
    link: "#",
    text: "Services",
    submenu: [
      { link: "/design", text: "Design" },
      { link: "/consulting", text: "Consulting" },
      {
        link: "#",
        text: "Web Development",
        submenu: [
          { link: "/web/frontend", text: "Frontend" },
          { link: "/web/backend", text: "Backend" },
          { link: "/web/fullstack", text: "Full Stack" },
        ],
      },
    ],
  },
  { link: "/about", text: "About" },
  { link: "/contact", text: "Contact" },
];

const theme = {
  light: {
    accentColor: "#ff0000",
    backgroundColor: "rgba(255, 255, 255, 0.8)",
  },
  dark: {
    accentColor: "#00ffff",
    backgroundColor: "rgba(20, 20, 20, 0.9)",
  },
};
---

<Header
  headerType="floating"
  preset="dark"
  logo={{
    src: "https://itssofi.dev/img/icons/sofi-icon.webp",
    alt: "My Site Logo",
    width: "44px",
  }}
  navigation={{
    homeUrl: "/",
    menuItems: menuItems,
  }}
  theme={theme}
>
  <button slot="actions">Login</button>
</Header>

Header Types

Floating Header

  • Centered with max-width constraint
  • Rounded corners
  • Padding around container
  • Perfect for modern, card-like designs

Fullscreen Header

  • Full viewport width
  • No border radius
  • Edge-to-edge design
  • Ideal for traditional website layouts

Styling and Customization

The component uses CSS custom properties that you can override:

:root {
  --light-spot-color: #00ffff;
  --color-tertiary: #ffffff;
  --color-hamburger-lines: #ffffff;
}

TypeScript Support

The package provides full TypeScript support. You can import types to ensure your configuration is correct:

---
import Header from '@sofidevo/astro-dynamic-header/Header';
import type {
  NavConfig,
  DualThemeConfig,
  MenuItem,
  SecondaryMenuItem
} from '@sofidevo/astro-dynamic-header';

const navigation: NavConfig = {
  menuItems: [
    {
      link: '/products',
      text: 'Products',
      submenu: [
        { link: '/software', text: 'Software' },
        { link: '/hardware', text: 'Hardware' }
      ]
    }
  ]
};

const theme: DualThemeConfig = {
  light: {
    accentColor: "#3e1c71",
    backgroundColor: "rgba(255, 255, 255, 0.8)",
    backgroundColorOpaque: "#ffffff"
  },
  dark: {
    accentColor: "#00ffff",
    backgroundColor: "rgba(10, 10, 10, 0.9)",
    backgroundColorOpaque: "#0a0a0a"
  }
};
---

<Header
  navigation={navigation}
  theme={theme}
  preset="auto"
/>

Available Types

TypeDescription
MenuItemTop-level menu item with optional properties
SecondaryMenuItemSecond-level menu item
TertiaryMenuItemThird-level menu item
NavConfigMain navigation configuration object
ThemeConfigIndividual theme settings (colors, blur, etc.)
DualThemeConfigCombined settings for light and dark modes
LogoConfigLogo image and text configuration
HeaderPropsMain props for the Header component

Browser Support

  • All modern browsers (Chrome, Firefox, Safari, Edge)
  • Mobile responsive design with optimized touch targets
  • Supports CSS backdrop-filter for glassmorphism
  • Automatic theme switching based on OS or site preference via .dark class

Troubleshooting

Import Issues

If you encounter import errors, try these solutions:

  • Use direct subpath import:

    import Header from '@sofidevo/astro-dynamic-header/Header';
    
  • Check relative imports in TS: In some environments (like node16), you might need to use the .js extension even for TypeScript files when importing from the package internals, though the main entry point handles this for you.

  • Verify TypeScript configuration:

    // tsconfig.json
    {
      "compilerOptions": {
        "moduleResolution": "bundler",
        "allowImportingTsExtensions": true
      }
    }
    

Compatibility

  • Astro 4.x and 5.x
  • SSG Projects (Static Site Generation)
  • SSR Projects (Server-Side Rendering)
  • Hybrid Projects (output: 'hybrid')

Live Examples

Visit our demo website to see the component in action with interactive examples and complete documentation.

License

MIT License - see the LICENSE file for details.

Support

If you find this package helpful, please consider giving it a star on GitHub!

Keywords

astro

FAQs

Package last updated on 20 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts