Add Alert Component#162
Conversation
Adds a component that renders a Bootstrap 4 alert. Supports dismissing alerts and animated fade out.
e87abc2 to
a1a9fa0
Compare
| dismissible: false | ||
| } | ||
|
|
||
| class AlertWrapper extends React.Component { |
There was a problem hiding this comment.
This should be in it's own file
There was a problem hiding this comment.
it might just be one component if you move the ReactCSSTransitionGroup up to Alert. Also, you could pass tag through as the component prop of ReactCSSTransitionGroup.
There was a problem hiding this comment.
Yeah, I totally agree--especially if we support a fade-in animation and do the single child thing, there isn't really a need for a separate wrapping component.
|
|
||
| if (dismissible) { | ||
| return ( | ||
| <ReactCSSTransitionGroup |
There was a problem hiding this comment.
Consider using the Render a single child method to avoid the extra element created by ReactCSSTransitionGroup. I've never done this before but it seems like just the right thing to use.
There was a problem hiding this comment.
I haven't either, but it seems cool!
| } | ||
|
|
||
| onDismiss = () => { | ||
| this.setState({ visible: false }); |
There was a problem hiding this comment.
I don't think this needs to be an uncontrolled component. Users should control state. I think this could accept the isOpen prop for toggling visibility and use that logic with single child method to control how it's shown. onDismiss would be replaced by the toggle callback.
There was a problem hiding this comment.
I agree with the notion that this doesn't need to be an uncontrolled component but for simplicity perhaps theres another way to achieve the same goal? Which do you prefer: someone rendering an long-lasting alert and toggling its visibility or mounting and un-mounting the component?
There was a problem hiding this comment.
It could be a controlled and uncontrolled component. But I think that leads to inconsistency (updating a prop vs updating via setState) and extra docs. Preferring props over internal state is a general rule for this library. I built component-template with this sort of thing in mind. Someone could build reactstrap-controlled-components, which wrap these components and adds a controlled version of Alert. It's not the most convenient thing to do but it definitely enables more prescriptive ways of doing things. Even though that prescription is simplicity.
There was a problem hiding this comment.
Yeah, I hear ya. In terms of development, a controlled component is real simple so I'll go with that. Are you using the isOpen and toggle terminology to be consistent throughout the library? I suppose isVisible matches what's going on semantically but comes at a cost of inconsistency.
There was a problem hiding this comment.
Also, to clarify, I wasn't suggesting a mix of controlled and uncontrolled, rather an approach like a dropdown where it internally controlled its own state. All in all, a controlled component is in the works.
There was a problem hiding this comment.
The Dropdown examples do advocate set state but that's in the example files vs the src. The only things I see that use state in the src files are Fade and TabContent. I think isOpen is not the best term but it's not way off from describing this.
There was a problem hiding this comment.
I'm cool with isOpen. The fact that people can probably guess most of the property names in this library is awesome.
| }, | ||
| { | ||
| name: 'Alert', | ||
| to: '/components/alert/' |
There was a problem hiding this comment.
I would update title and url to be pluralized to closer match v4 docs.
There was a problem hiding this comment.
Woops...Good call
| }; | ||
|
|
||
| const defaultProps = { | ||
| color: 'warning', |
There was a problem hiding this comment.
can you change this to success for default
| leave: 'fade', | ||
| leaveActive: 'out' | ||
| }} | ||
| transitionEnter={false} |
There was a problem hiding this comment.
I think it should be possible to transition on enter, not sure what that involves. Any reason not to include it?
There was a problem hiding this comment.
That's a great suggestion. I only omitted it for attempted parity with Bootstrap, but it's an easy 2-liner addition. I suppose we should also support the transitionAppear for initial mounting too.
| leaveActive: 'out' | ||
| }} | ||
| transitionEnter={false} | ||
| transitionLeaveTimeout={300}> |
There was a problem hiding this comment.
I would make this configurable for leave and onenter similar to delay in this example.
There was a problem hiding this comment.
Awesome! That works for me.
|
Did you look at using the |
|
@eddywashere Thanks for the comments! One question about procedure: for the changes, should I add separate commits (and leave them separate), or squash the changes into the originals, or separate and squash later (when merging)? Also, I did take a quick look at the |
|
Don't worry about squashing things. I prefer detailed commits. I squash and merge via github once it's all good to go. I'll need some time to better describe the limitations I thought I found in css transition group. But feel free to look into it as well. I think it was regarding unique class names on transition life cycle events, maybe something specific to "while transitioning". which bootstrap applies classes to. |
| return ( | ||
| <ReactCSSTransitionGroup | ||
| component={FirstChild} | ||
| transitionName={{ |
There was a problem hiding this comment.
experimented with this, the following example seems to apply the right classes and works with the default opacity animation of .15s.
<ReactCSSTransitionGroup
component={FirstChild}
transitionName={{
enter: 'fade',
enterActive: 'in',
leave: 'fade',
leaveActive: 'out',
appear: 'fade',
appearActive: 'in'
}}
transitionEnterTimeout={150}
transitionLeaveTimeout={150}
>
{isOpen ? alert : null}
</ReactCSSTransitionGroup>|
Notes in animation docs
That's why I went with it for If you stick with Thanks again for working on this. Can't wait to use it! Let me know what you think about direction for this. |
|
Sorry for the delay -- I just moved to a new apartment! I agree with the direction: lets stick with |
14894b5 to
1dc4e6d
Compare
|
@aaronpanch no rush, I see commits added after your comment. Could you let me know when this is good to review? |
|
@eddywashere I think they're good to review when you have a chance! Thanks for all the feedback! |
|
thanks @aaronpanch! |
|
I'm getting the following error after this change; any thoughts? It's causing webpack build to fail. ERROR in ./ |
|
@IndifferentDisdain A new peer dependency was added. I was considering moving it to dependencies to avoid problems like this. I'm not sure if that would cause more problems. For now, I would recommend saving this dep to your project. |
|
@eddywashere Thanks, I just rtfm'd and noticed the additional dependency. 😸 |
Hello! I was working on a small project using reactstrap, made an alert, and thought it would be cool to clean things up and make a PR. In summary, this simply adds a Bootstrap 4 alert, and a documentation page with some examples.
I would like to note a few things for discussion, in addition to any comments or suggestions you might have!
react-addons-css-transition-group. It wasn't my favorite thing to do; however, it made implementing the dismissible fade-out easier..alert-headingand.alert-link? I only ask to maintain some feature parity with Bootstrap 4.Thanks!