为checkout添加切换状态时添加回调函数

This commit is contained in:
浔阳陌客 2024-04-05 16:37:25 +08:00
parent ec00075b4e
commit c58c836b7c
5 changed files with 11 additions and 1 deletions

View file

@ -191,6 +191,11 @@ export default class PluginSample extends Plugin {
type: "checkbox",
title: "Checkbox text",
description: "Check description",
checkbox: {
callback: () => {
console.log("Checkbox clicked");
}
}
});
this.settingUtils.addItem({
key: "Select",

3
src/libs/index.d.ts vendored
View file

@ -12,6 +12,9 @@ interface ISettingItem {
step: number;
};
options?: { [key: string | number]: string };
checkbox?: {
callback: () => void;
}
button?: {
label: string;
callback: () => void;

View file

@ -31,7 +31,7 @@
{title}
<div class="b3-label__text">
{@html description}
</div>
</div>
</div>
<span class="fn__space" />
<!-- <slot /> -->

View file

@ -104,6 +104,7 @@ export class SettingUtils {
element.checked = item.value;
element.className = "b3-switch fn__flex-center";
itemElement = element;
element.onchange = item.checkbox?.callback ?? (() => { });
break;
case 'select':
let selectElement: HTMLSelectElement = document.createElement('select');