1- import React , { memo , useCallback , useEffect , useState } from "react" ;
2- import { useGlobals , useParameter , useStorybookApi } from "@storybook/manager-api" ;
3- import { Icons , IconButton } from "@storybook/components" ;
4- import { ADDON_ID , PARAM_KEY , TOOL_ID } from "./constants" ;
5- import { StackBlitzLogo } from "./components/StackBlitzLogo" ;
1+ import React , { useState , MouseEvent } from "react" ;
2+ import { useParameter , useStorybookApi } from "@storybook/manager-api" ;
3+ import { IconButton } from "@storybook/components" ;
4+ import { PARAM_KEY , TOOL_ID } from "./constants" ;
65import CodeflowLogo from "./components/CodeflowLogo" ;
76
8- export const Tool = memo ( function MyAddonSelector ( ) {
9- const [ globals , updateGlobals ] = useGlobals ( ) ;
7+ export const Tool = function MyAddonSelector ( ) {
108 const githubUrl = useParameter ( PARAM_KEY ) ;
119 const api = useStorybookApi ( ) ;
1210 const [ disabled , setDisabled ] = useState ( false )
1311
14- // TODO: get the github repository from the settings;
15- // const githubUrl = `https://github.com/stackblitz/docs`;
16-
1712 const currentStory = api . getCurrentStoryData ( ) ;
1813
1914 if ( ! currentStory ) {
@@ -27,58 +22,18 @@ export const Tool = memo(function MyAddonSelector() {
2722 setDisabled ( false ) ;
2823 }
2924
30- const { id } = api . getCurrentStoryData ( ) ;
31-
3225 const stackblitzUrl = `https://pr.new/${ githubUrl } ` ;
3326
34- // api.on('STORY_CHANGED', () => {
35- // const { id } = api.getCurrentStoryData();
36- // // Extract the component name from the story ID.
37- // componentName = id.split('--')[0];
38- // });
39-
40- console . log ( { disabled} ) ;
41-
4227 return (
4328 < IconButton
4429 disabled = { disabled }
4530 key = { TOOL_ID }
4631 href = { stackblitzUrl }
32+ onClick = { ( e : MouseEvent ) => disabled && e . preventDefault ( ) }
4733 target = "_blank"
4834 title = "Open in StackBlitz and make a pull request"
4935 >
5036 < CodeflowLogo />
5137 </ IconButton >
5238 ) ;
53- } ) ;
54-
55-
56- // addons.register('dynamicLinkButton', api => {
57- // const renderLinkButton = (componentName) => {
58- // const url = `https://example.com/${componentName}`;
59-
60- // const handleClick = () => {
61- // window.open(url, '_blank');
62- // };
63-
64- // const LinkButton = () => (
65- // <button onClick={handleClick}>Visit "{componentName}"</button>
66- // );
67-
68- // const container = document.createElement('div');
69- // ReactDOM.render(<LinkButton />, container);
70- // return container;
71- // };
72-
73- // let currentComponentName = null;
74-
75- // api.on(STORY_CHANGED, () => {
76- // const { id } = api.getCurrentStoryData();
77- // // Extract the component name from the story ID.
78- // currentComponentName = id.split('--')[0];
79-
80- // const element = renderLinkButton(currentComponentName);
81- // document.getElementById('root').innerHTML = '';
82- // document.getElementById('root').appendChild(element);
83- // });
84- // });
39+ } ;
0 commit comments