Skip to content
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

Docs: Added a How To guide for working with ShadCN #10459

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ahaywood
Copy link
Contributor

Recently, someone within the Discord forums asked how to get ShadCN working with Redwood. Since Redwood uses yarn workspaces the installation process isn't as straightforward as simply following ShadCN's documentation. However, since it's all React, it's mostly a matter mapping files and folders so ShadCN knows where to place its files.

@ahaywood ahaywood added topic/docs release:docs This PR only updates docs labels Apr 15, 2024
@ahaywood ahaywood added this to the next-release-patch milestone Apr 15, 2024
Copy link
Collaborator

@Josh-Walker-GM Josh-Walker-GM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! One minor comment but otherwise awesome. I walked through the instructions and it was clear and went smoothly for me.

Comment on lines +58 to +64
```js
import tsconfigPaths from 'vite-tsconfig-paths';

export default {
plugins: [tsconfigPaths()],
}
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We omit the default contents of the vite.config.js here. I think it's obvious enough that this plugin should be in addition to the existing redwood one. Do you think it would be more or less confusing to alter this code block to include the default contents?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! ... I can add the default contents

"config": "./config/tailwind.config.js",
"css": "./src/index.css",
"cssVariables": true,
"prefix": "tw-",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahaywood I believe this tw- should be removed from this PR. Took me a bit to track down why the tailwind styles weren't being applied specifically on components imported from shadcn but finally realized it's because all of the class names were prefixed with tw- which were being completely ignored.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nathanmacfarlane for helping to find this - would have probably been running around in circles if not for this. Was very puzzled by the issues I was facing too, and upon trying out on a fresh repo the instructions at the separate PR for shadcn's page (which correctly omitted the tw- prefix, but left out the tsconfigpaths plugin), came to the same conclusion that it was due to this. (Truly being misled by the documentation on shadcn's page...)

E.g. classNames were ending up as:

className={cn("tw-fixed tw-inset-0 tw-z-50 tw-bg-black/80 tw- data-[state=open]:tw-animate-in data-[state=closed]:tw-animate-out data-[state=closed]:tw-fade-out-0 data-[state=open]:tw-fade-in-0",className)

Leaving it as "prefix": "" fixes it.

Just in case someone else stumbles upon this issue too, I also had to delete all shadcn components that had been earlier yarn shad <insert component> to reset the problematic classNames.

@shansmith01
Copy link
Contributor

Great tutorial. I managed to get everything working except that tests are failing when importing anything with the @ alias. eg
import { cn } from '@/lib/utils'

eg. error is " Cannot find module '@/components/Button/Button' from 'web/src/components/Calendar/Calendar.tsx'

If I swap out @ for src everything works fine

This can be replicated in the example repo in the docs

Does anyone have any ideas on getting that working?

@twoflyingforks
Copy link

twoflyingforks commented May 21, 2024

Great tutorial. I managed to get everything working except that tests are failing when importing anything with the @ alias. eg import { cn } from '@/lib/utils'

eg. error is " Cannot find module '@/components/Button/Button' from 'web/src/components/Calendar/Calendar.tsx'

If I swap out @ for src everything works fine

This can be replicated in the example repo in the docs

Does anyone have any ideas on getting that working?

In tsconfig.json, under "compilerOptions" > "paths", I have the following (see the specific line which was added). Hope it helps!

"compilerOptions": {
   "paths": {
     ...
     "@/*": ["./src/*"]

"cssVariables": true,
"prefix": "tw-",
"rsc": false,
"tsx": true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed a minor typo error here in that the rsc and tsx parameters should be placed outside the tailwind section, instead of within.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:docs This PR only updates docs topic/docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants