Skip to content

Commit 1b5bed2

Browse files
Merge pull request #24 from jeffreylauwers/feature/codetabs-dynamic-css-fix
fix(storybook): CodeTabs CSS fix + dynamische React tab
2 parents 35ae7c8 + 72b97c9 commit 1b5bed2

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* CodeTabs — override Storybook's Source block default styles.
3+
*
4+
* Storybook's .docblock-source element has margin (25px 0 40px) and border-radius (4px)
5+
* that create visual gaps and rounding inside our wrapper. We remove these so the code
6+
* block connects seamlessly with the tab bar above and the wrapper border below.
7+
*/
8+
.dsn-code-tabs .docblock-source {
9+
margin: 0;
10+
border-radius: 0;
11+
box-shadow: none;
12+
}

packages/storybook/src/components/CodeTabs.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import React, { useState } from 'react';
22
import { Source } from '@storybook/blocks';
3+
import './CodeTabs.css';
34

45
interface CodeTabsProps {
5-
/** JSX/TSX code snippet for the React tab */
6-
react: string;
6+
/**
7+
* @deprecated — React tab now uses SourceType.DYNAMIC to show live story code
8+
* that updates with Controls. This prop is kept for backward compatibility but ignored.
9+
*/
10+
react?: string;
711
/** HTML/CSS markup snippet for the HTML/CSS tab */
812
html: string;
913
}
@@ -16,9 +20,11 @@ type Tab = 'react' | 'html';
1620
* - HTML/CSS tab: shows the equivalent vanilla HTML markup
1721
*
1822
* Syntax highlighting via Storybook's built-in Source block from @storybook/blocks.
23+
* The React tab uses Source without explicit type (defaults to AUTO, which resolves to
24+
* DYNAMIC for stories with args). This shows live story code and updates with Controls.
1925
* The tab bar uses design token CSS variables so it responds to dark mode.
2026
*/
21-
export function CodeTabs({ react, html }: CodeTabsProps) {
27+
export function CodeTabs({ html }: CodeTabsProps) {
2228
const [activeTab, setActiveTab] = useState<Tab>('react');
2329

2430
const tabBarStyle: React.CSSProperties = {
@@ -54,7 +60,7 @@ export function CodeTabs({ react, html }: CodeTabsProps) {
5460
};
5561

5662
return (
57-
<div>
63+
<div className="dsn-code-tabs">
5864
<div style={tabBarStyle}>
5965
<button
6066
type="button"
@@ -75,7 +81,7 @@ export function CodeTabs({ react, html }: CodeTabsProps) {
7581
</div>
7682
<div style={codeWrapperStyle}>
7783
{activeTab === 'react' ? (
78-
<Source code={react} language="tsx" dark />
84+
<Source dark />
7985
) : (
8086
<Source code={html} language="html" dark />
8187
)}

0 commit comments

Comments
 (0)