-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
/
useThemeConfig.ts
141 lines (119 loc) · 3.09 KB
/
useThemeConfig.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import type {PrismTheme} from 'prism-react-renderer';
import type {DeepPartial} from 'utility-types';
import type {MagicCommentConfig} from './codeBlockUtils';
export type DocsVersionPersistence = 'localStorage' | 'none';
// TODO improve types, use unions
export type NavbarItem = {
type?: string | undefined;
items?: NavbarItem[];
label?: string;
position?: 'left' | 'right';
} & {[key: string]: unknown};
type BaseLogo = {
alt?: string;
src: string;
srcDark?: string;
href?: string;
width?: string | number;
height?: string | number;
target?: string;
style?: object;
className?: string;
};
export type NavbarLogo = BaseLogo;
// TODO improve
export type Navbar = {
style?: 'dark' | 'primary';
hideOnScroll: boolean;
title?: string;
items: NavbarItem[];
logo?: NavbarLogo;
};
export type ColorModeConfig = {
defaultMode: 'light' | 'dark';
disableSwitch: boolean;
respectPrefersColorScheme: boolean;
};
export type AnnouncementBarConfig = {
id: string;
content: string;
backgroundColor: string;
textColor: string;
isCloseable: boolean;
};
export type PrismConfig = {
theme: PrismTheme;
darkTheme?: PrismTheme;
defaultLanguage?: string;
additionalLanguages: string[];
magicComments: MagicCommentConfig[];
};
export type FooterLinkItem = {
label?: string;
to?: string;
href?: string;
html?: string;
prependBaseUrlToHref?: string;
} & {[key: string]: unknown};
export type FooterLogo = BaseLogo;
export type FooterBase = {
style: 'light' | 'dark';
logo?: FooterLogo;
copyright?: string;
};
export type MultiColumnFooter = FooterBase & {
links: {
title: string | null;
items: FooterLinkItem[];
}[];
};
export type SimpleFooter = FooterBase & {
links: FooterLinkItem[];
};
export type Footer = MultiColumnFooter | SimpleFooter;
export type TableOfContents = {
minHeadingLevel: number;
maxHeadingLevel: number;
};
// Theme config after validation/normalization
export type ThemeConfig = {
docs: {
versionPersistence: DocsVersionPersistence;
sidebar: {
hideable: boolean;
autoCollapseCategories: boolean;
};
};
blog: {
sidebar: {
groupByYear: boolean;
};
};
// TODO we should complete this theme config type over time
// and share it across all themes
// and use it in the Joi validation schema?
// TODO temporary types
navbar: Navbar;
colorMode: ColorModeConfig;
announcementBar?: AnnouncementBarConfig;
prism: PrismConfig;
footer?: Footer;
image?: string;
metadata: {[key: string]: string}[];
tableOfContents: TableOfContents;
};
// User-provided theme config, unnormalized
export type UserThemeConfig = DeepPartial<ThemeConfig>;
/**
* A convenient/more semantic way to get theme config from context.
*/
export function useThemeConfig(): ThemeConfig {
return useDocusaurusContext().siteConfig.themeConfig as ThemeConfig;
}