Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nameguard-react): canonical badge #170

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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.7",
"version": "0.0.10",
"scripts": {
"build": "tsup",
"dev": "tsup --watch --clean=false",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ import { ConfusableListItem } from "./ConfusableListItem";

type ConfusableListProps = {
items: GraphemeGuardReport["confusables"];
canonicalGrapheme?: GraphemeGuardReport["canonical_grapheme"];
};

export const ConfusableList = ({ items }: ConfusableListProps) => {
export const ConfusableList = ({
items,
canonicalGrapheme,
}: ConfusableListProps) => {
if (!items || items?.length === 0) return null;

return (
<div className="rounded-md border border-gray-200 divide-y divide-gray-200">
{items?.map((confusable, index) => (
<ConfusableListItem key={index} item={confusable} />
<ConfusableListItem
key={index}
item={confusable}
isCanonical={canonicalGrapheme === confusable.grapheme}
/>
))}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import { useGraphemeModalStore } from "../../stores/grapheme";

type ConfusableListItemProps = {
item: GraphemeGuardReport["confusables"][0];
isCanonical: boolean;
};

export const ConfusableListItem = ({ item }: ConfusableListItemProps) => {
export const ConfusableListItem = ({
item,
isCanonical,
notrab marked this conversation as resolved.
Show resolved Hide resolved
}: ConfusableListItemProps) => {
const { openGraphemeModal } = useGraphemeModalStore();

const handleClick = () => {
Expand All @@ -25,6 +29,11 @@ export const ConfusableListItem = ({ item }: ConfusableListItemProps) => {
</div>
<div className="md:grid md:grid-cols-7 md:gap-4 col-span-7 md:col-span-11">
<div className="md:col-span-3">
{isCanonical && (
<div className="mb-1.5 -mt-4 relative text-green-800 text-xs font-medium rounded-full px-2 py-0.5 bg-green-100 inline-block">
Canonical
</div>
)}
<p className="text-black text-sm font-medium">{item.grapheme_name}</p>
<p className="hidden md:inline-block text-gray-500 text-sm font-normal">
{item.grapheme_description}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ export const GraphemeModal = forwardRef((_, ref: Ref<HTMLDivElement>) => {
</p>
</div>

<ConfusableList items={data?.confusables} />
<ConfusableList
items={data?.confusables}
canonicalGrapheme={data?.canonical_grapheme}
/>
</div>
)}
</div>
Expand Down
2 changes: 0 additions & 2 deletions packages/nameguard-react/src/components/Shield/Shield.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ export const Shield = ({ name }: ShieldProps) => {
(n: string) => nameguard.bulkInspectNames([parseName(n).outputName.name])
);

console.log({ data });

// const [result] = data.results;
const result = data.results[0];

Expand Down
1 change: 1 addition & 0 deletions packages/nameguard-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export { useChatModalStore } from "./stores/chat";
export { useSearchStore } from "./stores/search";

export { NameBadge } from "./components/NameBadge/NameBadge";
export { NameShield } from "./components/NameShield";
export { Shield } from "./components/Shield/Shield";