mirror of
https://github.com/Xevion/rdap.git
synced 2025-12-11 02:08:20 -06:00
Add raw JSON viewing ability to AbstractCard
This commit is contained in:
@@ -1,22 +1,46 @@
|
|||||||
import React, { FunctionComponent, ReactNode } from "react";
|
import React, { FunctionComponent, ReactNode } from "react";
|
||||||
|
import { useBoolean } from "usehooks-ts";
|
||||||
|
import { CodeBracketIcon } from "@heroicons/react/24/solid";
|
||||||
|
|
||||||
type AbstractCardProps = {
|
type AbstractCardProps = {
|
||||||
children: ReactNode;
|
children?: ReactNode;
|
||||||
header?: ReactNode;
|
header?: ReactNode;
|
||||||
footer?: ReactNode;
|
footer?: ReactNode;
|
||||||
|
data?: object;
|
||||||
};
|
};
|
||||||
|
|
||||||
const AbstractCard: FunctionComponent<AbstractCardProps> = ({
|
const AbstractCard: FunctionComponent<AbstractCardProps> = ({
|
||||||
children,
|
children,
|
||||||
header,
|
header,
|
||||||
footer,
|
footer,
|
||||||
|
data,
|
||||||
}) => {
|
}) => {
|
||||||
|
const { value: showRaw, toggle: toggleRaw } = useBoolean(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mb-4 overflow-clip rounded bg-zinc-800 shadow">
|
<div className="mb-4 overflow-clip rounded bg-zinc-800 shadow">
|
||||||
{header != null ? (
|
{header != undefined || data != undefined ? (
|
||||||
<div className="space-x-2 bg-zinc-700 p-2 pl-5">{header}</div>
|
<div className="flex bg-zinc-700 p-2 pl-5">
|
||||||
|
<div className="grow space-x-2">{header}</div>
|
||||||
|
{data != undefined ? (
|
||||||
|
<div className="pr-1">
|
||||||
|
<CodeBracketIcon
|
||||||
|
onClick={toggleRaw}
|
||||||
|
className="h-6 w-6 cursor-pointer"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
<div className="p-2 px-4">{children}</div>
|
<div className="max-w-full p-2 px-4">
|
||||||
|
{showRaw ? (
|
||||||
|
<pre className="m-2 max-h-[40rem] max-w-full overflow-y-auto whitespace-pre-wrap rounded">
|
||||||
|
{JSON.stringify(data, null, 4)}
|
||||||
|
</pre>
|
||||||
|
) : (
|
||||||
|
children
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
{footer != null ? (
|
{footer != null ? (
|
||||||
<div className="space-x-2 bg-zinc-700 p-2 pl-5">{footer}</div>
|
<div className="space-x-2 bg-zinc-700 p-2 pl-5">{footer}</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ export type DomainProps = {
|
|||||||
const DomainCard: FunctionComponent<DomainProps> = ({ data }: DomainProps) => {
|
const DomainCard: FunctionComponent<DomainProps> = ({ data }: DomainProps) => {
|
||||||
return (
|
return (
|
||||||
<AbstractCard
|
<AbstractCard
|
||||||
|
data={data}
|
||||||
header={
|
header={
|
||||||
<>
|
<>
|
||||||
<span className="font-mono">{data.ldhName ?? data.unicodeName}</span>
|
<span className="font-mono">{data.ldhName ?? data.unicodeName}</span>
|
||||||
|
|||||||
Reference in New Issue
Block a user