Skip to content

Commit

Permalink
docs: Improve filepicker related documentation and exported types
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Aug 17, 2023
1 parent 27f560b commit bf5c7e9
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 18 deletions.
6 changes: 3 additions & 3 deletions lib/components/FilePicker/FilePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<FilePickerBreadcrumbs v-if="currentView === 'files'"
:path.sync="currentPath"
:show-menu="allowPickDirectory"
@create-node="onCreateFolder"/>
@create-node="onCreateFolder" />
<div v-else class="file-picker__view">
<h3>{{ viewHeadline }}</h3>
</div>
Expand All @@ -28,7 +28,7 @@
</template>

<script setup lang="ts">
import type { IFilePickerButton } from '../types'
import type { IFilePickerButton, IFilePickerFilter } from '../types'
import { davRootPath, type Node } from '@nextcloud/files'
import DialogBase from '../DialogBase.vue'
Expand Down Expand Up @@ -65,7 +65,7 @@ const props = withDefaults(defineProps<{
/**
* Custom filter function used to filter pickable files
*/
filterFn?: (node: Node) => boolean
filterFn?: IFilePickerFilter
/**
* List of allowed mime types
Expand Down
31 changes: 30 additions & 1 deletion lib/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,42 @@
import type { Node } from '@nextcloud/files'
import type { AsyncComponent, Component } from 'vue'

/**
* Interface for defining buttons passed to the Dialog component
*/
export interface IDialogButton {
/** Label of the button */
label: string,
icon?: Component | AsyncComponent,

/** Callback on button click */
callback: () => void,
/**
* Optional Icon for the button
* Can be a Vue component or async component
*/
icon?: Component | AsyncComponent,

/**
* Button type
* @see https://nextcloud-vue-components.netlify.app/#/Components/NcButton
*/
type?: 'primary' | 'secondary' | 'error' | 'warning' | 'success'
}

/**
* Interface to define buttons of the FilePicker component
* The buttons are based on the Dialog buttons but the callback gets the array of selected nodes
*/
export interface IFilePickerButton extends Omit<IDialogButton, 'callback'> {
/**
* Callback on button click
*
* @param nodes Array of `@nextcloud/files` Nodes that were selected
*/
callback: (nodes: Node[]) => void
}

/**
* Type of filter functions to filter the FilePicker's file list
*/
export type IFilePickerFilter = (node: Node) => boolean
15 changes: 5 additions & 10 deletions lib/filepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,13 @@
*
*/

import type { IFilePickerButton } from './components/types'
import type { IFilePickerButton, IFilePickerFilter } from './components/types'
import type { Node } from '@nextcloud/files'

import { spawnDialog } from './utils/dialogs'
import { FilePickerVue } from './components/FilePicker/index'
import { t } from './utils/l10n'

/**
* Type of filter functions to filter the FilePicker's file list
*/
export type FilePickerFilter = (node: Node) => boolean

/**
* @deprecated
*/
Expand All @@ -51,15 +46,15 @@ export class FilePicker {
private directoriesAllowed: boolean
private buttons: IFilePickerButton[]
private path?: string
private filter?: FilePickerFilter
private filter?: IFilePickerFilter

public constructor(title: string,
multiSelect: boolean,
mimeTypeFilter: string[],
directoriesAllowed: boolean,
buttons: IFilePickerButton[],
path?: string,
filter?: FilePickerFilter) {
filter?: IFilePickerFilter) {
this.title = title
this.multiSelect = multiSelect
this.mimeTypeFilter = mimeTypeFilter
Expand Down Expand Up @@ -105,7 +100,7 @@ export class FilePickerBuilder {
private mimeTypeFilter: string[] = []
private directoriesAllowed = false
private path?: string
private filter?: FilePickerFilter
private filter?: IFilePickerFilter
private buttons: IFilePickerButton[] = []

/**
Expand Down Expand Up @@ -221,7 +216,7 @@ export class FilePickerBuilder {
*
* @param filter Filter function to apply
*/
public setFilter(filter: FilePickerFilter): FilePickerBuilder {
public setFilter(filter: IFilePickerFilter): FilePickerBuilder {
this.filter = filter
return this
}
Expand Down
33 changes: 29 additions & 4 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
export { FilePicker, FilePickerType, FilePickerBuilder, getFilePickerBuilder } from './filepicker.js'
export { TOAST_UNDO_TIMEOUT, TOAST_DEFAULT_TIMEOUT, TOAST_PERMANENT_TIMEOUT } from './toast.js'
export { TOAST_ARIA_LIVE_OFF, TOAST_ARIA_LIVE_POLITE, TOAST_ARIA_LIVE_ASSERTIVE } from './toast.js'
export { showMessage, showSuccess, showWarning, showInfo, showError, showUndo } from './toast.js'
export {
FilePicker,
FilePickerType,
FilePickerBuilder,
getFilePickerBuilder,
} from './filepicker.js'

export {
ToastAriaLive,
ToastType,
TOAST_UNDO_TIMEOUT,
TOAST_DEFAULT_TIMEOUT,
TOAST_PERMANENT_TIMEOUT,
TOAST_ARIA_LIVE_OFF,
TOAST_ARIA_LIVE_POLITE,
TOAST_ARIA_LIVE_ASSERTIVE,
showMessage,
showSuccess,
showWarning,
showInfo,
showError,
showUndo,
} from './toast.js'

export type {
ToastOptions,
} from './toast.js'

export { spawnDialog } from './utils/dialogs.js'

export { FilePickerVue } from './components/FilePicker/index.js'
export type { IFilePickerButton } from './components/types.js'

0 comments on commit bf5c7e9

Please sign in to comment.