Dynamic Scroll Island Filter

A dynamic Table of Contents, crafted in React's grace, with scrolling magic and animations fair. It tracks thy progress, marks each chosen place; perfect for pages long—thy reader's guide with flair!



All

image
image
image
image
image
image
image
image
image
image
image
image
image
image
image
image
image
image
image
image
image

Installation



Understanding the Component

The DynamicToc component manages a table-of-contents (TOC) with interactive and animated behavior:


  1. State Management:

    • Uses local state to track whether the TOC is open (open) and the currently selected TOC item (value).
    • Listens for the Escape key to close the TOC.
  2. Animation & Layout:

    • Uses the motion library to animate transitions for opening/closing the overlay and the TOC panel.
    • The component toggles between a compact view and an expanded view using animated layout transitions with predefined keys for smooth motion.
  3. UI Elements:

    • Text Section: Displays the selected TOC item's name alongside a circular progress indicator that animates based on scroll position.
    • Progress Indicator: Shows a percentage or an icon based on the selection; updates as the user scrolls.
    • Items List: Renders a list of TOC items. Hover and click interactions change the opacity for visual feedback.
    • Overlay: When open, a backdrop is rendered to focus user interaction on the TOC and enable closing via clicking outside.
  4. Scroll Integration:

    • Uses hooks like useScroll, useSpring, and useTransform to bind scroll progress to the SVG animation, creating a visual representation of scroll progress around a circle.

Props

PropTypeDefaultDescription
valueTOC_INTERFACEnoneThe currently selected TOC item.
setValue(v: TOC_INTERFACE) => voidnoneCallback to update the selected TOC item.
dataTOC_INTERFACE[]noneArray of TOC items used to render the list of selectable items.
refanynoneReference to the container used for tracking scroll progress.
transitionTransition{ type: "spring", duration: 0.5, bounce: 0.1 }Configuration for the animation transitions.
classNamestringnoneAdditional CSS classes for custom styling of the component.

TOC_INTERFACE (exported)

PropTypeDefaultDescription
namestringnoneTitle or label of the TOC item.
valuestringnoneOptional value associated with the TOC item.