Skip to content

Instantly share code, notes, and snippets.

@kimihito
Last active March 20, 2019 14:31
Show Gist options
  • Save kimihito/bfe1f60148b37ccfb0f8db28886ddc17 to your computer and use it in GitHub Desktop.
Save kimihito/bfe1f60148b37ccfb0f8db28886ddc17 to your computer and use it in GitHub Desktop.
Close flash message using Stimulus.js + octicons
// 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
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