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(fonts): Update @font-face recommendation #8986

Merged
merged 7 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
22 changes: 17 additions & 5 deletions docs/docs/assets-and-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,24 +145,36 @@ export const CarIcon = (props: SVGProps) => {
If you needed to convert a whole library of SVGs into stylable (or animatable!) components, one easy way would be to use the [SVGR cli](https://react-svgr.com/docs/cli/)



## Custom fonts
There are many different ways to peel this potato – it's all a search away – but if you're using the CSS `@font-face` rule, we have a quick tip for you:

1. Place your fonts in the public folder, so it gets carried across
2. In your CSS, use relative paths to point to the font file, for example:
2. In your CSS, use absolute paths - the public folder being your root - to point to the font file (same as the [Vite docs](https://vitejs.dev/guide/assets.html#the-public-directory)), for example:

```shell
web/
├── src
├── App.tsx
├── entry.client.tsx
├── index.css
├── ...
├── public
│ ├── favicon.png
│ ├── fonts
// highlight-next-line
│ │ └── RedwoodNeue.woff2
```

```css
/* in some CSS file you are loading in your project */
/* in e.g. index.css file you are loading in your project */
dac09 marked this conversation as resolved.
Show resolved Hide resolved
@font-face {
font-family: 'Redwood Neue';
/* 👇 it's a relative path */
// highlight-next-line
src: url('../../public/fonts/RedwoodNeue.woff2')
src: url('/fonts/RedwoodNeue.woff2')
format('woff2');
font-weight: 300;
font-style: italic;
ascent-override: 97%;
}
```
This will make sure that the fonts are being loaded correctly across your dev server and storybook – where there are subtle differences in how paths are processed.
22 changes: 18 additions & 4 deletions docs/versioned_docs/version-6.0/assets-and-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,33 @@ If you needed to convert a whole library of SVGs into stylable (or animatable!)
There are many different ways to peel this potato – it's all a search away – but if you're using the CSS `@font-face` rule, we have a quick tip for you:

1. Place your fonts in the public folder, so it gets carried across
2. In your CSS, use relative paths to point to the font file, for example:
2. In your CSS, use absolute paths - the public folder being your root - to point to the font file (same as the [Vite docs](https://vitejs.dev/guide/assets.html#the-public-directory)), for example:


```shell
web/
├── src
├── App.tsx
├── entry.client.tsx
├── index.css
├── ...
├── public
│ ├── favicon.png
│ ├── fonts
// highlight-next-line
│ │ └── RedwoodNeue.woff2
```

```css
/* in some CSS file you are loading in your project */
/* in e.g. index.css file you are loading in your project */
dac09 marked this conversation as resolved.
Show resolved Hide resolved
dac09 marked this conversation as resolved.
Show resolved Hide resolved
@font-face {
font-family: 'Redwood Neue';
/* 👇 it's a relative path */
// highlight-next-line
src: url('../../public/fonts/RedwoodNeue.woff2')
src: url('/fonts/RedwoodNeue.woff2')
format('woff2');
font-weight: 300;
font-style: italic;
ascent-override: 97%;
}
```
This will make sure that the fonts are being loaded correctly across your dev server and storybook – where there are subtle differences in how paths are processed.