Skip to content

Commit d4cf9ce

Browse files
Merge pull request #312 from jwthomson/recipe-ui-add-style
Update "add style" recipe for SAFE v5
2 parents 295fea9 + fc43294 commit d4cf9ce

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

docs/recipes/ui/add-style.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# How do I use stylesheets with SAFE?
2+
The default way to add extra styles is to add them using Tailwind classes.
3+
If you wish to use your own CSS stylesheets with SAFE apps, Vite can bundle them up for you.
4+
5+
There are two different approaches to adding your own CSS file, depending on what files you have available.
6+
7+
## Method A: Import into `index.css`
8+
The default template includes a stylesheet at `src/Client/index.css` which contains references to Tailwind.
9+
The cleanest way to add your own stylesheet is to create a new file e.g. `src/Client/custom-style.css` and then reference it from `index.css`.
10+
11+
1. Create your custom css file in `src/Client`, e.g. `custom-style.css`
12+
1. Import it into `index.css`
13+
```diff
14+
+@import "./custom-style.css";
15+
@tailwind base;
16+
@tailwind components;
17+
@tailwind utilities;
18+
```
19+
20+
## Method B: Import without `index.css`
21+
In order for Vite to know that there are styles to be bundled, you must import them into your app. By default this is already configured for `index.css` but if you don't have it set up, not to worry! Follow these steps:
22+
23+
1. Create your custom css file in `src/Client`, e.g. `custom-style.css`
24+
1. Direct Fable to emit an import for your style file.
25+
- Add the following to `App.fs`:
26+
```fsharp
27+
open Fable.Core.JsInterop
28+
importSideEffects "./custom-style.css"
29+
```
30+
31+
## There you have it!
32+
You can now style your app by writing to the `custom-style.css` file.

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ nav:
7575
- UI:
7676
- Add Tailwind support: "recipes/ui/add-tailwind.md"
7777
- Add daisyUI support: "recipes/ui/add-daisyui.md"
78+
- Add Stylesheet support: "recipes/ui/add-style.md"
7879
- Add Feliz support: "recipes/ui/add-feliz.md"
7980
- Add FontAwesome support: "recipes/ui/add-fontawesome.md"
8081
- Migrate from a CDN stylesheet to an NPM package: "recipes/ui/cdn-to-npm.md"
@@ -136,7 +137,6 @@ nav:
136137
- Create a data module using SQLProvider SQL Server SSDT: "v4-recipes/storage/use-sqlprovider-ssdt.md"
137138
- UI:
138139
- Add FontAwesome support: "v4-recipes/ui/add-fontawesome.md"
139-
- Add Stylesheet support: "v4-recipes/ui/add-style.md"
140140
- Add Bulma support: "v4-recipes/ui/add-bulma.md"
141141
- Use different Bulma Themes: "v4-recipes/ui/use-different-bulma-themes.md"
142142
- Remove Bulma: "v4-recipes/ui/remove-bulma.md"

0 commit comments

Comments
 (0)