Skip to content
Open
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
51 changes: 51 additions & 0 deletions src/LangTag.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,36 @@

/** @type {boolean} */
export let langtag = false;

let copyBtnText = "Copy";
function onCopyBtnClicked() {
copyBtnText = "Copied!";
setTimeout(() => {
copyBtnText = "Copy";
}, 1000);
navigator.clipboard.writeText(code);
}
</script>

<div class="copy-btn-container">
<button class="copy-btn" on:click={() => onCopyBtnClicked()}>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="copy-icon"
><rect width="14" height="14" x="8" y="8" rx="2" ry="2" /><path
d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"
/></svg
>
<span class="copy-text">{copyBtnText}</span>
</button>
</div>

<pre class:langtag data-language={languageName} {...$$restProps}><code
class:hljs={true}
>{#if highlighted}{@html highlighted}{:else}{code}{/if}</code
Expand All @@ -37,4 +65,27 @@
border-radius: var(--langtag-border-radius, 0);
padding: var(--langtag-padding, 1em);
}

.copy-btn-container {
width: 100%;
display: flex;
justify-content: end;
align-items: center;
float: right;
padding: 5px;
}

.copy-btn {
display: flex;
align-items: center;
background: var(--langtag-background, inherit);
color: var(--langtag-color, inherit);
border: none;
}

.copy-icon {
width: 20px;
height: 20px;
padding-right: 5px;
}
</style>