Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/Copy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface CopyButtonProps {
children: React.ReactNode;
}

export default function CopyButton ({ text, children }: CopyButtonProps) {
export default function CopyButton({ text, children }: CopyButtonProps) {
const { copy, status } = useClipboard(text);
let value = children;

Expand All @@ -25,4 +25,4 @@ export default function CopyButton ({ text, children }: CopyButtonProps) {
{value}
</button>
);
}
}
18 changes: 9 additions & 9 deletions components/mdx/Code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default function Code({
breakWords = true;
}

const hasCopy = props.copy || language === "copy";
const hasCopy = /*props.copy || language === "copy"*/ true;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want everything to be copyable? Wondering if it makes more sense to make this opt-in instead

(For opt in, you would do this:

```json copy
code

Copy link
Contributor

@lavgup lavgup Sep 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think it would make more sense for it to be opt-out rather than opt-in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we were to go with a make every languaged code copyable route, some stuff like URLs and weird examples wouldn't be copyable.
If we were to go with an opt in version, we'd have to update the docs a ton
If we were to go with an opt out version, we'd still have to update the docs, but it might be the easiest method.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think opt in is better, most of the docs don't need to be copyable (e.g. example objects)

const isTerminal = props.terminal || language === "terminal";
const hasLines = file != null || props.lines;

Expand All @@ -83,7 +83,7 @@ export default function Code({
);

return (
<div className="code-block relative my-6 font-mono rounded-md">
<div className="code-block relative my-3 font-mono rounded-md">
<InfoBar fileName={file} language={language} />
<Highlight {...defaultProps} code={children} language={language}>
{({
Expand All @@ -99,13 +99,6 @@ export default function Code({
blockClassName
)}
>
{(props.copy || language === "copy") && (
<div className="copy-button">
<CopyButton text={children}>
<CopyIcon />
</CopyButton>
</div>
)}
<code className="p-4 rounded-md">
{cleanTokens(tokens).map((line, i) => {
const lineClass = {};
Expand Down Expand Up @@ -187,6 +180,13 @@ export default function Code({
</pre>
)}
</Highlight>
{hasCopy && (
<div className="copy-button absolute bottom-4 right-2 hidden p-3 transition md:block">
<CopyButton text={children}>
<CopyIcon className="w-5" />
</CopyButton>
</div>
)}
</div>
);
}
8 changes: 8 additions & 0 deletions stylesheets/styles.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
abbr[title].no-underline {
text-decoration: none;
}

.code-block .copy-button {
opacity: 0;
}

.code-block:hover .copy-button {
opacity: 100;
}