-
-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass 'close' as closure action #230
Pass 'close' as closure action #230
Conversation
I'm not 100% sure I want to yield it as another ordered parameter, but I don't quite wanna make a separate actions hash for it either lol |
I tried writing some tests for this feature, but they all suck so far lol: |
This branch has an integration test now - this PR should be good to go! :) |
1c510d1
to
b2d6660
Compare
b2d6660
to
61a62dd
Compare
@sbatson5 could you look over this when you get a chance? :) |
@caseywatts sorry for the delay. The test looks good. Just want to pull it into a dummy app real quick and test it. Should be able to get to that tonight |
sweet! thanks @sbatson5 :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we can expand this to be a bit more flexible. Rather than adding a closure action to the component, we could add a flashAction
property to the flash object itself. This keeps us from yielding another property and would make it easier to control the destroyOnClick
logic. We could also have the label of the action button as another property. So we could create messages like:
get(this, 'flashMessages').success('Success!!', {
flashAction: {
label: 'Close'
}
});
Then we could add a default action
property that calls flash.destroyMessage()
. Or the user could overwrite it with their own action if they wanted to do something other than closing (i.e. they wanted to rollback attributes on a model or something similar).
Although this adds some extra conditions to the template:
{{#flash-message flash=flash}}
{{flash.message}}
{{#if flash.flashAction}}
<a href="#" {{action (action flash.flashAction.action)}}>
{{flash.flashAction.label}}
</a>
{{/if}}
{{/flash-message}}
So if the user sets a flashAction
, we render it with their label and default flashAction.action
to destroyMessage
, otherwise we use an action they pass in.
This may be overcomplicating the API, however. Let me know your thoughts!
cc @poteto
@@ -1,5 +1,5 @@ | |||
{{#if hasBlock}} | |||
{{yield this flash}} | |||
{{yield this flash (action 'close')}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, we try to use double quotes on templates. Can you wrap close
in double quotes?
this.set('flash', FlashMessage.create({ | ||
message: 'flash message content', | ||
sticky: true, | ||
destroyOnClick: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 I'm wondering if there is a way for us to default this to false when yielding/using the close action. It could be confusing if both are enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uh oh right, destroyOnClick=true is the default :/
I was surprised that was true when I first read the docs for this. And I'm surprised again just now haha (I wonder if other users are surprised by this default too?)
Hmm - we could at least document it in the README.md next to an example that uses close
?
I imagine this is a pretty common use case and I'd love to make it super straightforward, too. -- This is a pretty common fork-in-the-road when designing Ember components. I'm not 100% that my suggestion is the better of the two paths, but I can provide more arguments for it at least :) contextual-component vs pass-in-more-arguments@sbatson5 we're also going to want to put some classes on this - that'll lead us to three arguments. Next (and this is probably going too far lol): some people may want this to be a styled
I think a contextual component sort of thing gets around this sort of argument-passing-bloat pretty nicely :) Also - the last argument |
@caseywatts ok, you convinced me :). Would you mind just updating the README and just mention to disable |
|
||
actions: { | ||
close() { | ||
this._destroyFlashMessage(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of adding a warning via Ember.Logger.warn
if flash.destroyOnClick
is true? Something like:
close() {
if (get(this, 'flash.destroyOnClick')) {
Logger.warn('This flash message has `destroyOnClick` enabled -- be sure to disable it when using the close action')
}
this._destroyFlashMessage();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sbatson5 keep in mind that warn
is stripped from Production builds: https://emberjs.com/api/#method_warn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of this!
If it's stripped when this package is packaged (production build) then this one would be stripped out, hrm :/
How do other addons add warnings for users of the addon?
updated the readme! 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just 1 small typo. Otherwise, looks good.
README.md
Outdated
@@ -273,6 +272,20 @@ It also accepts your own template: | |||
{{/each}} | |||
``` | |||
|
|||
### Custom `close` action | |||
The `close` action is always passed to the component whether it is used or not. It can be used to implement your own close button, such an an `x` in the top-right corner. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
such *as* an x
.
typo corrected ✨ |
and it's in! 🎉 now that master displays this option, we'll probably want to do a release soon so it matches up? cc @sbatson5 @Dhaulagiri |
Unfortunately, I don't have npm access to this package, so we will need @Dhaulagiri to publish and update for us. |
published in 1.4.3 🎉 |
This adds in the ability to close the flash message in your own custom components. I tweaked the example in the readme to include a close button in the template there. I've also tried this in my own app :)
If we like this idea, we should probably make a separate example that has close on click set to false (since currently this example it wouldn't quite make sense why we want the close button when you can click on the whole thing to close it).