Last active
March 20, 2019 14:31
-
-
Save kimihito/bfe1f60148b37ccfb0f8db28886ddc17 to your computer and use it in GitHub Desktop.
Close flash message using Stimulus.js + octicons
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
// Using https://primer.style/css | |
- flash.each do |key, value| | |
.flash-messages{data: { controller: 'flash'}} | |
.flash{class: "flash-#{key == 'alert' ? 'error' : key}"} | |
%button.flash-close{data: { action: 'flash#dismiss', target: 'flash.close'}, type: 'button'} | |
× | |
= value |
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" | |
import octicons from 'octicons' | |
export default class extends Controller { | |
static targets = ["close"] | |
connect() { | |
const closeElement = this.closeTarget | |
closeElement.innerHTML = octicons.x.toSVG({"aria-label": 'Close'}) | |
} | |
dismiss() { | |
this.element.style.display = 'none'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment