-
-
Save noelrappin/b87ee470f760d2496d2d03a0187a33f3 to your computer and use it in GitHub Desktop.
Copy paste parts from RailsConf Workshop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/views/schedule/show.html.erb:29-30 | |
<section class="day-body" | |
id="day-body-<%= schedule_day.day.by_example("2006-01-02") %>" | |
data-controller="toggle"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/javascript/controllers/toggle_controller.js | |
import { Controller } from "stimulus" | |
export default class extends Controller { | |
connect() { | |
console.log("The Controller is Connected") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/views/schedule/show.html.erb:34 | |
<div class="button is-primary" | |
data-action="click->toggle#toggle"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in the class in app/javascript/controllers/toggle_controller.rb | |
toggle() { | |
console.log("click") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/views/schedule/show.html.erb:39 | |
<section data-target="toggle.thingToHide"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in the class in app/javascript/controllers/toggle_controller.rb | |
static targets = ["thingToHide"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in the class in app/javascript/controllers/toggle_controller.rb | |
toggle() { | |
this.thingToHideTarget.classList.toggle("is-hidden") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in app/views/schedule/show.html.haml | |
<section class="day-body" | |
id="day-body-<%= schedule_day.day.by_example("2006-01-02") %>" | |
data-controller="toggle" | |
data-toggle-hidden="false"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<span data-target="toggle.text">Hide</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller } from "stimulus" | |
export default class extends Controller { | |
static targets = ["text", "thingToHide"] | |
isHidden() { return this.data.get("hidden") === "true" } | |
flip() { this.data.set("hidden", this.isHidden() ? "false" : "true") } | |
toggle() { | |
this.flip() | |
this.thingToHideTarget.classList.toggle("is-hidden", this.isHidden()) | |
this.textTarget.innerText = this.isHidden() ? "Show" : "Hide" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment