Skip to content

Commit 6b1abf3

Browse files
authored
Merge pull request #372 from SAFE-Stack/shadcn-recipe
Add shadcn recipe to docs
2 parents 8563932 + f5e4729 commit 6b1abf3

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

docs/recipes/ui/add-shadcn.md

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# How do I add shadcn to a SAFE project?
2+
3+
> Note: The SAFE.Template has recently been updated to move `package.json` and `package-lock.json`. If you are using a version of the template prior to this change, you will need to move those files into the `src/Client` directory. For reference, here is the [PR](https://github.com/SAFE-Stack/SAFE-template/pull/658) detailing this change.
4+
5+
Integrating Feliz.Shadcn into your SAFE Stack application is straightforward. The following example demonstrates how to integrate Shadcn copmonents within an existing SAFE app.
6+
7+
We will be using the [Feliz.Shadcn](https://github.com/reaptor/feliz.shadcn) wrapper written by [reaptor](https://github.com/reaptor)
8+
9+
#### 1. Setup Tailwind
10+
> Note: When you use the SAFE template you will already have Tailwind installed by default. You can skip this step.
11+
12+
Check out the following recipe here to install Tailwind: [Add Tailwind](https://safe-stack.github.io/docs/recipes/ui/add-tailwind/)
13+
14+
#### 2. Configure import alias in tsconfig:
15+
16+
Create a file named `tsconfig.json` in `/src/Client` and add the following:
17+
18+
```json
19+
{
20+
"files": [],
21+
"compilerOptions": {
22+
"baseUrl": ".",
23+
"paths": {
24+
"@/*": [
25+
"./*"
26+
]
27+
}
28+
}
29+
}
30+
```
31+
32+
#### 3. Update the `vite.config.mts` within `/src/Client`
33+
34+
Add the `resolve` property below under the `defineConfig`
35+
36+
```
37+
export default defineConfig({
38+
...
39+
resolve: {
40+
alias: {
41+
"@": path.resolve(__dirname),
42+
},
43+
},
44+
...
45+
});
46+
```
47+
48+
#### 4. Install shadcn/ui
49+
50+
> Note: ensure your node version is > 20.5.0
51+
52+
Inside the `/src/Client` directory run:
53+
```
54+
npx shadcn@latest init
55+
```
56+
57+
You will be asked a few questions to configure components.json
58+
59+
#### 5. Add Feliz.Shadcn
60+
61+
Inside the `/src/Client` directory run:
62+
```
63+
dotnet add package Feliz.Shadcn
64+
```
65+
66+
#### 6. Start adding any shadcn component
67+
68+
Specify first which components you want to use.
69+
You can find the list of available components [here](https://reaptor.github.io/Feliz.Shadcn/):
70+
71+
Inside the `/src/Client` directory run:
72+
```
73+
npx shadcn@latest add button
74+
```
75+
76+
#### 7. Use it in Feliz:
77+
78+
```fsharp
79+
open Feliz.Shadcn
80+
81+
82+
let view =
83+
Shadcn.button [
84+
prop.text "Button" ]
85+
86+
```
87+
88+
Congratulations, now you can use shadcn components!
89+
Further documentation can be found at [https://reaptor.github.io/Feliz.Shadcn/](https://reaptor.github.io/Feliz.Shadcn/)

mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ nav:
9494
- Add Tailwind support: "recipes/ui/add-tailwind.md"
9595
- Remove Tailwind support: "recipes/ui/remove-tailwind.md"
9696
- Add daisyUI support: "recipes/ui/add-daisyui.md"
97+
- Add shadcn support: "recipes/ui/add-shadcn.md"
9798
- Add Stylesheet support: "recipes/ui/add-style.md"
9899
- Add Feliz support: "recipes/ui/add-feliz.md"
99100
- Add FontAwesome support: "recipes/ui/add-fontawesome.md"

0 commit comments

Comments
 (0)