stack
diceui-radix/stackFreeComponent
diceui/radix publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/sadmann7/diceui/HEAD/docs/public/r/styles/radix-nova/stack.jsonSource
1"use client";23import { cva } from "class-variance-authority";4import { Slot as SlotPrimitive } from "radix-ui";5import * as React from "react";6import { cn } from "@/lib/utils";78interface ItemDimension {9 itemId: number;10 size: number;11}1213type Side = "top" | "bottom";1415function getDataState(isExpanded: boolean) {16 return isExpanded ? "expanded" : "collapsed";17}1819interface StackContextValue {20 side: Side;21 childrenCount: number;22 itemCount: number;23 expandedItemCount: number;24 gap: number;25 scale: number;26 offset: number;27 expandOnHover: boolean;28 isExpanded: boolean;29 isInteracting: boolean;30 dimensions: ItemDimension[];31 setDimensions: React.Dispatch<React.SetStateAction<ItemDimension[]>>;32}3334const StackContext = React.createContext<StackContextValue | null>(null);3536function useStackContext(consumerName: string) {37 const context = React.useContext(StackContext);38 if (!context) {39 throw new Error(`\`${consumerName}\` must be used within \`Stack\``);40 }41 return context;42}4344interface StackProps extends React.ComponentProps<"div"> {45 side?: Side;46 itemCount?: number;47 expandedItemCount?: number;48 gap?: number;49 scale?: number;50 offset?: number;51 expandOnHover?: boolean;52 asChild?: boolean;53}5455function Stack(props: StackProps) {56 const {57 side = "bottom",58 itemCount = 3,59 expandedItemCount,60 gap = 8,61 scale = 0.05,62 offset = 10,63 className,64 children,65 style,66 onMouseEnter: onMouseEnterProp,67 onMouseLeave: onMouseLeaveProp,68 onMouseMove: onMouseMoveProp,69 onPointerDown: onPointerDownProp,70 onPointerUp: onPointerUpProp,71 expandOnHover = false,72 asChild,73 ...rootProps74 } = props;7576 const [isExpanded, setIsExpanded] = React.useState(false);77 const [isInteracting, setIsInteracting] = React.useState(false);78 const [dimensions, setDimensions] = React.useState<ItemDimension[]>([]);7980 const childrenArray = React.Children.toArray(children).filter(81 React.isValidElement,82 );83 const childrenCount = childrenArray.length;8485 const effectiveExpandedItemCount = expandedItemCount ?? childrenCount;8687 const onMouseEnter = React.useCallback(88 (event: React.MouseEvent<HTMLDivElement>) => {89 onMouseEnterProp?.(event);90 if (event.defaultPrevented) return;9192 if (expandOnHover) {93 setIsExpanded(true);94 }95 },96 [expandOnHover, onMouseEnterProp],97 );9899 const onMouseMove = React.useCallback(100 (event: React.MouseEvent<HTMLDivElement>) => {101// … truncated
What it pulls in
npm packages
Files it writes
More from diceui/radix
All 58 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| action-baraction-bar | diceui/radix | Components | Free | 1 dep · 2 files | |
| angle-sliderangle-slider | diceui/radix | Components | Free | 1 dep · 3 files | |
| avatar-groupavatar-group | diceui/radix | Components | Free | 1 dep | |
| badge-overflowbadge-overflow | diceui/radix | Components | Free | 1 dep · 2 files | |
| bannerbanner | diceui/radix | Components | Free | 1 dep | |
| checkbox-groupcheckbox-group | diceui/radix | Components | Free | 1 dep | |
| circular-progresscircular-progress | diceui/radix | Components | Free | 1 dep | |
| client-onlyclient-only | diceui/radix | Components | Free | no deps |
