Skip to content

Commit

Permalink
feat: adds typography urls support (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrk authored Jun 1, 2021
1 parent 7f3915c commit 9bfd3c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ConfigContext } from "./context";
import { defaultState, apiDefaults, fallbackLng, LOCALE_KEY } from "./constants";
import useStyles from "./styles";
import { ConfigProviderProps, ConfigState, Locale } from "./types";
import { injectStylesheetLink } from "./util/injectStylesheetLink";

export const ConfigProvider: React.FC<ConfigProviderProps> = ({ children, api, translations, ...rest }) => {
const classes = useStyles();
Expand Down Expand Up @@ -49,6 +50,13 @@ export const ConfigProvider: React.FC<ConfigProviderProps> = ({ children, api, t
responses.map((r) => r.json()),
);

const fontUrls = theme?.typography?.urls;

// load fonts
if (Array.isArray(fontUrls)) {
fontUrls.forEach((url) => injectStylesheetLink(url));
}

// create theme from API configurations
appTheme.current = createMuiTheme(theme);

Expand Down
9 changes: 9 additions & 0 deletions lib/util/injectStylesheetLink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** injects a link tag of rel stylesheet in the head of the document */
export function injectStylesheetLink(url: string) {
const link = document.createElement("link");

link.rel= "stylesheet";
link.href = url;

document.head.appendChild(link);
}

0 comments on commit 9bfd3c6

Please sign in to comment.