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

Proposal: combining classes using only className #154

Open
rafikalid opened this issue Nov 10, 2022 · 2 comments
Open

Proposal: combining classes using only className #154

rafikalid opened this issue Nov 10, 2022 · 2 comments

Comments

@rafikalid
Copy link

rafikalid commented Nov 10, 2022

Actual behaviour

We need to use third party libs like clsx to complish this very common behaviour

<div className={ clsx( 'class1', condition && 'class2', condiction2 ? 'class3' : null ) } />

Wanted behaviour

Use JSX to accomplish this common task directly

<div
     className = "class1"
     className = { condition && 'class2' }
     className = { condition2 ? 'class3' : null }
     />

// OR
<div
     className={ [
          'class1',
          condition && 'class2',
          condition3 ? 'class3' : null
     ] }
     />

This should compile everything to somthing like :

React.createElement( 'div', {className: ['class1', condition && 'class2', condition2 ? 'class3' : null ] } );
@rafikalid
Copy link
Author

I propose in general to compile duplicated attributes to arrays as follow:

<div
    className = "c1"
    className = "c2"
    className = "c3"
/>

// TO

React.createElement(Component, {
  className: [ 'c1', 'c2', 'c3' ]
});

and

<div
    anyAttr = "value 1"
    anyAttr = { true }
    anyAttr = { callLogic() }
    anyAttr
    !anyAttr
/>

// TO

React.createElement(Component, {
  anyAttr: [ "value1", true, callLogic(), true, false ]
});

@fabiospampinato
Copy link

This is a problem that must be solved at the framework level, React is just giving you a very basic API for setting classes, that's the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants