mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-07 07:21:17 +08:00
feat: sync light/dark mode with theme
This commit is contained in:
parent
2528db8b21
commit
1f21e81315
@ -3,7 +3,7 @@ import React from 'react';
|
|||||||
import { AddonPanel, type SyntaxHighlighterFormatTypes } from 'storybook/internal/components';
|
import { AddonPanel, type SyntaxHighlighterFormatTypes } from 'storybook/internal/components';
|
||||||
import { ADDON_ID, PANEL_ID, PARAM_KEY, SNIPPET_RENDERED } from 'storybook/internal/docs-tools';
|
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 { 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';
|
import { Source, type SourceParameters } from '@storybook/blocks';
|
||||||
|
|
||||||
@ -30,6 +30,7 @@ addons.register(ADDON_ID, (api) => {
|
|||||||
render: ({ active }) => {
|
render: ({ active }) => {
|
||||||
const parameter = useParameter(PARAM_KEY, {
|
const parameter = useParameter(PARAM_KEY, {
|
||||||
source: { code: '' } as SourceParameters,
|
source: { code: '' } as SourceParameters,
|
||||||
|
theme: 'dark',
|
||||||
});
|
});
|
||||||
|
|
||||||
const [codeSnippet, setSourceCode] = React.useState<{
|
const [codeSnippet, setSourceCode] = React.useState<{
|
||||||
@ -43,6 +44,9 @@ addons.register(ADDON_ID, (api) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const theme = useTheme();
|
||||||
|
const isDark = theme.base !== 'light';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AddonPanel active={!!active}>
|
<AddonPanel active={!!active}>
|
||||||
<SourceStyles>
|
<SourceStyles>
|
||||||
@ -50,7 +54,7 @@ addons.register(ADDON_ID, (api) => {
|
|||||||
{...parameter.source}
|
{...parameter.source}
|
||||||
code={parameter.source.code || codeSnippet.source}
|
code={parameter.source.code || codeSnippet.source}
|
||||||
format={parameter.source.format || codeSnippet.format}
|
format={parameter.source.format || codeSnippet.format}
|
||||||
dark
|
dark={isDark}
|
||||||
/>
|
/>
|
||||||
</SourceStyles>
|
</SourceStyles>
|
||||||
</AddonPanel>
|
</AddonPanel>
|
||||||
|
@ -3,6 +3,9 @@ export default {
|
|||||||
tags: ['autodocs'],
|
tags: ['autodocs'],
|
||||||
parameters: {
|
parameters: {
|
||||||
chromatic: { disable: true },
|
chromatic: { disable: true },
|
||||||
|
docs: {
|
||||||
|
codePanel: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user