You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@alexander-akait could you help me getting through this issue.
So far i have created an copybutton component , integrated it with pre tag and replaced pre element with the integrated one using mdxProvider. But its not working
import{useState}from'react';importPropTypesfrom'prop-types';functionCopyButton({ text }){const[copied,setCopied]=useState(false);consthandleCopy=()=>{navigator.clipboard.writeText(text).then(()=>{setCopied(true);setTimeout(()=>setCopied(false),2000);});};constbuttonStyle={position: 'absolute',top: '0.5rem',right: '0.5rem',backgroundColor: '#e5e7eb',fontSize: '0.875rem',padding: '0.25rem 0.5rem',borderRadius: '0.25rem',cursor: 'pointer',transition: 'background-color 0.3s ease',};consthandleMouseOver=(e)=>{e.target.style.backgroundColor='#d1d5db';};consthandleMouseOut=(e)=>{e.target.style.backgroundColor='#e5e7eb';};return(<buttonclassName="copy-button"style={buttonStyle}onClick={handleCopy}onMouseOver={handleMouseOver}onMouseOut={handleMouseOut}>{copied ? 'Copied!' : 'Copy'}</button>);}CopyButton.propTypes={text: PropTypes.string.isRequired,};//integrating the CopyButton component into the CodeBlock componentexportdefaultfunctionCodeBlock({ children }){constcodeText=children?.props?.children?.toString()||'';return(<divstyle={{position: 'relative',}}><CopyButtontext={codeText}/><pre>{children}</pre></div>);}CodeBlock.propTypes={children: PropTypes.node.isRequired,};
Code added into page.jsx:
// Import External Dependenciesimport{useEffect,useState}from'react';importPropTypesfrom'prop-types';import{useLocation}from'react-router-dom';import{MDXProvider}from'@mdx-js/react';// Import ComponentsimportPageLinksfrom'../PageLinks/PageLinks';importMarkdownfrom'../Markdown/Markdown';importContributorsfrom'../Contributors/Contributors';import{PlaceholderString}from'../Placeholder/Placeholder';importAdjacentPagesfrom'./AdjacentPages';importCodeBlockfrom'../CodeBlock/CodeBlock';// Load Stylingimport'./Page.scss';importLinkfrom'../Link/Link';// **change**constcomponents={pre: CodeBlock};exportdefaultfunctionPage(props){const{title,
contributors =[],
related =[],........restofcode.......
<Markdown><h1>{title}</h1>{rest.thirdParty ? (<divclassName="italic my-[20px]"><strongclassName="font-bold">Disclaimer:</strong>{title} is a
third-party package maintained by community members, it potentially
does not have the same support, security policy or license as
webpack, and it is not maintained by webpack.
</div>) : null}// **change** <MDXProvidercomponents={components}><divid="md-content">{contentRender}</div></MDXProvider>{loadRelated&&(<divclassName="print:hidden">......... code continues
@evenstensberg i am done with creating a custom component which renders a copy button inside button , the only problem i am facing is passing of components inside the imported mdx document , i.e. .
But in this code base there is no direct import of mdx which is making me stuck on where to pass the custom component.
Activity
TusharThakur04 commentedon Dec 31, 2024
@snitin315 Could you please assign this issue to me.
TusharThakur04 commentedon Jan 17, 2025
@alexander-akait could you help me getting through this issue.
So far i have created an copybutton component , integrated it with pre tag and replaced pre element with the integrated one using mdxProvider. But its not working
Code added into page.jsx:
alexander-akait commentedon Feb 4, 2025
@TusharThakur04 Yeash, it will be useful, do you want to send a PR? I am glad to review them
alexander-akait commentedon Feb 4, 2025
It is hard to say what it wrong, if you send a PR and can loop deeply on this
TusharThakur04 commentedon Feb 21, 2025
@evenstensberg i am done with creating a custom component which renders a copy button inside button , the only problem i am facing is passing of components inside the imported mdx document , i.e. .
But in this code base there is no direct import of mdx which is making me stuck on where to pass the custom component.
Page.jsx

this is how its rendering the mdx document.
swastikCommits commentedon Mar 1, 2025
I am willing to send a PR