Skip to content

Commit 96118f2

Browse files
committedNov 22, 2024
add methods for enabling and disabling save button
1 parent 6cb08dd commit 96118f2

File tree

6 files changed

+68
-16
lines changed

6 files changed

+68
-16
lines changed
 

‎CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ All notable changes to `@homebridge/plugin-ui-utils` will be documented in this
66

77
### Notable Changes
88

9-
- update to esm package
9+
- ⚠️ update to esm package
10+
- add methods for enabling and disabling save button
11+
- requires homebridge ui `^5.0.0-beta.4`
1012

1113
## v1.0.3 (2024-04-06)
1214

‎README.md

+20
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,26 @@ Hide the spinner / loading overlay.
303303
homebridge.hideSpinner()
304304
```
305305

306+
#### `homebridge.disableSaveButton`
307+
308+
> `homebridge.disableSaveButton(): void`
309+
310+
Disables the save button in the settings modal.
311+
312+
```ts
313+
homebridge.disableSaveButton()
314+
```
315+
316+
#### `homebridge.enableSaveButton`
317+
318+
> `homebridge.enableSaveButton(): void`
319+
320+
Enables the save button in the settings modal.
321+
322+
```ts
323+
homebridge.enableSaveButton()
324+
```
325+
306326
### Forms
307327

308328
The custom user interface allows you to create two types of forms:

‎package-lock.json

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/ui.interface.ts

+29-9
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ export declare class IHomebridgePluginUi extends EventTarget {
102102

103103
/**
104104
* Show a loading spinner overlay.
105-
* Prevents user input until cleared with `homebridge.hideSpinner();`
105+
* Prevents user input until cleared with `homebridge.hideSpinner()`
106106
*
107107
* @example
108108
* ```ts
109-
* homebridge.showSpinner();
109+
* homebridge.showSpinner()
110110
* ```
111111
*/
112112
public showSpinner(): void
@@ -116,18 +116,38 @@ export declare class IHomebridgePluginUi extends EventTarget {
116116
*
117117
* @example
118118
* ```ts
119-
* homebridge.hideSpinner();
119+
* homebridge.hideSpinner()
120120
* ```
121121
*/
122122
public hideSpinner(): void
123123

124+
/**
125+
* Disable the save button in the UI.
126+
*
127+
* @example
128+
* ```ts
129+
* homebridge.disableSaveButton()
130+
* ```
131+
*/
132+
public disableSaveButton(): void
133+
134+
/**
135+
* Enable the save button in the UI.
136+
*
137+
* @example
138+
* ```ts
139+
* homebridge.enableSaveButton()
140+
* ```
141+
*/
142+
public enableSaveButton(): void
143+
124144
/**
125145
* Show the schema-generated form below the custom UI.
126146
* This only works for platform plugins that have set `singular` = `true` in their config.schema.json file.
127147
*
128148
* @example
129149
* ```ts
130-
* homebridge.showSchemaForm();
150+
* homebridge.showSchemaForm()
131151
* ```
132152
*/
133153
public showSchemaForm(): void
@@ -137,7 +157,7 @@ export declare class IHomebridgePluginUi extends EventTarget {
137157
*
138158
* @example
139159
* ```ts
140-
* this.hideSchemaForm();
160+
* this.hideSchemaForm()
141161
* ```
142162
*/
143163
public hideSchemaForm(): void
@@ -179,7 +199,7 @@ export declare class IHomebridgePluginUi extends EventTarget {
179199
* });
180200
*
181201
* // stop listening / hide the form
182-
* myForm.end();
202+
* myForm.end()
183203
* ```
184204
*/
185205
public createForm(schema: PluginFormSchema, data: any, submitButton?: string, cancelButton?: string): IHomebridgeUiFormHelper
@@ -196,7 +216,7 @@ export declare class IHomebridgePluginUi extends EventTarget {
196216
*
197217
* @example
198218
* ```ts
199-
* const pluginConfigBlocks = await homebridge.getPluginConfig();
219+
* const pluginConfigBlocks = await homebridge.getPluginConfig()
200220
* ```
201221
*/
202222
public getPluginConfig(): Promise<PluginConfig[]>
@@ -227,7 +247,7 @@ export declare class IHomebridgePluginUi extends EventTarget {
227247
*
228248
* @example
229249
* ```ts
230-
* await homebridge.savePluginConfig();
250+
* await homebridge.savePluginConfig()
231251
* ```
232252
*/
233253
public savePluginConfig(): Promise<void>
@@ -237,7 +257,7 @@ export declare class IHomebridgePluginUi extends EventTarget {
237257
*
238258
* @example
239259
* ```ts
240-
* const schema = await homebridge.getPluginConfigSchema();
260+
* const schema = await homebridge.getPluginConfigSchema()
241261
* ```
242262
*/
243263
public getPluginConfigSchema(): Promise<PluginSchema>

‎src/ui.mock.ts

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ export class MockHomebridgePluginUi extends EventTarget implements IHomebridgePl
6767
public closeSettings() { }
6868
public showSpinner() { }
6969
public hideSpinner() { }
70+
public disableSaveButton() {}
71+
public enableSaveButton() {}
7072
public showSchemaForm() { }
7173
public hideSchemaForm() { }
7274
public endForm() { }

‎src/ui.ts

+8
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,14 @@ class HomebridgePluginUi extends EventTargetConstructor {
203203
this._postMessage({ action: 'spinner.hide' })
204204
}
205205

206+
public disableSaveButton(): void {
207+
this._postMessage({ action: 'button.save.disabled' })
208+
}
209+
210+
public enableSaveButton(): void {
211+
this._postMessage({ action: 'button.save.enabled' })
212+
}
213+
206214
public showSchemaForm(): void {
207215
this._postMessage({ action: 'schema.show' })
208216
}

0 commit comments

Comments
 (0)
Please sign in to comment.