Skip to content

Commit

Permalink
feat: add switch to settingsPage type
Browse files Browse the repository at this point in the history
  • Loading branch information
pilar6195 committed Jun 19, 2024
1 parent 212297a commit fd38c0a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/modules/anilist/settingsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,24 @@ registerModule.anilist({
break;
}

case 'switch': {
const switchToggle = createSwitch({
label: setting.label,
description: setting.description,
enabled: savedSetting,
appendTo: modelBody,
});

optionElement = switchToggle.element;

switchToggle.on('change', (event) => {
const checked = (event.target as HTMLInputElement).checked;
ModuleSettings.set(key, checked);
});

break;
}

case 'number': {
const input = createInput({
type: setting.type,
Expand Down
7 changes: 6 additions & 1 deletion src/utils/Helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1003,11 +1003,12 @@ addStyles(`
/* Switch Label */
.alextras--switch .el-switch__label:not(.is-active) {
color: rgb(var(--color-text-light));
color: rgb(var(--color-text));
}
/* Input Descriptions */
.alextras--switch h5,
.alextras--checkbox h5,
.alextras--textarea h5,
.alextras--input h5,
Expand All @@ -1022,6 +1023,10 @@ addStyles(`
margin-left: 2.2em;
}
.alextras--switch h5 {
margin-left: 4.5em;
}
/* Input Backgrounds */
.alextras--dropdown .el-input__inner,
Expand Down
7 changes: 6 additions & 1 deletion types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ type ModuleSettingCheckbox = ModuleSettingBase & {
default?: boolean;
};

type ModuleSettingSwitch = ModuleSettingBase & {
type: 'switch';
default?: boolean;
};

type ModuleSettingNumber = ModuleSettingBase & {
type: 'number';
min?: number;
Expand Down Expand Up @@ -305,7 +310,7 @@ type BaseModule = {
* Options that will appear in the settings menu.
*/
settingsPage?: {
[key: string]: ModuleSettingCheckbox | ModuleSettingNumber | ModuleSettingSelect | ModuleSettingText;
[key: string]: ModuleSettingCheckbox | ModuleSettingNumber | ModuleSettingSelect | ModuleSettingSwitch | ModuleSettingText;
}
/**
* Whether the module is disabled by default.
Expand Down

0 comments on commit fd38c0a

Please sign in to comment.