Skip to content

Commit

Permalink
feat: ComposerPrimitive.Attachments (#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Sep 7, 2024
1 parent b9a3309 commit 3ba193e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-rings-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@assistant-ui/react": patch
---

feat: AttachmentContext
5 changes: 5 additions & 0 deletions .changeset/swift-lemons-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@assistant-ui/react": patch
---

feat: ComposerPrimitive.Attachments
24 changes: 24 additions & 0 deletions apps/docs/components/docs/parameters/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -521,3 +521,27 @@ export const MessageUtilsState: ParametersTableProps = {
},
],
};

export const AttachmentContextValue: ParametersTableProps = {
type: "AttachmentContextValue",
parameters: [
{
name: "useAttachment",
type: "ReadonlyStore<AttachmentState>",
required: true,
description: "Provides functions to perform actions on the attachment.",
},
],
};

export const AttachmentState: ParametersTableProps = {
type: "AttachmentState",
parameters: [
{
name: "attachment",
type: "Attachment",
required: true,
description: "The current attachment.",
},
],
};
29 changes: 29 additions & 0 deletions apps/docs/content/docs/reference/context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
ContentPartState,
MessageState,
MessageUtilsState,
AttachmentContextValue,
AttachmentState,
} from "@/components/docs/parameters/context";

## Assistant Context
Expand Down Expand Up @@ -352,3 +354,30 @@ const value = useComposer.getState().value;
const setText = useComposer((m) => m.setText);
const setText = useComposer.getState().setText;
```

## Attachment Context

Provides access to the current attachment state.

### `useAttachmentContext`

This hook provides access to the context stores.

```tsx
import { useAttachmentContext } from "@assistant-ui/react";

const { useAttachment } = useAttachmentContext();
```

<ParametersTable {...AttachmentContextValue} />

### `useAttachment`

```tsx
const { useAttachment } = useAttachmentContext();

const attachment = useAttachment((m) => m.attachment);
const attachment = useAttachment.getState().attachment;
```

<ParametersTable {...AttachmentState} />

0 comments on commit 3ba193e

Please sign in to comment.