From 4b4fc9368740c2a5dd74f5904dd8e62e5980abd8 Mon Sep 17 00:00:00 2001 From: Rob Snow Date: Fri, 12 Jun 2026 13:29:33 +1000 Subject: [PATCH] chore: setup AI exports --- .../ai/exports/AttachmentList.ts | 2 + .../ai/exports/HorizontalCard.ts | 2 +- .../ai/exports/MessageFeedback.ts | 2 + .../ai/exports/MessageSuggestion.ts | 2 + packages/@react-spectrum/ai/exports/Thread.ts | 8 + .../@react-spectrum/ai/exports/UserMessage.ts | 2 + packages/@react-spectrum/ai/exports/index.ts | 20 ++- .../@react-spectrum/ai/src/AttachmentList.tsx | 15 +- .../@react-spectrum/ai/src/HorizontalCard.tsx | 18 +-- .../@react-spectrum/ai/src/MessageSource.tsx | 1 + packages/@react-spectrum/ai/src/Thread.tsx | 11 +- .../ai/stories/AttachmentList.stories.tsx | 73 +++++++++ .../stories/BasicHorizontalCard.stories.tsx | 141 ++++++++++++++++++ .../ai/stories/HorizontalCard.stories.tsx | 132 +--------------- .../ai/stories/MessageSource.stories.tsx | 2 +- .../ai/stories/ResponseStatus.stories.tsx | 6 +- .../ai/stories/Thread.stories.tsx | 16 +- 17 files changed, 297 insertions(+), 156 deletions(-) create mode 100644 packages/@react-spectrum/ai/exports/Thread.ts create mode 100644 packages/@react-spectrum/ai/stories/AttachmentList.stories.tsx create mode 100644 packages/@react-spectrum/ai/stories/BasicHorizontalCard.stories.tsx diff --git a/packages/@react-spectrum/ai/exports/AttachmentList.ts b/packages/@react-spectrum/ai/exports/AttachmentList.ts index 6daac523b4d..67c8c3dab02 100644 --- a/packages/@react-spectrum/ai/exports/AttachmentList.ts +++ b/packages/@react-spectrum/ai/exports/AttachmentList.ts @@ -1 +1,3 @@ export {Attachment, AttachmentList} from '../src/AttachmentList'; + +export type {AttachmentProps, AttachmentListProps} from '../src/AttachmentList'; diff --git a/packages/@react-spectrum/ai/exports/HorizontalCard.ts b/packages/@react-spectrum/ai/exports/HorizontalCard.ts index 07442cb6638..d27371e15cb 100644 --- a/packages/@react-spectrum/ai/exports/HorizontalCard.ts +++ b/packages/@react-spectrum/ai/exports/HorizontalCard.ts @@ -1,2 +1,2 @@ export {BasicHorizontalCard, HorizontalCard, CardPreview} from '../src/HorizontalCard'; -export type {CardProps, BasicCardProps} from '../src/HorizontalCard'; +export type {HorizontalCardProps, BasicCardProps} from '../src/HorizontalCard'; diff --git a/packages/@react-spectrum/ai/exports/MessageFeedback.ts b/packages/@react-spectrum/ai/exports/MessageFeedback.ts index cca83d4afb5..9a11b9caa64 100644 --- a/packages/@react-spectrum/ai/exports/MessageFeedback.ts +++ b/packages/@react-spectrum/ai/exports/MessageFeedback.ts @@ -1 +1,3 @@ export {MessageFeedback} from '../src/MessageFeedback'; + +export type {MessageFeedbackProps} from '../src/MessageFeedback'; diff --git a/packages/@react-spectrum/ai/exports/MessageSuggestion.ts b/packages/@react-spectrum/ai/exports/MessageSuggestion.ts index 03edf7e545e..b2e2c681020 100644 --- a/packages/@react-spectrum/ai/exports/MessageSuggestion.ts +++ b/packages/@react-spectrum/ai/exports/MessageSuggestion.ts @@ -1 +1,3 @@ export {MessageSuggestion, MessageSuggestionList} from '../src/MessageSuggestion'; + +export type {MessageSuggestionProps, MessageSuggestionListProps} from '../src/MessageSuggestion'; diff --git a/packages/@react-spectrum/ai/exports/Thread.ts b/packages/@react-spectrum/ai/exports/Thread.ts new file mode 100644 index 00000000000..03d7e7db6c7 --- /dev/null +++ b/packages/@react-spectrum/ai/exports/Thread.ts @@ -0,0 +1,8 @@ +export {Thread, ThreadItem, ThreadList, ThreadScrollButton} from '../src/Thread'; + +export type { + ThreadProps, + ThreadItemProps, + ThreadListProps, + ThreadScrollButtonProps +} from '../src/Thread'; diff --git a/packages/@react-spectrum/ai/exports/UserMessage.ts b/packages/@react-spectrum/ai/exports/UserMessage.ts index f5cbd1b36bf..28e9ee0a48e 100644 --- a/packages/@react-spectrum/ai/exports/UserMessage.ts +++ b/packages/@react-spectrum/ai/exports/UserMessage.ts @@ -1 +1,3 @@ export {UserMessage} from '../src/UserMessage'; + +export type {UserMessageProps} from '../src/UserMessage'; diff --git a/packages/@react-spectrum/ai/exports/index.ts b/packages/@react-spectrum/ai/exports/index.ts index 40978ed667f..b1e77ac4915 100644 --- a/packages/@react-spectrum/ai/exports/index.ts +++ b/packages/@react-spectrum/ai/exports/index.ts @@ -2,5 +2,23 @@ export {Attachment, AttachmentList} from '../src/AttachmentList'; export {BasicHorizontalCard, HorizontalCard} from '../src/HorizontalCard'; export {MessageFeedback} from '../src/MessageFeedback'; export {MessageSuggestion, MessageSuggestionList} from '../src/MessageSuggestion'; -export {ResponseStatus, ResponseStatusPanel} from '../src/ResponseStatus'; +export {ResponseStatus, ResponseStatusTitle, ResponseStatusPanel} from '../src/ResponseStatus'; +export {Thread, ThreadItem, ThreadList, ThreadScrollButton} from '../src/Thread'; export {UserMessage} from '../src/UserMessage'; + +export type {AttachmentProps, AttachmentListProps} from '../src/AttachmentList'; +export type {HorizontalCardProps, BasicCardProps} from '../src/HorizontalCard'; +export type {MessageFeedbackProps} from '../src/MessageFeedback'; +export type {MessageSuggestionProps, MessageSuggestionListProps} from '../src/MessageSuggestion'; +export type { + ResponseStatusProps, + ResponseStatusTitleProps, + ResponseStatusPanelProps +} from '../src/ResponseStatus'; +export type { + ThreadProps, + ThreadItemProps, + ThreadListProps, + ThreadScrollButtonProps +} from '../src/Thread'; +export type {UserMessageProps} from '../src/UserMessage'; diff --git a/packages/@react-spectrum/ai/src/AttachmentList.tsx b/packages/@react-spectrum/ai/src/AttachmentList.tsx index 2d864dce7df..2b9058bcedf 100644 --- a/packages/@react-spectrum/ai/src/AttachmentList.tsx +++ b/packages/@react-spectrum/ai/src/AttachmentList.tsx @@ -16,13 +16,22 @@ import {BasicHorizontalCard} from './HorizontalCard'; import {Button} from 'react-aria-components/Button'; import {CardProps} from '@react-spectrum/s2/Card'; import Close from '@react-spectrum/s2/icons/Close'; -import {forwardRef, useRef} from 'react'; +import {forwardRef, ReactNode, useRef} from 'react'; import {iconStyle} from '@react-spectrum/s2/style' with {type: 'macro'}; import {mergeStyles} from '@react-spectrum/s2/mergeStyles'; import {pressScale} from '@react-spectrum/s2/pressScale'; -import {Tag, TagGroup, TagList} from 'react-aria-components/TagGroup'; +import type {StyleProps} from '@react-spectrum/s2'; +import {Tag, TagGroup, TagGroupProps, TagList} from 'react-aria-components/TagGroup'; import {useDOMRef} from './useDOMRef'; +export interface AttachmentListProps extends TagGroupProps, StyleProps { + children: ReactNode; +} + +export interface AttachmentProps extends CardProps { + children: ReactNode; +} + const controlSizeM = { default: 32, size: { @@ -104,7 +113,7 @@ const CloseButton = function CloseButton(props) { }; export const AttachmentList = forwardRef(function AttachmentList( - props: any, + props: AttachmentListProps, ref: DOMRef ) { let domRef = useDOMRef(ref); diff --git a/packages/@react-spectrum/ai/src/HorizontalCard.tsx b/packages/@react-spectrum/ai/src/HorizontalCard.tsx index b56af6bcc1f..ec1ac2fdc36 100644 --- a/packages/@react-spectrum/ai/src/HorizontalCard.tsx +++ b/packages/@react-spectrum/ai/src/HorizontalCard.tsx @@ -39,12 +39,12 @@ import {SkeletonContext, useIsSkeleton} from '@react-spectrum/s2/Skeleton'; import {StyleString} from './types'; import {TextContext} from '@react-spectrum/s2/Text'; import {useDOMRef} from './useDOMRef'; -interface CardRenderProps { +interface HorizontalCardRenderProps { /** The size of the Card. */ size: 'XS' | 'S' | 'M' | 'L' | 'XL'; } -export interface CardProps extends Omit< +export interface HorizontalCardProps extends Omit< GridListItemProps, | 'className' | 'style' @@ -57,7 +57,7 @@ export interface CardProps extends Omit< | keyof GlobalDOMAttributes > { /** The children of the Card. */ - children: ReactNode | ((renderProps: CardRenderProps) => ReactNode); + children: ReactNode | ((renderProps: HorizontalCardRenderProps) => ReactNode); /** * The size of the Card. * @@ -82,7 +82,7 @@ export interface CardProps extends Omit< styles?: StyleString; } -export interface BasicCardProps extends Omit { +export interface BasicCardProps extends Omit { /** * The visual style of the Card. * @@ -456,7 +456,7 @@ const actionButtonSize = { } as const; const Card = forwardRef(function Card( - props: Omit & { + props: Omit & { isBasic?: boolean; variant?: 'primary' | 'secondary' | 'tertiary' | 'quiet'; }, @@ -669,6 +669,7 @@ export interface CardPreviewProps extends DOMProps { styles?: StyleString; } +// TODO: this should be the same component as the one in @react-spectrum/s2/Card export const CardPreview = forwardRef(function CardPreview( props: CardPreviewProps, ref: DOMRef @@ -681,10 +682,7 @@ export const CardPreview = forwardRef(function CardPreview( {...filterDOMProps(props)} slot="preview" ref={domRef} - className={mergeStyles( - preview({size, isQuiet, isHovered, isFocusVisible, isSelected}), - props.styles - )} + className={preview({size, isQuiet, isHovered, isFocusVisible, isSelected})} style={isQuiet ? pressScale(domRef)({isPressed}) : undefined}> {isQuiet && } {isQuiet && isCheckboxSelection && } @@ -742,7 +740,7 @@ const buttonSize = { } as const; export const HorizontalCard = forwardRef(function HorizontalCard( - props: CardProps, + props: HorizontalCardProps, ref: DOMRef ) { let {size = 'M'} = props; diff --git a/packages/@react-spectrum/ai/src/MessageSource.tsx b/packages/@react-spectrum/ai/src/MessageSource.tsx index c6167945dce..9ac2cf972d0 100644 --- a/packages/@react-spectrum/ai/src/MessageSource.tsx +++ b/packages/@react-spectrum/ai/src/MessageSource.tsx @@ -28,6 +28,7 @@ import {SlotProps} from 'react-aria-components/slots'; import {StyleString} from './types'; import {useDOMRef} from './useDOMRef'; import {useLocale} from 'react-aria/I18nProvider'; + export interface MessageSourceProps extends Omit< DisclosureProps, 'isQuiet' | 'styles' | 'UNSAFE_className' | 'UNSAFE_style' diff --git a/packages/@react-spectrum/ai/src/Thread.tsx b/packages/@react-spectrum/ai/src/Thread.tsx index f2beefb9c81..ac106fc709d 100644 --- a/packages/@react-spectrum/ai/src/Thread.tsx +++ b/packages/@react-spectrum/ai/src/Thread.tsx @@ -61,7 +61,7 @@ const ThreadScrollButtonContext = createContext( }); // TODO: make this more RAC like (aka default class name and other RAC prop) -interface ThreadProps { +export interface ThreadProps { className?: string; style?: CSSProperties; children?: ReactNode; @@ -157,7 +157,7 @@ export const Thread = /*#__PURE__*/ (forwardRef as forwardRefType)(function Thre }); // TODO: update the items/className/children/etc type to reflect a thread specific classname once we finalize API -interface ThreadListProps extends Pick< +export interface ThreadListProps extends Pick< GridListProps, 'items' | 'children' | 'focusOnEntry' | 'aria-label' | 'aria-labelledby' | 'className' > {} @@ -249,7 +249,7 @@ export function ThreadList(props: ThreadListProps) { ); } -interface ThreadScrollButtonProps { +export interface ThreadScrollButtonProps { children?: ReactNode; } @@ -271,7 +271,10 @@ export function ThreadScrollButton({children}: ThreadScrollButtonProps) { } // TODO: update the className type to reflect a thread specific classname once we finalize API -interface ThreadItemProps extends Pick { +export interface ThreadItemProps extends Pick< + GridListItemProps, + 'className' | 'children' | 'textValue' +> { /** Whether or not the item's content is currently being streamed in. */ isStreaming?: boolean; /** Announce textValue on mount even when isStreaming is provided. */ diff --git a/packages/@react-spectrum/ai/stories/AttachmentList.stories.tsx b/packages/@react-spectrum/ai/stories/AttachmentList.stories.tsx new file mode 100644 index 00000000000..6986b1d3e3d --- /dev/null +++ b/packages/@react-spectrum/ai/stories/AttachmentList.stories.tsx @@ -0,0 +1,73 @@ +/* + * Copyright 2024 Adobe. All rights reserved. + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy + * of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ + +import { + Attachment as AttachmentComponent, + AttachmentList, + type AttachmentListProps +} from '@react-spectrum/ai/AttachmentList'; +import {Content} from '@react-spectrum/s2/Content'; +import {Image} from '@react-spectrum/s2/Image'; +import type {Meta, StoryObj} from '@storybook/react'; +import {style} from '@react-spectrum/s2/style' with {type: 'macro'}; +import {Text} from '@react-spectrum/s2/Text'; + +const meta: Meta = { + component: AttachmentList, + parameters: { + layout: 'centered' + }, + tags: ['autodocs'], + argTypes: { + children: {table: {disable: true}} + }, + title: 'AI/AttachmentList' +}; + +export default meta; + +type Story = StoryObj; + +export const AIAttachmentList: Story = { + render: args => ( + + + + + + + + + + + + + + Card title + Card description. + + + + ) +}; diff --git a/packages/@react-spectrum/ai/stories/BasicHorizontalCard.stories.tsx b/packages/@react-spectrum/ai/stories/BasicHorizontalCard.stories.tsx new file mode 100644 index 00000000000..0a35b49a219 --- /dev/null +++ b/packages/@react-spectrum/ai/stories/BasicHorizontalCard.stories.tsx @@ -0,0 +1,141 @@ +/* + * Copyright 2024 Adobe. All rights reserved. + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy + * of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ + +import {ActionButton} from '@react-spectrum/s2/ActionButton'; +import {ActionMenu} from '@react-spectrum/s2/ActionMenu'; +import {type BasicCardProps, BasicHorizontalCard} from '@react-spectrum/ai/HorizontalCard'; +import ChevronRight from '@react-spectrum/s2/icons/ChevronRight'; +import {Content} from '@react-spectrum/s2/Content'; +import {Footer} from '@react-spectrum/s2/Footer'; +import {Image} from '@react-spectrum/s2/Image'; +import {MenuItem} from '@react-spectrum/s2/Menu'; +import type {Meta, StoryObj} from '@storybook/react'; +import {Skeleton} from '@react-spectrum/s2/Skeleton'; +import {style} from '@react-spectrum/s2/style' with {type: 'macro'}; +import {Text} from '@react-spectrum/s2/Text'; + +const meta: Meta = { + component: BasicHorizontalCard, + parameters: { + layout: 'centered' + }, + tags: ['autodocs'], + args: { + isLoading: false + }, + argTypes: { + href: {table: {disable: true}}, + download: {table: {disable: true}}, + hrefLang: {table: {disable: true}}, + referrerPolicy: {table: {disable: true}}, + rel: {table: {disable: true}}, + routerOptions: {table: {disable: true}}, + ping: {table: {disable: true}}, + target: {table: {disable: true}}, + value: {table: {disable: true}}, + textValue: {table: {disable: true}}, + onAction: {table: {disable: true}}, + isDisabled: {table: {disable: true}}, + children: {table: {disable: true}} + }, + decorators: (children, {args}) => ( + {children(args)} + ), + title: 'AI/BasicHorizontalCard' +}; + +export default meta; + +type BasicStory = StoryObj; + +export const Basic: BasicStory = { + render: args => ( +
+ + + + Card title + Card description. + +
+ + Test + +
+
+ + + + Card title + Card description. + +
+ + + +
+
+ + + + Card title + Card description. + + + + + + Card title + Card description. + + + + + +
+ ), + argTypes: { + variant: { + control: 'radio', + options: ['primary', 'secondary', 'tertiary', 'quiet'] + } + } +}; diff --git a/packages/@react-spectrum/ai/stories/HorizontalCard.stories.tsx b/packages/@react-spectrum/ai/stories/HorizontalCard.stories.tsx index 50a5e109fa8..e143022f271 100644 --- a/packages/@react-spectrum/ai/stories/HorizontalCard.stories.tsx +++ b/packages/@react-spectrum/ai/stories/HorizontalCard.stories.tsx @@ -10,26 +10,19 @@ * governing permissions and limitations under the License. */ -import {ActionButton} from '@react-spectrum/s2/ActionButton'; -import {ActionMenu} from '@react-spectrum/s2/ActionMenu'; -import {Attachment as AttachmentComponent, AttachmentList} from '@react-spectrum/ai/AttachmentList'; import { - BasicHorizontalCard, CardPreview, - type CardProps, - HorizontalCard + HorizontalCard, + type HorizontalCardProps } from '@react-spectrum/ai/HorizontalCard'; -import ChevronRight from '@react-spectrum/s2/icons/ChevronRight'; import {Content} from '@react-spectrum/s2/Content'; -import {Footer} from '@react-spectrum/s2/Footer'; import {Image} from '@react-spectrum/s2/Image'; -import {MenuItem} from '@react-spectrum/s2/Menu'; import type {Meta, StoryObj} from '@storybook/react'; import {Skeleton} from '@react-spectrum/s2/Skeleton'; import {style} from '@react-spectrum/s2/style' with {type: 'macro'}; import {Text} from '@react-spectrum/s2/Text'; -const meta: Meta = { +const meta: Meta = { component: HorizontalCard, parameters: { layout: 'centered' @@ -62,7 +55,6 @@ const meta: Meta = { export default meta; type Story = StoryObj; -type BasicStory = StoryObj; export const Horizontal: Story = { render: args => ( @@ -117,121 +109,3 @@ export const Horizontal: Story = { ) }; - -export const Basic: BasicStory = { - render: args => ( -
- - - - Card title - Card description. - -
- - Test - -
-
- - - - Card title - Card description. - -
- - - -
-
- - - - Card title - Card description. - - - - - - Card title - Card description. - - - - - -
- ), - argTypes: { - variant: { - control: 'radio', - options: ['primary', 'secondary', 'tertiary', 'quiet'] - } - } -}; - -export const AIAttachmentList: Story = { - render: args => ( - - - - - - - - - - - - - - Card title - Card description. - - - - ) -}; diff --git a/packages/@react-spectrum/ai/stories/MessageSource.stories.tsx b/packages/@react-spectrum/ai/stories/MessageSource.stories.tsx index ccde02a1048..5fb79e15fef 100644 --- a/packages/@react-spectrum/ai/stories/MessageSource.stories.tsx +++ b/packages/@react-spectrum/ai/stories/MessageSource.stories.tsx @@ -10,7 +10,7 @@ * governing permissions and limitations under the License. */ -import {MessageSource, SourceList, SourceListItem} from '../src/MessageSource'; +import {MessageSource, SourceList, SourceListItem} from '@react-spectrum/ai/MessageSource'; import type {Meta, StoryObj} from '@storybook/react'; import React from 'react'; import {style} from '@react-spectrum/s2/style' with {type: 'macro'}; diff --git a/packages/@react-spectrum/ai/stories/ResponseStatus.stories.tsx b/packages/@react-spectrum/ai/stories/ResponseStatus.stories.tsx index db71b09640b..a40e67d41df 100644 --- a/packages/@react-spectrum/ai/stories/ResponseStatus.stories.tsx +++ b/packages/@react-spectrum/ai/stories/ResponseStatus.stories.tsx @@ -12,7 +12,11 @@ import type {Meta, StoryObj} from '@storybook/react'; import React from 'react'; -import {ResponseStatus, ResponseStatusPanel, ResponseStatusTitle} from '../src/ResponseStatus'; +import { + ResponseStatus, + ResponseStatusPanel, + ResponseStatusTitle +} from '@react-spectrum/ai/ResponseStatus'; import {style} from '@react-spectrum/s2/style' with {type: 'macro'}; const meta: Meta = { diff --git a/packages/@react-spectrum/ai/stories/Thread.stories.tsx b/packages/@react-spectrum/ai/stories/Thread.stories.tsx index 3bdd7438078..e3588d74e1a 100644 --- a/packages/@react-spectrum/ai/stories/Thread.stories.tsx +++ b/packages/@react-spectrum/ai/stories/Thread.stories.tsx @@ -35,17 +35,21 @@ import {Image} from '@react-spectrum/s2/Image'; import {Link} from '@react-spectrum/s2/Link'; import {ListLayout} from 'react-stately/useVirtualizerState'; import {MenuItem} from '@react-spectrum/s2/Menu'; -import {MessageFeedback} from '../src/MessageFeedback'; -import {MessageSource, SourceList, SourceListItem} from '../src/MessageSource'; -import {MessageSuggestion, MessageSuggestionList} from '../src/MessageSuggestion'; +import {MessageFeedback} from '@react-spectrum/ai/MessageFeedback'; +import {MessageSource, SourceList, SourceListItem} from '@react-spectrum/ai/MessageSource'; +import {MessageSuggestion, MessageSuggestionList} from '@react-spectrum/ai/MessageSuggestion'; import type {Meta} from '@storybook/react'; import Plus from '@react-spectrum/s2/icons/Add'; import {ReactNode, useRef, useState} from 'react'; -import {ResponseStatus, ResponseStatusPanel, ResponseStatusTitle} from '../src/ResponseStatus'; +import { + ResponseStatus, + ResponseStatusPanel, + ResponseStatusTitle +} from '@react-spectrum/ai/ResponseStatus'; import Send from '@react-spectrum/s2/icons/ArrowUpSend'; import {Text} from '@react-spectrum/s2/Text'; -import {Thread, ThreadItem, ThreadList, ThreadScrollButton} from '../src/Thread'; -import {UserMessage} from '../src/UserMessage'; +import {Thread, ThreadItem, ThreadList, ThreadScrollButton} from '@react-spectrum/ai/Thread'; +import {UserMessage} from '@react-spectrum/ai/UserMessage'; import {Virtualizer} from 'react-aria-components/Virtualizer'; const meta: Meta = {