Last active
December 22, 2020 14:00
-
-
Save jonathan-s/7fc7cbe8c2b80831fb804565524316bb to your computer and use it in GitHub Desktop.
Stimulus.js snippets that are useful for controllers, see it as a playground for now.
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 { | |
addClasses(element) { | |
let toId = element.dataset.toId | |
let toElement | |
if (toId) { | |
toElement = document.getElementById(toId) | |
} else { | |
toElement = element | |
} | |
let classes = element.dataset.addClasses.split(' ') | |
toElement.classList.add(...classes) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment