1- import { Box , Code , Heading , Text } from '@chakra-ui/react' ;
1+ import {
2+ Blockquote ,
3+ Box ,
4+ Code ,
5+ Heading ,
6+ HStack ,
7+ Link ,
8+ List ,
9+ Text ,
10+ VStack ,
11+ type HTMLChakraProps ,
12+ } from '@chakra-ui/react' ;
213import { MDXProvider } from '@mdx-js/react' ;
314import { DocsContext , SourceContainer } from '@storybook/addon-docs/blocks' ;
4- import { useEffect , useMemo , type PropsWithChildren } from 'react' ;
15+ import {
16+ Children ,
17+ useContext ,
18+ useEffect ,
19+ useMemo ,
20+ type MouseEvent ,
21+ type PropsWithChildren ,
22+ type ReactNode ,
23+ } from 'react' ;
24+ import { NAVIGATE_URL } from 'storybook/internal/core-events' ;
525import type { DocsContextProps } from 'storybook/internal/types' ;
626import { styled , ThemeProvider } from 'storybook/theming' ;
727
28+ import { Table } from '../../src' ;
829import { storybookTheme } from '../storybookTheme' ;
930import { StorybookThemeProvider } from '../StorybookThemeProvider' ;
1031import { getThemes } from '../themes' ;
1132import { CodeBlock } from './CodeBlock' ;
33+ import { DocsNavigation } from './DocsNavigation' ;
34+ import { TableOfContents } from './TableOfContents' ;
1235
1336interface ContextOverride extends DocsContextProps {
1437 store : {
@@ -30,8 +53,97 @@ const StorybookOverrides = styled.div`
3053 color: var(--teleport-colors-text-main);
3154 margin: 0;
3255 }
56+
57+ .markdown-alert {
58+ padding: var(--teleport-spacing-2) var(--teleport-spacing-3);
59+ margin: var(--teleport-spacing-4) 0;
60+ border: 1px solid;
61+ border-radius: var(--teleport-radii-md);
62+
63+ & > :first-child {
64+ margin-top: 0;
65+ }
66+
67+ & > :last-child {
68+ margin-bottom: 0;
69+ }
70+ }
71+
72+ .markdown-alert-note {
73+ background: var(--teleport-colors-interactive-tonal-informational-2);
74+ border-color: var(--teleport-colors-interactive-solid-accent-default);
75+
76+ .octicon {
77+ fill: var(--teleport-colors-interactive-solid-accent-default);
78+ }
79+ }
80+
81+ .markdown-alert-tip {
82+ background: var(--teleport-colors-interactive-tonal-success-2);
83+ border-color: var(--teleport-colors-interactive-solid-success-default);
84+
85+ .octicon {
86+ fill: var(--teleport-colors-interactive-solid-success-default);
87+ }
88+ }
89+
90+ .markdown-alert-warning {
91+ background: var(--teleport-colors-interactive-tonal-alert-2);
92+ border-color: var(--teleport-colors-interactive-solid-alert-default);
93+
94+ .octicon {
95+ fill: var(--teleport-colors-interactive-solid-alert-default);
96+ }
97+ }
98+
99+ .markdown-alert-caution {
100+ background: var(--teleport-colors-interactive-tonal-danger-2);
101+ border-color: var(--teleport-colors-interactive-solid-danger-default);
102+
103+ .octicon {
104+ fill: var(--teleport-colors-interactive-solid-danger-default);
105+ }
106+ }
107+
108+ .markdown-alert-title {
109+ display: flex;
110+ margin-bottom: var(--teleport-spacing-2);
111+ align-items: center;
112+ font-weight: var(--teleport-font-weights-bold);
113+ }
114+
115+ .octicon {
116+ margin-right: var(--teleport-spacing-2);
117+ display: inline-block;
118+ overflow: visible !important;
119+ vertical-align: text-bottom;
120+ }
33121` ;
34122
123+ export function DocsLink ( props : HTMLChakraProps < 'a' > ) {
124+ const context = useContext ( DocsContext ) ;
125+
126+ function handleClick ( event : MouseEvent ) {
127+ const LEFT_BUTTON = 0 ;
128+ const isLeftClick =
129+ event . button === LEFT_BUTTON &&
130+ ! event . altKey &&
131+ ! event . ctrlKey &&
132+ ! event . metaKey &&
133+ ! event . shiftKey ;
134+
135+ if ( isLeftClick ) {
136+ event . preventDefault ( ) ;
137+ context . channel . emit (
138+ NAVIGATE_URL ,
139+ event . currentTarget . getAttribute ( 'href' ) ?? ''
140+ ) ;
141+ }
142+ }
143+
144+ return < Link { ...props } onClick = { handleClick } /> ;
145+ }
146+
35147export function DocsContainerWrapper ( {
36148 children,
37149 context,
@@ -88,24 +200,59 @@ export function DocsContainerWrapper({
88200 < Heading { ...props } as = "h1" mt = { 3 } mb = { 4 } size = "3xl" />
89201 ) ,
90202 h2 : props => (
91- < Heading { ...props } as = "h2" mt = { 6 } mb = { 3 } size = "2xl" />
203+ < Heading { ...props } as = "h2" mt = { 6 } mb = { 4 } size = "2xl" />
92204 ) ,
93- h3 : props => < Heading { ...props } as = "h3" mt = { 6 } mb = { 3 } size = "xl" /> ,
94- h4 : props => < Heading { ...props } as = "h4" size = "md" /> ,
205+ h3 : props => < Heading { ...props } as = "h3" mt = { 3 } mb = { 3 } size = "xl" /> ,
206+ h4 : props => < Heading { ...props } as = "h4" mt = { 2 } mb = { 2 } size = "md" /> ,
95207 h5 : props => < Heading { ...props } as = "h5" size = "sm" /> ,
96208 h6 : props => < Heading { ...props } as = "h6" size = "xs" /> ,
97209 p : props => < Text { ...props } mb = { 2 } /> ,
98210 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
99211 pre : props => < CodeBlock text = { props . children . props . children } /> ,
212+ ul : props => < List . Root mt = { 4 } mb = { 6 } pl = { 4 } { ...props } /> ,
213+ li : props => < List . Item pl = { 1 } { ...props } /> ,
214+ a : props => < DocsLink { ...props } /> ,
215+ table : props => (
216+ < Table . Root size = "sm" variant = "outline" mb = { 6 } { ...props } />
217+ ) ,
218+ thead : props => < Table . Header { ...props } /> ,
219+ td : props => < Table . Cell { ...props } /> ,
220+ tr : props => < Table . Row { ...props } /> ,
221+ th : props => < Table . ColumnHeader { ...props } /> ,
222+ blockquote : ( { children, ...rest } ) => {
223+ const child = Children . toArray ( children as ReactNode [ ] ) . find (
224+ child => typeof child !== 'string'
225+ ) ;
226+
227+ // @ts -expect-error TS2322 - need to figure out type here
228+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
229+ const content = child . props . children ;
230+
231+ return (
232+ < Blockquote . Root { ...rest } my = { 5 } >
233+ < Blockquote . Content > { content } </ Blockquote . Content >
234+ </ Blockquote . Root >
235+ ) ;
236+ } ,
100237 code : Code ,
101238 } }
102239 >
103240 < DocsContext . Provider value = { context } >
104241 < SourceContainer channel = { context . channel } >
105242 < ThemeProvider theme = { storybookTheme } >
106- < Box py = { 4 } px = { 10 } >
107- { children }
108- </ Box >
243+ < VStack flex = "1" >
244+ < Box maxW = "7xl" w = "100%" data-docs-content mr = { - 4 } >
245+ < HStack gap = { 6 } align = "flex-start" >
246+ < Box flex = { 1 } py = { 4 } >
247+ { children }
248+
249+ < DocsNavigation />
250+ </ Box >
251+
252+ < TableOfContents channel = { context . channel } />
253+ </ HStack >
254+ </ Box >
255+ </ VStack >
109256 </ ThemeProvider >
110257 </ SourceContainer >
111258 </ DocsContext . Provider >
0 commit comments