Navigationduskmoonimplemented5 demos

Anchor

Anchor builds in-page navigation for long documentation or settings screens.

Import@duskmoon-dev/components/anchor
5API sections
22documented props
3behavior scenarios
Key API
itemstargetOffsetboundsoffsetTopgetContainergetCurrentAnchor

Usage

When to use

  • Use it when users need to move between sections, pages, steps, or contextual actions.
  • Expose current and disabled state so navigation remains clear to keyboard and screen-reader users.

Implementation notes

StylesheetImport @duskmoon-dev/components/styles.css once in the app or docs shell.
StateStart with default props for static examples, then switch to controlled props when state must be shared.
ThemeThe preview inherits the active DuskMoon data-theme value from the docs layout.

Features

Wayfinding

Covers the route, section, step, or action-list patterns that help users move through an interface.

Current state

Shows selected, active, open, or current props where the component exposes them.

Primary API surface

Anchor is most often configured through `items`, `targetOffset`, `bounds`, `offsetTop`.

Covered behavior

Renders nested item links and tracks active href on click

Feature Demos

Feature demos are authored for the component page, then supplemented with behavior scenarios from the component test coverage.

Preview

Basic usage

authored

Import the component stylesheet and Anchor from its package subpath, then render it with the core props.

Source
import "@duskmoon-dev/components/styles.css";
import { Anchor } from "@duskmoon-dev/components/anchor";

export function Example() {
  return (<Anchor
  affix={false}
  showInkInFixed
  items={[
    {
      href: "#intro",
      title: "Intro",
      children: [{ href: "#demos", title: "Demos" }]
    }
  ]}
/>);
}
Preview

Renders nested item links and tracks active href on click

test-backed

Anchor scenario from the component test coverage: renders nested item links and tracks active href on click.

Source
import "@duskmoon-dev/components/styles.css";
import { Anchor } from "@duskmoon-dev/components/anchor";

export function AnchorRendersNestedItemLinksDemo() {
  return (<Anchor
  affix={false}
  showInkInFixed
  items={[
    {
      href: "#intro",
      title: "Intro",
      children: [{ href: "#demos", title: "Demos" }]
    }
  ]}
/>);
}
Preview

Supports Anchor.Link children and hash changes

test-backed

Anchor scenario from the component test coverage: supports anchor.link children and hash changes.

Source
import "@duskmoon-dev/components/styles.css";
import { Anchor } from "@duskmoon-dev/components/anchor";

export function AnchorSupportsAnchorLinkChildrenDemo() {
  return (<Anchor
  affix={false}
  showInkInFixed
  items={[
    {
      href: "#intro",
      title: "Intro",
      children: [{ href: "#demos", title: "Demos" }]
    }
  ]}
/>);
}
Preview

Accepts nav props, className, ref, and getCurrentAnchor

test-backed

Anchor scenario from the component test coverage: accepts nav props, classname, ref, and getcurrentanchor.

Source
import "@duskmoon-dev/components/styles.css";
import { Anchor } from "@duskmoon-dev/components/anchor";

export function AnchorAcceptsNavPropsClassNameDemo() {
  return (<Anchor
  affix={false}
  showInkInFixed
  items={[
    {
      href: "#intro",
      title: "Intro",
      children: [{ href: "#demos", title: "Demos" }]
    }
  ]}
/>);
}
Preview
Sunshine Theme
Moonlight Theme

Theme aware

authored

Docs previews inherit the DuskMoon data-theme value. Use the header switch to compare light and dark rendering.

Source
<div data-theme="sunshine">
  <Anchor
  affix={false}
  showInkInFixed
  items={[
    {
      href: "#intro",
      title: "Intro",
      children: [{ href: "#demos", title: "Demos" }]
    }
  ]}
/>
</div>

<div data-theme="moonlight">
  <Anchor
  affix={false}
  showInkInFixed
  items={[
    {
      href: "#intro",
      title: "Intro",
      children: [{ href: "#demos", title: "Demos" }]
    }
  ]}
/>
</div>

API

The API reference below lists every parsed exported type or interface for Anchor. Start with `items`, `targetOffset`, `bounds`, `offsetTop` for common usage.

Types: packages/components/src/components/anchor/Anchor.types.tsScenarios: packages/components/src/components/anchor/Anchor.test.tsx
AnchorPropsinterface extends Omit< ComponentProps<"nav">, "onChange" | "onClick" >
PropTypeRequiredDescription
itemsAnchorItem[]Noitems configures Anchor.
targetOffsetnumberNotargetOffset configures Anchor.
boundsnumberNobounds configures Anchor.
offsetTopnumberNooffsetTop configures Anchor.
getContainer() => Window | HTMLElementNogetContainer configures Anchor.
getCurrentAnchor(activeLink: string) => stringNogetCurrentAnchor configures Anchor.
affixbooleanNoaffix configures Anchor.
showInkInFixedbooleanNoshowInkInFixed configures Anchor.
onClick(NoonClick configures Anchor.
eventMouseEvent<HTMLElement>,Yesevent configures Anchor.
link{ title: ReactNode; href: string },Yeslink configures Anchor.
onChange(currentActiveLink: string) => voidNoonChange configures Anchor.
AnchorIteminterface
PropTypeRequiredDescription
keystringNokey configures Anchor.
hrefstringYeshref configures Anchor.
titleReactNodeYestitle configures Anchor.
targetstringNotarget configures Anchor.
childrenAnchorItem[]Nochildren configures Anchor.
AnchorLinkPropsinterface extends Omit< ComponentProps<"a">, "children" | "href" | "onClick" | "title" >
PropTypeRequiredDescription
hrefstringYeshref configures Anchor.
titleReactNodeYestitle configures Anchor.
targetstringNotarget configures Anchor.
childrenReactNodeNochildren configures Anchor.
onClickComponentProps<"a">["onClick"]NoonClick configures Anchor.
AnchorLinkComponenttype
ForwardRefExoticComponent< AnchorLinkProps & RefAttributes<HTMLAnchorElement> >
AnchorComponenttype
ForwardRefExoticComponent< AnchorProps & RefAttributes<HTMLElement> > & { Link: AnchorLinkComponent