Skip to content

Commit

Permalink
feat(CodeSnippet): Truncate filename in middle
Browse files Browse the repository at this point in the history
  • Loading branch information
timglaser committed Jun 22, 2020
1 parent 6b41998 commit 95f69b0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 35 deletions.
49 changes: 17 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"react-helmet": "^6.0.0",
"react-live": "^2.2.2",
"react-markdown": "^4.3.1",
"react-middle-ellipsis": "^1.1.0",
"react-shadow": "^18.1.2"
},
"devDependencies": {
Expand Down
11 changes: 9 additions & 2 deletions src/components/CodeSnippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import Highlight, { defaultProps } from 'prism-react-renderer';
import github from 'prism-react-renderer/themes/github';
import MiddleEllipsis from 'react-middle-ellipsis';
import FeatherIcon from './FeatherIcon';
import styles from './CodeSnippet.module.scss';
import useClipboard from '../hooks/useClipboard';
Expand Down Expand Up @@ -39,9 +40,15 @@ const CodeSnippet = ({ children, copy, className, lineNumbers, fileName }) => {
)}
</Highlight>
</div>
{(copy !== 'false' || !!fileName) && (
{(copy !== 'false' || fileName) && (
<div className={styles.bottomBar}>
<div className={styles.fileName}>{fileName}</div>
<div className={styles.fileName}>
{fileName && (
<MiddleEllipsis>
<span title={fileName}>{fileName}</span>
</MiddleEllipsis>
)}
</div>
{copy !== 'false' && (
<button
className={styles.copyButton}
Expand Down
1 change: 0 additions & 1 deletion src/components/CodeSnippet.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
.fileName {
font-family: var(--code-font);
font-size: 0.75rem;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
padding-right: 0.5rem;
Expand Down

0 comments on commit 95f69b0

Please sign in to comment.