Skip to content

Add shadcn recipe to docs #372

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions docs/recipes/ui/add-shadcn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# How do I add shadcn to a SAFE project?

Integrating Feliz.Shadcn into your SAFE Stack application is straightforward. The following example demonstrates how to integrate Shadcn copmonents within an existing SAFE app.

We will be using the [Feliz.Shadcn](https://github.com/reaptor/feliz.shadcn) wrapper written by [reaptor](https://github.com/reaptor)

#### 1. Setup Tailwind
> Note: When you use the SAFE template you will already have Tailwind installed by default. You can skip this step.

Check out the following recipe here to install Tailwind: [Add Tailwind](https://safe-stack.github.io/docs/recipes/ui/add-tailwind/)

#### 2. Move `package.json` & `package-lock.json` to `/src/Client`

#### 3. Configure import alias in tsconfig:

Create a file named `tsconfig.json` in `/src/Client` and add the following:

```json
{
"files": [],
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": [
"./*"
]
}
}
}
```

#### 4. Update the `vite.config.mts` within `/src/Client`

Add the `resolve` property below under the `defineConfig`

```
export default defineConfig({
...
resolve: {
alias: {
"@": path.resolve(__dirname),
},
},
...
});
```

#### 5. Install shadcn/ui

> Note: ensure your node version is > 20.5.0

```
npx shadcn@latest init
```

You will be asked a few questions to configure components.json

#### 6. Add Feliz.Shadcn

Inside the `/src/Client` directory run:

```
dotnet add package Feliz.Shadcn
```

#### 7. Start adding any shadcn component

Specify first which components you want to use.
You can find the list of available components [here](https://reaptor.github.io/Feliz.Shadcn/):

```
npx shadcn@latest add button
```

#### 8. Use it in Feliz:

```fsharp
open Feliz.Shadcn


let view =
Shadcn.button [
prop.text "Button" ]

```

Congratulations, now you can use shadcn components!
Further documentation can be found at [https://reaptor.github.io/Feliz.Shadcn/](https://reaptor.github.io/Feliz.Shadcn/)
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ nav:
- Add Tailwind support: "recipes/ui/add-tailwind.md"
- Remove Tailwind support: "recipes/ui/remove-tailwind.md"
- Add daisyUI support: "recipes/ui/add-daisyui.md"
- Add shadcn support: "recipes/ui/add-shadcn.md"
- Add Stylesheet support: "recipes/ui/add-style.md"
- Add Feliz support: "recipes/ui/add-feliz.md"
- Add FontAwesome support: "recipes/ui/add-fontawesome.md"
Expand Down