Cards Stack

PreviousNext

Stack of cards to showcase a related set of element, like your services, your work, features, process of work, timeline, etc.

Docs
systaliko-uiblock

Preview

Loading preview…
registry/cards/cards-stack/index.tsx
'use client';

import * as React from 'react';
import { HTMLMotionProps, motion } from 'motion/react';

import { cn } from '@/lib/utils';

interface CardStickyProps extends HTMLMotionProps<'div'> {
  index?: number;
  incrementY?: number;
  incrementZ?: number;
}

export const CardsStackContainer = React.forwardRef<
  HTMLDivElement,
  React.HTMLProps<HTMLDivElement>
>(({ children, className, ...props }, ref) => {
  return (
    <div
      ref={ref}
      className={cn('relative w-full', className)}
      style={{ perspective: '1000px', ...props.style }}
      {...props}
    >
      {children}
    </div>
  );
});
CardsStackContainer.displayName = 'CardsStackContainer';

export const CardSticky = React.forwardRef<HTMLDivElement, CardStickyProps>(
  (
    {
      index = 1,
      incrementY = 10,
      incrementZ = 10,
      children,
      className,
      style,
      ...props
    },
    ref,
  ) => {
    const y = index * incrementY;
    const z = index * incrementZ;

    return (
      <motion.div
        ref={ref}
        layout="position"
        style={{
          top: y,
          z,
          backfaceVisibility: 'hidden',
          ...style,
        }}
        className={cn('sticky', className)}
        {...props}
      >
        {children}
      </motion.div>
    );
  },
);
CardSticky.displayName = 'CardSticky';

Installation

npx shadcn@latest add @systaliko-ui/cards-stack

Usage

import { CardsStack } from "@/components/cards-stack"
<CardsStack />