3
3
/* eslint-disable @typescript-eslint/no-unused-vars */
4
4
import 'github-markdown-css/github-markdown.css' ;
5
5
6
- import {
7
- addons ,
8
- types ,
9
- useStorybookApi ,
10
- useChannel ,
11
- } from '@storybook/manager-api' ;
6
+ import { addons , types , useParameter } from '@storybook/manager-api' ;
12
7
import { AddonPanel } from '@storybook/components' ;
13
- import { STORY_RENDERED } from '@storybook/core-events' ;
14
8
import React , { useEffect , useState } from 'react' ;
15
9
import ReactMarkdown from 'react-markdown' ;
16
10
import { PrismLight as SyntaxHighlighter } from 'react-syntax-highlighter' ;
@@ -22,44 +16,13 @@ import remarkGfm from 'remark-gfm';
22
16
23
17
const ADDON_ID = 'readme' ;
24
18
const PANEL_ID = `${ ADDON_ID } /panel` ;
19
+ const PARAM_KEY = 'readme' ;
25
20
26
21
const Readme = ( ) => {
27
- const api = useStorybookApi ( ) ;
28
- const [ markdown , setMarkdown ] = useState ( ) ;
29
22
const [ useDarkMode , setUseDarkMode ] = useState ( ) ;
30
23
31
- useChannel ( {
32
- [ STORY_RENDERED ] : async ( ) => {
33
- setMarkdown ( '' ) ;
34
- const componentPath = api . getCurrentStoryData ( ) . importPath . split ( '/' ) ;
35
- const component = componentPath [ componentPath . length - 1 ] . split ( '.' ) [ 0 ] ;
36
- if ( component ) {
37
- try {
38
- const readmeUrl = `../../packages/${ component } /README.md` ;
39
- const readme = await fetch ( readmeUrl , {
40
- headers : { 'Content-Type' : 'text/plain' } ,
41
- } ) . then ( res => res . text ( ) ) ;
42
-
43
- setMarkdown ( readme ) ;
44
-
45
- const syntaxHighlighters = document . querySelectorAll (
46
- '.storybook-readme-syntax-highlighter'
47
- ) ;
48
-
49
- if ( syntaxHighlighters . length > 0 ) {
50
- for ( const item of syntaxHighlighters ) {
51
- const children = item . children ;
52
- const parent = item . parentElement ;
53
-
54
- parent . append ( ...children ) ;
55
- }
56
- }
57
- } catch ( e ) {
58
- console . warn ( 'No README file found for' , component ) ;
59
- }
60
- }
61
- } ,
62
- } ) ;
24
+ const markdownParameter = useParameter ( PARAM_KEY , null ) ;
25
+ const markdown = markdownParameter ? markdownParameter . data : null ;
63
26
64
27
const updateUseDarkMode = event => {
65
28
setUseDarkMode ( event . matches ) ;
0 commit comments