Skip to content
Merged
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
25 changes: 21 additions & 4 deletions site/src/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,29 @@ layout: base
<div class="p-4 p-md-4 border rounded-3 bg-body-tertiary">
<a href="/docs/" class="mb-3 w-100 btn btn-lg btn-primary">Docs</a>
<a href="https://github.com/microsoft/TypeChat" target="_blank" class="mb-2 w-100 btn btn-lg btn-primary">GitHub</a>

<hr class="mb-4" />
<div class="w-100 typechat-code-copy">
<code class="fs-5">npm install typechat</code>
<button class="btn btn-dark" type="button" title="Copy 'npm install' command." aria-label="Copy 'npm install' command.">📋</button>

<div class="mb-3">
<p class="fw-semibold mb-2">JavaScript / TypeScript</p>
<div class="w-100 typechat-code-copy">
<code class="fs-5">npm install typechat</code>
<button class="btn btn-dark" type="button"
title="Copy npm install command."
aria-label="Copy npm install command.">&#128203;</button>
</div>
</div>

<div>
<p class="fw-semibold mb-2">Python</p>
<div class="w-100 typechat-code-copy">
<code class="fs-5">pip install typechat</code>
<button class="btn btn-dark" type="button"
title="Copy pip install command."
aria-label="Copy pip install command.">&#128203;</button>
</div>
</div>
</div>
</div>
</div>
</main>
</main>
63 changes: 38 additions & 25 deletions site/src/js/interactivity.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,51 @@
// @ts-check

{
/** @type {any} */
let lastTimeout;

/** @type {HTMLButtonElement | null} */
const copyButton = document.querySelector(".typechat-code-copy button");
copyButton?.addEventListener("click", async () => {
clearTimeout(lastTimeout);
try {
await navigator.clipboard.writeText("npm install typechat");
copyButton.textContent = "✅";
copyButton.title = copyButton.ariaLabel = "Command copied."
}
catch {
copyButton.textContent = "❌";
copyButton.title = copyButton.ariaLabel = "Error copying."
const copyContainers = document.querySelectorAll(".typechat-code-copy");

for (const container of copyContainers) {
const copyButton = container.querySelector("button");
const command = container.querySelector("code")?.textContent?.trim();

if (!copyButton || !command) {
continue;
}
lastTimeout = setTimeout(() => {
copyButton.textContent = "📋";
copyButton.title = copyButton.ariaLabel = "Copy 'npm install' command."
}, 1500);
});

/** @type {ReturnType<typeof setTimeout> | undefined} */
let lastTimeout;

copyButton.addEventListener("click", async () => {
clearTimeout(lastTimeout);

try {
await navigator.clipboard.writeText(command);

copyButton.textContent = "\u2705";
copyButton.title = copyButton.ariaLabel = "Command copied.";
} catch {
copyButton.textContent = "\u274C";
copyButton.title = copyButton.ariaLabel = "Error copying.";
}

lastTimeout = setTimeout(() => {
copyButton.textContent = "\u{1F4CB}";
copyButton.title = copyButton.ariaLabel =
`Copy ${command} command.`;
}, 1500);
});
}
}

{
const selectElements = /** @type {HTMLCollectionOf<HTMLSelectElement>} */ (document.getElementsByClassName("nav-on-change"));
const selectElements = /** @type {HTMLCollectionOf<HTMLSelectElement>} */ (
document.getElementsByClassName("nav-on-change")
);

for (const select of selectElements) {
const change = () => {
window.location.pathname = select.value;
};

select.onchange = change;
// if (select.options.length === 1 && window.location.pathname !== select.value) {
// change();
// }
}
}
}
Loading