Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ describe('ActionGroup', function () {
${'(up/down arrows, ltr + horizontal) ActionGroup'} | ${{locale: 'de-DE'}} | ${[{action: tab, result: () => expectedButtonIndices.button1Focused}, {action: pressArrowDown, result: btnBehavior.forward}, {action: pressArrowUp, result: btnBehavior.backward}, {action: pressArrowUp, result: btnBehavior.backward}]}
${'(up/down arrows, rtl + horizontal) ActionGroup'} | ${{locale: 'ar-AE'}} | ${[{action: tab, result: () => expectedButtonIndices.button1Focused}, {action: pressArrowDown, result: btnBehavior.forward}, {action: pressArrowUp, result: btnBehavior.backward}, {action: pressArrowUp, result: btnBehavior.backward}]}
${'(left/right arrows, ltr + vertical) ActionGroup'} | ${{locale: 'de-DE', orientation: 'vertical'}} | ${[{action: tab, result: () => expectedButtonIndices.button1Focused}, {action: pressArrowRight, result: btnBehavior.forward}, {action: pressArrowLeft, result: btnBehavior.backward}, {action: pressArrowLeft, result: btnBehavior.backward}]}
${'(left/right arrows, rtl + vertical) ActionGroup'} | ${{locale: 'ar-AE', orientation: 'vertical'}} | ${[{action: tab, result: () => expectedButtonIndices.button1Focused}, {action: pressArrowRight, result: btnBehavior.forward}, {action: pressArrowLeft, result: btnBehavior.backward}, {action: pressArrowLeft, result: btnBehavior.backward}]}
${'(left/right arrows, rtl + vertical) ActionGroup'} | ${{locale: 'ar-AE', orientation: 'vertical'}} | ${[{action: tab, result: () => expectedButtonIndices.button1Focused}, {action: pressArrowRight, result: btnBehavior.backward}, {action: pressArrowLeft, result: btnBehavior.forward}, {action: pressArrowLeft, result: btnBehavior.forward}]}
${'(up/down arrows, ltr + vertical) ActionGroup'} | ${{locale: 'de-DE', orientation: 'vertical'}} | ${[{action: tab, result: () => expectedButtonIndices.button1Focused}, {action: pressArrowDown, result: btnBehavior.forward}, {action: pressArrowUp, result: btnBehavior.backward}, {action: pressArrowUp, result: btnBehavior.backward}]}
${'(up/down arrows, rtl + vertical) ActionGroup'} | ${{locale: 'ar-AE', orientation: 'vertical'}} | ${[{action: tab, result: () => expectedButtonIndices.button1Focused}, {action: pressArrowDown, result: btnBehavior.forward}, {action: pressArrowUp, result: btnBehavior.backward}, {action: pressArrowUp, result: btnBehavior.backward}]}
`(
Expand Down
134 changes: 134 additions & 0 deletions packages/@react-spectrum/ai/chromatic/PromptField.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* Copyright 2026 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 {AttachFileMenuItem, InsertMenuButton, PromptFieldVoiceButton} from '../src/PromptField';
import {Button} from '@react-spectrum/s2/Button';
import {
Header,
Heading,
Menu,
MenuItem,
MenuSection,
MenuTrigger,
Text
} from '@react-spectrum/s2/Menu';
import Keyboard from '@react-spectrum/s2/icons/Keyboard';
import {LinkButton} from '@react-spectrum/s2/LinkButton';
import ListMultiSelect from '@react-spectrum/s2/icons/ListMultiSelect';
import type {Meta, StoryObj} from '@storybook/react';
import {
PromptField,
PromptFieldSubmitButton,
PromptFieldToolbar,
PromptTokenField
} from '@react-spectrum/ai';
import {style} from '@react-spectrum/s2/style' with {type: 'macro'};
import {ToggleButton} from '@react-spectrum/s2/ToggleButton';

const meta: Meta = {
parameters: {
chromaticProvider: {
disableAnimations: true,
colorSchemes: ['light', 'dark'],
locales: ['en-US']
}
},
title: 'AI Chromatic/PromptField'
};

export default meta;

type Story = StoryObj<typeof meta>;

function ToolbarButtons() {
return (
<div className={style({display: 'flex', gap: 8})}>
<ToggleButton isQuiet size="S">
<ListMultiSelect />
<Text>Plan mode</Text>
</ToggleButton>
<MenuTrigger>
<ActionButton isQuiet size="S">
<Keyboard />
<Text>Normal</Text>
</ActionButton>
<Menu>
<MenuSection>
<Header>
<Heading>Transcript view</Heading>
</Header>
<MenuItem>Normal</MenuItem>
</MenuSection>
</Menu>
</MenuTrigger>
<Button size="S" fillStyle="outline">
Model
</Button>
<LinkButton size="S" fillStyle="outline" href="#">
Terms and conditions
</LinkButton>
</div>
);
}

export const ToolbarButtonsStory: Story = {
render: () => (
<div className={style({width: 800, maxWidth: '90vw', marginX: 'auto'})}>
<PromptField>
<PromptTokenField />
<PromptFieldToolbar>
<div className={style({display: 'flex', gap: 8, alignItems: 'center'})}>
<InsertMenuButton>
<AttachFileMenuItem />
</InsertMenuButton>
<ToolbarButtons />
</div>
<div style={{display: 'flex', gap: 8, alignItems: 'center'}}>
<PromptFieldVoiceButton />
<PromptFieldSubmitButton />
</div>
</PromptFieldToolbar>
</PromptField>
<PromptField variant="prominent">
<PromptTokenField />
<PromptFieldToolbar>
<div className={style({display: 'flex', gap: 8, alignItems: 'center'})}>
<InsertMenuButton>
<AttachFileMenuItem />
</InsertMenuButton>
<ToolbarButtons />
</div>
<div style={{display: 'flex', gap: 8, alignItems: 'center'}}>
<PromptFieldVoiceButton />
<PromptFieldSubmitButton />
</div>
</PromptFieldToolbar>
</PromptField>
<PromptField variant="subtle">
<PromptTokenField />
<PromptFieldToolbar>
<div className={style({display: 'flex', gap: 8, alignItems: 'center'})}>
<InsertMenuButton>
<AttachFileMenuItem />
</InsertMenuButton>
<ToolbarButtons />
</div>
<div style={{display: 'flex', gap: 8, alignItems: 'center'}}>
<PromptFieldVoiceButton />
<PromptFieldSubmitButton />
</div>
</PromptFieldToolbar>
</PromptField>
</div>
)
};
62 changes: 36 additions & 26 deletions packages/@react-spectrum/ai/src/PromptField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
* governing permissions and limitations under the License.
*/

import {ActionButton} from '@react-spectrum/s2/ActionButton';
import {ActionButton, ActionButtonContext} from '@react-spectrum/s2/ActionButton';
import Attach from '@react-spectrum/s2/icons/Attach';
import {Attachment, AttachmentList, AttachmentListProps} from './AttachmentList';
import {Autocomplete} from 'react-aria-components/Autocomplete';
import {Button} from '@react-spectrum/s2/Button';
import {Button, ButtonContext} from '@react-spectrum/s2/Button';
import {Cell} from './loader/data';
import {CenterBaseline} from '@react-spectrum/s2/CenterBaseline';
import {color, css, space, style, StyleString} from '@react-spectrum/s2/style' with {type: 'macro'};
Expand All @@ -39,6 +39,7 @@ import {Image, Text} from '@react-spectrum/s2/Card';
import intlMessages from '../intl/*.json';
import {isFileDropItem, useDrop} from 'react-aria-components/useDrop';
import {Link} from '@react-spectrum/s2/Link';
import {LinkButtonContext} from '@react-spectrum/s2/LinkButton';
import {Menu, MenuItem, MenuItemProps, MenuTrigger} from '@react-spectrum/s2/Menu';
import Microphone from '@react-spectrum/s2/icons/Microphone';
import {PixelLoader} from './loader/react';
Expand All @@ -53,10 +54,11 @@ import {
} from 'react-stately/useTokenFieldState';
import {PromptFieldContainer} from './PromptFieldContainer';
import {PromptFocusContext} from './Chat';
import {Provider} from 'react-aria-components/slots';
import Send from '@react-spectrum/s2/icons/ArrowUpSend';
import {setTokenFieldSelection} from 'react-aria/useTokenField';
import Stop from '@react-spectrum/s2/icons/StopProcessing';
import {ToggleButton} from '@react-spectrum/s2/ToggleButton';
import {ToggleButton, ToggleButtonContext} from '@react-spectrum/s2/ToggleButton';
import {
Token,
TokenField,
Expand Down Expand Up @@ -337,28 +339,36 @@ export const PromptField = forwardRef(function PromptField(
onAddAttachments,
onRemoveAttachments
}}>
<div ref={domRef} {...focusWithinProps}>
<PromptFieldContainer
{...dropProps}
role="group"
variant={variant}
brandColor={brandColor}
isGenerating={isGenerating ?? false}
isDropTarget={isDropTarget}
styles={styles}
inputRef={inputRef}>
{children}
</PromptFieldContainer>
<p className={style({font: 'ui-sm', textAlign: 'center'})}>
{stringFormatter.format('promptfield.aiDisclaimer')}{' '}
<Link
variant="secondary"
href="https://www.adobe.com/legal/licenses-terms/adobe-gen-ai-user-guidelines.html"
target="_blank">
{stringFormatter.format('promptfield.aiUserGuidlines')}
</Link>
</p>
</div>
<Provider
values={[
[ButtonContext, {staticColor: 'auto'}],
[LinkButtonContext, {staticColor: 'auto'}],
[ActionButtonContext, {staticColor: 'auto'}],
[ToggleButtonContext, {staticColor: 'auto'}]
]}>
<div ref={domRef} {...focusWithinProps}>
<PromptFieldContainer
{...dropProps}
role="group"
variant={variant}
brandColor={brandColor}
isGenerating={isGenerating ?? false}
isDropTarget={isDropTarget}
styles={styles}
inputRef={inputRef}>
{children}
</PromptFieldContainer>
<p className={style({font: 'ui-sm', textAlign: 'center'})}>
{stringFormatter.format('promptfield.aiDisclaimer')}{' '}
<Link
variant="secondary"
href="https://www.adobe.com/legal/licenses-terms/adobe-gen-ai-user-guidelines.html"
target="_blank">
{stringFormatter.format('promptfield.aiUserGuidlines')}
</Link>
</p>
</div>
</Provider>
</PromptFieldContext.Provider>
);
});
Expand Down Expand Up @@ -520,7 +530,7 @@ export function PromptTokenField(props: PromptTokenFieldProps) {
},
transition: 'default',
transitionDuration: 350,
paddingStart: 4,
paddingStart: space(5),
width: 'full',
'--loader-color': {
type: 'color',
Expand Down
26 changes: 15 additions & 11 deletions packages/@react-spectrum/ai/src/PromptFieldContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,7 @@ export function PromptFieldContainer(props: PropFieldContainerProps) {
data-variant={variant}
data-state={isGenerating ? 'generating' : 'idle'}
data-focused={isFocused || undefined}
className={
outerBorder +
// outline for WHCM
style({
outlineStyle: 'solid',
outlineColor: 'transparent',
outlineWidth: 1,
containerType: 'inline-size'
})
}
className={outerBorder + style({containerType: 'inline-size'})}
style={{
...props.style,
// @ts-ignore
Expand Down Expand Up @@ -400,7 +391,20 @@ export function PromptFieldContainer(props: PropFieldContainerProps) {
style({
borderRadius: '[24px]',
position: 'relative',
overflow: 'clip'
overflow: 'clip',
outlineStyle: 'solid',
outlineColor: {
default: 'transparent', // for WHCM
':has([contenteditable][data-focus-visible])': {
default: 'transparent',
'@media (prefers-contrast: more)': 'gray-1000',
forcedColors: 'Highlight'
}
},
outlineWidth: {
default: 1,
':has([contenteditable][data-focus-visible])': 2
}
}),
styles
)
Expand Down
28 changes: 14 additions & 14 deletions packages/@react-spectrum/ai/src/loader/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
export interface Cell {
cx: number;
cy: number;
// Retained from the source data; no longer affects rendering.
outer: boolean;
stagger: number;
adjustX?: number;
adjustY?: number;
}

type StaggerMode = 'individual' | 'grouped' | 'by-row';
Expand All @@ -30,18 +30,18 @@ interface BuildOptions {
// ai-logo: original 12-cell diamond layout with hand-tuned timings.
// ─────────────────────────────────────────────────────────────
export const aiLogo: Cell[] = [
{cx: 240, cy: 360, outer: true, stagger: 0},
{cx: 160, cy: 320, outer: true, stagger: 2},
{cx: 320, cy: 320, outer: true, stagger: 4},
{cx: 200, cy: 280, outer: false, stagger: 6},
{cx: 280, cy: 280, outer: false, stagger: 8},
{cx: 120, cy: 240, outer: true, stagger: 10},
{cx: 360, cy: 240, outer: true, stagger: 14},
{cx: 200, cy: 200, outer: false, stagger: 16},
{cx: 280, cy: 200, outer: false, stagger: 18},
{cx: 160, cy: 160, outer: true, stagger: 20},
{cx: 320, cy: 160, outer: true, stagger: 22},
{cx: 240, cy: 120, outer: true, stagger: 24}
{cx: 240, cy: 360, adjustY: -0.5, stagger: 0},
{cx: 160, cy: 320, stagger: 2},
{cx: 320, cy: 320, stagger: 4},
{cx: 200, cy: 280, stagger: 6},
{cx: 280, cy: 280, stagger: 8},
{cx: 120, cy: 240, adjustX: 0.5, stagger: 10},
{cx: 360, cy: 240, adjustX: -0.5, stagger: 14},
{cx: 200, cy: 200, stagger: 16},
{cx: 280, cy: 200, stagger: 18},
{cx: 160, cy: 160, stagger: 20},
{cx: 320, cy: 160, stagger: 22},
{cx: 240, cy: 120, adjustY: 0.5, stagger: 24}
];

// ─────────────────────────────────────────────────────────────
Expand Down
5 changes: 3 additions & 2 deletions packages/@react-spectrum/ai/src/loader/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ export function PixelLoader(props: PixelLoaderProps) {
}
return matrix;
}, [cells]);
const isHighDPI = window.devicePixelRatio >= 2;

return (
<div
Expand Down Expand Up @@ -332,8 +333,8 @@ export function PixelLoader(props: PixelLoaderProps) {
let corner = (a, b, diag) => (!a && !b && !diag ? '1px' : '0px');

// Adjust position for outer cells on high DPI displays.
let xPx = x * cellSize + offset;
let yPx = y * cellSize + offset;
let xPx = x * cellSize + offset + (isHighDPI ? (c.adjustX ?? 0) : 0);
let yPx = y * cellSize + offset + (isHighDPI ? (c.adjustY ?? 0) : 0);

return (
<div
Expand Down
Loading
Loading