forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d49b658
commit bca349d
Showing
19 changed files
with
592 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const importModuleRegexp = /^import [^'"]* from ['"]([^'"\n ][^'"\n ]*)['"]/gm; | ||
|
||
function extractImports(code) { | ||
return (code.match(importModuleRegexp) || []).map((x) => x.replace(importModuleRegexp, '$1')); | ||
} | ||
|
||
module.exports = extractImports; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as React from 'react'; | ||
import copy from 'clipboard-copy'; | ||
|
||
interface CodeCopyButtonProps { | ||
code: string; | ||
} | ||
|
||
export default function CodeCopyButton(props: CodeCopyButtonProps) { | ||
const { code, ...other } = props; | ||
const [copied, setCopied] = React.useState(false); | ||
// This component is designed to be wrapped in NoSsr | ||
const macOS = window.navigator.platform.toUpperCase().indexOf('MAC') >= 0; | ||
const key = macOS ? '⌘' : 'Ctrl + '; | ||
|
||
React.useEffect(() => { | ||
if (copied) { | ||
const timeout = setTimeout(() => { | ||
setCopied(false); | ||
}, 2000); | ||
return () => { | ||
clearTimeout(timeout); | ||
}; | ||
} | ||
return undefined; | ||
}, [copied]); | ||
|
||
return ( | ||
<button | ||
{...other} | ||
aria-label="Copy the code" | ||
type="button" | ||
className="MuiCode-copy" | ||
onClick={async (event) => { | ||
event.stopPropagation(); | ||
setCopied(true); | ||
await copy(code); | ||
}} | ||
> | ||
{/* material-ui/no-hardcoded-labels */} | ||
{copied ? 'Copied' : 'Copy'} | ||
<span className="MuiCode-copyKeypress"> | ||
<span>(or</span> {key}C<span>)</span> | ||
</span> | ||
</button> | ||
); | ||
} |
Oops, something went wrong.