From 46830f50cd93bd4e5126dad0f1b0d1cae1d96b77 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Thu, 12 Jan 2023 18:26:30 +0100 Subject: [PATCH] Add Stimulus controller for collapse functionality --- .../controllers/collapse_controller.ts | 16 ++++++++++++++++ .../retrospring/initializers/stimulus.ts | 2 ++ 2 files changed, 18 insertions(+) create mode 100644 app/javascript/retrospring/controllers/collapse_controller.ts diff --git a/app/javascript/retrospring/controllers/collapse_controller.ts b/app/javascript/retrospring/controllers/collapse_controller.ts new file mode 100644 index 00000000..9b282ad9 --- /dev/null +++ b/app/javascript/retrospring/controllers/collapse_controller.ts @@ -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'); + } +} diff --git a/app/javascript/retrospring/initializers/stimulus.ts b/app/javascript/retrospring/initializers/stimulus.ts index 90b3a96d..56e27d7f 100644 --- a/app/javascript/retrospring/initializers/stimulus.ts +++ b/app/javascript/retrospring/initializers/stimulus.ts @@ -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); }