diff --git a/src/components/CodeSnippet.js b/src/components/CodeSnippet.js
index 0ecef8fba..c85a9192c 100644
--- a/src/components/CodeSnippet.js
+++ b/src/components/CodeSnippet.js
@@ -7,7 +7,7 @@ import styles from './CodeSnippet.module.scss';
import useClipboard from '../hooks/useClipboard';
import useFormattedCode from '../hooks/useFormattedCode';
-const CodeSnippet = ({ children, copy, className, lineNumbers }) => {
+const CodeSnippet = ({ children, copy, className, lineNumbers, fileName }) => {
const language = className.replace('language-', '');
const formattedCode = useFormattedCode(children ?? '');
const [copied, copyCode] = useClipboard();
@@ -39,12 +39,23 @@ const CodeSnippet = ({ children, copy, className, lineNumbers }) => {
)}
- {copy !== 'false' && (
-
-
+ {(copy !== 'false' || !!fileName) && (
+
+
{fileName}
+ {copy !== 'false' && (
+
+ )}
)}
@@ -53,15 +64,16 @@ const CodeSnippet = ({ children, copy, className, lineNumbers }) => {
CodeSnippet.propTypes = {
children: PropTypes.node.isRequired,
- copy: PropTypes.string,
className: PropTypes.string,
+ copy: PropTypes.string,
+ fileName: PropTypes.string,
lineNumbers: PropTypes.string,
};
CodeSnippet.defaultProps = {
+ className: 'language-javascript',
copy: 'true',
lineNumbers: 'true',
- className: 'language-javascript',
};
export default CodeSnippet;
diff --git a/src/components/CodeSnippet.module.scss b/src/components/CodeSnippet.module.scss
index a125d219c..024955fe9 100644
--- a/src/components/CodeSnippet.module.scss
+++ b/src/components/CodeSnippet.module.scss
@@ -28,20 +28,30 @@
opacity: 0.5;
}
-.copyBar {
+.bottomBar {
box-sizing: border-box;
display: flex;
- justify-content: flex-end;
+ justify-content: space-between;
align-items: center;
background: var(--color-neutrals-200);
+ padding: 0 1rem;
+}
- button {
- font-size: 0.75rem;
- color: var(--color-brand-800);
- background: none;
- border: none;
- outline: none;
- }
+.fileName {
+ font-family: var(--code-font);
+ font-size: 0.75rem;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ overflow: hidden;
+ padding-right: 0.5rem;
+}
+
+.copyButton {
+ font-size: 0.75rem;
+ color: var(--color-brand-800);
+ background: none;
+ border: none;
+ outline: none;
}
.copyIcon {