Skip to content

Commit

Permalink
New option for a different primary color in dark mode (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
benbrandt committed Jul 16, 2022
1 parent df43d74 commit d881f52
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
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

1 comment on commit d881f52

@vercel
Copy link

@vercel vercel bot commented on d881f52 Jul 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.