# Tech Orbit
*URL: https://www.grettech.com/components/tech-orbit*

Your tech stack on orbiting rings. Hover or focus a logo to pause its ring and see its name. Pure CSS, server-rendered.

- Any number of rings, each with its own speed and direction
- Logos stay upright while the rings turn
- Hover or keyboard focus pauses the ring and shows a label
- No JavaScript; a plain list for screen readers; still with reduced motion

## Install with the shadcn CLI
```bash
npx shadcn@latest add https://www.grettech.com/api/registry/tech-orbit
```
With its demo: `npx shadcn@latest add https://www.grettech.com/api/registry/tech-orbit-demo`

**Dependencies:** npm: clsx, tailwind-merge

## Manual installation
**Step 1: Install dependencies**
Install the packages this component uses and the shadcn/ui components it builds on. It also needs the `cn` helper in `lib/utils.ts`, which `npx shadcn@latest init` adds.

```bash
npm install clsx tailwind-merge
```

**Step 2: Copy the source code**
Add these files to your project components directory.

File: `components/ui/tech-orbit.tsx`
```tsx
import { cn } from "@/lib/utils"
import * as React from "react"

export interface OrbitItem {
  name: string
  /** Logo URL… */
  src?: string
  /** …or any icon element */
  icon?: React.ReactNode
  href?: string
  /** Inverts a dark logo in dark mode */
  invertOnDark?: boolean
}

export interface OrbitRing {
  items: OrbitItem[]
  /** Seconds per revolution */
  duration?: number
  /** Spin counter-clockwise */
  reverse?: boolean
}

export interface TechOrbitProps extends React.HTMLAttributes<HTMLDivElement> {
  /** Innermost ring first */
  rings: OrbitRing[]
  /** Content in the middle, e.g. your logo */
  center?: React.ReactNode
  /** Width of the whole orbit in px; shrinks to fit narrower containers */
  size?: number
  /** Size of each logo bubble in px */
  itemSize?: number
  /** Accessible name of the list */
  label?: string
}

/**
 * Pure CSS: rings spin with Tailwind's animate-spin at their own speed, and
 * each logo spins back the other way so it stays upright. Hovering or
 * focusing a logo pauses its ring. No JavaScript, so it renders on the server.
 */
export const TechOrbit = React.forwardRef<HTMLDivElement, TechOrbitProps>(
  (
    {
      rings,
      center,
      size = 420,
      itemSize = 44,
      label = "Tech stack",
      className,
      style,
      ...props
    },
    ref
  ) => {
    return (
      <div
        ref={ref}
        className={cn("relative mx-auto aspect-square max-w-full", className)}
        // Everything inside is absolutely positioned, so the width is set
        // here rather than coming from the content
        style={{ width: size, padding: itemSize / 2, ...style }}
        {...props}
      >
        <div className="relative size-full">
          {center && (
            <div className="absolute top-1/2 left-1/2 z-10 flex size-[24%] -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full border bg-background shadow-sm">
              {center}
            </div>
          )}

          <ul aria-label={label} className="contents">
            {rings.map((ring, r) => {
              // Rings spread from 40% to 100% of the size
              const diameter =
                rings.length === 1 ? 100 : 40 + (60 * r) / (rings.length - 1)
              const duration = `${ring.duration ?? 30 + r * 15}s`
              const direction = ring.reverse ? "reverse" : "normal"
              const counter = ring.reverse ? "normal" : "reverse"
              return (
                // While one of its logos is hovered or focused, the ring rises
                // above the centre (z-10) and the other rings, so the label
                // isn't covered
                <li
                  key={r}
                  className="group/ring pointer-events-none absolute top-1/2 left-1/2 z-0 -translate-x-1/2 -translate-y-1/2 rounded-full border border-dashed border-foreground/15 focus-within:z-20 hover:z-20"
                  style={{ width: `${diameter}%`, height: `${diameter}%` }}
                >
                  <ul
                    className="relative size-full animate-spin group-focus-within/ring:[animation-play-state:paused] group-hover/ring:[animation-play-state:paused] motion-reduce:animate-none"
                    style={{
                      animationDuration: duration,
                      animationDirection: direction,
                    }}
                  >
                    {ring.items.map((item, i) => {
                      // Even spacing around the ring, starting at the top
                      const angle = (2 * Math.PI * i) / ring.items.length
                      const Tag = item.href ? "a" : "span"
                      return (
                        <li
                          key={`${item.name}-${i}`}
                          // Above its neighbours on the same ring when active
                          className="absolute focus-within:z-10 hover:z-10"
                          style={{
                            // Rounded so server and browser write the
                            // same value (avoids a hydration mismatch)
                            left: `${(50 + 50 * Math.sin(angle)).toFixed(3)}%`,
                            top: `${(50 - 50 * Math.cos(angle)).toFixed(3)}%`,
                          }}
                        >
                          <Tag
                            {...(item.href
                              ? {
                                  href: item.href,
                                  target: "_blank",
                                  rel: "noopener noreferrer",
                                }
                              : { tabIndex: 0, role: "img" })}
                            aria-label={item.name}
                            // Spins against the ring so the logo stays upright
                            className="group/item pointer-events-auto absolute flex -translate-x-1/2 -translate-y-1/2 animate-spin items-center justify-center rounded-full border bg-background shadow-sm transition-shadow group-focus-within/ring:[animation-play-state:paused] group-hover/ring:[animation-play-state:paused] hover:shadow-md focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none motion-reduce:animate-none"
                            style={{
                              width: itemSize,
                              height: itemSize,
                              animationDuration: duration,
                              animationDirection: counter,
                            }}
                          >
                            {item.src ? (
                              // eslint-disable-next-line @next/next/no-img-element
                              <img
                                src={item.src}
                                alt=""
                                loading="lazy"
                                className={cn(
                                  "size-[55%] object-contain",
                                  item.invertOnDark && "dark:invert"
                                )}
                              />
                            ) : (
                              <span
                                aria-hidden="true"
                                className="flex size-[55%] items-center justify-center [&_svg]:size-full"
                              >
                                {item.icon}
                              </span>
                            )}
                            <span
                              aria-hidden="true"
                              className="pointer-events-none absolute top-full left-1/2 mt-1.5 -translate-x-1/2 rounded-md bg-foreground px-2 py-0.5 text-[11px] font-medium whitespace-nowrap text-background opacity-0 transition-opacity group-hover/item:opacity-100 group-focus-visible/item:opacity-100"
                            >
                              {item.name}
                            </span>
                          </Tag>
                        </li>
                      )
                    })}
                  </ul>
                </li>
              )
            })}
          </ul>
        </div>
      </div>
    )
  }
)
TechOrbit.displayName = "TechOrbit"

```

