Files
Trilium/apps/client/src/widgets/switch.ts

50 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-09-08 22:18:54 +03:00
import { t } from "../services/i18n.js";
2021-12-20 17:30:47 +01:00
import NoteContextAwareWidget from "./note_context_aware_widget.js";
const TPL = /*html*/`
2021-12-20 17:30:47 +01:00
<div class="switch-widget">
<style>
2021-12-20 17:30:47 +01:00
</style>
</div>`;
export default class SwitchWidget extends NoteContextAwareWidget {
doRender() {
this.$widget = $(TPL);
this.$switchButton = this.$widget.find(".switch-button");
2025-01-21 04:49:07 +02:00
this.$switchToggle = this.$widget.find(".switch-toggle");
this.$switchName = this.$widget.find(".switch-name");
2021-12-20 17:30:47 +01:00
this.$helpButton = this.$widget.find(".switch-help-button");
}
switchOff() {}
switchOn() {}
/** Gets or sets whether the switch is toggled. */
get isToggled() {
return this.currentState;
}
set isToggled(state) {
this.currentState = !!state;
2025-01-21 04:49:07 +02:00
this.$switchButton.toggleClass("on", this.currentState);
}
2025-01-22 01:30:10 +02:00
/** Gets or sets whether the switch is enabled. */
get canToggle() {
2025-03-02 20:47:57 +01:00
return !this.$switchButton.hasClass("disabled");
}
set canToggle(isEnabled) {
if (isEnabled) {
this.isToggled = this.currentState; // Reapply the correct tooltip
} else {
this.$switchButton.attr("title", this.disabledTooltip);
}
}
2021-12-20 17:30:47 +01:00
}