-
Notifications
You must be signed in to change notification settings - Fork 1k
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
cli/lib/merge
& setup ui mantine
#4900
Conversation
Essentially copies the Chakra-UI implementation and gently refactors Chakra's setup implementation to use a now-shared function.
✅ Deploy Preview for redwoodjs-docs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
This is a great start @nickpdemarco! Thanks for taking the time to work on this. One of the more difficult parts when adding new styling frameworks seems to be to get the StoryBook integration working. So please make sure give that an extra round of testing. |
Thanks for the encouragement @Tobbe! I'll make a point to stress test the storybook integrations. |
…tine and Chakra, and leverage that (setup-component-library.js) in the implementations for each library setup command
@Tobbe With this last push, I think I've replicated chakra-ui's storybook integration. I'm creating a In writing that, though, I realized that we'll be wrapping the app component in a different instance of If I understand the situation correctly, this means we need some sort of standard location / file for theme overrides, so both |
@nickpdemarco Thanks for the summary of the problem. I agree that we should try to find a better solution. @virtuoushub Is this something you've been thinking about when working with RW's Storybook integration? |
A strawman for your consideration: I have something working reasonably well: When we run Then I can reference that in both App and the storybook preview as follows:
Does nothing by default, of course, but gives the user a reasonable place to put their theme overrides, and automatically gets changes visible in Storybook and in the app. I think Chakra would work similarly, if we decided to go this route. |
Great question and, yes, we want to make changes here per recommendations from the Storybook team. @Tobbe has already looped in @virtuoushub who can help sync things up. |
I'm going to be honest here and say I hadn't actually heard of mantine until you created this PR. And now I found https://ui.mantine.dev and I'm really impressed! This is going to be a great addition to RW 🚀 |
@Tobbe, yes, a bit. I quite like @nickpdemarco's approach:
@nickpdemarco thanks for this PR! 🔥 🔥 🔥 I have reached out to some of the folks who maintain Storybook to see what they recommend for things like this. Depending on how common of an interface we can get around things like extending themes, it might make sense to adopt a pattern that is framework agnostic. Rough idea is some template such as: import * as theme from `src/themes/${framework}.config`
const extendedTheme = extendTheme(theme) |
@virtuoushub I hear you - I think a generalized theme/library interface is plausible. Bear in mind that In this particular case, I think there's an unusual amount of API symmetry between Chakra and Mantine (Mantine took a lot of inspiration from Chakra, if I have my history right) I'm also realizing that the current tailwind theme configuration files end up in For this PR, to keep the surface area small and to be a good consistent citizen, I figure I'll move the mantine and chakra generated theme files to |
…uction. Need to refactor the wrapper functions a bit to be able to inject the lines in the correct place
Clean up setup-component-library to be a bit more general, and configure the mantine builder to use the new API.
rw setup ui mantine
rw setup ui mantine
& built-in styles for Chakra
@nickpdemarco @Tobbe @jtoar Well done! |
Using mantine breaks tests. tests are failing now because mantine requires the render function to include the 'mantineprovider' in the path. "@mantine/core: MantineProvider was not found in component tree, make sure you have it in your app" @nickpdemarco How should I handle the failing tests? |
Reviewer's Guide
Key files
packages/cli/src/lib/merge/index.js
Generic AST merging algorithm. Or, read the docs, or read the tests.packages/cli/src/lib/merge/strategy.js
Named higher-order merge strategies likeconcatUnique
.packages/cli/src/lib/extendFile.js
New utility for modifyingApp.js|tsx
etc.Straightforward changes
packages/cli/src/commands/setup/ui/libraries/mantine.js
Essentially a copy of chakra's approach.packages/cli/src/commands/setup/ui/libraries/chakra-ui.js
Tweaks to use new internal apis.packages/cli/src/lib/configureStorybook.js
Now, just calls tofs
andmerge
.Description
cli/lib/merge
This PR introduces a new
merge
sublibrary ofcli/lib
, designed to facilitate the merging of Javascript files. See the README for more complete documentation.The merge implementation requires
@babel/generator
and@types/babel__generator
, and both have been added to the framework-levelpackage.json
.Please note: I consider this code to be
0.1
quality - I've really only provided tests to prove it works for mostly-reasonable, small javascript files. Much more testing is required before using it in contexts outside of Storybook configuration merges. So, think of it as a foundation, rather than a perfectly complete, generic Javascript AST merger.rw setup *
This merge algorithm is used in service of
rw setup i18n
,rw setup ui chakra-ui
, and a newly-addedrw setup ui mantine
, each of which need to extend our storybook configuration file, which lives atweb/config
in Redwood Projects.To accomodate this, we've slightly changed how we handle storybook configurations. First, we have a "base" configuration, which provides some useful examples and comments, but is a no-op from the perspective of Storybook. In the framework, the file lives at
cli/src/lib/templates
. If a user never invokes a Redwood command that requires a storybook configuration, they'll never see this file. However, if they do, said file will be used as the "base" into which command-specific extensions (e.g. those needed by i18n) will be merged.This notion of "base" and "extension" occurs often in the merge code, and imply a handful of design decisions. Code in the base is considered sacred (since it may be user-generated) and is never deleted, overwritten, or otherwise manipulated in a lossy manner. As an example, leading comments on semantically-equivalent nodes will prefer the base version. Assuming we're using a
concatUnique
merge strategy forArrayExpression
, the following demonstrates a simple merge.extendJSXFile
See
extendFile
.One of the earlier problems addressed by this ever-expansive PR was the manipulation of
App.{js|tsx}
during variousrw setup
commands. I still believe the implementation provided in this PR is an improvement over mainline, but I am beginning to wonder ifextendFile.js
could also be improved by some Babel-ification. In the interest of preventing yet-further scope creep on this PR, I leave that as a task for another time.TODO
I believe the code in this PR is now ready for proper review. It has grown considerably in scope from its original mission (to simply add Mantine as another UI provider), and as such it may be appropriate to split the merge code into another PR. If any of the reviewers here deem that appropraite, I can make the change this weekend.
Furthermore, I need to enrich the documentation in the source tree, as well as on the public-facing websites. I figure that shouldn't block a review, so I'm taking this PR out of draft.
<lib>.config.js