-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #822 from centrapay/code-panel
✨ Add Code Panel
- Loading branch information
Showing
28 changed files
with
1,555 additions
and
1,121 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
@import "./buttons"; | ||
@import "./cards"; | ||
@import "./code"; | ||
@import "./icons"; |
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,75 @@ | ||
--- | ||
const { title = 'Example', method, path } = Astro.props; | ||
import Badge from "./Badge.astro"; | ||
--- | ||
|
||
<div | ||
data-code-block | ||
class="flex flex-col mb-8" | ||
> | ||
<div class="flex w-full rounded-t-3xl rounded-b-none border-b border-outline-inverse-opaque bg-surface-inverse-secondary shadow-sm p-4"> | ||
<span class="truncate type-subtitle-2 text-sm text-content-inverse-primary"> | ||
{ title } | ||
</span> | ||
</div> | ||
{ (method && path) && | ||
<div class="flex flex-row items-center border-b border-outline-inverse-opaque bg-surface-inverse-tertiary p-squish-2 space-x-2"> | ||
<Badge | ||
type={method} | ||
inverse | ||
/> | ||
<span class="text-content-inverse-primary type-caption-2 truncate">{ path }</span> | ||
</div> | ||
} | ||
<div | ||
data-code | ||
class="max-h-96 overflow-y-auto" | ||
> | ||
<slot /> | ||
</div> | ||
<div class="flex justify-end py-2 px-4 bg-surface-inverse-primary rounded-b-3xl border-t border-outline-inverse-opaque"> | ||
<button | ||
id="copy-button" | ||
data-copy-button | ||
class="type-overline py-2 px-3 bg-interactive-secondary hover:bg-interactive-secondary-hover text-content-inverse-primary transition hover:scale-105 active:scale-100 active:transition-none" | ||
> | ||
Copy | ||
</button> | ||
</div> | ||
</div> | ||
|
||
<script> | ||
function getElement( | ||
selector, | ||
Constructor, | ||
parent: ParentNode = document, | ||
) { | ||
const element = parent.querySelector(selector); | ||
if (!(element instanceof Constructor)) { | ||
throw new Error(`Element is not of type ${Constructor.name}: ${selector}`); | ||
} | ||
return element; | ||
} | ||
|
||
for (const codeBlock of document.querySelectorAll('[data-code-block]')) { | ||
const code = getElement('[data-code]', HTMLElement, codeBlock); | ||
const button = getElement('[data-copy-button]', HTMLButtonElement, codeBlock); | ||
button.addEventListener('click', () => { | ||
navigator.clipboard.writeText(code.innerText); | ||
button.innerText = "Copied"; | ||
button.classList.add('copy-button-active'); | ||
window.setTimeout(() => { | ||
button.innerText = "Copy"; | ||
button.classList.remove('copy-button-active'); | ||
}, 2000); | ||
}); | ||
} | ||
</script> | ||
|
||
<style> | ||
.copy-button-active { | ||
@apply | ||
bg-interactive-secondary-active | ||
; | ||
} | ||
</style> |
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
--- | ||
import ProseCode from "./ProseCode.vue"; | ||
const { class: className, ...rest } = Astro.props; | ||
--- | ||
|
||
<ProseCode client:load> | ||
<slot /> | ||
</ProseCode> | ||
<div class={className} {...rest}> | ||
<pre id="code" class="flex text-sm py-3 px-4"> | ||
<slot /> | ||
</pre> | ||
</div> |
Oops, something went wrong.