Skip to content

Commit

Permalink
feat: allow nameshield children (#175)
Browse files Browse the repository at this point in the history
* feat: allow nameshield children

* bump

* more props

* bump version

* remove notrab
  • Loading branch information
notrab authored Dec 4, 2023
1 parent fcb0d55 commit 3a7aab0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/nameguard-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@namehash/nameguard-react",
"version": "0.0.11",
"version": "0.0.13",
"scripts": {
"build": "tsup",
"dev": "tsup --watch --clean=false",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ export const NameBadge = ({ placeholder, onClick, data }: NameBadgeProps) => {
<span className="text-black text-sm leading-5">
{data.beautiful_name || data.name}
</span>
<NameShield data={data} />
<NameShield data={data}>
<div className="text-sm text-white">
<button className="appearance-none underline" onClick={onClick}>
Inspect name for details
</button>
</div>
</NameShield>
</button>
);
};
32 changes: 15 additions & 17 deletions packages/nameguard-react/src/components/NameShield/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { type ReactNode } from "react";
import type { ConsolidatedNameGuardReport, Rating } from "@namehash/nameguard";
import cc from "classcat";

Expand All @@ -24,15 +24,21 @@ function textColor(rating?: Rating) {

type NameShieldProps = {
data?: ConsolidatedNameGuardReport;
children?: ReactNode;
disableHover?: boolean;
};

export function NameShield({ data }: NameShieldProps) {
export function NameShield({ data, children, disableHover }: NameShieldProps) {
if (!data) return null;

const { title, name, rating, risk_count, highest_risk } = data;
const { title, subtitle, rating, risk_count, highest_risk } = data;

const textClass = cc(["font-semibold", textColor(rating)]);

if (disableHover) {
return <Shield status={rating} size="tiny" className="cursor-pointer" />;
}

return (
<Tooltip
trigger={
Expand All @@ -48,22 +54,14 @@ export function NameShield({ data }: NameShieldProps) {
<div className="flex items-center justify-between">
<span className={textClass}>{title}</span>
<span className="text-sm font-normal text-gray-400">
{risk_count} risk
{(risk_count || 0) > 1 && "s"} detected
{risk_count} risk{risk_count !== 1 && "s"} detected
</span>
</div>
<div className="space-y-0.5">
<div className="text-sm text-white">{highest_risk?.message}</div>
{/* <div className="text-sm text-white">
<a
href={`https://nameguard.io/inspect/${name}`}
className="underline"
rel="noopener noreferrer"
target="_blank"
>
Inspect name for details
</a>
</div> */}
<div className="space-y-2.5">
<div className="text-sm text-white">
{highest_risk?.message || subtitle}
</div>
{children}
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const SearchModal = () => {

return (
<Transition.Root show={modalOpen} as={Fragment}>
<Dialog as="div" className="relative z-20" onClose={handleClose}>
<Dialog as="div" className="relative z-40" onClose={handleClose}>
<Transition.Child
as={Fragment}
enter="ease-out duration-300"
Expand Down
3 changes: 2 additions & 1 deletion packages/nameguard-react/src/components/Shield/Shield.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export const Shield = ({ name }: ShieldProps) => {
<div className="flex items-center justify-between">
<span className={textClass}>{result.title}</span>
<span className="text-sm font-normal text-gray-400">
{result.risk_count} risk{result.risk_count >= 0 && "s"} detected
{result.risk_count} risk{result.risk_count === 1 ? "" : "s"}{" "}
detected
</span>
</div>
<div className="text-sm text-white">{result.subtitle}</div>
Expand Down

0 comments on commit 3a7aab0

Please sign in to comment.