Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
refactor(ui): Move expando construction
Browse files Browse the repository at this point in the history
  • Loading branch information
oliversalzburg committed Oct 8, 2022
1 parent 7b10ad2 commit b966dad
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
3 changes: 2 additions & 1 deletion packages/userscript/source/ui/EngineSettingsUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EngineSettings } from "../options/EngineSettings";
import { ucfirst } from "../tools/Format";
import { mustExist } from "../tools/Maybe";
import { UserScript } from "../UserScript";
import { SettingsPanelUi } from "./SettingsPanelUi";
import { SettingsSectionUi } from "./SettingsSectionUi";

export class EngineSettingsUi extends SettingsSectionUi {
Expand Down Expand Up @@ -44,7 +45,7 @@ export class EngineSettingsUi extends SettingsSectionUi {
}
});

const toggleOptionsVisiblity = this._getItemsToggle(toggleName);
const toggleOptionsVisiblity = SettingsPanelUi.makeItemsToggle(this._host, toggleName);
element.append(toggleOptionsVisiblity);

this.element = element;
Expand Down
25 changes: 19 additions & 6 deletions packages/userscript/source/ui/SettingsPanelUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ export class SettingsPanelUi {
});

// The expando button for this panel.
const itemsElement = $("<div/>", {
id: `toggle-items-${id}`,
title: host.engine.i18n("ui.itemsShow"),
})
.addClass("ks-expando-button")
.text(initiallyExpanded ? "-" : "+");
const itemsElement = SettingsPanelUi.makeItemsToggle(host, id).text(
initiallyExpanded ? "-" : "+"
);
panelElement.append(itemsElement);

let itemsExpanded = initiallyExpanded;
Expand All @@ -55,4 +52,20 @@ export class SettingsPanelUi {

return panelElement;
}

/**
* Constructs an expando element that is commonly used to expand and
* collapses a section of the UI.
*
* @param host A reference to the host.
* @param id The ID of the section this is the expando for.
* @returns The constructed expando element.
*/
static makeItemsToggle(host: UserScript, id: string): JQuery<HTMLElement> {
return $("<div/>", {
id: `toggle-items-${id}`,
title: host.engine.i18n("ui.itemsShow"),
text: "+",
}).addClass("ks-expando-button");
}
}
16 changes: 0 additions & 16 deletions packages/userscript/source/ui/SettingsSectionUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,6 @@ export abstract class SettingsSectionUi {

abstract refreshUi(): void;

/**
* Constructs an expando element that is commonly used to expand and
* collapses a section of the UI.
*
* @param id The ID of the section this is the expando for.
* @returns The constructed expando element.
*/
protected _getItemsToggle(id: string): JQuery<HTMLElement> {
return $("<div/>", {
id: `toggle-items-${id}`,
title: this._host.engine.i18n("ui.itemsShow"),
})
.addClass("ks-expando-button")
.text("+");
}

/**
* Creates a new button to control a trigger value in a configuration section.
*
Expand Down

0 comments on commit b966dad

Please sign in to comment.