Skip to content

Commit d881f52

Browse files
authored
New option for a different primary color in dark mode (#216)
1 parent df43d74 commit d881f52

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

.changeset/kind-emus-switch.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'docusaurus-theme-redoc': minor
3+
---
4+
5+
New option for a different primary color in dark mode

packages/docusaurus-theme-redoc/Readme.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ See [here for full example.](../../website/src/pages/examples/custom-page/index.
5656
* Highlight color for docs
5757
*/
5858
primaryColor: '#1890ff',
59+
/**
60+
* Highlight color for docs in dark mode, if different.
61+
* Will default to `primaryColor` if not set.
62+
*/
63+
primaryColorDark: '#25c2a0',
5964
/**
6065
* Options to pass to redoc
6166
* @see https://github.com/redocly/redoc#redoc-options-object
@@ -74,9 +79,14 @@ See [here for full example.](../../website/src/pages/examples/custom-page/index.
7479
Convenient way to provide the highlighted color used by Redoc.
7580
This value will be used as `colors.primary.main` in the `themes` option. Must be an actual color value and not a css variable.
7681

82+
### primaryColorDark (string, hex/rgba value)
83+
84+
Optional way to change the highlighted color used by Redoc in dark mode. Defaults to `primaryColor` if not set.
85+
This value will be used as `colors.primary.main` in the `themes` option. Must be an actual color value and not a css variable.
86+
7787
### options (optional, object)
7888

79-
Override redoc options passed to [RedocStandalone](https://redoc.ly/docs/redoc/quickstart/react/) component. See the defaults [here](./src/redocData.ts#L5-L12).
89+
Override redoc options passed to [RedocStandalone](https://redoc.ly/docs/redoc/quickstart/react/) component. See the defaults [here](./src/redocData.ts#L5-L12).
8090

8191
Available properties [here](https://github.com/Redocly/redoc#redoc-options-object).
8292
You cannot set theme property using this property, use `theme` option below instead.

packages/docusaurus-theme-redoc/src/redocData.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -127,24 +127,29 @@ function getThemeOptions(
127127
}
128128
}
129129

130-
export function getRedocThemes(customTheme: RedocThemeOverrides): {
130+
export function getRedocThemes(
131+
customTheme: RedocThemeOverrides,
132+
customDarkTheme: RedocThemeOverrides = customTheme,
133+
): {
131134
darkTheme: RedocThemeOverrides;
132135
lightTheme: RedocThemeOverrides;
133136
} {
134137
return {
135138
lightTheme: getThemeOptions(customTheme, false),
136-
darkTheme: getThemeOptions(customTheme, true),
139+
darkTheme: getThemeOptions(customDarkTheme, true),
137140
};
138141
}
139142

140143
export function getGlobalData({
141144
primaryColor,
145+
primaryColorDark = primaryColor,
142146
theme: customTheme,
143147
options,
144148
}: ThemeOptions): GlobalData {
145149
const overrides = getDefaultTheme(primaryColor, customTheme);
150+
const overridesDark = getDefaultTheme(primaryColorDark, customTheme);
146151

147-
const { lightTheme, darkTheme } = getRedocThemes(overrides);
152+
const { lightTheme, darkTheme } = getRedocThemes(overrides, overridesDark);
148153

149154
return {
150155
lightTheme,

packages/docusaurus-theme-redoc/src/types/options.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ export interface ThemeOptions {
1818
* ideally this should be all the customization you need
1919
*/
2020
primaryColor?: string;
21+
/**
22+
* Primary Color to pass to Redoc Theme in dark mode.
23+
* This option is only needed if you want a different primary color in dark
24+
* mode, and will default to `primaryColor` if not set.
25+
*/
26+
primaryColorDark?: string;
2127
/**
2228
* Options to pass to redoc
2329
* @see https://github.com/redocly/redoc#redoc-options-object

website/docs/getting-started/theme-options.md

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ author_url: https://rohit.page
1010
Convenient way to provide the highlighted color used by Redoc.
1111
This value will be used as `colors.primary.main` in the `themes` option. Must be an actual color value and not a css variable.
1212

13+
### primaryColorDark (string, hex/rgba value)
14+
15+
Optional way to change the highlighted color used by Redoc in dark mode. Defaults to `primaryColor` if not set.
16+
This value will be used as `colors.primary.main` in the `themes` option. Must be an actual color value and not a css variable.
17+
1318
### options (optional, object)
1419

1520
Override redoc options passed to [RedocStandalone](https://redoc.ly/docs/redoc/quickstart/react/) component. See the defaults [here](https://github.com/rohit-gohri/redocusaurus/blob/main/packages/docusaurus-theme-redoc/src/redocData.ts#L5-L12).

0 commit comments

Comments
 (0)