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

Is it possible to override theme in redocOptions? #16

Closed
joshtemple opened this issue Apr 13, 2021 · 9 comments
Closed

Is it possible to override theme in redocOptions? #16

joshtemple opened this issue Apr 13, 2021 · 9 comments
Labels
enhancement New feature or request

Comments

@joshtemple
Copy link
Contributor

No description provided.

@rohit-gohri
Copy link
Owner

Not in redocOptions because then there would be no point of this plugin, it's supposed to provide compatibility with docusaurus theme and dark mode. But you can make your own ApiDoc component and specify that to be used by the plugin:
https://github.com/rohit-gohri/redocusaurus/tree/main/packages/docusaurus-plugin-redoc#apidoccomponent-default-themeapidoc

If you want then I can export the getThemeOptions helper directly so you can make your own theme with Dark mode support?

@joshtemple
Copy link
Contributor Author

That's okay, I had some suggestions for making the theming more consistent with Docusaurus but I'm realizing it's probably better for me to submit those as pull requests here rather than customizing my own.

@rohit-gohri
Copy link
Owner

That would be great

@bash83
Copy link

bash83 commented Apr 18, 2021

@joshtemple any luck with the PR? I saw you had a PR moving the font weight around but not about overriding the theme.

@rohit-gohri You seem to be stripping the "theme" property from the redocOptions in "/docusaurus-theme-redoc/src/index.ts". Is there a way to make it optional for the user to either specify the "primaryColor" or provide a baseTheme object?

I just spent hours trying to set things up on my machine to create a PR but failed miserably to setup my environment (quite a noob when it comes to TS, node, and docusaurus).

(trying to implement something similar to https://davidgoss.co/blog/api-documentation-redoc-docusaurus/)

@rohit-gohri
Copy link
Owner

You can already override primaryColor, just pass it in the theme options. See example here:

theme: {
primaryColor: '#1890ff',
redocOptions: { hideDownloadButton: false },
},

@rohit-gohri rohit-gohri reopened this Apr 18, 2021
@rohit-gohri
Copy link
Owner

Let me know if this solves your problem @bash83, if not then I'll try to add a baseTheme option

@rohit-gohri rohit-gohri added the enhancement New feature or request label Apr 18, 2021
@bash83
Copy link

bash83 commented Apr 18, 2021

@rohit-gohri I’m actually trying to override the font but figured why not allow user to override any value (I know this might complicate things with dark/light theme but it’s on user to sort it out)

@rohit-gohri
Copy link
Owner

rohit-gohri commented Apr 18, 2021

If you want to override all the values you can just swizzle the component and customize everything, it's just a React component:

npm run swizzle -- docusaurus-theme-redoc Redoc --danger

Let me know if you face any problems with that.

You can also just directly specify your own component with the apiDocComponent option.

@rohit-gohri
Copy link
Owner

Swizzle now works without --danger flag:

JSX Component:

yarn docusaurus swizzle docusaurus-theme-redoc Redoc

TSX Component:

yarn docusaurus swizzle docusaurus-theme-redoc Redoc --typescript

I have abstracted away the theme merging logic out of the component, so customizing them should be more straightforward now:

const {
lightTheme,
darkTheme,
redocOptions = null,
} = usePluginData<GlobalData>('docusaurus-theme-redoc');
const theme = isDarkTheme ? darkTheme : lightTheme;

You get two theme configs from plugin data: lightTheme and darkTheme, you can just merge this over your custom baseTheme before passing it to Redoc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants