mirror of
https://github.com/wavetermdev/docusaurus-og.git
synced 2026-08-05 13:46:35 -07:00
feat: add support for custom global generic font family as a theme option closes #67
This commit is contained in:
@@ -8,6 +8,7 @@ import { useActivePlugin } from '@docusaurus/plugin-content-docs/lib/client/inde
|
||||
import { useColorMode } from '@docusaurus/theme-common'
|
||||
import { css } from '@emotion/react'
|
||||
import { useMemo } from 'react'
|
||||
import { useThemeOptions } from './useThemeOptions'
|
||||
|
||||
const typography: CreateThemeProps['typography'] = {
|
||||
h1: {
|
||||
@@ -99,8 +100,26 @@ const useThemeCssVars = (theme: Theme, colorMode: string) =>
|
||||
export const useTheme = () => {
|
||||
const colorMode = useColorMode()
|
||||
const activePlugin = useActivePlugin()
|
||||
const { typography } = useThemeOptions()
|
||||
const genericFontFamily = typography?.genericFontFamily ?? 'sans-serif'
|
||||
|
||||
const themes = activePlugin ? docThemes : defaultThemes
|
||||
const baseThemes = activePlugin ? docThemes : defaultThemes
|
||||
|
||||
const themes = useMemo(() => {
|
||||
const options = {
|
||||
breakpoints: {},
|
||||
palette: {},
|
||||
typography: {},
|
||||
typographyGlobal: {
|
||||
genericFontFamily,
|
||||
},
|
||||
}
|
||||
|
||||
return {
|
||||
light: createTheme(options, baseThemes.light),
|
||||
dark: createTheme(options, baseThemes.dark),
|
||||
}
|
||||
}, [baseThemes, genericFontFamily])
|
||||
|
||||
return {
|
||||
dark: themes.dark,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { GlobalTypographyStyles } from '@acid-info/lsd-react'
|
||||
import type { PluginOptions as DefaultPluginOptions } from '@docusaurus/theme-classic'
|
||||
|
||||
export type Author = {
|
||||
@@ -28,4 +29,5 @@ export type DocConfig = {
|
||||
|
||||
export type ThemeOptions = DefaultPluginOptions & {
|
||||
docs?: Record<string, DocConfig>
|
||||
typography?: GlobalTypographyStyles
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user