Open joshwcomeau opened 7 years ago
Good approach! I need to think more about it later (maybe at the time I wanted to implement it). Only thing I can think of now is we can use function + switch statement for those 4 generators, so we can group together similar inputs and return identical values for them at once (DRY).
// templates/render-contents.js
export default (style) => {
switch (style) {
case 'styled-components':
case 'glamorous':
return `<Wrapper />`;
}
};
BTW, I'd be happy to implement it next week or sooner.
Yeah, switch statement makes sense to me :)
Awesome to hear you're up for implementing it! I'll assign you to the issue. No pressure of course, just assigning you so that any others know to coordinate if they want to take a stab at it :)
It'd be awesome if
new-component
could include base styling.There are two issues here: Coming up with the individual templates for each style solution, as well as the underlying architecture changes to make this possible.
Templates by style solution
styled-components
For
styled-components
, I spoke with Max on twitter and we think the best solution would be to update the template to be something like this:A near-identical template could be used for
emotion
(literally just swapping outstyled-components
foremotion/react
, in the import line.CSS modules
For CSS modules, the JS template would need to be updated to something like this:
We'd also need the CSS file, but it can be super minimal:
Aphrodite
Finally, given that I work at KA, I'd like to add Aphrodite support! it would look like something of a mix of these earlier two solutions (all defined in the JS file, but using
className
and astyles
object)Architecture Changes
It actually seems like a pretty hard problem, figuring out how to add these new templates in a sustainable way. Because we support 3 different kinds of components (class, pure, functional), ideally I don't want to have to create 3 * 4 templates, for each possible permutation.
Thinking off the top of my head... One idea is to split the template into "quadrants", little mix-and-match pieces. You'd assemble the final template by picking the pieces you need, based on the type of component and style solution.
I imagine the different "areas" are:
const Wrapper = styled.div
)export default Whatever
)Here's a very rough first pass (this could be all wrong, just going with an idea :) )
And then you'd just combine them to create the actual template:
This is of course a very rough draft, haven't thought through all the implications. Happy to discuss!
Going forward, I don't anticipate having that much time to spend on this (currently deeply involved in another side project, + my day job), so if anyone wanted to take this on, that'd be awesome. I want this to be a community project! Otherwise, I'll do my best to get to this in the next month or two :)