Skip to content

Commit

Permalink
feat: add regular and monospace font (#102)
Browse files Browse the repository at this point in the history
<!-- Is your PR related to an issue? Then please link it via the "closes
#" below. Else, remove it. -->

## Description

Add CSS variables `--onyx-font-family` and `--onyx-font-family-mono`.
Also update docs on how to install the font families since we should not
directly bundle them with Onyx because the project should be able to use
different fonts.
  • Loading branch information
larsrickert authored Jan 15, 2024
1 parent 13f96c1 commit 0920aa6
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/tame-adults-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"sit-onyx": minor
---

feat: add CSS variables `--onyx-font-family` and `--onyx-font-family-mono`
1 change: 1 addition & 0 deletions apps/docs/src/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default defineConfig({
items: [
{ text: "Getting Started", link: "/getting-started" },
{ text: "i18n", link: "/i18n/" },
{ text: "Typography", link: "/typography" },
{ text: "The Team", link: "/team" },
],
},
Expand Down
37 changes: 37 additions & 0 deletions apps/docs/src/typography.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Typography

The Onyx design system relies on a default (sans-serif) and a monospace font family.

Onyx is intended to be used with the following font families which are open-source
and free to use under the [SIL Open Font License](https://en.wikipedia.org/wiki/SIL_Open_Font_License):

- Default: [Source Sans 3](https://fontsource.org/fonts/source-sans-3)
- Monospace: [Source Code Pro](https://fontsource.org/fonts/source-code-pro)

## Using custom font families

::: info Default font families
The above default font families are already bundled into the component library
so you don't need to install them manually.
:::

If you want to use custom font families, you need to install them and override the following CSS variables manually.

We recommend installing font families as npm package using [Fontsource](https://fontsource.org).

::: code-group

```css [custom.css]
/* import your custom fonts here... */
:root {
--onyx-font-family: "My custom font family", sans-serif;
--onyx-font-family-mono: "My custom mono font family", monospace;
}
```

```ts [main.ts]
// make sure to import your custom styles AFTER "sit-onyx/style.css"
import "custom.css";
```

:::
2 changes: 2 additions & 0 deletions packages/sit-onyx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"vue": ">= 3"
},
"devDependencies": {
"@fontsource-variable/source-code-pro": "^5.0.17",
"@fontsource-variable/source-sans-3": "^5.0.19",
"@playwright/experimental-ct-vue": "^1.40.1",
"@playwright/test": "^1.40.1",
"@sit-onyx/storybook-utils": "workspace:^",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/sit-onyx/src/components/TestInput/TestInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ watch(
.input {
width: max-content;
display: inline-block;
font-family: var(--onyx-font-family);
&__label {
margin-right: 8px;
Expand Down
10 changes: 9 additions & 1 deletion packages/sit-onyx/src/styles/index.scss
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
// global styles
// global component styles
// DO NOT ADD ANY STYLES HERE THAT HAVE SIDE EFFECTS ON THE GLOBAL APPLICATION (e.g. body, <a> etc.)
@use "@fontsource-variable/source-code-pro";
@use "@fontsource-variable/source-sans-3";

:root {
--onyx-font-family: "Source Sans 3 Variable", sans-serif;
--onyx-font-family-mono: "Source Code Pro Variable", monospace;
}
38 changes: 26 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0920aa6

Please sign in to comment.