Add Stimulus controller for collapse functionality

This commit is contained in:
Andreas Nedbal 2023-01-12 18:26:30 +01:00 committed by Andreas Nedbal
parent 3258ea4f0b
commit 46830f50cd
2 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,16 @@
import { Controller } from '@hotwired/stimulus';
export default class extends Controller {
static targets = ['action', 'content'];
declare readonly contentTarget: HTMLElement;
declare readonly actionTarget: HTMLElement;
connect(): void {
this.actionTarget.addEventListener('click', this.update.bind(this));
}
update(): void {
this.contentTarget.classList.toggle('collapsed');
}
}

View File

@ -4,6 +4,7 @@ import AutofocusController from "retrospring/controllers/autofocus_controller";
import CharacterCountController from "retrospring/controllers/character_count_controller";
import CharacterCountWarningController from "retrospring/controllers/character_count_warning_controller";
import FormatPopupController from "retrospring/controllers/format_popup_controller";
import CollapseController from "retrospring/controllers/collapse_controller";
/**
* This module sets up Stimulus and our controllers
@ -18,5 +19,6 @@ export default function (): void {
window['Stimulus'].register('autofocus', AutofocusController);
window['Stimulus'].register('character-count', CharacterCountController);
window['Stimulus'].register('character-count-warning', CharacterCountWarningController);
window['Stimulus'].register('collapse', CollapseController);
window['Stimulus'].register('format-popup', FormatPopupController);
}