Skip to content

Commit e7b1f92

Browse files
refactor(ui): Improve nesting buttons in lists
1 parent c2ca8ea commit e7b1f92

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

packages/userscript/source/ui/TimeSkipSettingsUi.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Icons } from "../images/Icons";
22
import { TimeSkipSettings } from "../settings/TimeSkipSettings";
33
import { ucfirst } from "../tools/Format";
44
import { UserScript } from "../UserScript";
5+
import { ButtonListItem } from "./components/ButtonListItem";
56
import { TriggerButton } from "./components/buttons-icon/TriggerButton";
67
import { MaxButton } from "./components/buttons-text/MaxButton";
78
import { CyclesList } from "./components/CyclesList";
@@ -30,12 +31,7 @@ export class TimeSkipSettingsUi extends SettingsPanel<TimeSkipSettings> {
3031
this.children.add(this._trigger);
3132

3233
this._maximum = new MaxButton(this._host, label, this.setting);
33-
this.addChild(this._maximum);
3434

35-
const list = new SettingsList(this._host, {
36-
hasDisableAll: false,
37-
hasEnableAll: false,
38-
});
3935
this._cycles = new Panel(
4036
this._host,
4137
new LabelListItem(host, ucfirst(this._host.engine.i18n("ui.cycles")), {
@@ -60,7 +56,16 @@ export class TimeSkipSettingsUi extends SettingsPanel<TimeSkipSettings> {
6056
}
6157
);
6258

63-
list.addChildren([this._cycles, this._seasons]);
64-
this.addChild(list);
59+
this.addChild(
60+
new SettingsList(this._host, {
61+
children: [
62+
new ButtonListItem(host, this._maximum, { delimiter: true }),
63+
this._cycles,
64+
this._seasons,
65+
],
66+
hasDisableAll: false,
67+
hasEnableAll: false,
68+
})
69+
);
6570
}
6671
}
Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
import { UserScript } from "../../UserScript";
2-
import { ListItem } from "./ListItem";
2+
import { ListItem, ListItemOptions } from "./ListItem";
33
import { TextButton } from "./TextButton";
4-
import { UiComponent } from "./UiComponent";
54

6-
export class ButtonListItem extends UiComponent implements ListItem {
7-
readonly element: JQuery<HTMLElement>;
5+
export class ButtonListItem extends ListItem {
86
readonly button: TextButton;
97

10-
get elementLabel() {
11-
return this.button.element;
12-
}
13-
14-
constructor(host: UserScript, button: TextButton, delimiter = false) {
15-
super(host);
8+
constructor(host: UserScript, button: TextButton, options?: Partial<ListItemOptions>) {
9+
super(host, options);
1610

17-
const element = $(`<li/>`);
18-
for (const cssClass of ["ks-setting", delimiter ? "ks-delimiter" : ""]) {
19-
element.addClass(cssClass);
20-
}
11+
this.button = button;
12+
this.element.append(button.element);
13+
}
2114

22-
element.append(button.element);
15+
refreshUi(): void {
16+
super.refreshUi();
2317

24-
this.element = element;
25-
this.button = button;
18+
this.button.refreshUi();
2619
}
2720
}

0 commit comments

Comments
 (0)