Skip to content

Commit e124718

Browse files
committed
docs: Improve filepicker related documentation and exported types
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent 27f560b commit e124718

File tree

5 files changed

+72
-23
lines changed

5 files changed

+72
-23
lines changed

l10n/messages.pot

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ msgstr ""
1818
msgid "All files"
1919
msgstr ""
2020

21-
#: lib/filepicker.ts:183
21+
#: lib/filepicker.ts:178
2222
msgid "Choose"
2323
msgstr ""
2424

25-
#: lib/filepicker.ts:171
25+
#: lib/filepicker.ts:166
2626
msgid "Copy"
2727
msgstr ""
2828

@@ -43,8 +43,8 @@ msgstr ""
4343
msgid "Modified"
4444
msgstr ""
4545

46-
#: lib/filepicker.ts:177
47-
#: lib/filepicker.ts:191
46+
#: lib/filepicker.ts:172
47+
#: lib/filepicker.ts:186
4848
msgid "Move"
4949
msgstr ""
5050

@@ -65,6 +65,6 @@ msgstr ""
6565
msgid "Size"
6666
msgstr ""
6767

68-
#: lib/toast.ts:229
68+
#: lib/toast.ts:242
6969
msgid "Undo"
7070
msgstr ""

lib/components/FilePicker/FilePicker.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<FilePickerBreadcrumbs v-if="currentView === 'files'"
1010
:path.sync="currentPath"
1111
:show-menu="allowPickDirectory"
12-
@create-node="onCreateFolder"/>
12+
@create-node="onCreateFolder" />
1313
<div v-else class="file-picker__view">
1414
<h3>{{ viewHeadline }}</h3>
1515
</div>
@@ -28,7 +28,7 @@
2828
</template>
2929

3030
<script setup lang="ts">
31-
import type { IFilePickerButton } from '../types'
31+
import type { IFilePickerButton, IFilePickerFilter } from '../types'
3232
import { davRootPath, type Node } from '@nextcloud/files'
3333
3434
import DialogBase from '../DialogBase.vue'
@@ -65,7 +65,7 @@ const props = withDefaults(defineProps<{
6565
/**
6666
* Custom filter function used to filter pickable files
6767
*/
68-
filterFn?: (node: Node) => boolean
68+
filterFn?: IFilePickerFilter
6969
7070
/**
7171
* List of allowed mime types

lib/components/types.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,42 @@
2323
import type { Node } from '@nextcloud/files'
2424
import type { AsyncComponent, Component } from 'vue'
2525

26+
/**
27+
* Interface for defining buttons passed to the Dialog component
28+
*/
2629
export interface IDialogButton {
30+
/** Label of the button */
2731
label: string,
28-
icon?: Component | AsyncComponent,
32+
33+
/** Callback on button click */
2934
callback: () => void,
35+
/**
36+
* Optional Icon for the button
37+
* Can be a Vue component or async component
38+
*/
39+
icon?: Component | AsyncComponent,
40+
41+
/**
42+
* Button type
43+
* @see https://nextcloud-vue-components.netlify.app/#/Components/NcButton
44+
*/
3045
type?: 'primary' | 'secondary' | 'error' | 'warning' | 'success'
3146
}
3247

48+
/**
49+
* Interface to define buttons of the FilePicker component
50+
* The buttons are based on the Dialog buttons but the callback gets the array of selected nodes
51+
*/
3352
export interface IFilePickerButton extends Omit<IDialogButton, 'callback'> {
53+
/**
54+
* Callback on button click
55+
*
56+
* @param nodes Array of `@nextcloud/files` Nodes that were selected
57+
*/
3458
callback: (nodes: Node[]) => void
3559
}
60+
61+
/**
62+
* Type of filter functions to filter the FilePicker's file list
63+
*/
64+
export type IFilePickerFilter = (node: Node) => boolean

lib/filepicker.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,13 @@
2020
*
2121
*/
2222

23-
import type { IFilePickerButton } from './components/types'
23+
import type { IFilePickerButton, IFilePickerFilter } from './components/types'
2424
import type { Node } from '@nextcloud/files'
2525

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

30-
/**
31-
* Type of filter functions to filter the FilePicker's file list
32-
*/
33-
export type FilePickerFilter = (node: Node) => boolean
34-
3530
/**
3631
* @deprecated
3732
*/
@@ -51,15 +46,15 @@ export class FilePicker {
5146
private directoriesAllowed: boolean
5247
private buttons: IFilePickerButton[]
5348
private path?: string
54-
private filter?: FilePickerFilter
49+
private filter?: IFilePickerFilter
5550

5651
public constructor(title: string,
5752
multiSelect: boolean,
5853
mimeTypeFilter: string[],
5954
directoriesAllowed: boolean,
6055
buttons: IFilePickerButton[],
6156
path?: string,
62-
filter?: FilePickerFilter) {
57+
filter?: IFilePickerFilter) {
6358
this.title = title
6459
this.multiSelect = multiSelect
6560
this.mimeTypeFilter = mimeTypeFilter
@@ -105,7 +100,7 @@ export class FilePickerBuilder {
105100
private mimeTypeFilter: string[] = []
106101
private directoriesAllowed = false
107102
private path?: string
108-
private filter?: FilePickerFilter
103+
private filter?: IFilePickerFilter
109104
private buttons: IFilePickerButton[] = []
110105

111106
/**
@@ -221,7 +216,7 @@ export class FilePickerBuilder {
221216
*
222217
* @param filter Filter function to apply
223218
*/
224-
public setFilter(filter: FilePickerFilter): FilePickerBuilder {
219+
public setFilter(filter: IFilePickerFilter): FilePickerBuilder {
225220
this.filter = filter
226221
return this
227222
}

lib/index.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
1-
export { FilePicker, FilePickerType, FilePickerBuilder, getFilePickerBuilder } from './filepicker.js'
2-
export { TOAST_UNDO_TIMEOUT, TOAST_DEFAULT_TIMEOUT, TOAST_PERMANENT_TIMEOUT } from './toast.js'
3-
export { TOAST_ARIA_LIVE_OFF, TOAST_ARIA_LIVE_POLITE, TOAST_ARIA_LIVE_ASSERTIVE } from './toast.js'
4-
export { showMessage, showSuccess, showWarning, showInfo, showError, showUndo } from './toast.js'
1+
export {
2+
FilePicker,
3+
FilePickerType,
4+
FilePickerBuilder,
5+
getFilePickerBuilder,
6+
} from './filepicker.js'
7+
8+
export {
9+
ToastAriaLive,
10+
ToastType,
11+
TOAST_UNDO_TIMEOUT,
12+
TOAST_DEFAULT_TIMEOUT,
13+
TOAST_PERMANENT_TIMEOUT,
14+
TOAST_ARIA_LIVE_OFF,
15+
TOAST_ARIA_LIVE_POLITE,
16+
TOAST_ARIA_LIVE_ASSERTIVE,
17+
showMessage,
18+
showSuccess,
19+
showWarning,
20+
showInfo,
21+
showError,
22+
showUndo,
23+
} from './toast.js'
24+
25+
export type {
26+
ToastOptions,
27+
} from './toast.js'
528

629
export { spawnDialog } from './utils/dialogs.js'
30+
731
export { FilePickerVue } from './components/FilePicker/index.js'
32+
export type { IFilePickerButton, IFilePickerFilter } from './components/types.js'

0 commit comments

Comments
 (0)