All components · Category: Navigation
Shrinking header
A header that slims down when the page scrolls and grows back at the top.
Smaller padding, a smaller logo and a soft shadow once the visitor scrolls, and back again at the top, with a small margin so it never flickers at the edge. It can scroll a sample page by itself or follow the window.
01
Try it
Props
Generated from the component's manifest and the values above.
index.html
<nav-shrink-header locale="en"></nav-shrink-header>
<script>
const element = document.querySelector("nav-shrink-header");
element.addEventListener("nav-shrink-header:compacted", (event) => {
console.log(event.detail);
});
</script>
- Add the site's Taggor script once; the component appears when it loads.
taggor-component.js
const element = document.createElement("nav-shrink-header");
element.setAttribute("locale", "en");
element.addEventListener("nav-shrink-header:compacted", (event) => {
console.log(event.detail);
});
document.body.append(element);
- Add the site's Taggor script once; the component appears when it loads.
NavShrinkHeader.tsx
import { useEffect, useRef } from "react";
export function NavShrinkHeader() {
const ref = useRef<HTMLElement>(null);
useEffect(() => {
const element = ref.current;
if (!element) return;
const onCompacted = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("nav-shrink-header:compacted", onCompacted);
return () => {
element.removeEventListener("nav-shrink-header:compacted", onCompacted);
};
}, []);
return <nav-shrink-header ref={ref} locale="en" />;
}
- Add the site's Taggor script once; the component appears when it loads.
- React 18 sends every prop of a custom element as a text attribute.
- The event is heard with addEventListener, inside an effect.
NavShrinkHeader.tsx
import { useEffect, useRef } from "react";
export function NavShrinkHeader() {
const ref = useRef<HTMLElement>(null);
useEffect(() => {
const element = ref.current;
if (!element) return;
const onCompacted = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("nav-shrink-header:compacted", onCompacted);
return () => {
element.removeEventListener("nav-shrink-header:compacted", onCompacted);
};
}, []);
return <nav-shrink-header ref={ref} locale="en" />;
}
- Add the site's Taggor script once; the component appears when it loads.
- React 19 sets a property when the element already has it, an attribute otherwise.
- The event is heard with addEventListener, inside an effect.
src/NavShrinkHeader.vue
<script setup lang="ts">
function onCompacted(event: Event) {
console.log((event as CustomEvent).detail);
}
</script>
<template>
<nav-shrink-header locale="en" @nav-shrink-header:compacted="onCompacted" />
</template>
vite.config.ts
import vue from "@vitejs/plugin-vue";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: (tag) => tag === "nav-shrink-header",
},
},
}),
],
});
- Add the site's Taggor script once; the component appears when it loads.
- vite.config.ts tells Vue that this tag is not a Vue component.
src/app/nav-shrink-header.component.ts
import { afterNextRender, Component, CUSTOM_ELEMENTS_SCHEMA, DestroyRef, ElementRef, inject } from "@angular/core";
@Component({
selector: "app-nav-shrink-header",
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<nav-shrink-header locale="en"></nav-shrink-header>
`,
})
export class NavShrinkHeaderComponent {
constructor() {
const host = inject<ElementRef<HTMLElement>>(ElementRef);
const element = () => host.nativeElement.querySelector("nav-shrink-header");
const onCompacted = (event: Event) => {
console.log((event as CustomEvent).detail);
};
afterNextRender(() => element()?.addEventListener("nav-shrink-header:compacted", onCompacted));
inject(DestroyRef).onDestroy(() => element()?.removeEventListener("nav-shrink-header:compacted", onCompacted));
}
}
- Add the site's Taggor script once; the component appears when it loads.
- The component declares CUSTOM_ELEMENTS_SCHEMA.
- The event is heard with addEventListener, inside an effect.
src/TaggorComponent.svelte
<script>
function onCompacted(event) {
console.log(event.detail);
}
</script>
<nav-shrink-header locale="en" onnav-shrink-header:compacted={onCompacted}></nav-shrink-header>
- Add the site's Taggor script once; the component appears when it loads.
How an agent gets a component like this onto a site:
taggor checktaggor publishThe CSS variables the component exposes, set the way a customer's page would.
styles.css
nav-shrink-header {
--ns-radius: 16px;
}02
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| brand | string | Acme Studio | The name on the left. |
| mode | box | page | box | box scrolls a sample page inside the component; page follows the window scroll. |
| compact | boolean | false | Starts compact (the picture of a scrolled page). |
| locale | pt-BR | en | en | – |
Prop names and descriptions are the component's own, in English, as its author wrote them.
03
Events
| Event | When it fires |
|---|---|
| compacted | The header went compact or expanded. |
04
Build one with your agent
Build me a Taggor component like "Shrinking header" (nav-shrink-header): A header that slims down when the page scrolls and grows back at the top.
Fetch https://taggor.dev/agent-setup/prompt.md and follow its instructions to set me up for Taggor. Ask me before you sign in, create an account, accept terms, pay for anything or type a secret.
Check it with `taggor check` and publish it with `taggor publish`, and stop there.
Do not promote it to production, attach it to a site, roll back anything or use --yes, --force or --force-drop-invalid unless I ask for exactly that in this conversation.
05
Related components
- Mega menu<nav-mega-menu>
- Morphing drawer menu<nav-drawer-morph>
- Breadcrumb trail<breadcrumb-trail>