pugjs / babel-plugin-transform-react-pug

A plugin for transpiling pug templates to jsx
MIT License
811 stars 47 forks source link

How to use namespaced components (e.g. animated.div) in pug? #86

Open mostrecent opened 5 years ago

mostrecent commented 5 years ago

I'd like to use react-spring as animation lib and there is an option , check: http://react-spring.surge.sh/perf and I wasn't able to reflect this in pug so that it correctly transpiles to

Is it possible after all or did I just missed the right way?

ezhlobo commented 5 years ago

@mostrecent that is the limitation of pugjs, you have to create a variable and assign animated.div to it. For example:

import { animated } from 'react-spring' 

const AnimatedDiv = animated.div

pug`
  AnimatedDiv
`

// This will generate:
// <AnimatedDiv />

You also can use the plugin which will transform className generated by pug into property. Take a look at documentation: #limitations (and plugin).

Unfortunately, it will work if the object will start with upcase, like this:

import { animated as Animated } from 'react-spring' 

pug`
  Animated.div
`

// This will generate:
// <Animated.div />

That plugin can be easily changed to make it more natural in this case, I've just created an issue: https://github.com/ezhlobo/babel-plugin-transform-jsx-classname-components/issues/5

Please, share your thoughts regarding that.

mostrecent commented 5 years ago

@ezhlobo thanks for your reply and I did try your other lib at https://github.com/ezhlobo/babel-plugin-transform-jsx-classname-components/issues/5 before as well and I think your proposed solution (using that extra lib) might be a good, more elegant one.

Just wondering if this extra lib should be built into this main lib where you could turn it on and setup via webpack/babel options. However, heading over to the other's lib's issues...

mostrecent commented 5 years ago

Just wondering if this extra lib should be built into this main lib

Thought again about my idea and I think that both libs should be separated like it is right now. It's cleaner.