-
Notifications
You must be signed in to change notification settings - Fork 111
/
redocData.ts
162 lines (151 loc) · 3.98 KB
/
redocData.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import type { RedocRawOptions } from 'redoc';
import merge from 'lodash/merge';
import { GlobalData, RedocThemeOverrides, ThemeOptions } from './types/options';
const defaultOptions: Partial<RedocRawOptions> = {
scrollYOffset: 'nav.navbar',
expandSingleSchemaField: true,
menuToggle: true,
// @ts-expect-error not available in types
suppressWarnings: true,
};
const getDefaultTheme = (
primaryColor?: string,
customTheme?: RedocThemeOverrides,
): RedocThemeOverrides => {
return merge(
{
colors: {
primary: {
main: primaryColor || '#25c2a0',
},
},
theme: {
prism: {
additionalLanguages: ['scala'],
},
},
},
customTheme,
);
};
/**
* TODO: Update colors from infima
* @see https://github.com/facebookincubator/infima/blob/master/packages/core/styles/common/variables.pcss
*/
const DOCUSAURUS = {
darkGray: '#303846',
dark: {
primaryText: '#f5f6f7',
secondaryText: 'rgba(255, 255, 255, 1)',
backgroundColor: 'rgb(24, 25, 26)',
},
};
/**
* Theme override that is independant of Light/Black themes
*/
const COMMON_THEME: RedocThemeOverrides = {
typography: {
fontFamily: 'var(--ifm-font-family-base)',
fontSize: 'var(--ifm-font-size-base)',
lineHeight: 'var(--ifm-line-height-base)',
fontWeightLight: 'var(--ifm-font-weight-light)',
fontWeightRegular: 'var(--ifm-font-weight-base)',
fontWeightBold: 'var(--ifm-font-weight-bold)',
headings: {
fontFamily: 'var(--ifm-heading-font-family)',
fontWeight: 'var(--ifm-heading-font-weight)',
lineHeight: 'var(--ifm-heading-line-height)',
},
code: {
fontFamily: 'var(--ifm-font-family-monospace)',
lineHeight: 'var(--ifm-pre-line-height)',
},
},
sidebar: {
/**
* about the same as the sidebar in the docs area, for consistency
* @see https://davidgoss.co/blog/api-documentation-redoc-docusaurus/
*/
width: '300px',
},
};
/**
* NOTE: Variables taken from infima
* @see https://github.com/facebookincubator/infima/blob/master/packages/core/styles/common/variables.pcss
*/
const LIGHT_THEME_OPTIONS: RedocThemeOverrides = {
sidebar: {
backgroundColor: '#ffffff',
},
rightPanel: {
backgroundColor: DOCUSAURUS.darkGray,
},
};
const DARK_THEME_OPTIONS: RedocThemeOverrides = {
colors: {
text: {
primary: DOCUSAURUS.dark.primaryText,
secondary: DOCUSAURUS.dark.secondaryText,
},
gray: {
50: '#FAFAFA',
100: '#F5F5F5',
},
border: {
dark: '#ffffff',
light: 'rgba(0,0,0, 0.1)',
},
},
schema: {
nestedBackground: DOCUSAURUS.dark.backgroundColor,
typeNameColor: DOCUSAURUS.dark.secondaryText,
typeTitleColor: DOCUSAURUS.dark.secondaryText,
},
sidebar: {
backgroundColor: DOCUSAURUS.dark.backgroundColor,
textColor: DOCUSAURUS.dark.primaryText,
arrow: {
color: DOCUSAURUS.dark.primaryText,
},
},
};
function getThemeOptions(
customTheme: RedocThemeOverrides,
isDarkMode = false,
): RedocThemeOverrides {
if (isDarkMode) {
return merge({}, COMMON_THEME, DARK_THEME_OPTIONS, customTheme);
} else {
return merge({}, COMMON_THEME, LIGHT_THEME_OPTIONS, customTheme);
}
}
export function getRedocThemes(
customTheme: RedocThemeOverrides,
customDarkTheme: RedocThemeOverrides = customTheme,
): {
darkTheme: RedocThemeOverrides;
lightTheme: RedocThemeOverrides;
} {
return {
lightTheme: getThemeOptions(customTheme, false),
darkTheme: getThemeOptions(customDarkTheme, true),
};
}
export function getGlobalData({
primaryColor,
primaryColorDark = primaryColor,
theme: customTheme,
options,
}: ThemeOptions): GlobalData {
const overrides = getDefaultTheme(primaryColor, customTheme);
const overridesDark = getDefaultTheme(primaryColorDark, customTheme);
const { lightTheme, darkTheme } = getRedocThemes(overrides, overridesDark);
return {
lightTheme,
darkTheme,
options: {
...defaultOptions,
...options,
},
};
}