Skip to content

Commit 5b9f8ea

Browse files
fix: copy complete link from # button
1 parent a3252ca commit 5b9f8ea

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

packages/react-renderer-demo/src/components/mdx/share-button.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
33
import IconButton from '@mui/material/IconButton';
44
import CopyToClipboard from 'react-copy-to-clipboard';
55
import SvgIcon from '@mui/material/SvgIcon';
6+
import { urlFormatter } from '../../helpers/url-formatter';
67

78
const HashTagSvg = (props) => (
89
// eslint-disable-next-line max-len
@@ -14,15 +15,19 @@ const HashTagSvg = (props) => (
1415
></path>
1516
);
1617

17-
const ShareButton = ({ path }) => (
18-
<CopyToClipboard text={path}>
19-
<IconButton size="medium">
20-
<SvgIcon fontSize="small" viewBox="0 0 48 48">
21-
<HashTagSvg />
22-
</SvgIcon>
23-
</IconButton>
24-
</CopyToClipboard>
25-
);
18+
const ShareButton = ({ path }) => {
19+
console.log(process.env.NEXT_PUBLIC_VAR_VAL);
20+
21+
return (
22+
<CopyToClipboard text={urlFormatter(path)}>
23+
<IconButton size="medium">
24+
<SvgIcon fontSize="small" viewBox="0 0 48 48">
25+
<HashTagSvg />
26+
</SvgIcon>
27+
</IconButton>
28+
</CopyToClipboard>
29+
);
30+
};
2631

2732
ShareButton.propTypes = {
2833
path: PropTypes.string.isRequired,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const urlFormatter = (initPath) => {
2+
const env = process.env.NEXT_PUBLIC_VERCEL_ENV;
3+
const url = process.env.NEXT_PUBLIC_VERCEL_URL;
4+
const branchUrl = process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL;
5+
6+
if (env === 'preview') {
7+
return `https://${branchUrl + initPath}`;
8+
}
9+
10+
return `https://${url + initPath}`;
11+
};

0 commit comments

Comments
 (0)