Storage Components

3 Components

Pre-built, customizable upload components. Drop-in UI for file uploads, image handling, and avatar management with drag-and-drop support.

Quick Start

All storage components are available from the SDK. Wrap your app with SylphxProvider for automatic storage context and authentication.
Installation
import {
  FileUpload,
  ImageUploader,
  AvatarUpload,
} from '@sylphx/platform-sdk/react'

FileUpload

A versatile file upload component with drag-and-drop support, progress tracking, and file type validation. Handles single or multiple file uploads with customizable restrictions.

Drag & Drop
Themeable
Type Validation
Basic Usage
import { FileUpload } from '@sylphx/platform-sdk/react'

export default function UploadPage() {
  return (
    <div className="max-w-xl mx-auto py-8">
      <FileUpload
        onUpload={(files) => {
          console.log('Uploaded files:', files)
        }}
        onError={(error) => {
          console.error('Upload failed:', error.message)
        }}
      />
    </div>
  )
}

Props

PropertyTypeDescription
onUploadrequired(files: UploadedFile[]) => voidCallback fired after successful upload
onError(error: UploadError) => voidCallback fired on upload error
onProgress(progress: number) => voidCallback fired during upload with progress percentage
acceptstring | string[]= "*/*"Accepted file types (MIME or extensions)
maxSizenumber= 10485760Maximum file size in bytes
maxFilesnumber= 10Maximum number of files for multi-upload
multipleboolean= falseAllow multiple file selection
pathstring= "uploads"Storage path/folder for uploads
publicboolean= trueMake uploaded files publicly accessible
showPreviewboolean= trueShow file preview after selection
showProgressboolean= trueShow upload progress bar
disabledboolean= falseDisable the upload component
placeholderstring= "Drag & drop files here"Placeholder text
themeThemeVariablesCustom theme overrides
classNamestringAdditional CSS classes

Advanced Examples

<FileUpload
  accept={['.pdf', '.doc', '.docx', '.txt']}
  maxSize={25 * 1024 * 1024} // 25MB
  path="documents"
  public={false}
  placeholder="Drop your documents here"
  onUpload={(files) => {
    files.forEach(file => {
      console.log('Uploaded:', file.filename, file.url)
    })
  }}
/>

File Type Validation

Use MIME types (image/*, application/pdf) or extensions (.pdf, .docx) in the accept prop. Arrays allow multiple types.

ImageUploader

An image-specific upload component with instant preview, dimension validation, and format conversion. Optimized for image handling with built-in compression options.

Preview
Auto Resize
Compression
Basic Usage
import { ImageUploader } from '@sylphx/platform-sdk/react'

export default function GalleryPage() {
  return (
    <div className="max-w-xl mx-auto py-8">
      <ImageUploader
        onUpload={(image) => {
          console.log('Uploaded image:', image.url)
          console.log('Dimensions:', image.width, 'x', image.height)
        }}
      />
    </div>
  )
}

Props

PropertyTypeDescription
onUploadrequired(image: UploadedImage) => voidCallback fired after successful upload
onError(error: UploadError) => voidCallback fired on upload error
onPreview(preview: string) => voidCallback fired when preview is generated
acceptstring[]= ["image/jpeg", "image/png", "image/webp", "image/gif"]Accepted image types
maxSizenumber= 10485760Maximum file size in bytes
maxWidthnumberMaximum image width (auto-resize if exceeded)
maxHeightnumberMaximum image height (auto-resize if exceeded)
minWidthnumberMinimum required image width
minHeightnumberMinimum required image height
aspectRationumberRequired aspect ratio (width/height)
qualitynumber= 85Compression quality (0-100)
format"jpeg" | "png" | "webp"Output format (converts if different)
pathstring= "images"Storage path/folder
publicboolean= trueMake publicly accessible
showPreviewboolean= trueShow image preview
previewSize"sm" | "md" | "lg" | "full"= "md"Preview size
themeThemeVariablesCustom theme overrides
classNamestringAdditional CSS classes

Advanced Examples

<ImageUploader
  minWidth={800}
  minHeight={800}
  maxWidth={2000}
  maxHeight={2000}
  aspectRatio={1} // Square images
  quality={90}
  format="webp"
  path="products"
  onUpload={(image) => {
    setProductImage(image.url)
    toast.success('Product image uploaded!')
  }}
  onError={(error) => {
    if (error.code === 'DIMENSION_TOO_SMALL') {
      toast.error('Image must be at least 800x800 pixels')
    }
  }}
/>

WebP Format

Using format="webp" typically reduces file size by 25-35% compared to JPEG while maintaining quality. All modern browsers support WebP.

AvatarUpload

A specialized avatar upload component with built-in circular cropping, zoom controls, and automatic resizing. Designed for profile pictures with an intuitive editing experience.

Circular Crop
Profile Ready
Zoom & Pan
Basic Usage
import { AvatarUpload } from '@sylphx/platform-sdk/react'

export default function ProfilePage() {
  const { user, refreshUser } = useUser()

  return (
    <div className="flex items-center gap-6">
      <AvatarUpload
        currentImage={user?.avatar}
        onUpload={async (avatar) => {
          await refreshUser()
          toast.success('Avatar updated!')
        }}
      />
      <div>
        <h2 className="text-xl font-semibold">{user?.name}</h2>
        <p className="text-muted-foreground">{user?.email}</p>
      </div>
    </div>
  )
}

Props

PropertyTypeDescription
onUploadrequired(avatar: UploadedImage) => voidCallback fired after successful upload
onError(error: UploadError) => voidCallback fired on upload error
onRemove() => voidCallback fired when avatar is removed
currentImagestringCurrent avatar URL to display
sizenumber= 120Avatar size in pixels
outputSizenumber= 256Output image size in pixels
acceptstring[]= ["image/jpeg", "image/png", "image/webp"]Accepted image types
maxSizenumber= 5242880Maximum file size in bytes
qualitynumber= 90Output quality (0-100)
showCropperboolean= trueShow crop interface
cropShape"circle" | "square"= "circle"Crop area shape
allowZoomboolean= trueAllow zoom controls in cropper
allowRemoveboolean= trueShow remove avatar button
fallbackReactNodeFallback content when no image
fallbackInitialsstringInitials to show as fallback
updateUserProfileboolean= trueAuto-update user profile
themeThemeVariablesCustom theme overrides
classNamestringAdditional CSS classes

Advanced Examples

<AvatarUpload
  currentImage={user?.avatar}
  fallbackInitials={user?.name?.split(' ').map(n => n[0]).join('')}
  size={100}
  outputSize={256}
  onUpload={(avatar) => {
    updateUser({ avatar: avatar.url })
  }}
  onRemove={() => {
    updateUser({ avatar: null })
  }}
/>

Automatic Profile Update

When updateUserProfile is enabled (default), the component automatically updates the current user's profile. Disable this for team member avatars or other non-user images.

Theming

All storage components support theming via the theme prop. Customize colors, borders, and spacing to match your brand.

Custom Theme
import { FileUpload, ImageUploader, AvatarUpload, defaultTheme, type ThemeVariables } from '@sylphx/platform-sdk/react'

const customTheme: ThemeVariables = {
  ...defaultTheme,
  colorPrimary: '#6366f1',
  colorPrimaryHover: '#4f46e5',
  colorBackground: '#ffffff',
  colorForeground: '#1f2937',
  colorMuted: '#f3f4f6',
  colorMutedForeground: '#6b7280',
  colorBorder: '#e5e7eb',
  colorSuccess: '#22c55e',
  colorDestructive: '#ef4444',
  fontFamily: 'Inter, sans-serif',
  borderRadius: '0.75rem',
}

<FileUpload theme={customTheme} />
<ImageUploader theme={customTheme} />
<AvatarUpload theme={customTheme} />
PropertyTypeDescription
colorPrimarystring= #000000Primary/accent color
colorPrimaryHoverstring= #1f2937Primary color on hover
colorBackgroundstring= #ffffffComponent background
colorForegroundstring= #1f2937Primary text color
colorMutedstring= #f3f4f6Muted/secondary background
colorMutedForegroundstring= #6b7280Secondary text color
colorBorderstring= #e5e7ebBorder color
colorSuccessstring= #22c55eSuccess/complete color
colorDestructivestring= #ef4444Error/remove color
fontFamilystring= system-uiFont family
borderRadiusstring= 0.5remBorder radius

Best Practices

Validate File Types

Always specify accepted file types to prevent unwanted uploads and improve user experience.

Set Size Limits

Configure appropriate maxSize limits based on your use case and storage plan.

Handle Errors Gracefully

Provide onError callbacks with user-friendly messages for validation and upload failures.

Optimize Images

Use compression (quality prop) and format conversion (WebP) to reduce storage and bandwidth costs.

Need more control?

Use the storage hooks for custom upload UI while keeping all the processing and validation.