Skip to content

Commit

Permalink
feat: log when click type label
Browse files Browse the repository at this point in the history
  • Loading branch information
lawvs committed Apr 7, 2024
1 parent c12524b commit 6c7cbf3
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions src/data-types.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineDataType, objectType, stringType } from "@textea/json-viewer";
import * as Y from "yjs";
import { Badge } from "./components/ui/badge";
import { useToast } from "./components/ui/use-toast";

/**
* Guess AbstractType
Expand All @@ -21,8 +22,31 @@ function guessType(abstractType: Y.AbstractType<any>) {
return Y.AbstractType;
}

const TypeLabel = ({ children }: { children: string }) => {
return <Badge variant="outline">{children}</Badge>;
const TypeLabel = ({
value,
children,
}: {
value: unknown;
children: string;
}) => {
const { toast } = useToast();

return (
<Badge
variant="outline"
className="cursor-pointer"
onClick={(e) => {
e.stopPropagation();
console.log(value);
toast({
duration: 2000,
description: "Check the console for the value",
});
}}
>
{children}
</Badge>
);
};

const yDocType = defineDataType<object>({
Expand All @@ -34,7 +58,7 @@ const yDocType = defineDataType<object>({
const ObjPreComponent = objectType.PreComponent!;
return (
<span>
<TypeLabel>YDoc</TypeLabel>&nbsp;
<TypeLabel value={props.value}>YDoc</TypeLabel>&nbsp;
<ObjPreComponent {...props}></ObjPreComponent>
</span>
);
Expand Down Expand Up @@ -69,7 +93,7 @@ const yMapType = defineDataType<object>({
const ObjPreComponent = objectType.PreComponent!;
return (
<span>
<TypeLabel>YMap</TypeLabel>&nbsp;
<TypeLabel value={props.value}>YMap</TypeLabel>&nbsp;
<ObjPreComponent {...props}></ObjPreComponent>
</span>
);
Expand Down Expand Up @@ -102,7 +126,7 @@ const yArrayType = defineDataType<object>({
const ObjPreComponent = objectType.PreComponent!;
return (
<span>
<TypeLabel>YArray</TypeLabel>&nbsp;
<TypeLabel value={props.value}>YArray</TypeLabel>&nbsp;
<ObjPreComponent {...props}></ObjPreComponent>
</span>
);
Expand All @@ -129,7 +153,7 @@ const yTextType = defineDataType<object>({
const ObjPreComponent = objectType.PreComponent!;
return (
<span>
<TypeLabel>YText</TypeLabel>&nbsp;
<TypeLabel value={props.value}>YText</TypeLabel>&nbsp;
<ObjPreComponent {...props}></ObjPreComponent>
</span>
);
Expand All @@ -156,7 +180,7 @@ export const yTextStringType = defineDataType<object>({
const ObjPreComponent = objectType.PreComponent!;
return (
<span>
<TypeLabel>YText</TypeLabel>&nbsp;
<TypeLabel value={props.value}>YText</TypeLabel>&nbsp;
<ObjPreComponent {...props}></ObjPreComponent>
</span>
);
Expand Down

0 comments on commit 6c7cbf3

Please sign in to comment.