Files
basecoat/src/js/sidebar.js
T

23 lines
840 B
JavaScript
Raw Normal View History

2025-05-02 18:27:45 +08:00
window.basecoat = window.basecoat || {};
window.basecoat.registerSidebar= function(Alpine) {
if (Alpine.components && Alpine.components.sidebar) return;
Alpine.data('sidebar', (initialOpen = true) => ({
id: null,
open: true,
init() {
this.id = this.$el.id;
this.open = initialOpen;
},
$main: {
'@sidebar:open.window'(e) { if (!this.id || (e.detail && e.detail.id === this.id)) this.open = true },
'@sidebar:close.window'(e) { if (!this.id || (e.detail && e.detail.id === this.id)) this.open = false },
2025-05-02 22:43:40 +08:00
'@sidebar:toggle.window'(e) { if (!this.id || (e.detail && e.detail.id === this.id)) this.open = !this.open },
'@click'(e) { if (e.target === this.$el) this.open = false },
2025-05-02 18:27:45 +08:00
':aria-hidden'() { return !this.open },
':inert'() { return !this.open },
},
}));
};