Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New option for a different primary color in dark mode #216

Merged
merged 2 commits into from
Jul 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/kind-emus-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'docusaurus-theme-redoc': minor
---

New option for a different primary color in dark mode
12 changes: 11 additions & 1 deletion packages/docusaurus-theme-redoc/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ See [here for full example.](../../website/src/pages/examples/custom-page/index.
* Highlight color for docs
*/
primaryColor: '#1890ff',
/**
* Highlight color for docs in dark mode, if different.
* Will default to `primaryColor` if not set.
*/
primaryColorDark: '#25c2a0',
/**
* Options to pass to redoc
* @see https://github.com/redocly/redoc#redoc-options-object
Expand All @@ -74,9 +79,14 @@ See [here for full example.](../../website/src/pages/examples/custom-page/index.
Convenient way to provide the highlighted color used by Redoc.
This value will be used as `colors.primary.main` in the `themes` option. Must be an actual color value and not a css variable.

### primaryColorDark (string, hex/rgba value)

Optional way to change the highlighted color used by Redoc in dark mode. Defaults to `primaryColor` if not set.
This value will be used as `colors.primary.main` in the `themes` option. Must be an actual color value and not a css variable.

### options (optional, object)

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

Available properties [here](https://github.com/Redocly/redoc#redoc-options-object).
You cannot set theme property using this property, use `theme` option below instead.
Expand Down
11 changes: 8 additions & 3 deletions packages/docusaurus-theme-redoc/src/redocData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,29 @@ function getThemeOptions(
}
}

export function getRedocThemes(customTheme: RedocThemeOverrides): {
export function getRedocThemes(
customTheme: RedocThemeOverrides,
customDarkTheme: RedocThemeOverrides = customTheme,
): {
darkTheme: RedocThemeOverrides;
lightTheme: RedocThemeOverrides;
} {
return {
lightTheme: getThemeOptions(customTheme, false),
darkTheme: getThemeOptions(customTheme, true),
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);
const { lightTheme, darkTheme } = getRedocThemes(overrides, overridesDark);

return {
lightTheme,
Expand Down
6 changes: 6 additions & 0 deletions packages/docusaurus-theme-redoc/src/types/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export interface ThemeOptions {
* ideally this should be all the customization you need
*/
primaryColor?: string;
/**
* Primary Color to pass to Redoc Theme in dark mode.
* This option is only needed if you want a different primary color in dark
* mode, and will default to `primaryColor` if not set.
*/
primaryColorDark?: string;
/**
* Options to pass to redoc
* @see https://github.com/redocly/redoc#redoc-options-object
Expand Down
5 changes: 5 additions & 0 deletions website/docs/getting-started/theme-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ author_url: https://rohit.page
Convenient way to provide the highlighted color used by Redoc.
This value will be used as `colors.primary.main` in the `themes` option. Must be an actual color value and not a css variable.

### primaryColorDark (string, hex/rgba value)

Optional way to change the highlighted color used by Redoc in dark mode. Defaults to `primaryColor` if not set.
This value will be used as `colors.primary.main` in the `themes` option. Must be an actual color value and not a css variable.

### options (optional, object)

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).
Expand Down