FreeMIT LicenseFeatured

Media Folder — macOS-Style Draggable Window Desktop for React & Framer Motion

A macOS-style folder for React that bursts open into draggable windows: photos, videos, a working music player, weather and swatches with real traffic lights, focus, minimize and an expanded view. Framer Motion, light/dark themes, keyboard, touch and phone layouts.

by UpFork, built by Ramin ValadanComponentUpdated 26 Oct 2026

Read how it was madePerformance7 lessons
Watch0
Preview of Media Folder — macOS-Style Draggable Window Desktop for React & Framer Motion

Code

32 files · 1 package · 29 assets

"use client";

import { useEffect, useRef, useSyncExternalStore } from "react";
import { useDesktop, useWin } from "../context";
import type { AudioItem } from "../types";

export const clock = (s: number) => {
  const t = Math.max(0, Math.floor(Number.isFinite(s) ? s : 0));
  return `${Math.floor(t / 60)}:${String(t % 60).padStart(2, "0")}`;
};

/**
 * A working player: the cover turns like a record while it plays, play/pause, a scrubber you can drag or use with
 * the arrow keys, and m:ss / m:ss. The <audio> element comes from the desktop's controller, so only one window
 * plays at a time and the expanded view shares the same playhead. The bar and the times are written straight to
 * the DOM every frame while playing: React does not re-render for the clock.
 */
export function AudioContent({ item }: { item: AudioItem }) {
  const w = useWin();
  const { audio } = useDesktop();
  const playing = useSyncExternalStore(audio.subscribe, () => audio.playing() === w.wkey, () => false);
  const bar = useRef<HTMLInputElement>(null);
  const now = useRef<HTMLSpanElement>(null);
  const total = useRef<HTMLSpanElement>(null);

  useEffect(() => {
    const el = audio.get(w.wkey, item.src);
    const length = () => (Number.isFinite(el.duration) && el.duration > 0 ? el.duration : (item.duration ?? 0));
    const paint = () => {
      const d = length();
      const p = d ? Math.min(1, el.currentTime / d) : 0;
      const b = bar.current;
      if (b) {
        if (document.activeElement !== b) b.value = String(Math.round(p * 1000));
        b.style.setProperty("--md-p", `${p * 100}%`);
        b.setAttribute("aria-valuetext", `${clock(el.currentTime)} of ${clock(d)}`);
      }
      if (now.current) now.current.textContent = clock(el.currentTime);
      if (total.current) total.current.textContent = clock(d);
    };
    let raf = 0;
    const loop = () => {
      paint();
      raf = requestAnimationFrame(loop);
    };
    const sync = () => {
      cancelAnimationFrame(raf);
      if (audio.playing() === w.wkey) raf = requestAnimationFrame(loop);
      else paint();
    };
    paint();
    sync();
    el.addEventListener("loadedmetadata", paint);
    el.addEventListener("seeked", paint);
    const off = audio.subscribe(sync);
    return () => {
      cancelAnimationFrame(raf);
      off();
      el.removeEventListener("loadedmetadata", paint);
      el.removeEventListener("seeked", paint);
    };
  }, [audio, w.wkey, item.src, item.duration]);

  const seek = (v: number) => {
    const el = audio.get(w.wkey, item.src);
    const d = Number.isFinite(el.duration) && el.duration > 0 ? el.duration : (item.duration ?? 0);
    if (d) el.currentTime = (v / 1000) * d;
    bar.current?.style.setProperty("--md-p", `${v / 10}%`);
  };

  const tab = w.active ? 0 : -1;
  return (
    <div className="md-audio" data-playing={playing || undefined}>
      <span className="md-record" aria-hidden>
        {/* eslint-disable-next-line @next/next/no-img-element */}
        <img src={item.cover} alt="" width={64} height={64} loading={w.eager ? "eager" : "lazy"} draggable={false} />
      </span>
      <div className="md-audio-main">
        <div className="md-audio-head">
          <div className="md-audio-text">
            <p className="md-track">{item.track}</p>
            {item.artist && <p className="md-artist">{item.artist}</p>}
          </div>
          <button type="button" className="md-play" tabIndex={tab} aria-label={playing ? `Pause ${item.track}` : `Play ${item.track}`} onClick={() => (audio.get(w.wkey, item.src), audio.toggle(w.wkey))}>
            <svg viewBox="0 0 16 16" aria-hidden>
              {playing ? <path d="M5 3.5h2v9H5zm4 0h2v9H9z" /> : <path d="M5.5 3.2v9.6L13 8z" />}
            </svg>
          </button>
        </div>
        <input
          ref={bar}
          className="md-range"
          type="range"
          min={0}
          max={1000}
          step={1}
          defaultValue={0}
          tabIndex={tab}
          aria-label={`Seek ${item.track}`}
          onInput={(e) => seek(Number(e.currentTarget.value))}
        />
        <p className="md-times">
          <span ref={now}>0:00</span> / <span ref={total}>{clock(item.duration ?? 0)}</span>
        </p>
      </div>
    </div>
  );
}
32 files29 assets1 package

From the workbench

Written about Media Folder — macOS-Style Draggable Window Desktop for React & Framer Motion

By the developer who built it: how it works, with its real code and live preview in the text, and the lessons learned along the way.

About

Media Folder turns a collection into a desktop. A folder icon sits on a calm wallpaper; hover it and its front panel hinges open while the folder tilts toward your cursor. Open it and everything inside — photos, videos, a music player, the weather, a colour palette, notes and links — bursts out as small macOS-style windows that land around it, nearest first, the peeking photos growing into their windows. Close the folder and they all fly back in.

A real window manager, not a picture of one

  • Traffic lights that work. Red flies a window back into its folder, yellow squashes it in like a genie (it peeks out of the folder until you bring it back), green grows it into an expanded view you can page through with ← and →.
  • Drag anything. 1:1 with the pointer, a slight lift and tilt, a short glide on release; a window can hang off an edge but never loses its title bar. Shift locks an axis, arrow keys nudge, and Tidy springs everything back.
  • Focus and z-order. Click to bring a window to front; one active window at a time; several folders share one stacking order. A badge on the folder lists every window as open, minimized or closed.
  • Never a mess. A seeded placement engine packs the windows around the folder with no overlap at any screen size, and re-flows them when the window resizes.

Content that actually works

Pictures with blurred placeholders; videos that play only while visible and uncovered (two at most); a music player with a spinning record, a scrubber and one-song-at-a-time; a weather card that counts up its temperature; swatches that copy their hex; sticky notes; link cards; or anything you render yourself.

Every screen and every user

  • Tablets get a tidy grid; phones a scrollable deck of cards that open as a full-screen sheet you swipe down.
  • Keyboard and screen readers: real buttons, a roving tab order through windows, a modal expanded view with a focus trap, live announcements.
  • Reduced motion: windows fade in place; nothing springs, tilts or spins.
  • Light, dark or auto, recolourable folders (color), four icon glyphs, any wallpaper or a slow mesh.

Fast by design

Dragging and hovering never re-render React and touch only transform and opacity; the drag is composite-only and holds 60 fps on an integrated-GPU laptop with twelve windows open. 16 kB gzipped on first load, with the windows and the expanded view loading as small chunks when needed. Our demo scores 98 for performance and 100 for accessibility, best practices and SEO in Lighthouse (desktop), with zero layout shift.

What's included

  • MediaDesktop, MediaFolder and MediaWindow in TypeScript, with their own stylesheet
  • The pure engine (placement, window manager, audio controller) and hooks (useWindowManager, useDraggableWindow, useSeededScatter)
  • Three demos: the full desktop (follows your theme), dark with the mesh wallpaper, and a single folder
  • Demo media ready to swap: photos from Unsplash, clips from Pexels, two original rendered loops and a CC0 music track

Stack and requirements

  • React 18 or 19, TypeScript
  • motion (Framer Motion) is the only dependency
  • Works in the Next.js App Router and in Vite; Tailwind CSS is optional because the styles ship with the component
  • Use next/image through the renderImage prop

Reviews and bugs

0 reviews · 0 bugs

Ship it0With fixes0Skip0· 0 reviews

0 bugs0 open0 fixed

Members who have it review it and report its bugs. Sign in

No reviews or bugs yet.

Manual installation

Without the CLI

  1. 01

    Install the packages

    npm install motion
  2. 02

    Copy the files into your project

    • components/media-folder/content/AudioContent.tsx
    • components/media-folder/content/ImageContent.tsx
    • components/media-folder/content/index.tsx
    • components/media-folder/content/LinkContent.tsx
    • components/media-folder/content/NoteContent.tsx
    • components/media-folder/content/PaletteContent.tsx
    • components/media-folder/content/VideoContent.tsx
    • components/media-folder/content/WeatherContent.tsx
    • components/media-folder/context.ts
    • components/media-folder/engine/audioController.ts
    • components/media-folder/engine/grid.ts
    • components/media-folder/engine/prng.ts
    • components/media-folder/engine/scatter.ts
    • components/media-folder/engine/separate.ts
    • components/media-folder/engine/windowManager.ts
    • components/media-folder/ExpandedView.tsx
    • components/media-folder/FreeWindow.tsx
    • components/media-folder/hooks/useDraggableWindow.ts
    • components/media-folder/hooks/useFocusTrap.ts
    • components/media-folder/hooks/useFolderHover.ts
    • components/media-folder/hooks/usePersistedLayout.ts
    • components/media-folder/hooks/useReducedMotion.ts
    • components/media-folder/hooks/useSeededScatter.ts
    • components/media-folder/hooks/useVisibilityPlayback.ts
    • components/media-folder/index.ts
    • components/media-folder/MediaDesktop.tsx
    • components/media-folder/MediaFolder.tsx
    • components/media-folder/MediaWindow.tsx
    • components/media-folder/sound.ts
    • components/media-folder/springs.ts
    • components/media-folder/styles.css
    • components/media-folder/types.ts

    The paths follow the shadcn/ui layout, with @/ as your project’s import alias.

  3. 03

    Its pictures, videos and a sound load from UpFork

    The code above points at UpFork’s copies (8.2 MB), so there’s nothing to copy. To host them yourself, use Download source: its ZIP has the files where the code expects them, and a README on the switch.

Before you buy

Everything you need to know

How this component gets from the preview into your project, and what buyers ask most.

How to use it

From the preview to your project

  1. 01

    Try it in the preview

    Switch between light and dark, and resize it to phone and tablet widths, before you decide.

  2. 02

    Get it

    Free products are yours with a free account. Paid ones settle in USDT on TRON, sent straight to the wallet on your order.

  3. 03

    Install it

    Components go into your project with one shadcn command, dependencies included. Everything else downloads with a checksum.

  4. 04

    Make it yours

    It's your code now: rename it, restyle it and wire in your real data.

  5. 05

    Or hand it to your AI

    Copy the prompt and let your coding assistant place it in your project, following your conventions.

Building with an AI assistant?

Copy a ready-made prompt with the code, its dependencies and a demo, and your assistant can put it in place for you.

Copy AI prompt

Selling your own work?

Get approved once, then publish components, templates and mobile components, paid in USDT straight to your own wallet.