import React from 'react'; import PropTypes from 'prop-types'; // eslint-disable-next-line import/no-extraneous-dependencies import { drawSelectedElement } from '@storybook/addon-measure/dist/esm/box-model/visualizer'; // eslint-disable-next-line import/no-extraneous-dependencies import { init, destroy } from '@storybook/addon-measure/dist/esm/box-model/canvas'; export const ShadowRoot = ({ label = 'Hello from shadow DOM', drawMode = 'ROOT' }) => { const ref = React.useRef(); React.useEffect(() => { if (!ref.current.attachShadow) return; ref.current.attachShadow({ mode: 'open' }); ref.current.shadowRoot.innerHTML = ` `; init(); drawSelectedElement(drawMode === 'ROOT' ? ref.current : ref.current.shadowRoot.children[1]); // eslint-disable-next-line consistent-return return () => { destroy(); }; }, []); return
; }; ShadowRoot.propTypes = { label: PropTypes.string, drawMode: PropTypes.oneOf(['ROOT', 'NESTED']), }; ShadowRoot.defaultProps = { label: 'Hello from shadow DOM', drawMode: 'ROOT', };