diff --git a/app/javascript/controllers/forecasts_controller.js b/app/javascript/controllers/forecasts_controller.js deleted file mode 100644 index 43f6d95..0000000 --- a/app/javascript/controllers/forecasts_controller.js +++ /dev/null @@ -1,8 +0,0 @@ -import { Controller } from "@hotwired/stimulus" - -// Connects to data-controller="forecasts" -export default class extends Controller { - connect() { - console.log("connected Stimulus!") - } -} diff --git a/app/javascript/controllers/index.js b/app/javascript/controllers/index.js index 7e792bd..608283b 100644 --- a/app/javascript/controllers/index.js +++ b/app/javascript/controllers/index.js @@ -4,6 +4,5 @@ import { application } from "./application" -import ForecastsController from "./forecasts_controller" -application.register("forecasts", ForecastsController) - +import TabController from "./tab_controller" +application.register("tab", TabController) diff --git a/app/javascript/controllers/tab_controller.js b/app/javascript/controllers/tab_controller.js new file mode 100644 index 0000000..53c875a --- /dev/null +++ b/app/javascript/controllers/tab_controller.js @@ -0,0 +1,21 @@ +import { Controller } from "@hotwired/stimulus" + +// Connects to data-controller="tab" +export default class extends Controller { + static classes = [ "active" ] + static targets = [ "day" ] + + connect() { + } + + switch_tab() { + this.makeAllTabsInactive() + this.dayTarget.classList.toggle(this.activeClass) + } + + makeAllTabsInactive() { + document.querySelectorAll('.tabs .tab').forEach( + (el) => el.classList.remove(this.activeClass) + ) + } +} diff --git a/app/views/styled_forecasts/_day_tab.html.erb b/app/views/styled_forecasts/_day_tab.html.erb index d98d7e6..3fdf66f 100644 --- a/app/views/styled_forecasts/_day_tab.html.erb +++ b/app/views/styled_forecasts/_day_tab.html.erb @@ -1,19 +1,31 @@ -