Proximity Sidebar
rare-ui/proximity-sidebarFreeComponent
A dash-style scroll sidebar whose items expand as the pointer approaches.
Install it
npx shadcn@latest add https://rareui.com/r/proximity-sidebar.jsonSource
1"use client"23import React, {4 useCallback,5 useEffect,6 useMemo,7 useRef,8 useState,9} from "react"10import {11 motion,12 useMotionValue,13 useReducedMotion,14 useSpring,15 useTransform,16 type MotionValue,17} from "motion/react"1819type Side = "left" | "right"20type SectionKind = "title" | "subtitle" | "section" | "body"21type SectionLevel = 1 | 2 | 3 | 4 | 5 | 62223export type ProximitySection = {24 id: string25 label: string26 kind?: SectionKind27 level?: SectionLevel28}2930type DashPreset = {31 base: number32 bump: number33 thickness: number34 className: string35}3637type DashProps = {38 active: boolean39 mouseY: MotionValue<number>40 onSelect: (id: string) => void41 registerDash: (id: string, node: HTMLButtonElement | null) => void42 section: ProximitySection43 sectionKind: SectionKind44 side: Side45}4647type ProximitySidebarProps = {48 activeOffset?: number49 className?: string50 sections: ProximitySection[]51 side?: Side52}5354const RADIUS = 4055const MAX_DASH_WIDTH = 11056const SCROLL_IDLE_RESET_DELAY = 805758const DASH_PRESETS: Record<SectionKind, DashPreset> = {59 title: {60 base: 40,61 bump: 70,62 thickness: 1,63 className: "bg-foreground",64 },65 subtitle: {66 base: 36,67 bump: 64,68 thickness: 1,69 className: "bg-foreground",70 },71 section: {72 base: 30,73 bump: 56,74 thickness: 1,75 className: "bg-muted-foreground/40",76 },77 body: {78 base: 24,79 bump: 50,80 thickness: 1,81 className: "bg-muted-foreground/40",82 },83}8485const getSectionElement = (id: string) =>86 typeof document === "undefined" ? null : document.getElementById(id)8788const getSectionKind = (section: ProximitySection): SectionKind => {89 if (section.kind) return section.kind90 if (section.level === 1) return "title"91 if (section.level === 2) return "subtitle"92 if (section.level === 3) return "section"93 return "body"94}9596const getElementSectionKind = (id: string): SectionKind | undefined => {97 const heading = getSectionElement(id)?.querySelector("h1, h2, h3, h4, h5, h6")98 const tagName = heading?.tagName.toLowerCase()99100 if (tagName === "h1") return "title"101 if (tagName === "h2") return "subtitle"102 if (tagName === "h3") return "section"103 if (tagName) return "body"104}105106const getScrollParent = (element: HTMLElement) => {107 let parent = element.parentElement108109 while (parent) {110 const { overflowY } = window.getComputedStyle(parent)111112 if (/(auto|scroll|overlay)/.test(overflowY)) {113 return parent114 }115116 parent = parent.parentElement117 }118119// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from rare-ui
All 13 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Bounce Sidebarbounce-sidebar | rare-ui | Components | Free | 1 dep | |
| Code Blockcode-block | rare-ui | Components | Free | 3 deps | |
| Duration Pickerduration-picker | rare-ui | Components | Free | 5 deps | |
| Emoji Reactionemoji-reaction | rare-ui | Components | Free | 4 deps | |
| Family Drawerfamily-drawer | rare-ui | Components | Free | 2 deps | |
| Fluid Orbfluid-orb | rare-ui | Components | Free | no deps | |
| Folder Componentfolder-component | rare-ui | Components | Free | 1 dep | |
| GitHub Activitygithub-activity | rare-ui | Components | Free | 1 dep |
