A headless UI, fast media library for React 19+.
- 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
- 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
Try it live at reactkits.dev/react-media-library
npm install @reactkits.dev/react-media-library
# Optional: icons
npm install lucide-react
# Optional: server-side image processing (thumbnails, resizing)
npm install sharpimport {
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.
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.
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
| Module | Gzipped |
|---|---|
| Core | 17 KB |
| Image Editor | 4.6 KB (lazy) |
| Cropper (optional) | 15 KB (lazy) |
We welcome contributions! When contributing, please ensure the demo maintains the Lighthouse scores shown in the repository.
- Clone the repository
- Install dependencies:
npm install cd demo && npm install
To build and preview the demo, then verify Lighthouse scores match the repository:
-
Build and preview the demo:
cd demo npm run preview -
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/.
To maintain the Lighthouse scores, please follow these guidelines:
- Code Splitting: Keep manual chunk splitting as configured in
demo/vite.config.ts - Minification: Ensure
terseris used with console removal enabled - Lazy Loading: Image Editor and Cropper should remain lazy-loaded
- CSS: Keep
cssCodeSplit: falseto 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
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:
esnextfor modern browsers
If you like what I'm doing, consider following me:
MIT

