Skip to content

Commit

Permalink
@uppy/dashboard: stylistic changes for plugin options (#5384)
Browse files Browse the repository at this point in the history
  • Loading branch information
lakesare authored Oct 15, 2024
1 parent 9508a84 commit 94b6a47
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions packages/@uppy/dashboard/src/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ interface DashboardMiscOptions<M extends Meta, B extends Body>
thumbnailHeight?: number
thumbnailType?: string
thumbnailWidth?: number
trigger?: string | Element
trigger?: string | Element | null
waitForThumbnailsBeforeUpload?: boolean
}

Expand All @@ -183,9 +183,6 @@ export type DashboardOptions<
const defaultOptions = {
target: 'body',
metaFields: [],
inline: false as boolean,
width: 750,
height: 550,
thumbnailWidth: 280,
thumbnailType: 'image/jpeg',
waitForThumbnailsBeforeUpload: false,
Expand All @@ -198,32 +195,44 @@ const defaultOptions = {
hidePauseResumeButton: false,
hideProgressAfterFinish: false,
note: null,
closeModalOnClickOutside: false,
closeAfterFinish: false,
singleFileFullScreen: true,
disableStatusBar: false,
disableInformer: false,
disableThumbnailGenerator: false,
disablePageScrollWhenModalOpen: true,
animateOpenClose: true,
fileManagerSelectionType: 'files',
proudlyDisplayPoweredByUppy: true,
showSelectedFiles: true,
showRemoveButtonAfterComplete: false,
browserBackButtonClose: false,
showNativePhotoCameraButton: false,
showNativeVideoCameraButton: false,
theme: 'light',
autoOpen: null,
disabled: false,
disableLocalFiles: false,
nativeCameraFacingMode: '',
onDragLeave: () => {},
onDragOver: () => {},
onDrop: () => {},
plugins: [],

// Dynamic default options, they have to be defined in the constructor (because
// they require access to the `this` keyword), but we still want them to
// appear in the default options so TS knows they'll be defined.
doneButtonHandler: undefined as any,
onRequestCloseModal: null as any,

// defaultModalOptions
inline: false as boolean,
animateOpenClose: true,
browserBackButtonClose: false,
closeAfterFinish: false,
closeModalOnClickOutside: false,
disablePageScrollWhenModalOpen: true,
trigger: null,

// defaultInlineOptions
width: 750,
height: 550,
} satisfies Partial<DashboardOptions<any, any>>

/**
Expand Down Expand Up @@ -828,7 +837,7 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<

this.setPluginState({ isDraggingOver: true })

this.opts.onDragOver?.(event)
this.opts.onDragOver(event)
}

private handleDragLeave = (event: DragEvent) => {
Expand All @@ -837,7 +846,7 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<

this.setPluginState({ isDraggingOver: false })

this.opts.onDragLeave?.(event)
this.opts.onDragLeave(event)
}

private handleDrop = async (event: DragEvent) => {
Expand Down Expand Up @@ -876,7 +885,7 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<
this.addFiles(files)
}

this.opts.onDrop?.(event)
this.opts.onDrop(event)
}

private handleRequestThumbnail = (file: UppyFile<M, B>) => {
Expand Down Expand Up @@ -1264,7 +1273,7 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<
}

#addSpecifiedPluginsFromOptions = () => {
const plugins = this.opts.plugins || []
const { plugins } = this.opts

plugins.forEach((pluginID) => {
const plugin = this.uppy.getPlugin(pluginID)
Expand Down Expand Up @@ -1470,7 +1479,7 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<
if (thumbnail) this.uppy.removePlugin(thumbnail)
}

const plugins = this.opts.plugins || []
const { plugins } = this.opts
plugins.forEach((pluginID) => {
const plugin = this.uppy.getPlugin(pluginID)
if (plugin) (plugin as any).unmount()
Expand Down

0 comments on commit 94b6a47

Please sign in to comment.