diff --git a/code/addons/docs/src/manager.tsx b/code/addons/docs/src/manager.tsx
index 749465692e79..436ec2333540 100644
--- a/code/addons/docs/src/manager.tsx
+++ b/code/addons/docs/src/manager.tsx
@@ -2,9 +2,10 @@ 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, useAddonState, useChannel } from 'storybook/internal/manager-api';
+import { addons, types, useChannel, useParameter } from 'storybook/internal/manager-api';
+import { ignoreSsrWarning, styled, useTheme } from 'storybook/internal/theming';
-import { Source } from '@storybook/blocks';
+import { Source, type SourceParameters } from '@storybook/blocks';
addons.register(ADDON_ID, (api) => {
addons.add(PANEL_ID, {
@@ -27,25 +28,46 @@ addons.register(ADDON_ID, (api) => {
disabled: (parameters) => !parameters?.docs?.codePanel,
match: ({ viewMode }) => viewMode === 'story',
render: ({ active }) => {
- const [codeSnippet, setSourceCode] = useAddonState<{
- source: string;
- format: SyntaxHighlighterFormatTypes;
- }>(ADDON_ID, {
- source: '',
- format: 'html',
+ const parameter = useParameter(PARAM_KEY, {
+ source: { code: '' } as SourceParameters,
+ theme: 'dark',
});
+ const [codeSnippet, setSourceCode] = React.useState<{
+ source?: string;
+ format?: SyntaxHighlighterFormatTypes;
+ }>({});
+
useChannel({
[SNIPPET_RENDERED]: ({ source, format }) => {
setSourceCode({ source, format });
},
});
+ const theme = useTheme();
+ const isDark = theme.base !== 'light';
+
return (
-
+
+
+
);
},
});
});
+
+const SourceStyles = styled.div(() => ({
+ height: '100%',
+ [`> :first-child${ignoreSsrWarning}`]: {
+ margin: 0,
+ height: '100%',
+ boxShadow: 'none',
+ },
+}));
diff --git a/code/addons/docs/template/stories/codePanel/index.stories.tsx b/code/addons/docs/template/stories/codePanel/index.stories.tsx
new file mode 100644
index 000000000000..8ddc1fbf6d24
--- /dev/null
+++ b/code/addons/docs/template/stories/codePanel/index.stories.tsx
@@ -0,0 +1,32 @@
+export default {
+ component: globalThis.Components.Button,
+ tags: ['autodocs'],
+ parameters: {
+ chromatic: { disable: true },
+ docs: {
+ codePanel: true,
+ },
+ },
+};
+
+export const Default = { args: { label: 'Default' } };
+
+export const CustomCode = {
+ args: { label: 'Custom code' },
+ parameters: {
+ docs: {
+ source: {
+ code: '',
+ },
+ },
+ },
+};
+
+export const WithoutPanel = {
+ args: { label: 'Without panel' },
+ parameters: {
+ docs: {
+ codePanel: false,
+ },
+ },
+};
diff --git a/code/addons/docs/template/stories/sourcePanel/index.stories.tsx b/code/addons/docs/template/stories/sourcePanel/index.stories.tsx
deleted file mode 100644
index 9958096cb815..000000000000
--- a/code/addons/docs/template/stories/sourcePanel/index.stories.tsx
+++ /dev/null
@@ -1,23 +0,0 @@
-export default {
- component: globalThis.Components.Button,
- tags: ['autodocs'],
- parameters: {
- chromatic: { disable: true },
- docs: {
- codePanel: false,
- },
- },
-};
-
-export const One = { args: { label: 'One' } };
-
-export const Two = { args: { label: 'Two' } };
-
-export const WithSource = {
- args: { label: 'Three' },
- parameters: {
- docs: {
- codePanel: true,
- },
- },
-};
diff --git a/code/lib/blocks/src/blocks/Source.tsx b/code/lib/blocks/src/blocks/Source.tsx
index 3ce0134c35b0..f43f8808599e 100644
--- a/code/lib/blocks/src/blocks/Source.tsx
+++ b/code/lib/blocks/src/blocks/Source.tsx
@@ -11,7 +11,7 @@ import { DocsContext } from './DocsContext';
import type { SourceContextProps, SourceItem } from './SourceContainer';
import { SourceContext, UNKNOWN_ARGS_HASH, argsHash } from './SourceContainer';
-type SourceParameters = SourceCodeProps & {
+export type SourceParameters = SourceCodeProps & {
/** Where to read the source code from, see `SourceType` */
type?: SourceType;
/** Transform the detected source for display */