-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Proposition of builtin CSS transition handlers with react-transition-group #1036
Comments
Cool idea! My suggestion would be to have the API called import { transition, animated } from 'styled-components-transition-group'
const List = transition.div``;
const ListItem = animated.div`
transition: opacity 300ms cubic-bezier(0.4, 0.0, 0.2, 1) 0ms;
&:appear, &:enter, &:exit {
opacity: 0;
}
&:appear-active, &:enter-active {
opacity: 1;
}
`; That way you could publish it as a separate package and get people playing with it. If we need to make some internal changes to SC to better facilitate packages like this, I'm open to that. |
What I did in the example repository was not overriding any original function of the original package, but rather wrapping it. The
The
The
Notice that I even made available the original methods to be used with These methods works.
I'm thinking that removing the styled reference would be an issue...
On the other hand
I would rather believe that the user would create its on But it would be nicer if styled-components attach some sort of extending methods for styled and css. So something like bellow come to place.
|
Why? You already use injection in
It gets messy if you're injecting multiple things
but it's not particularly cleaner than a plugin system would be.
|
@ezsper I would love to make use of this, and I think it's a great idea to make it a separate package that does not require bundling into styled-components to get out the door. |
We're not going to add any configuration to styled-components, see #1143. This would be great as an external package! |
If anyone's still interested, I made styled-transition-group, which exports a new styled object as geelen proposed. |
I appreciate the conciseness of the proposed APIs of styled-transition-group and styled-components-transition-group, but couldn't this easily be accomplished by just creating a little component that takes styles (as strings or maybe as styled-components.css templates) for the entering/entered/exiting/exited states, and a few other options, and a styled component, and returns a react-transition-group/Transition and just applies the styles to the styled component as the state changes? Something like: // in some component's render method
const animationStyleProps = {
entering,
exiting,
transition,
duration
}
return <Animate status={this.state.show} {...animationStyleProps} component={SomeStyledComponent} /> I like the creativity, but it seems like there's a high cost in terms hackiness (reaching into styled-components internals, for example) to get the sole benefit of concise syntax. Plus, we'd have to create editor extensions (or create a PRs for existing extensions) for CSS syntax highlighting within these new "transition" styled components. Am I missing part of the picture here? |
@ezsper @gabiseabra Thank you! This is beautiful and makes animations a joy to work with. |
I'm throwing my hat in the ring. I've used a slightly different, more minimal approach: https://github.com/granmoe/styled-animate |
Gonna try to get one of these working with https://github.com/cheapsteak/react-transition-group-plus (Sarah Drasner mentioned this pairs well with GSAP which is exciting), and react-router for cancelable/reversable page transitions 🤤. Will post boilerplate if I get it. @granmoe btw your lib reminds me a lot of how https://github.com/SamKnows/transform-when handles animation with arrays and such. 👌 |
I looked into a couple of implementations here and ended up abstracting what I was looking for to something much simpler (doesn't require // animates a child
<Animated>
<Foo />
</Animated>
// animates a group of children
<Animated items>
{foos.map(() => <Animated item><Foo /></Animated>)}
</Animated> |
I tried to make it play nice with Let's say that we have: const Foo = styled.p`color: red;`;
const Bar = styled.p`color: red;`; @geelen Will |
@sonaye That's actually really awesome. Will definitely start using that (I'm back on SCSS now). If you require a fixed class name you could do |
@corysimmons I actually didn't know that you can do that, nice. This addresses something I was looking for in this library a while ago (composition of styled-components #932). I've been stubborn about writing css in string templates, but I finally gave it a shot and I kind of like it now, I am gradually moving to use
I was able to integrate the package with |
@granmoe Thanks for this package, it works like a charm! :) |
@yss14 Thanks! 😄 I would very much welcome PRs for it if you find that there's anything missing or if anything can be improved--I'm working on a deep learning project in most of my off time currently. |
Great tip @sonaye ! I applied you tip, and working with animations is so much easier now 🙂 If someone is curious, I pieced together an example of Happy codding! 🚀 |
Most of the time transitions are hard and messy to perform and maintain, Styled Components bring us a very easy API to handle styling. I was thinking of an idea to add transition helpers to the API levered by react-transition-group and make it even better.
Access my example repository and launch storybook for a working demo of this proposition.
![storybook](https://user-images.githubusercontent.com/798804/28619716-1e739c46-71e0-11e7-97b7-cfab48a1339b.gif)
The text was updated successfully, but these errors were encountered: