mirror of
https://github.com/Xevion/dynamic-preauth.git
synced 2025-12-06 05:15:00 -06:00
Emboldened component, copyToClipboard
This commit is contained in:
30
frontend/src/components/Emboldened.tsx
Normal file
30
frontend/src/components/Emboldened.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import { cn, type ClassValue } from "@/util";
|
||||
|
||||
type EmboldenedProps = {
|
||||
children: string | number;
|
||||
className?: ClassValue;
|
||||
copyable?: boolean;
|
||||
};
|
||||
|
||||
const Emboldened = ({ children, copyable }: EmboldenedProps) => {
|
||||
function copyToClipboard() {
|
||||
// Copy to clipboard
|
||||
navigator.clipboard.writeText(children.toString());
|
||||
}
|
||||
|
||||
return (
|
||||
<span
|
||||
onClick={copyable ? copyToClipboard : undefined}
|
||||
className={cn(
|
||||
"bg-zinc-900/40 rounded border border-zinc-700 py-0.5 px-1 font-mono text-teal-400",
|
||||
{
|
||||
"cursor-pointer": copyable,
|
||||
}
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
export default Emboldened;
|
||||
@@ -1,4 +1,5 @@
|
||||
import Badge from "@/components/Badge";
|
||||
import Emboldened from "@/components/Emboldened";
|
||||
import { cn, plural, type ClassValue } from "@/util";
|
||||
import { useState } from "preact/hooks";
|
||||
|
||||
@@ -32,9 +33,11 @@ const StatefulDemo = ({ class: className }: StatefulDemoProps) => {
|
||||
<br />
|
||||
{session != null ? (
|
||||
<>
|
||||
Your session is <b class="text-teal-400 font-inter">{session.id}</b>
|
||||
. You have{" "}
|
||||
<b class="text-teal-400 font-inter">{session.downloads.length}</b>{" "}
|
||||
Your session is{" "}
|
||||
<Emboldened copyable={true}>{session.id}</Emboldened>. You have{" "}
|
||||
<Emboldened className="text-teal-400 font-inter">
|
||||
{session.downloads.length}
|
||||
</Emboldened>{" "}
|
||||
known {plural("download", session.downloads.length)}.
|
||||
</>
|
||||
) : null}
|
||||
|
||||
Reference in New Issue
Block a user