Skip to content
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

[feat]: Integration of Tailwind CSS with React Spring for Declarative and Styled Animations #2220

Open
nicolashedoire opened this issue Nov 16, 2023 · 1 comment
Labels
template: request is a request someone has submitted

Comments

@nicolashedoire
Copy link

nicolashedoire commented Nov 16, 2023

A clear and concise description of what the feature is

This proposal aims to integrate Tailwind CSS, a utility-first styling framework, with React Spring, an animation library for React, to enable declarative and styled animations using Tailwind classes. The goal is to create a more intuitive and efficient development experience by allowing developers to apply React Spring animations via Tailwind classes, thereby simplifying the process of styling and animating React components.

Currently, React Spring enables the animation of CSS styles and values but does not directly support the use of Tailwind classes, a popular styling framework in the React ecosystem. This limitation necessitates indirect approaches to combine React Spring animations with Tailwind styling, often involving custom CSS styles or juggling between inline styles and CSS classes.

The proposed integration seeks to bridge this gap by enabling developers to use Tailwind classes directly within React Spring animation configurations. For instance, a developer could specify Tailwind classes for different animation states, such as text-xl for the initial state and text-3xl for the animated state, and React Spring would handle the transition between these states smoothly and naturally.

This integration would offer several benefits:

Workflow Simplification: Reduce complexity by eliminating the need to juggle between inline styles and Tailwind classes.
Style Consistency: Maintain style consistency by using a single styling system throughout the application.
Enhanced Development Experience: Provide a smoother and more natural development experience for Tailwind and React Spring users.
The implementation of this feature could take the form of a wrapper or an extension of React Spring that interprets and converts Tailwind classes into animatable styles. This proposal aims to explore the feasibility, design, and implementation of this integration and seeks contributions and ideas from the community on the best way to achieve this integration.

Why should this feature be included?

The integration of Tailwind CSS with React Spring should be included for several compelling reasons:

Enhanced Developer Productivity and Experience: By combining the utility-first approach of Tailwind CSS with the powerful animation capabilities of React Spring, developers can achieve more with less code. This integration simplifies the process of applying animations and styling, making it more efficient and less error-prone. Developers can focus more on building features and less on the intricacies of CSS and animation syntax.

Consistency and Maintainability: Integrating these two popular libraries encourages consistency in styling and animation across the application. It streamlines the workflow, making it easier to maintain and update styles and animations. Consistency is key to a scalable and maintainable codebase, especially in larger projects.

Leveraging Community Adoption: Both Tailwind CSS and React Spring have substantial community adoption and support. By integrating them, we leverage the strengths and popularity of both, providing a solution that resonates with a wide range of developers. This integration meets the needs of a growing trend towards utility-first CSS frameworks and sophisticated web animations.

Innovation in Web Development: This integration represents an innovative step in web development, combining two modern and highly regarded frameworks. It aligns with the industry's move towards more modular, composable libraries that emphasize developer experience and performance.

Flexibility and Customization: Tailwind CSS offers immense flexibility in styling, and React Spring offers versatile animation options. Their integration allows developers to harness this flexibility and versatility in a unified way, enabling more creative and dynamic web applications.

Responding to Community Demand: There is a growing demand in the developer community for more integrated and cohesive tools that streamline the development process. By responding to this demand, we ensure that the tooling evolves in line with developers' real-world needs and preferences.

In summary, the integration of Tailwind CSS with React Spring addresses a significant need in the developer community for a more streamlined, efficient, and powerful way to apply styling and animations in React applications. It combines the best of both worlds - utility-based styling and sophisticated animations, thereby enhancing the overall development experience and the quality of web applications.

Please provide an example for how this would work

import React from 'react';
import { useSpring, animated } from 'react-spring';
import 'tailwindcss/tailwind.css';

const AnimatedButton = () => {
  const [hover, setHover] = React.useState(false);

  const animation = useSpring({
    config: { tension: 150, friction: 10 },
    tailwindClasses: hover ? 'text-xl bg-blue-500 py-2 px-4' : 'text-base bg-blue-300 py-1 px-2',
  });

  return (
    <animated.button
      style={animation}
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      className="text-white font-bold rounded"
    >
      Hover Me
    </animated.button>
  );
};
@nicolashedoire nicolashedoire added the template: request is a request someone has submitted label Nov 16, 2023
@LoganDark
Copy link
Contributor

Is this AI-generated? Once #2292 lands you'll be able to use an interpolation to animate the className perfectly fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
template: request is a request someone has submitted
Projects
None yet
Development

No branches or pull requests

2 participants