Skip to content

Commit 5d49b77

Browse files
authored
Merge pull request #483 from Dataport/feature/make-font-family-selectable
feat: make font family selectable
2 parents dae4461 + d7a5170 commit 5d49b77

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

examples/snowbox/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ const dataportTheme = {
6262
default: '0 10px 10px 10px',
6363
},
6464
},
65+
typography: {
66+
font: {
67+
family: {
68+
default: 'Consolas',
69+
},
70+
},
71+
},
6572
},
6673
}
6774

src/core/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010
/* eslint-enable tsdoc/syntax */
1111

12-
import '@kern-ux/native/dist/fonts/fira-sans.css'
1312
import { defineCustomElement } from 'vue'
1413

1514
import PolarContainer from './components/PolarContainer.ce.vue'

src/core/types/theme.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,22 @@ export interface KernThemeTree {
1414
/**
1515
* Describes the theming options of KERN.
1616
* The exhaustive list of parameters is documented in `@kern-ux/native`.
17+
*
18+
* **About fonts**
19+
*
20+
* Please mind that setting a value to `kern.typography.font.family.default`
21+
* will stop the client from loading the font `Fira Sans` used in the KERN
22+
* design system. 'inherit' will not work as a value due to technical
23+
* limitations of the ShadowDOM. To inherit whatever would naturally arrive or
24+
* is styled on the host node, use `''` (empty string).
25+
* You may also set `"Fira Sans", sans-serif` (the default value) to this
26+
* variable in case you already have the font loaded to prevent loading it
27+
* twice.
1728
*/
1829
export interface KernTheme {
1930
color: KernThemeTree
2031
metric: KernThemeTree
32+
typography: KernThemeTree
2133
}
2234

2335
/**

src/core/utils/loadKern.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ export function loadKern(host: ShadowRoot, theme: Partial<KernTheme> = {}) {
3737
`)
3838
host.adoptedStyleSheets.push(kernSheet)
3939

40+
// @ts-expect-error | It's fine, we're getting `undefined` for an access on string, too.
41+
if (typeof theme.typography?.font?.family?.default !== 'undefined') {
42+
void import('@kern-ux/native/dist/fonts/fira-sans.css')
43+
}
44+
4045
const kernTheme = buildKernTheme(theme)
4146
host.adoptedStyleSheets.push(kernTheme)
4247
}

0 commit comments

Comments
 (0)