aktonay/skillz / skills/design/react-bits
react-bits
VerifiedOver 215+ animated, interactive, copy-paste React micro-components and effects (text animations, interactive backgrounds, physics cards, custom cursors, blobs, and dock bars).
src/components/common/FluidMenuContent.jsx
View on GitHubimport { useLayoutEffect, useRef, useState } from 'react';
import { Menu, Select, useMenuContext, useSelectContext } from '@chakra-ui/react';
import { motion, useReducedMotion } from 'motion/react';
const ITEM_CSS = {
'& [data-part="item"]': {
position: 'relative',
zIndex: 1,
bg: 'transparent',
_hover: { bg: 'transparent' },
_highlighted: { bg: 'transparent' }
}
};
const useFluidHighlight = (open, highlightedValue) => {
const contentRef = useRef(null);
const [highlight, setHighlight] = useState(null);
useLayoutEffect(() => {
if (!open) {
setHighlight(null);
return;
}
if (!highlightedValue) return;
const content = contentRef.current;
const item = content?.querySelector('[data-part="item"][data-highlighted]');
if (!item) return;
const update = activate => {
setHighlight(previous => {
const next = {
x: item.offsetLeft,
y: item.offsetTop,
width: item.offsetWidth,
height: item.offsetHeight,
visible: activate || previous?.visible || false
};
return previous && Object.keys(next).every(key => previous[key] === next[key]) ? previous : next;
});
};
update(true);
const observer = new ResizeObserver(() => update(false));
observer.observe(content);
observer.observe(item);
return () => observer.disconnect();
}, [open, highlightedValue]);
const reveal = () => {
setHighlight(previous => (previous && !previous.visible ? { ...previous, visible: true } : previous));
};
const handlers = {
onPointerMove: event => {
if (event.pointerType === 'mouse' && event.target.closest('[data-part="item"]:not([data-disabled])')) {
reveal();
}
},
onKeyDown: reveal,
onPointerLeave: () => setHighlight(previous => (previous ? { ...previous, visible: false } : previous))
};
return { contentRef, highlight, handlers };
};
const Highlight = ({ highlight }) => {
const reduceMotion = useReducedMotion();
if (!highlight) return null;
return (
<motion.div
aria-hidden="true"
data-menu-highlight=""
initial={false}
animate={{
x: highlight.x,
y: highlight.y,
width: highlight.width,
height: highlight.height,
opacity: highlight.visible ? 1 : 0
}}
transition={
reduceMotion
? { duration: 0 }
: { type: 'spring', stiffness: 550, damping: 42, mass: 0.7, opacity: { duration: 0.12 } }
}
style={{
position: 'absolute',
top: 0,
left: 0,
zIndex: 0,
borderRadius: 9,
background: 'var(--menu-highlight)',
pointerEvents: 'none'
}}
/>
);
};
const withMenuClass = className => (className ? `docs-menu ${className}` : 'docs-menu');
export const FluidSelectContent = ({ children, className, ...props }) => {
const select = useSelectContext();
const { contentRef, highlight, handlers } = useFluidHighlight(select.open, select.highlightedValue);
return (
<Select.Content
{...props}
{...handlers}
className={withMenuClass(className)}
ref={contentRef}
position="relative"
isolation="isolate"
css={ITEM_CSS}
>
{children}
<Highlight highlight={highlight} />
</Select.Content>
);
};
const FluidMenuContent = ({ children, className, ...props }) => {
const menu = useMenuContext();
const { contentRef, highlight, handlers } = useFluidHighlight(menu.open, menu.highlightedValue);
return (
<Menu.Content
{...props}
{...handlers}
className={withMenuClass(className)}
ref={contentRef}
position="relative"
isolation="isolate"
css={ITEM_CSS}
>
{children}
<Highlight highlight={highlight} />
</Menu.Content>
);
};
export default FluidMenuContent;
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |