/* eslint-disable react-hooks/rules-of-hooks / "use client"; import { useRef, useState }…
- User
/* eslint-disable react-hooks/rules-of-hooks */ "use client";
import { useRef, useState } from "react";
import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { theme } from "@/lib/theme"; import { cn, colorAlpha } from "@/lib/utils"; import { interpolate, motion, SpringOptions, useMotionValue, useMotionValueEvent, useSpring, useTransform, } from "framer-motion";
// Sigmoid-based decay function export function decay(value: number, max: number) { if (max === 0) { return 0; }
let entry = value / max; let sigmoid = 2 * (1 / (1 + Math.exp(-entry)) - 0.5);
return sigmoid * max; }
type SnapFunction = (value: number) => number;
function snap(points: number | number[], threshold: number): SnapFunction { if (Array.isArray(points)) { // Calculate the snap points for a list of points const snapPoints: number[] = [ points[0] + threshold * (points[1] - points[0]), ]; for (let i = 1; i < points.length - 1; i++) { const snapPoint = points[i] + threshold * (points[i + 1] - points[i]); snapPoints.push(snapPoint); }
codereturn (value: number) => { for (let i = 0; i < snapPoints.length; i++) { if (value <= snapPoints[i]) { return points[i]; } } return points[points.length - 1]; };} else { // Calculate the snap point for a single number const snapPoint = threshold * points;
codereturn (value: number) => { if (value <= snapPoint) { return 0; // Assuming we snap to 0 if below threshold } return points; };} }
const LIST = { HEIGHT: 48, GAP: 0, ITEMS: [ { id: 1, title: "Person 1", }, { id: 2, title: "Person 2", }, { id: 3, title: "Person 3", }, { id: 4, title: "Person 4", }, { id: 5, title: "Person 5", }, { id: 6, title: "Person 6", }, ], };
type Position = { x: number; y: number; width: number; height: number; offset: { y: number; }; };
const Menu = () => { const [open, setOpen] = useState(false); const [activeIndex, setActiveIndex] = useState(-1); const [direction, setDirection] = useState(0);
const containerRef = useRef(null);
const [transit, setTransit] = useState(false);
const indexY = useMotionValue(0);
const selectorY = useMotionValue(0);
const stickyMotionX = useMotionValue(0); const stickyMotionY = useMotionValue(0); const [stickyY, setStickyY] = useState(0); const [stickyX, setStickyX] = useState(0);
const [isOverflow, setIsOverflow] = useState(false);
- Assistant