Skip to content

Commit

Permalink
feat: sync light/dark mode with theme
Browse files Browse the repository at this point in the history
  • Loading branch information
larsrickert committed Jan 15, 2025
1 parent 1a656bc commit 686b102
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 6 additions & 2 deletions code/addons/docs/src/manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import { AddonPanel, type SyntaxHighlighterFormatTypes } from 'storybook/internal/components';
import { ADDON_ID, PANEL_ID, PARAM_KEY, SNIPPET_RENDERED } from 'storybook/internal/docs-tools';
import { addons, types, useChannel, useParameter } from 'storybook/internal/manager-api';
import { ignoreSsrWarning, styled } from 'storybook/internal/theming';
import { ignoreSsrWarning, styled, useTheme } from 'storybook/internal/theming';

import { Source, type SourceParameters } from '@storybook/blocks';

Expand All @@ -30,6 +30,7 @@ addons.register(ADDON_ID, (api) => {
render: ({ active }) => {
const parameter = useParameter(PARAM_KEY, {
source: { code: '' } as SourceParameters,
theme: 'dark',
});

const [codeSnippet, setSourceCode] = React.useState<{
Expand All @@ -43,14 +44,17 @@ addons.register(ADDON_ID, (api) => {
},
});

const theme = useTheme();
const isDark = theme.base !== 'light';

return (
<AddonPanel active={!!active}>
<SourceStyles>
<Source
{...parameter.source}
code={parameter.source.code || codeSnippet.source}
format={parameter.source.format || codeSnippet.format}
dark
dark={isDark}
/>
</SourceStyles>
</AddonPanel>
Expand Down
3 changes: 3 additions & 0 deletions code/addons/docs/template/stories/codePanel/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ export default {
tags: ['autodocs'],
parameters: {
chromatic: { disable: true },
docs: {
codePanel: true,
},
},
};

Expand Down

0 comments on commit 686b102

Please sign in to comment.