Skip to content

Commit

Permalink
docs: add parameters table component and document react-hook-form par…
Browse files Browse the repository at this point in the history
…ameters (#258)
  • Loading branch information
Yonom authored Jun 20, 2024
1 parent b33d7f5 commit d8a3abe
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 2 deletions.
70 changes: 70 additions & 0 deletions apps/www/components/docs/ParametersTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import type { FC } from "react";

type ParameterDef = {
name: string;
type: string;
description: string;
isOptional?: boolean;
children?: Array<{
type: string;
parameters: Array<ParameterDef>;
}>;
};

type ParameterProps = {
parameter: ParameterDef;
isLast: boolean;
};

const Parameter: FC<ParameterProps> = ({ parameter, isLast }) => {
return (
<div
className={`flex flex-col gap-1 px-3 py-3${!isLast ? " border-b" : ""}`}
>
<div className="relative flex gap-2">
<h3 className="font-mono font-semibold text-sm">
{parameter.name}
{parameter.isOptional && "?"}:
</h3>
<div className="no-scrollbar w-full overflow-x-scroll text-nowrap pr-12 font-mono text-foreground/70 text-sm">
{parameter.type}
</div>
<div className="pointer-events-none absolute top-0 right-0 h-5 w-12 bg-gradient-to-r from-white/0 to-white/100" />
</div>
<div>
<p className="text-foreground/70 text-sm">{parameter.description}</p>
</div>
{parameter.children?.map((property) => (
<div
key={property.type}
className="relative m-2 flex flex-col rounded-lg border px-3"
>
{!!property.type && (
<h3 className="bg-secondary p-2 font-mono text-foreground/70 text-xs">
{property.type}
</h3>
)}
<ParametersTable parameters={property.parameters} />
</div>
))}
</div>
);
};

type ParametersTableProps = {
parameters: Array<ParameterDef>;
};

export const ParametersTable: FC<ParametersTableProps> = ({ parameters }) => {
return (
<div className="-mx-3">
{parameters.map((parameter, idx) => (
<Parameter
key={parameter.name}
parameter={parameter}
isLast={idx === parameters.length - 1}
/>
))}
</div>
);
};
1 change: 1 addition & 0 deletions apps/www/components/docs/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { PropsTable } from "./PropsTable";
export { KeyboardTable } from "./KeyboardTable";
export { DataAttributesTable } from "./DataAttributesTable";
export { ParametersTable } from "./ParametersTable";
2 changes: 1 addition & 1 deletion apps/www/pages/docs/runtimes/pick-a-runtime.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ title: Picking a Runtime

If you are already using the Vercel AI SDK, assistant-ui can be used as a drop-in replacement for your existing UI. Simply follow the instructions for the API you are using (`useChat`, `useAssistant` or `ai/rsc`).

If you are not using the Vercel AI SDK, it is currently recommended to start with Vercel AI SDK UI `useChat`. Simply follow the [useChat](/docs/runtimes/vercel-ai-sdk-ui/use-chat) guide.
If you are not using the Vercel AI SDK, it is currently recommended to start with Vercel AI SDK UI `useChat`. Simply follow the [useChat](/docs/runtimes/vercel-ai-sdk/use-chat) guide.
66 changes: 65 additions & 1 deletion apps/www/pages/reference/integrations/react-hook-form.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ title: "@assistant-ui/react-hook-form"
description: A React Hook Form integration for @assistant-ui.
---

import { ParametersTable } from "@/components/docs";

## API Reference

### `useAssistantForm`
Expand All @@ -19,7 +21,69 @@ Drop-in replacement hook for `useForm` that adds support for `@assistant-ui/reac
});
```

{/** TODO document assistant.tools property */}
#### Properties

<ParametersTable
parameters={[
{
name: "assistant",
type: 'object',
description: "Configuration for useAssistantForm",
children: [
{
parameters: [
{
name: "tools",
type: 'object',
description: "Tools configuration for useAssistantForm",
children: [
{
parameters: [
{
name: "set_form_field",
type: 'object',
description:
"Configuration for the set_form_field tool",
children: [
{
parameters: [
{
name: "renderer",
type: "ToolContentPartRenderer<{ name: string; value: string; }, {}>",
description:
"The component to render when set_form_field is called.",
},
],
},
],
},
{
name: "submit_form",
type: 'object',
description: "Configuration for the submit_form tool",
children: [
{
parameters: [
{
name: "renderer",
type: "ToolContentPartRenderer<{}, {}>",
description:
"The component to render when submit_form is called.",
},
],
},
],
},
],
},
],
},
],
},
],
},
]}
/>

### `formTools`

Expand Down

0 comments on commit d8a3abe

Please sign in to comment.