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

Addon-docs: Make syntax-highlighter theme configurable #9641

Open
patricklafrance opened this issue Jan 26, 2020 · 8 comments
Open

Addon-docs: Make syntax-highlighter theme configurable #9641

patricklafrance opened this issue Jan 26, 2020 · 8 comments

Comments

@patricklafrance
Copy link
Member

Is your feature request related to a problem? Please describe.

React-Syntaxt-Highlighter support a lot of Prism themes. It would be nice if Storybook provide a way for the user to pick the theme of is choice.

Describe the solution you'd like

One solution would be to make it configurable through SB theme system.

Something like:

// my-custom-sb-theme.js

import { create } from '@storybook/theming/create';
import { darcula } from 'react-syntax-highlighter/dist/esm/styles/prism';

export default create({
  base: 'light',

  ....

  prismTheme: darcula
});
import { addons } from '@storybook/addons';
import myCustomTheme from './my-custom-sb-theme';

addons.setConfig({
  theme: myCustomTheme
});

Additional context

#9640 could be tackled with this story

@Smolations
Copy link

@shilman Is there any workaround for this currently? I am not theming storybook at all and the default syntax highlighting is basically unusable. I have no idea who designed this particular theme, but it is bad:
Screen Shot 2020-02-11 at 6 11 40 PM

@shilman
Copy link
Member

shilman commented Feb 12, 2020

@Smolations i think that's a CSS collision between the prism theme and your CSS. Here's how it should look:

Design_System___Badge_-_All_⋅_Storybook

So in my estimation there are two separate issues:

  1. Figuring out how to scope the prism themes (see bug(addon-docs): Code styling preview bug in CSF format #9718)
  2. Adding configuration support (this issue)

Help wanted on either issue!

@Smolations
Copy link

Well I'll be a monkey's uncle...shame on me for not checking that in the first place! 🙈

Sorry for wasting your time on this. Keep up the good work! 😁

@stale
Copy link

stale bot commented Mar 4, 2020

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

@stale stale bot added the inactive label Mar 4, 2020
@stale stale bot removed the inactive label Mar 4, 2020
@shilman shilman modified the milestones: 6.0, 6.0 docs May 8, 2020
@shilman shilman modified the milestones: 6.0 docs, 6.1 docs Jun 24, 2020
@shilman shilman modified the milestones: 6.1 docs, 6.2 docs Oct 13, 2020
@manuelmeister
Copy link
Contributor

@shilman I tried to add this in

const Source: FunctionComponent<SourceProps> = (props) => {
const { error } = props as SourceErrorProps;
if (error) {
return <EmptyBlock>{error}</EmptyBlock>;
}
const { language, code, dark, format, ...rest } = props as SourceCodeProps;
const syntaxHighlighter = (
<StyledSyntaxHighlighter
bordered
copyable
format={format}
language={language}
className="docblock-source"
{...rest}
>
{code}
</StyledSyntaxHighlighter>
);
if (typeof dark === 'undefined') {
return syntaxHighlighter;
}
const overrideTheme = dark ? themes.dark : themes.light;
return <ThemeProvider theme={convert(overrideTheme)}>{syntaxHighlighter}</ThemeProvider>;
};

but I couldn't figure out how to get a theme var.

@shilman
Copy link
Member

shilman commented Nov 4, 2020

@peiris
Copy link

peiris commented Jan 9, 2021

@shilman Any update on this?

@shilman shilman removed this from the 6.2 docs milestone Jun 8, 2021
@quantizor
Copy link

@shilman would love to see configuration for this land in v7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants