-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Expand file tree
/
Copy pathSetting.ts
More file actions
69 lines (58 loc) · 1.47 KB
/
Copy pathSetting.ts
File metadata and controls
69 lines (58 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
export interface SettingData {
el: () => HTMLElement
open?: () => void
close?: () => void
order?: number
}
export default class Setting {
#name: string
#options: Required<SettingData>
/**
* Create a new files app setting
*
* @param name - The name of this setting
* @param options - The setting options
* @param options.el - Function that returns an unmounted dom element to be added
* @param options.open - Callback for when setting is added
* @param options.close - Callback for when setting is closed
* @param options.order - The order of this setting, lower numbers are shown first
* @since 19.0.0
*/
constructor(name: string, options: SettingData) {
this.#name = name
this.#options = {
open: () => {},
close: () => {},
order: 0,
...options,
}
if (typeof this.#options.el !== 'function') {
throw new Error('Setting must have an `el` function that returns a DOM element')
}
if (typeof this.#name !== 'string') {
throw new Error('Setting must have a `name` string')
}
if (typeof this.#options.order !== 'number') {
throw new Error('Setting must have an `order` number')
}
}
get name() {
return this.#name
}
get el() {
return this.#options.el
}
get open() {
return this.#options.open
}
get close() {
return this.#options.close
}
get order() {
return this.#options.order
}
}