A reusable React component library for an image/video Resource Center. It supports ImageKit listing, uploading, selection, multi-select confirmation, preview (images and videos), and can be used in a modal.
npm install imagekit-react-widgets
# or
yarn add imagekit-react-widgetsimport { ResourceCenter } from 'imagekit-react-widgets'
import 'imagekit-react-widgets/dist/index.css'
function Demo() {
const [open, setOpen] = useState(false)
return (
<div>
<button onClick={() => setOpen(true)}>Open Resource Center</button>
<ResourceCenter
open={open}
onOpenChange={setOpen}
listEndpoint="https://api.imagekit.io/v1/files"
uploadEndpoint="https://upload.imagekit.io/api/v1/files/upload"
privateKey={IMAGEKIT_PRIVATE_KEY}
onConfirm={(files) => {
console.log('Selected', files)
}}
/>
</div>
)
}open: whether the modal is open, defaultfalseonOpenChange(open): modal open/close callbackonConfirm(files): selection confirm callback, returnsImageKitFile[]onError(message): error callbacklistEndpoint: ImageKit list endpoint, e.g.https://api.imagekit.io/v1/filesfolderPath?: only show resources under a specific folder, e.g."/products/2024"- If
folderPathis provided, the list endpoint (default or custom) is auto-appended withpathunless it already containspath
- If
uploadEndpoint: ImageKit upload endpoint, e.g.https://upload.imagekit.io/api/v1/files/uploadprivateKey: ImageKit private key (Basic Auth), inject securelyuploadFolder?: upload target directory, e.g./assets- Default behavior: if
folderPathis provided anduploadFolderis not explicitly set, uploads will go to the folder indicated byfolderPath(e.g.folderPath="/css"uploads into/css). If you explicitly setuploadFolder, your value takes precedence.
- Default behavior: if
uploadTags?: tags array to attach on uploadmaxFileSize?: max file size (default 10MB)allowedTypes?: allowed MIME types (default images only)allowedExts?: allowed extensions (default images only)enableDelete?: show delete action, defaulttrueenableUpload?: allow uploading, defaulttruemultiSelect?: allow multi-select, defaulttruetitle?: custom top header text
interface ImageKitFile {
fileId: string
name: string
url: string
thumbnailUrl: string
height: number
width: number
size: number
createdAt: string
}See CHANGELOG.md