DNS records
90 lines · 1 file · MIT
Type, name and value on one line each, with a copy button that carries the whole record.
Preparing the records for go.northwind.example. This takes a few seconds.
CNAME
go.northwind.exampledomains.rdyrct.comTXT
_cf-custom-hostname.go.northwind.example7c1f3a8e-5b2d-4e91-a0c6-d3f94b21e7a8import { CopyButton } from "./copy-button";
import { Skeleton } from "./skeleton";
export interface DnsRecord {
type: string;
name: string;
value: string;
}
const copyText = (text: string) => navigator.clipboard.writeText(text);
/**
* The DNS records a domain needs, one line each with its own copy button:
* type, name and value, what a DNS provider's form asks for. While the
* records are being made (`records` undefined) it shows two placeholder
* lines the height of the real ones, so nothing moves when they arrive.
*/
export function DnsRecords({
records,
hostname,
onCopy = copyText,
}: {
records?: DnsRecord[];
/** Named in the waiting line. */
hostname?: string;
/** Where the text goes. Defaults to the clipboard; pass yours to toast too. */
onCopy?: (text: string) => void | Promise<void>;
}) {
if (!records)
return (
<div className="flex flex-col gap-1.5" aria-busy>
<p className="text-sm text-muted">
Preparing the records{hostname ? ` for ${hostname}` : ""}. This takes a few seconds.
</p>
<Skeleton className="h-11 w-full rounded-[10px]" />
<Skeleton className="h-11 w-full rounded-[10px]" />
</div>
);
return (
<div className="flex flex-col gap-1.5">
{records.map((record) => (
<RecordLine key={`${record.type}-${record.name}`} {...record} onCopy={onCopy} />
))}
</div>
);
}
/**
* One DNS record on one line: its type, the name and where it points, and
* one copy button that copies the whole record as a message for whoever
* manages the DNS. Long names and values truncate, with the full text on
* hover; the copy always carries all of it. On a narrow card the value goes
* under the name, so neither truncates to nothing.
*/
export function RecordLine({
type,
name,
value,
onCopy = copyText,
}: DnsRecord & {
onCopy?: (text: string) => void | Promise<void>;
}) {
return (
<div
data-record={type}
className="@container flex min-h-11 min-w-0 items-center gap-3 rounded-[10px] bg-bg py-1 pr-1 pl-3 shadow-[inset_0_0_0_1px_var(--border)]"
>
<span className="shrink-0 rounded-[5px] px-1.5 text-[11px] text-muted shadow-[inset_0_0_0_1px_var(--border)]">
{type}
</span>
<div className="flex min-w-0 flex-1 flex-col py-1 font-mono text-[13px] @lg:flex-row @lg:items-center @lg:gap-3 @lg:py-0">
<code title={name} className="min-w-0 truncate @lg:max-w-[55%]">
{name}
</code>
<span aria-hidden className="shrink-0 text-placeholder @max-lg:hidden">
→
</span>
<code title={value} className="min-w-0 truncate text-muted @lg:flex-1 @lg:text-text">
{value}
</code>
</div>
<CopyButton
text={`Type: ${type}\nName: ${name}\nValue: ${value}`}
label="Copy the record"
onCopy={onCopy}
/>
</div>
);
}
Install
One command. The files land in your repo, with everything they import.
$ bunx shadcn@latest add @blocco/dns-records- Category
- Display
- Files
- dns-records.tsx