rtaylorzfin / ribbon-sandbox

sandbox to play around with go ribbon
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Allow importing the react components #2

Open rtaylorzfin opened 2 years ago

rtaylorzfin commented 2 years ago

This is a feature request for upstream wc-ribbon-strips. It would be nice to be able to import the react components directly instead of needing to use the WebComponents. For example, in order to add a cellClick handler in the current system, we need to do something like this:

import { applyPolyfills, defineCustomElements } from '@geneontology/wc-ribbon-strips/loader';
applyPolyfills().then(() => {
    defineCustomElements(window);
});
//...
    const ribbonStripsRef = useRef();
//...
    useEffect(() => {
        console.log('ribbonStripsRef.current', ribbonStripsRef.current);
        ribbonStripsRef.current.addEventListener('cellClick', handleItemClick);
    },[]);
//...
    <wc-ribbon-strips ref={ribbonStripsRef} ... />
//...

If we could import the react component directly, we should be able to simplify the above with something like this:

import { RibbonStrips } from '@geneontology/wc-ribbon-strips/dist';
//...
    <RibbonStrips onCellClick=handleItemClick ... />

It appears that stenciljs allows exporting as a react component. If I have some more time, I may be able to look into how to do this and send in a PR.

rtaylorzfin commented 2 years ago

@tmushayahama , you mentioned to tag you in an issue if I had any questions. What do you think about this feature request?

tmushayahama commented 2 years ago

@rtaylorzfin I think we didn't want to tie it to a specific framework. That was the reason to move away from the React Version of it. It is also being used by non React clients.

rtaylorzfin commented 2 years ago

@tmushayahama , okay, thanks for looking at it.

tmushayahama commented 2 years ago

Were you able to run it okay? Are the events working fine?

rtaylorzfin commented 2 years ago

Thanks for following up. Yes, it seems to be working. I'll let you know if I run into anything.