**Step 3: Framework Adjustments (Optional)**
If you are manually copying this code into a Vite or Remix project (without using the CLI), make sure to remove the `"use client";` directive from the very top of the file.

## Props
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| `rings` | `OrbitRing[]` | - | Yes | Innermost ring first. |
| `rings.items` | `OrbitItem[]` | - | Yes | Logos on the ring: { name, src?, icon?, href?, invertOnDark? }. name is the label and accessible name; use src for a logo URL or icon for any element; href makes it a link; invertOnDark flips dark logos in dark mode. |
| `rings.items.name` | `string` | - | Yes | - |
| `rings.items.src` | `string` | - | No | Logo URL… |
| `rings.items.icon` | `React.ReactNode` | - | No | …or any icon element |
| `rings.items.href` | `string` | - | No | - |
| `rings.items.invertOnDark` | `boolean` | - | No | Inverts a dark logo in dark mode |
| `rings.duration` | `number` | `30 + 15 × ring index` | No | Seconds per revolution. |
| `rings.reverse` | `boolean` | - | No | Spin counter-clockwise. |
| `center` | `React.ReactNode` | - | No | Content in the middle, e.g. your logo. |
| `size` | `number` | `420` | No | Width of the orbit in px. It shrinks to fit narrower containers. |
| `itemSize` | `number` | `44` | No | Size of each logo bubble in px. |
| `label` | `string` | `"Tech stack"` | No | Accessible name of the list. |
| `className` | `string` | - | No | Extra classes for the root element. |
| `...props` | `React.HTMLAttributes<HTMLDivElement>` | - | No | Any other attributes, passed to the root element. |

## Usage
```tsx
"use client"

import { TechOrbit, type OrbitRing } from "@/components/ui/tech-orbit"

// Logos from devicon (https://devicon.dev)
const RINGS: OrbitRing[] = [
  {
    duration: 28,
    items: [
      {
        name: "React",
        src: "https://cdn.jsdelivr.net/gh/devicons/devicon@v2.16.0/icons/react/react-original.svg",
      },
      {
        name: "Next.js",
        src: "https://cdn.jsdelivr.net/gh/devicons/devicon@v2.16.0/icons/nextjs/nextjs-original.svg",
        invertOnDark: true,
      },
      {
        name: "TypeScript",
        src: "https://cdn.jsdelivr.net/gh/devicons/devicon@v2.16.0/icons/typescript/typescript-original.svg",
      },
      {
        name: "Tailwind CSS",
        src: "https://cdn.jsdelivr.net/gh/devicons/devicon@v2.16.0/icons/tailwindcss/tailwindcss-original.svg",
      },
    ],
  },
  {
    duration: 44,
    reverse: true,
    items: [
      {
        name: "Node.js",
        src: "https://cdn.jsdelivr.net/gh/devicons/devicon@v2.16.0/icons/nodejs/nodejs-original.svg",
      },
      {
        name: "PostgreSQL",
        src: "https://cdn.jsdelivr.net/gh/devicons/devicon@v2.16.0/icons/postgresql/postgresql-original.svg",
      },
      {
        name: "Figma",
        src: "https://cdn.jsdelivr.net/gh/devicons/devicon@v2.16.0/icons/figma/figma-original.svg",
      },
      {
        name: "Docker",
        src: "https://cdn.jsdelivr.net/gh/devicons/devicon@v2.16.0/icons/docker/docker-original.svg",
      },
      {
        name: "Vercel",
        src: "https://cdn.jsdelivr.net/gh/devicons/devicon@v2.16.0/icons/vercel/vercel-original.svg",
        invertOnDark: true,
      },
      {
        name: "GitHub",
        src: "https://cdn.jsdelivr.net/gh/devicons/devicon@v2.16.0/icons/github/github-original.svg",
        invertOnDark: true,
      },
    ],
  },
]

export default function TechOrbitDemo() {
  return (
    <div className="p-4">
      <TechOrbit
        rings={RINGS}
        center={
          <span className="text-sm font-semibold tracking-tight">
            Our stack
          </span>
        }
      />
    </div>
  )
}

```
