Skip to content

Commit

Permalink
add methods for enabling and disabling save button
Browse files Browse the repository at this point in the history
  • Loading branch information
bwp91 committed Nov 21, 2024
1 parent 5409ad5 commit 77a3f22
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to `@homebridge/plugin-ui-utils` will be documented in this
### Notable Changes

- update to esm package
- add methods for enabling and disabling save button

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

Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,26 @@ Hide the spinner / loading overlay.
homebridge.hideSpinner()
```

#### `homebridge.disableSaveButton`

> `homebridge.disableSaveButton(): void`
Disables the save button in the settings modal.

```ts
homebridge.disableSaveButton()
```

#### `homebridge.enableSaveButton`

> `homebridge.enableSaveButton(): void`
Enables the save button in the settings modal.

```ts
homebridge.enableSaveButton()
```

### Forms

The custom user interface allows you to create two types of forms:
Expand Down
38 changes: 29 additions & 9 deletions src/ui.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ export declare class IHomebridgePluginUi extends EventTarget {

/**
* Show a loading spinner overlay.
* Prevents user input until cleared with `homebridge.hideSpinner();`
* Prevents user input until cleared with `homebridge.hideSpinner()`
*
* @example
* ```ts
* homebridge.showSpinner();
* homebridge.showSpinner()
* ```
*/
public showSpinner(): void
Expand All @@ -116,18 +116,38 @@ export declare class IHomebridgePluginUi extends EventTarget {
*
* @example
* ```ts
* homebridge.hideSpinner();
* homebridge.hideSpinner()
* ```
*/
public hideSpinner(): void

/**
* Disable the save button in the UI.
*
* @example
* ```ts
* homebridge.disableSaveButton()
* ```
*/
public disableSaveButton(): void

/**
* Enable the save button in the UI.
*
* @example
* ```ts
* homebridge.enableSaveButton()
* ```
*/
public enableSaveButton(): void

/**
* Show the schema-generated form below the custom UI.
* This only works for platform plugins that have set `singular` = `true` in their config.schema.json file.
*
* @example
* ```ts
* homebridge.showSchemaForm();
* homebridge.showSchemaForm()
* ```
*/
public showSchemaForm(): void
Expand All @@ -137,7 +157,7 @@ export declare class IHomebridgePluginUi extends EventTarget {
*
* @example
* ```ts
* this.hideSchemaForm();
* this.hideSchemaForm()
* ```
*/
public hideSchemaForm(): void
Expand Down Expand Up @@ -179,7 +199,7 @@ export declare class IHomebridgePluginUi extends EventTarget {
* });
*
* // stop listening / hide the form
* myForm.end();
* myForm.end()
* ```
*/
public createForm(schema: PluginFormSchema, data: any, submitButton?: string, cancelButton?: string): IHomebridgeUiFormHelper
Expand All @@ -196,7 +216,7 @@ export declare class IHomebridgePluginUi extends EventTarget {
*
* @example
* ```ts
* const pluginConfigBlocks = await homebridge.getPluginConfig();
* const pluginConfigBlocks = await homebridge.getPluginConfig()
* ```
*/
public getPluginConfig(): Promise<PluginConfig[]>
Expand Down Expand Up @@ -227,7 +247,7 @@ export declare class IHomebridgePluginUi extends EventTarget {
*
* @example
* ```ts
* await homebridge.savePluginConfig();
* await homebridge.savePluginConfig()
* ```
*/
public savePluginConfig(): Promise<void>
Expand All @@ -237,7 +257,7 @@ export declare class IHomebridgePluginUi extends EventTarget {
*
* @example
* ```ts
* const schema = await homebridge.getPluginConfigSchema();
* const schema = await homebridge.getPluginConfigSchema()
* ```
*/
public getPluginConfigSchema(): Promise<PluginSchema>
Expand Down
2 changes: 2 additions & 0 deletions src/ui.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export class MockHomebridgePluginUi extends EventTarget implements IHomebridgePl
public closeSettings() { }
public showSpinner() { }
public hideSpinner() { }
public disableSaveButton() {}
public enableSaveButton() {}
public showSchemaForm() { }
public hideSchemaForm() { }
public endForm() { }
Expand Down
8 changes: 8 additions & 0 deletions src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ class HomebridgePluginUi extends EventTargetConstructor {
this._postMessage({ action: 'spinner.hide' })
}

public disableSaveButton(): void {
this._postMessage({ action: 'button.save.disabled' })
}

public enableSaveButton(): void {
this._postMessage({ action: 'button.save.enabled' })
}

public showSchemaForm(): void {
this._postMessage({ action: 'schema.show' })
}
Expand Down

0 comments on commit 77a3f22

Please sign in to comment.