pugjs / babel-plugin-transform-react-pug

A plugin for transpiling pug templates to jsx
MIT License
808 stars 46 forks source link

Make transforming class attributes more obvious #69

Closed ezhlobo closed 5 years ago

ezhlobo commented 5 years ago

For now we try to resolve all arrays, and make combinations into arrays to combine shorthands and className attribute.

The idea is to remove own judgement of how people want to use class attribute. Now we make it more consistent: if we pass array or object — we get array or object. More examples:

.one.two
div(className="one two")
//- <div className="one two" />

div(className=100)
//- <div className={100} />

div(className=variable)
//- <div className={variable} />

div(className=['one', 'two'])
//- <div className={['one', 'two']} />

div(className=['one', 'two'].join(' '))
//- <div className={['one', 'two'].join(' ')} />

div(className={first: true})
//- <div className={{first: true}} />

It becomes more interesting when it mixes with shorthands:

.mix(className="one two")
//- <div className="mix one two" />

.mix(className=100)
//- <div className={'mix ' + 100} />

.mix(className=variable)
//- <div className={'mix ' + variable} />

.mix(className=['one', 'two'])
//- <div className={['mix', 'one', 'two']} />

.mix(className=['one', 'two'].join(' '))
//- <div className={'mix ' + ['one', 'two'].join(' ')} />

.mix(className={first: true})
//- <div className={'mix ' + {first: true}} />