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: added dynamic class-name feature via classNames attribute #26730

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

vijaypushkin
Copy link

@vijaypushkin vijaypushkin commented Apr 26, 2023

Summary

The proposed feature is to add a new syntax for dynamically adding classes to React components. This syntax would be similar to the ngClass directive in Angular, allowing developers to use a classNames attribute to add or remove classes based on certain conditions.

View RFC

How did you test this change?

  1. I ran yarn build react/index,react-dom/index --type=UMD
  2. Made changes in fixtures/packaging/babel-standalone/dev.html as follows:
    <script type="text/babel">
      const isHovering = false;
      const isDisabled = true;
      ReactDOM.render(
        <button classNames={[
          "primary",
          ["teal", "semi-transparent", isHovering && ["hover", "darken-2"]],
          {loading: true, 'is-disabled': isDisabled},
          undefined,
          false,
          null,
          `custom-class`
        ]}>Click Me!</button>,
        document.getElementById('container')
      );
    </script>

and output was generated as expected

<div id="container">
  <button class="primary teal semi-transparent loading is-disabled custom-class">Click Me!</button>
</div>

Related Issues
#3138, #16705, #20050

@react-sizebot
Copy link

react-sizebot commented Apr 26, 2023

Comparing: 559e83a...de18653

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js +0.28% 164.18 kB 164.65 kB +0.32% 51.78 kB 51.94 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js +0.27% 171.57 kB 172.04 kB +0.32% 53.99 kB 54.16 kB
facebook-www/ReactDOM-prod.classic.js +0.19% 570.19 kB 571.26 kB +0.24% 100.62 kB 100.86 kB
facebook-www/ReactDOM-prod.modern.js +0.19% 553.93 kB 555.00 kB +0.24% 97.80 kB 98.04 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable-semver/react-dom/umd/react-dom.production.min.js +0.29% 164.02 kB 164.49 kB +0.32% 52.08 kB 52.25 kB
oss-stable/react-dom/umd/react-dom.production.min.js +0.29% 164.09 kB 164.56 kB +0.33% 52.10 kB 52.27 kB
oss-stable-semver/react-dom/cjs/react-dom.production.min.js +0.28% 164.11 kB 164.57 kB +0.31% 51.76 kB 51.91 kB
oss-stable/react-dom/cjs/react-dom.production.min.js +0.28% 164.18 kB 164.65 kB +0.32% 51.78 kB 51.94 kB
oss-experimental/react-dom/umd/react-dom.production.min.js +0.28% 171.41 kB 171.88 kB +0.22% 54.27 kB 54.39 kB
oss-stable-semver/react-dom/umd/react-dom.profiling.min.js +0.27% 173.00 kB 173.47 kB +0.30% 54.47 kB 54.64 kB
oss-stable/react-dom/umd/react-dom.profiling.min.js +0.27% 173.07 kB 173.55 kB +0.30% 54.50 kB 54.66 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js +0.27% 171.57 kB 172.04 kB +0.32% 53.99 kB 54.16 kB
oss-stable-semver/react-dom/cjs/react-dom.profiling.min.js +0.27% 173.74 kB 174.21 kB +0.31% 54.19 kB 54.36 kB
oss-stable/react-dom/cjs/react-dom.profiling.min.js +0.27% 173.81 kB 174.28 kB +0.31% 54.21 kB 54.38 kB
oss-experimental/react-dom/cjs/react-dom-unstable_testing.production.min.js +0.26% 177.78 kB 178.25 kB +0.26% 56.32 kB 56.47 kB
oss-experimental/react-dom/umd/react-dom.profiling.min.js +0.26% 180.40 kB 180.87 kB +0.23% 56.60 kB 56.73 kB
oss-experimental/react-dom/cjs/react-dom.profiling.min.js +0.26% 181.21 kB 181.68 kB +0.30% 56.40 kB 56.57 kB

Generated by 🚫 dangerJS against de18653

Copy link

github-actions bot commented Apr 9, 2024

This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated.

@github-actions github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Apr 9, 2024
@github-actions github-actions bot removed the Resolution: Stale Automatically closed due to inactivity label Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants