Skip to content

About

Headless React media library you can mount on your app

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

@reactkits.dev/react-media-library

A headless UI, fast media library for React 19+.

Bundlephobia min Bundlephobia minzip Lighthouse Scores

Why This Library?

  • Headless - Bring your own UI. Works with Tailwind, Mantine, or any component library
  • Fast - Optimized for performance from day one. Zero layout shift, lazy loading, tree-shakeable
  • Simple - Full media library in 10 lines of code
  • Local Storage - No server needed. Uses IndexedDB + OPFS

Features

  • File Upload - Drag & drop or button upload for images, videos, audio, documents
  • Search & Filter - Search by filename, filter by file type (image/video/audio/document)
  • Date Range Filtering - Filter media by upload date range
  • Multiple View Modes - Grid, List, and Masonry layouts
  • Image Viewer - Full-screen modal viewer with navigation
  • Image Editor - Crop, rotate, flip, zoom (lazy-loaded, optional)
  • Selection Mode - Single or multi-select with bulk delete
  • Customizable UI - Headless architecture - bring your own components
  • Local Storage - IndexedDB for metadata + OPFS for file storage
  • Performance - Lazy loading, code splitting, zero layout shift
  • Responsive - Works on desktop, tablet, and mobile
  • Accessible - ARIA labels and keyboard navigation support

Demo

Demo

Try it live at reactkits.dev/react-media-library

Installation

npm install @reactkits.dev/react-media-library

# Optional: icons
npm install lucide-react

# Optional: server-side image processing (thumbnails, resizing)
npm install sharp

Quick Start

import {
  MediaLibraryProvider,
  MediaGrid,
  tailwindPreset,
  lucideIcons
} from '@reactkits.dev/react-media-library';

function App() {
  return (
    <MediaLibraryProvider enableDragDrop={true}>
      <MediaGrid
        preset={tailwindPreset}
        icons={lucideIcons}
      />
    </MediaLibraryProvider>
  );
}

That's it. Drag & drop uploads, search, filters, grid/list/masonry views - all included.

Themes

The prebuilt MediaGrid has a standalone system theme by default and also supports explicit or inherited themes:

<MediaGrid preset={tailwindPreset} theme="system" />
<MediaGrid preset={tailwindPreset} theme="light" />
<MediaGrid preset={tailwindPreset} theme="dark" />
<MediaGrid preset={tailwindPreset} theme="inherit" />

Use inherit for a transparent, host-controlled appearance. It leaves color tokens unset so the library can consume inherited --rml-* variables or a tokens mapping supplied by the host application:

.my-media-theme {
  --rml-background: var(--app-background);
  --rml-surface: var(--app-surface);
  --rml-foreground: var(--app-text);
  --rml-muted: var(--app-muted-text);
  --rml-border: var(--app-border);
  --rml-accent: var(--app-accent);
}

Applications can also override individual package tokens without replacing the component preset:

<MediaGrid
  preset={tailwindPreset}
  theme="dark"
  tokens={{
    accent: '#14b8a6',
    surface: '#111827',
  }}
/>

The supported semantic tokens are background, surface, surfaceMuted, foreground, muted, border, accent, accentSoft, danger, dangerSoft, and warning.

Headless Architecture

The library doesn't ship any UI. You provide components via a preset:

const myPreset = {
  Card: (props) => <div className="my-card" {...props} />,
  Button: (props) => <button className="my-btn" {...props} />,
  TextInput: ({ value, onChange }) => (
    <input value={value} onChange={e => onChange(e.target.value)} />
  ),
  // ... see types for full list
};

<MediaGrid preset={myPreset} />

Built-in presets: tailwindPreset, mantinePreset

Bundle Size

Module Gzipped
Core 17 KB
Image Editor 4.6 KB (lazy)
Cropper (optional) 15 KB (lazy)

Contributing

We welcome contributions! When contributing, please ensure the demo maintains the Lighthouse scores shown in the repository.

Setup

  1. Clone the repository
  2. Install dependencies:
    npm install
    cd demo && npm install

Verifying Lighthouse Scores

To build and preview the demo, then verify Lighthouse scores match the repository:

  1. Build and preview the demo:

    cd demo
    npm run preview
  2. Run Lighthouse audit:

    • Open Chrome DevTools
    • Go to the Lighthouse tab
    • Select "Performance", "Accessibility", "Best Practices", and "SEO"
    • Click "Analyze page load"
    • Compare scores with the image in the repository (demo/lighthouse-result.png)

The build output will be in demo/dist/.

Performance Guidelines

To maintain the Lighthouse scores, please follow these guidelines:

  • Code Splitting: Keep manual chunk splitting as configured in demo/vite.config.ts
  • Minification: Ensure terser is used with console removal enabled
  • Lazy Loading: Image Editor and Cropper should remain lazy-loaded
  • CSS: Keep cssCodeSplit: false to minimize CSS files
  • Bundle Size: Monitor bundle sizes and avoid adding large dependencies
  • Tree Shaking: Ensure unused code is properly tree-shaken
  • No Console Logs: All console statements are removed in production builds

Key Build Configuration

The demo uses specific Vite optimizations:

  • Terser minification with console removal
  • Manual chunk splitting for React, lucide-react, and idb
  • CSS code splitting disabled
  • Target: esnext for modern browsers

If you like what I'm doing, consider following me:

GitHub LinkedIn X Reddit

License

MIT

About

Headless React media library you can mount on your app

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages