2022-09-30 22:20:17 +00:00
|
|
|
import { Documentation } from '../utils/doc-utils'
|
2022-10-01 20:32:01 +00:00
|
|
|
import { Link as LinkIcon } from 'react-feather'
|
|
|
|
import Link from 'next/link'
|
|
|
|
import { useRouter } from 'next/router'
|
2022-09-30 16:31:40 +00:00
|
|
|
|
|
|
|
export interface DocsProps {
|
2022-09-30 22:20:17 +00:00
|
|
|
docs: Documentation
|
|
|
|
braces: boolean
|
|
|
|
assign: boolean
|
2022-09-30 16:31:40 +00:00
|
|
|
}
|
|
|
|
|
2022-09-30 22:20:17 +00:00
|
|
|
export default function Docs({ docs, braces, assign }: DocsProps) {
|
2022-10-01 20:32:01 +00:00
|
|
|
const router = useRouter()
|
2022-09-30 16:31:40 +00:00
|
|
|
return (
|
2022-10-05 01:55:32 +00:00
|
|
|
<div className="prose dark:prose-invert prose-lg">
|
2022-10-01 20:32:01 +00:00
|
|
|
<div dangerouslySetInnerHTML={{ __html: docs.desc_md }} />
|
2022-10-04 16:18:21 +00:00
|
|
|
<div className="divide-y divide-gray-700/25 dark:divide-gray-300/25">
|
2022-10-01 20:32:01 +00:00
|
|
|
{docs.values.map((doc) => {
|
|
|
|
const target = router.asPath.endsWith(`#${doc.name}`)
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
id={doc.name}
|
|
|
|
key={doc.name}
|
|
|
|
className={
|
2022-10-05 01:55:32 +00:00
|
|
|
'pt-4 scroll-mt-16 ' +
|
|
|
|
(target
|
|
|
|
? 'bg-rose-300 dark:bg-rose-900'
|
|
|
|
: 'bg-slate-200 dark:bg-slate-800 target:bg-rose-300 target:dark:bg-rose-900') +
|
|
|
|
' hover:bg-opacity-25 dark:hover:bg-opacity-25 hover:ring-1 ring-black dark:ring-white ring-inset'
|
2022-10-01 20:32:01 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<div className="flex">
|
|
|
|
<div className="px-2 py-3">
|
|
|
|
<Link href={`#${doc.name}`}>
|
2023-02-26 01:12:11 +00:00
|
|
|
<LinkIcon size={20} />
|
2022-10-01 20:32:01 +00:00
|
|
|
</Link>
|
2022-09-30 16:31:40 +00:00
|
|
|
</div>
|
2022-10-01 20:32:01 +00:00
|
|
|
<div className="flex-col p-1">
|
2022-09-30 22:20:17 +00:00
|
|
|
<div>
|
2022-10-01 20:32:01 +00:00
|
|
|
{braces && <code>${</code>}
|
|
|
|
<code className="text-lg p-1 mx-1 bg-fuchsia-200 dark:bg-fuchsia-900 font-bold">
|
|
|
|
{doc.name}
|
2022-09-30 22:20:17 +00:00
|
|
|
</code>
|
2022-10-01 20:32:01 +00:00
|
|
|
{typeof doc.args != 'undefined' && doc.args.length > 0 && (
|
|
|
|
<>
|
|
|
|
{assign && <code>=</code>}
|
|
|
|
<em>
|
|
|
|
{doc.args.map((arg) => (
|
|
|
|
<code
|
|
|
|
className="text-lg p-1 mx-1 bg-slate-200 dark:bg-slate-800"
|
|
|
|
key={arg}
|
|
|
|
>
|
|
|
|
{arg}
|
|
|
|
</code>
|
|
|
|
))}
|
|
|
|
</em>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{braces && <code>}</code>}
|
2022-09-30 22:20:17 +00:00
|
|
|
</div>
|
2022-10-01 20:32:01 +00:00
|
|
|
<div
|
|
|
|
className="py-2"
|
|
|
|
dangerouslySetInnerHTML={{ __html: doc.desc_md }}
|
|
|
|
/>
|
|
|
|
{typeof doc.default != 'undefined' && (
|
|
|
|
<div>
|
|
|
|
Default:{' '}
|
|
|
|
<code className="px-1 mx-1 bg-slate-200 dark:bg-slate-800">
|
|
|
|
{doc.default}
|
|
|
|
</code>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
2022-09-30 22:20:17 +00:00
|
|
|
</div>
|
2022-09-30 16:31:40 +00:00
|
|
|
</div>
|
2022-10-01 20:32:01 +00:00
|
|
|
)
|
|
|
|
})}
|
2022-09-30 22:20:17 +00:00
|
|
|
</div>
|
2022-09-30 21:15:06 +00:00
|
|
|
</div>
|
2022-09-30 16:31:40 +00:00
|
|
|
)
|
|
|
|
}
|