adopted-ember-addons / ember-cli-flash

Simple, highly configurable flash messages for ember-cli
https://www.npmjs.com/package/ember-cli-flash
MIT License
355 stars 113 forks source link

Using a modifier for flash-message component #344

Open Techn1x opened 3 years ago

Techn1x commented 3 years ago

Would there be any interest in moving the current flash logic from the flash-message component, into a modifier?

Thinking it could be (somewhat) backwards compatible, the current flash-message component would end up looking like this;

// flash-message.hbs
<div
  ...attributes
  {{flash-modifier @flash}} // applies all the classes, attributes, event handlers, flash logic. The component JS would be mostly empty.
>
  {{#if hasBlock}}
    {{yield this @flash (action "onClose")}}
  {{else}}
    {{@flash.message}}
    <FlashMessage::Progress @showProgress={{this.showProgressBar}} @duration={{this.progressDuration}} />
  {{/if}}
</div>

It would also allow users of this addon to make custom flash components with relative ease if they wish to do so, without having to implement all of the logic from the flash message component.

{{#each flashMessages.queue as |flash|}}
  <my-flash class="abc" {{flash-modifier flash}}>
    wow, that's all I have to do, don't even need a component
  </my-flash>
{{/each}}