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

feat: add font family to theming #8797

Merged
merged 1 commit into from
Apr 12, 2023
Merged
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
6 changes: 6 additions & 0 deletions changelog/unreleased/enhancement-font-family-theming
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Font family in theming

We've added support for modifying the font family via theming.
Please note that the chosen font needs to be made available as `font-face` via additional CSS.

https://github.com/owncloud/web/pull/8797
14 changes: 14 additions & 0 deletions docs/theming/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ In general, the theme loader looks for a `designTokens` key inside your theme co
"designTokens": {
"breakpoints": {},
"colorPalette": {},
"fontFamily": "",
"fontSizes": {},
"sizes": {},
"spacing": {}
Expand Down Expand Up @@ -205,6 +206,18 @@ Font size variables get prepended with `--oc-font-size-`, so e.g. *"default"* cr
}
```

### Font family

You can change the font family according to your needs. The font family gets written into the `--oc-font-family` CSS variable.

```json
{
"fontFamily": ""
}
```

Please note that you also need to make the font available as a `font-face` via CSS.

### Sizes

Use sizing variables to change various UI elements, such as icon and logo appearance, table row or checkbox sizes, according to your needs.
Expand Down Expand Up @@ -330,6 +343,7 @@ An empty template for your custom theme is provided below, and you can use the i
"large": "",
"medium": ""
},
"fontFamily": "",
"sizes": {
"form-check-default": "",
"height-small": "",
Expand Down
13 changes: 9 additions & 4 deletions packages/design-system/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import * as directives from './directives'

const initializeCustomProps = (tokens = [], prefix) => {
for (const param in tokens) {
;(document.querySelector(':root') as HTMLElement).style.setProperty(
'--oc-' + prefix + param,
tokens[param]
)
initializeCustomProp(prefix + param, tokens[param])
}
}

const initializeCustomProp = (key: string, value: string | undefined) => {
if (value === undefined) {
return
}
;(document.querySelector(':root') as HTMLElement).style.setProperty('--oc-' + key, value)
}

export default {
install(app, options: any = {}) {
const themeOptions = options.tokens
Expand All @@ -21,6 +25,7 @@ export default {
initializeCustomProps(themeOptions?.fontSizes, 'font-size-')
initializeCustomProps(themeOptions?.sizes, 'size-')
initializeCustomProps(themeOptions?.spacing, 'space-')
initializeCustomProp('font-family', themeOptions?.fontFamily)

Object.values(components).forEach((c) => app.component(c.name, c))
Object.values(directives).forEach((d) => app.directive(d.name, d))
Expand Down