Skip to content

Commit

Permalink
Merge pull request #190 from neplextech/docgen
Browse files Browse the repository at this point in the history
fix: render new types
  • Loading branch information
twlite authored Dec 3, 2023
2 parents b15fbfe + 12abe44 commit 2a267ec
Show file tree
Hide file tree
Showing 12 changed files with 384 additions and 250 deletions.
3 changes: 2 additions & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
"eslint-config-next": "13.4.7",
"fuse.js": "^6.6.2",
"lucide-react": "^0.252.0",
"micro-docgen": "^0.2.0",
"next": "13.4.7",
"postcss": "8.4.24",
"react": "18.2.0",
"react-dom": "18.2.0",
"remark-gfm": "^3.0.1",
"semver": "^7.5.3",
"tailwindcss": "3.3.2",
"typescript": "5.1.3"
"typescript": "5.3.2"
},
"devDependencies": {
"@code-hike/mdx": "^0.9.0",
Expand Down
23 changes: 0 additions & 23 deletions apps/docs/src/components/assets/TextMark.tsx

This file was deleted.

40 changes: 35 additions & 5 deletions apps/docs/src/components/docs/ContentArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export function ContentArea({ data }: IProps) {
? "classes"
: type === "function"
? "functions"
: type === "variables"
? "variable"
: type === "enum"
? "enum"
: "types";
const res = data[t as Exclude<keyof typeof data, "name">] as unknown as {
data: DocumentedClass | DocumentedTypes | DocumentedFunction;
Expand All @@ -45,14 +49,32 @@ export function ContentArea({ data }: IProps) {
useEffect(() => {
if (!packageName) return;
if (!target || !type) {
if (data.classes.length || data.functions.length || data.types.length) {
if (
data.classes.length ||
data.functions.length ||
data.types.length ||
data.variables.length ||
data.enum.length
) {
const t = data.classes.length
? "classes"
: data.functions.length
? "functions"
: data.variables.length
? "variable"
: data.enum.length
? "enum"
: "types";
const resolvedType =
t === "classes" ? "class" : t === "functions" ? "function" : "type";
t === "classes"
? "class"
: t === "functions"
? "function"
: type === "variable"
? "variable"
: type === "enum"
? "enum"
: "type";
if (!type) {
const dest = `/docs/${encodeURIComponent(
packageName as string
Expand All @@ -70,11 +92,16 @@ export function ContentArea({ data }: IProps) {
? "classes"
: type === "function"
? "functions"
: type === "variable"
? "variables"
: type === "enum"
? "enum"
: "types";
const res = data[t as Exclude<keyof typeof data, "name">] as unknown as {
data: DocumentedClass | DocumentedTypes | DocumentedFunction;
}[];
const entity = res.find((e) => e.data.name === target)?.data || null;

const entity = res?.find((e) => e.data.name === target)?.data || null;
setCurrentItem(entity);
}
}, [target, type, packageName, data]);
Expand All @@ -89,8 +116,11 @@ export function ContentArea({ data }: IProps) {
description={`Documentation for ${currentItem.name}.`}
/>
<div className="mb-16">
{type === "type" ? (
<TypeRenderer entity={currentItem as DocumentedTypes} />
{["enum", "type", "variable"].includes(type as string) ? (
<TypeRenderer
entity={currentItem as DocumentedTypes}
type={type as any}
/>
) : type === "class" ? (
<ClassRenderer entity={currentItem as DocumentedClass} />
) : type === "function" ? (
Expand Down
101 changes: 58 additions & 43 deletions apps/docs/src/components/docs/DocsItemList.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,66 @@
import { Button, cn } from '@edge-ui/react';
import { Root as Collapsible, CollapsibleTrigger, CollapsibleContent } from '@radix-ui/react-collapsible';
import Link from 'next/link';
import { useRouter } from 'next/router';
import { useState } from 'react';
import { ChevronDown, ChevronUp } from 'lucide-react';
import { Button, cn } from "@edge-ui/react";
import {
Root as Collapsible,
CollapsibleTrigger,
CollapsibleContent,
} from "@radix-ui/react-collapsible";
import Link from "next/link";
import { useRouter } from "next/router";
import { useState } from "react";
import { ChevronDown, ChevronUp } from "lucide-react";

interface IProps {
name: string;
data: { name: string; type: string; lib: string }[];
link?: (name: string) => string;
icon?: React.ReactNode;
name: string;
data: { name: string; type: string; lib: string }[];
link?: (name: string) => string;
icon?: React.ReactNode;
}

export function DocsItemList({ data, name, link, icon }: IProps) {
const router = useRouter();
const [open, setOpen] = useState(true);
const router = useRouter();
const [open, setOpen] = useState(true);

return (
<Collapsible open={open} onOpenChange={setOpen}>
<CollapsibleTrigger className="w-full" asChild>
<Button className="w-full font-bold justify-between rounded-bl-none rounded-tr-none" variant="outline">
<span className="flex items-center gap-3">
{icon} {name}
</span>{' '}
{open ? <ChevronUp /> : <ChevronDown />}
</Button>
</CollapsibleTrigger>
<CollapsibleContent className="border-l pl-5">
{data.map((item) => {
const linker = (
<h1
className={cn(
'text-base font-normal text-muted-foreground cursor-pointer',
item.lib === router.query.package && item.name === router.query.target && item.type === router.query.type ? 'font-medium text-secondary' : ''
)}
>
{item.name}
</h1>
);
return (
<Collapsible open={open} onOpenChange={setOpen}>
<CollapsibleTrigger className="w-full" asChild>
<Button
className="w-full font-bold justify-between rounded-bl-none rounded-tr-none"
variant="outline"
>
<span className="flex items-center gap-3">
{icon} {name}
</span>{" "}
{open ? <ChevronUp /> : <ChevronDown />}
</Button>
</CollapsibleTrigger>
<CollapsibleContent className="border-l pl-5">
{data.map((item) => {
const linker = (
<h1
className={cn(
"text-base font-normal text-muted-foreground cursor-pointer",
item.lib === router.query.package &&
item.name === router.query.target &&
item.type === router.query.type
? "font-medium text-secondary"
: ""
)}
>
{item.name}
</h1>
);

return (
<div key={item.name} className="hover:bg-secondary">
{link ? <Link href={link(encodeURIComponent(item.name))}>{linker}</Link> : linker}
</div>
);
})}
</CollapsibleContent>
</Collapsible>
);
return (
<div key={item.name} className="hover:bg-secondary">
{link ? (
<Link href={link(encodeURIComponent(item.name))}>{linker}</Link>
) : (
linker
)}
</div>
);
})}
</CollapsibleContent>
</Collapsible>
);
}
Loading

0 comments on commit 2a267ec

Please sign in to comment.