-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
424 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/paste-core/components/ai-chat-log/src/AIChatMessageBody.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Box, safelySpreadBoxProps } from "@twilio-paste/box"; | ||
import type { BoxElementProps } from "@twilio-paste/box"; | ||
import type { ThemeShape } from "@twilio-paste/theme"; | ||
import type { HTMLPasteProps } from "@twilio-paste/types"; | ||
import * as React from "react"; | ||
|
||
const Variants = { | ||
default: { | ||
fontSize: "fontSize30" as ThemeShape["fontSizes"], | ||
lineHeight: "lineHeight30" as ThemeShape["lineHeights"], | ||
}, | ||
fullScreen: { | ||
fontSize: "fontSize40" as ThemeShape["fontSizes"], | ||
lineHeight: "lineHeight40" as ThemeShape["lineHeights"], | ||
}, | ||
}; | ||
|
||
export interface AIChatMessageBodyProps extends HTMLPasteProps<"div"> { | ||
children?: React.ReactNode; | ||
/** | ||
* Overrides the default element name to apply unique styles with the Customization Provider | ||
* | ||
* @default "CHAT_BUBBLE" | ||
* @type {BoxProps["element"]} | ||
* @memberof AIChatBubbleProps | ||
*/ | ||
element?: BoxElementProps["element"]; | ||
/** | ||
* Override the font size for full screen experiences. | ||
* | ||
* @default "CHAT_BUBBLE" | ||
* @type {"default" | "fullScreen"} | ||
* @memberof AIChatBubbleProps | ||
*/ | ||
variant?: "default" | "fullScreen"; | ||
} | ||
|
||
export const AIChatMessageBody = React.forwardRef<HTMLDivElement, AIChatMessageBodyProps>( | ||
({ children, variant = "default", element = "AI_CHAT_MESSAGE_BODY", ...props }, ref) => { | ||
return ( | ||
<Box | ||
{...safelySpreadBoxProps(props)} | ||
{...Variants[variant]} | ||
display="inline-block" | ||
color="colorText" | ||
wordWrap="break-word" | ||
maxWidth="100%" | ||
minWidth={0} | ||
element={element} | ||
ref={ref} | ||
whiteSpace="pre-wrap" | ||
> | ||
{children} | ||
</Box> | ||
); | ||
}, | ||
); | ||
|
||
AIChatMessageBody.displayName = "AIChatMessageBody"; |
67 changes: 67 additions & 0 deletions
67
packages/paste-core/components/ai-chat-log/src/AIChatMessageFeedback.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Box, safelySpreadBoxProps } from "@twilio-paste/box"; | ||
import type { BoxElementProps } from "@twilio-paste/box"; | ||
import { Button } from "@twilio-paste/button"; | ||
import { ThumbsDownIcon } from "@twilio-paste/icons/esm/ThumbsDownIcon"; | ||
import { ThumbsUpIcon } from "@twilio-paste/icons/esm/ThumbsUpIcon"; | ||
import type { HTMLPasteProps } from "@twilio-paste/types"; | ||
import * as React from "react"; | ||
|
||
export interface AIChatMessageFeedbackProps extends HTMLPasteProps<"div"> { | ||
children?: never; | ||
/** | ||
* Overrides the default element name to apply unique styles with the Customization Provider | ||
* | ||
* @default "CHAT_MESSAGE_META_ITEM" | ||
* @type {BoxProps["element"]} | ||
* @memberof AIChatMessageMetaItemProps | ||
*/ | ||
element?: BoxElementProps["element"]; | ||
label?: string; | ||
i18nLikeLabel?: string; | ||
i18nDislikeLabel?: string; | ||
onLike: () => void; | ||
onDislike: () => void; | ||
} | ||
|
||
export const AIChatMessageFeedback = React.forwardRef<HTMLDivElement, AIChatMessageFeedbackProps>( | ||
( | ||
{ | ||
label = "Is this helpful?", | ||
i18nLikeLabel = "Like result", | ||
i18nDislikeLabel = "Dislike result", | ||
onLike, | ||
onDislike, | ||
element = "AI_CHAT_MESSAGE_FEEDBACK", | ||
...props | ||
}, | ||
ref, | ||
) => ( | ||
<Box | ||
{...safelySpreadBoxProps(props)} | ||
ref={ref} | ||
element={element} | ||
display="inline-flex" | ||
alignItems="flex-start" | ||
columnGap="space30" | ||
marginTop="space40" | ||
color="colorTextIcon" | ||
lineHeight="lineHeight20" | ||
fontSize="fontSize20" | ||
backgroundColor="colorBackgroundBody" | ||
boxShadow="shadowBorderWeaker" | ||
borderRadius="borderRadius30" | ||
paddingX="space30" | ||
paddingY="space20" | ||
> | ||
<span>{label}</span> | ||
<Button variant="reset" size="reset" onClick={onLike}> | ||
<ThumbsUpIcon decorative={false} title={i18nLikeLabel} /> | ||
</Button> | ||
<Button variant="reset" size="reset" onClick={onDislike}> | ||
<ThumbsDownIcon decorative={false} title={i18nDislikeLabel} /> | ||
</Button> | ||
</Box> | ||
), | ||
); | ||
|
||
AIChatMessageFeedback.displayName = "AIChatMessageFeedback"; |
56 changes: 56 additions & 0 deletions
56
packages/paste-core/components/ai-chat-log/src/AIChatMessageLoading.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Box, safelySpreadBoxProps } from "@twilio-paste/box"; | ||
import type { BoxElementProps } from "@twilio-paste/box"; | ||
import { Button } from "@twilio-paste/button"; | ||
import { StopIcon } from "@twilio-paste/icons/esm/StopIcon"; | ||
import { ScreenReaderOnly } from "@twilio-paste/screen-reader-only"; | ||
import { SkeletonLoader } from "@twilio-paste/skeleton-loader"; | ||
import type { HTMLPasteProps } from "@twilio-paste/types"; | ||
import * as React from "react"; | ||
|
||
const clampedRandom = (min: number, max: number): number => { | ||
return Math.min(Math.max(min, Math.random() * max), max); | ||
}; | ||
export interface AIChatMessageLoadingProps extends HTMLPasteProps<"div"> { | ||
children?: never; | ||
/** | ||
* Overrides the default element name to apply unique styles with the Customization Provider | ||
* | ||
* @default "CHAT_MESSAGE" | ||
* @type {BoxProps["element"]} | ||
* @memberof ChatMessageProps | ||
*/ | ||
element?: BoxElementProps["element"]; | ||
onStopLoading?: () => void; | ||
} | ||
|
||
export const AIChatMessageLoading = React.forwardRef<HTMLDivElement, AIChatMessageLoadingProps>( | ||
({ onStopLoading, element = "AI_CHAT_MESSAGE_LOADING", ...props }, ref) => { | ||
const widths = React.useRef([clampedRandom(40, 75), clampedRandom(65, 100), clampedRandom(55, 80)]).current; | ||
|
||
return ( | ||
<Box | ||
{...safelySpreadBoxProps(props)} | ||
ref={ref} | ||
element={element} | ||
role="listitem" | ||
display="flex" | ||
flexDirection="column" | ||
rowGap="space40" | ||
> | ||
<SkeletonLoader width={`${widths[0]}%`} height="20px" /> | ||
<SkeletonLoader width={`${widths[1]}%`} height="20px" /> | ||
<SkeletonLoader width={`${widths[2]}%`} height="20px" /> | ||
{onStopLoading ? ( | ||
<Box display="flex" justifyContent="center"> | ||
<Button variant="secondary" size="rounded_small" onClick={onStopLoading}> | ||
<StopIcon decorative={true} /> | ||
Stop generating <ScreenReaderOnly>AI response</ScreenReaderOnly> | ||
</Button> | ||
</Box> | ||
) : null} | ||
</Box> | ||
); | ||
}, | ||
); | ||
|
||
AIChatMessageLoading.displayName = "AIChatMessageLoading"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.