Experimental babel macro #1296
Replies: 4 comments 11 replies
-
I've published an experimental tag to npm https://www.npmjs.com/package/theme-ui.macro and theres an example create-react-app here https://github.com/deckchairlabs/theme-ui.macro/tree/main/examples/create-react-app There's still quite a few edge cases to cover, but I'm pretty happy with how it's all progressed! |
Beta Was this translation helpful? Give feedback.
-
hi @deckchairlabs - sounds great. I am not familiar with babel macros and havent looked at your implementation yet - any chance you can make a comparison with the babel plugin - possibly we dont need to develop two different solutions if they solve the same goal. I am not set on the babel plugin development - Although currently the only remaining feature is split files, which i was thinking to solve this week end with a webpack source loader. |
Beta Was this translation helpful? Give feedback.
-
Hey @atanasster I guess the biggest difference is that it's more explicit, meaning you have to import the macro and call it with your theme object. It is also only dependent on import transformTheme from 'theme-ui.macro'
export default transformTheme({
colors: {
primary: 'red',
}
}) Plugins are also a core concept for both modifying the resulting theme object, as well as generating code. The one which I am most jazzed about is TypeScript Declaration generation. It also implements the idea of import transformTheme from 'theme-ui.macro'
export default transformTheme({
colors: {
primary: 'red',
},
buttons: {
base: {
paddingX: 2,
paddingY: 3,
},
primary: {
'@apply': 'buttons.base',
backgroundColor: 'primary',
}
}
})
↓ ↓ ↓ ↓ ↓ ↓ result ↓ ↓ ↓ ↓ ↓ ↓
export default {
colors: {
primary: 'red',
},
buttons: {
base: {
paddingX: 2,
paddingY: 3,
},
primary: {
paddingX: 2,
paddingY: 3,
backgroundColor: 'primary',
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Import and local variable resolution is handled in the macro, named, default and namespace imports are all working. The only issue is that this is not recursive currently, so will only handle imports one level deep. I don't think we need both solutions in my opinion, I would personally use the But I'd like to hear what @hasparus and others think about the direction. |
Beta Was this translation helpful? Give feedback.
-
I've been messing around with creating an experimental babel macro (originally forked from https://github.com/atanasster/babel-plugin-theme-ui thanks @atanasster! for sparking the idea), with the idea of breaking functionality out into plugins.
It is still very much a work in progress (handling imports are tricky), and nothing is published yet. Would love to get feedback, feature proposals etc.
The name is not final, as I wouldn't want to steal that namespace from this fine project.
https://github.com/deckchairlabs/theme-ui.macro
Beta Was this translation helpful? Give feedback.
All reactions