Skip to content

Commit

Permalink
feat!: ContentPartText is now a <p> (#325)
Browse files Browse the repository at this point in the history
* feat!: ContentPartText is now a <p>

* fix
  • Loading branch information
Yonom authored Jun 26, 2024
1 parent 5d54829 commit de20b1c
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 21 deletions.
6 changes: 6 additions & 0 deletions .changeset/seven-walls-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@assistant-ui/react-ui": minor
"@assistant-ui/react": minor
---

feat!: ContentPartText is now a <p> element
36 changes: 36 additions & 0 deletions apps/www/pages/docs/migrations/v0.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: Migration to v0.2
---

## Changes to the `Thread.tsx` template

1. Change the type of the wrapper around the `MessagePrimitive.Content` component to `<div>` instead of `<p>`.
2. Remove the `whitespace-pre-line` class from the wrapper.

```diff
const UserMessage = () => {
return (
...
- <p className="whitespace-pre-line ...">
+ <div className="...">
<MessagePrimitive.Content />
- </p>
+ </div>
</div>
...
);
};

const AssistantMessage = () => {
return (
...
- <p className="whitespace-pre-line ...">
+ <div className="...">
<MessagePrimitive.Content />
- </p>
+ </div>
</div>
...
);
};
```
2 changes: 1 addition & 1 deletion apps/www/pages/reference/primitives/ContentPart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const UIContentPart = () => {

Renders the text content of a text content part.

This primitive renders a `<span>` element.
This primitive renders a `<p>` element.

#### `useContentPartText`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ const UserMessage: FC = () => {
<div className="flex-grow">
<p className="font-semibold">You</p>

<p className="text-foreground whitespace-pre-line">
<div className="text-foreground">
<MessagePrimitive.Content />
</p>
</div>

<div className="flex pt-2">
<BranchPicker />
Expand Down Expand Up @@ -176,7 +176,7 @@ const AssistantMessage: FC = () => {
<p className="font-semibold">Assistant</p>

<MessagePrimitive.InProgress className="bg-foreground inline-block size-3 animate-pulse rounded-full" />
<div className="text-foreground flex flex-col gap-3 whitespace-pre-line">
<div className="text-foreground flex flex-col gap-3">
<MessagePrimitive.Content />
</div>

Expand Down
8 changes: 4 additions & 4 deletions packages/react-ui/src/thread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ const UserMessage: FC = () => {
return (
<MessagePrimitive.Root className="relative mb-6 flex w-full max-w-2xl flex-col items-end gap-2 pl-24">
<div className="relative mr-1 flex items-start gap-3">
<p className="bg-foreground/5 text-foreground max-w-xl whitespace-pre-line break-words rounded-3xl px-5 py-2.5">
<div className="bg-foreground/5 text-foreground max-w-xl break-words rounded-3xl px-5 py-2.5">
<MessagePrimitive.Content />
</p>
</div>
</div>
</MessagePrimitive.Root>
);
Expand All @@ -84,9 +84,9 @@ const AssistantMessage: FC = () => {

<div className="mt-2 flex-grow">
<MessagePrimitive.InProgress className="bg-foreground inline-block size-3 animate-[aui-pulse] rounded-full" />
<p className="text-foreground max-w-xl whitespace-pre-line break-words">
<div className="text-foreground max-w-xl break-words">
<MessagePrimitive.Content />
</p>
</div>
</div>
</MessagePrimitive.Root>
);
Expand Down
8 changes: 4 additions & 4 deletions packages/react/src/primitives/contentPart/ContentPartText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Primitive } from "@radix-ui/react-primitive";
import { type ElementRef, forwardRef, ComponentPropsWithoutRef } from "react";
import { useContentPartText } from "../../primitive-hooks/contentPart/useContentPartText";

type ContentPartTextElement = ElementRef<typeof Primitive.span>;
type PrimitiveSpanProps = ComponentPropsWithoutRef<typeof Primitive.span>;
type ContentPartTextElement = ElementRef<typeof Primitive.p>;
type PrimitiveSpanProps = ComponentPropsWithoutRef<typeof Primitive.p>;

type ContentPartTextProps = Omit<PrimitiveSpanProps, "children">;

Expand All @@ -14,9 +14,9 @@ export const ContentPartText = forwardRef<
const text = useContentPartText();

return (
<Primitive.span {...props} ref={forwardedRef}>
<Primitive.p {...props} ref={forwardedRef}>
{text}
</Primitive.span>
</Primitive.p>
);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/primitives/message/MessageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type MessageContentProps = {
const defaultComponents = {
Text: () => (
<>
<ContentPartText />
<ContentPartText style={{ whiteSpace: "pre-line" }} />
<ContentPartInProgressIndicator />
</>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ const UserMessage: FC = () => {
</ActionBarPrimitive.Edit>
</ActionBarPrimitive.Root>

<p className="bg-foreground/5 text-foreground max-w-xl whitespace-pre-line break-words rounded-3xl px-5 py-2.5">
<div className="bg-foreground/5 text-foreground max-w-xl break-words rounded-3xl px-5 py-2.5">
<MessagePrimitive.Content />
</p>
</div>
</div>

<BranchPicker />
Expand Down Expand Up @@ -158,9 +158,9 @@ const AssistantMessage: FC = () => {

<div className="mt-2 flex-grow">
<MessagePrimitive.InProgress className="bg-foreground inline-block size-3 animate-pulse rounded-full" />
<p className="text-foreground max-w-xl whitespace-pre-line break-words">
<div className="text-foreground max-w-xl break-words">
<MessagePrimitive.Content />
</p>
</div>

<div className="flex pt-2">
<BranchPicker />
Expand Down
8 changes: 4 additions & 4 deletions packages/shadcn-registry/registry/assistant-ui/thread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ const UserMessage: FC = () => {
return (
<MessagePrimitive.Root className="relative mb-6 flex w-full max-w-2xl flex-col items-end gap-2 pl-24">
<div className="relative mr-1 flex items-start gap-3">
<p className="bg-foreground/5 text-foreground max-w-xl whitespace-pre-line break-words rounded-3xl px-5 py-2.5">
<div className="bg-foreground/5 text-foreground max-w-xl break-words rounded-3xl px-5 py-2.5">
<MessagePrimitive.Content />
</p>
</div>
</div>
</MessagePrimitive.Root>
);
Expand All @@ -84,9 +84,9 @@ const AssistantMessage: FC = () => {

<div className="mt-2 flex-grow">
<MessagePrimitive.InProgress className="bg-foreground inline-block size-3 animate-pulse rounded-full" />
<p className="text-foreground max-w-xl whitespace-pre-line break-words">
<div className="text-foreground max-w-x break-words">
<MessagePrimitive.Content />
</p>
</div>
</div>
</MessagePrimitive.Root>
);
Expand Down

0 comments on commit de20b1c

Please sign in to comment.