@@ -19,7 +19,6 @@ import {
1919import AppContext , { AppContextType } from '../app/app-context' ;
2020import labels from '../app-layout/utils/labels' ;
2121import { i18nStrings } from '../file-upload/shared' ;
22- import ScreenshotArea from '../utils/screenshot-area' ;
2322
2423const MAX_CHARS = 2000 ;
2524
@@ -29,7 +28,6 @@ type DemoContext = React.Context<
2928 isReadOnly : boolean ;
3029 isInvalid : boolean ;
3130 hasWarning : boolean ;
32- hasText : boolean ;
3331 hasSecondaryContent : boolean ;
3432 hasSecondaryActions : boolean ;
3533 hasPrimaryActions : boolean ;
@@ -51,7 +49,6 @@ export default function PromptInputPage() {
5149 isReadOnly,
5250 isInvalid,
5351 hasWarning,
54- hasText,
5552 hasSecondaryActions,
5653 hasSecondaryContent,
5754 hasPrimaryActions,
@@ -64,19 +61,6 @@ export default function PromptInputPage() {
6461 { label : 'Item 3' , dismissLabel : 'Remove item 3' , disabled : isDisabled } ,
6562 ] ) ;
6663
67- useEffect ( ( ) => {
68- if ( hasText ) {
69- setTextareaValue ( placeholderText ) ;
70- }
71- } , [ hasText ] ) ;
72-
73- useEffect ( ( ) => {
74- if ( hasText && textareaValue !== placeholderText ) {
75- setUrlParams ( { hasText : false } ) ;
76- }
77- // eslint-disable-next-line react-hooks/exhaustive-deps
78- } , [ textareaValue ] ) ;
79-
8064 useEffect ( ( ) => {
8165 if ( items . length === 0 ) {
8266 ref . current ?. focus ( ) ;
@@ -165,7 +149,14 @@ export default function PromptInputPage() {
165149 Infinite max rows
166150 </ Checkbox >
167151 </ FormField >
168- < button id = "placeholder-text-button" onClick = { ( ) => setUrlParams ( { hasText : true } ) } >
152+ < button
153+ id = "placeholder-text-button"
154+ onClick = { ( ) => {
155+ if ( textareaValue === '' ) {
156+ setTextareaValue ( placeholderText ) ;
157+ }
158+ } }
159+ >
169160 Fill with placeholder text
170161 </ button >
171162
@@ -188,95 +179,93 @@ export default function PromptInputPage() {
188179 label = { < span > User prompt</ span > }
189180 i18nStrings = { { errorIconAriaLabel : 'Error' } }
190181 >
191- < ScreenshotArea disableAnimations = { true } >
192- < PromptInput
193- data-testid = "prompt-input"
194- ariaLabel = "Chat input"
195- actionButtonIconName = "send"
196- actionButtonAriaLabel = "Submit prompt"
197- value = { textareaValue }
198- onChange = { ( event : any ) => setTextareaValue ( event . detail . value ) }
199- onAction = { event => window . alert ( `Submitted the following: ${ event . detail . value } ` ) }
200- placeholder = "Ask a question"
201- maxRows = { hasInfiniteMaxRows ? - 1 : 4 }
202- disabled = { isDisabled }
203- readOnly = { isReadOnly }
204- invalid = { isInvalid || textareaValue . length > MAX_CHARS }
205- warning = { hasWarning }
206- ref = { ref }
207- disableSecondaryActionsPaddings = { true }
208- customPrimaryAction = {
209- hasPrimaryActions ? (
182+ < PromptInput
183+ data-testid = "prompt-input"
184+ ariaLabel = "Chat input"
185+ actionButtonIconName = "send"
186+ actionButtonAriaLabel = "Submit prompt"
187+ value = { textareaValue }
188+ onChange = { ( event : any ) => setTextareaValue ( event . detail . value ) }
189+ onAction = { event => window . alert ( `Submitted the following: ${ event . detail . value } ` ) }
190+ placeholder = "Ask a question"
191+ maxRows = { hasInfiniteMaxRows ? - 1 : 4 }
192+ disabled = { isDisabled }
193+ readOnly = { isReadOnly }
194+ invalid = { isInvalid || textareaValue . length > MAX_CHARS }
195+ warning = { hasWarning }
196+ ref = { ref }
197+ disableSecondaryActionsPaddings = { true }
198+ customPrimaryAction = {
199+ hasPrimaryActions ? (
200+ < ButtonGroup
201+ variant = "icon"
202+ items = { [
203+ {
204+ type : 'icon-button' ,
205+ id : 'record' ,
206+ text : 'Record' ,
207+ iconName : 'microphone' ,
208+ disabled : isDisabled || isReadOnly ,
209+ } ,
210+ {
211+ type : 'icon-button' ,
212+ id : 'submit' ,
213+ text : 'Submit' ,
214+ iconName : 'send' ,
215+ disabled : isDisabled || isReadOnly ,
216+ } ,
217+ ] }
218+ />
219+ ) : undefined
220+ }
221+ secondaryActions = {
222+ hasSecondaryActions ? (
223+ < Box padding = { { left : 'xxs' , top : 'xs' } } >
210224 < ButtonGroup
211- variant = "icon"
225+ ref = { buttonGroupRef }
226+ ariaLabel = "Chat actions"
227+ onFilesChange = { ( { detail } ) => detail . id . includes ( 'files' ) && setFiles ( detail . files ) }
212228 items = { [
229+ {
230+ type : 'icon-file-input' ,
231+ id : 'files' ,
232+ text : 'Upload files' ,
233+ multiple : true ,
234+ } ,
213235 {
214236 type : 'icon-button' ,
215- id : 'record ' ,
216- text : 'Record ' ,
217- iconName : 'microphone ' ,
237+ id : 'expand ' ,
238+ iconName : 'expand ' ,
239+ text : 'Go full page ' ,
218240 disabled : isDisabled || isReadOnly ,
219241 } ,
220242 {
221243 type : 'icon-button' ,
222- id : 'submit ' ,
223- text : 'Submit ' ,
224- iconName : 'send ' ,
244+ id : 'remove ' ,
245+ iconName : 'remove ' ,
246+ text : 'Remove ' ,
225247 disabled : isDisabled || isReadOnly ,
226248 } ,
227249 ] }
250+ variant = "icon"
228251 />
229- ) : undefined
230- }
231- secondaryActions = {
232- hasSecondaryActions ? (
233- < Box padding = { { left : 'xxs' , top : 'xs' } } >
234- < ButtonGroup
235- ref = { buttonGroupRef }
236- ariaLabel = "Chat actions"
237- onFilesChange = { ( { detail } ) => detail . id . includes ( 'files' ) && setFiles ( detail . files ) }
238- items = { [
239- {
240- type : 'icon-file-input' ,
241- id : 'files' ,
242- text : 'Upload files' ,
243- multiple : true ,
244- } ,
245- {
246- type : 'icon-button' ,
247- id : 'expand' ,
248- iconName : 'expand' ,
249- text : 'Go full page' ,
250- disabled : isDisabled || isReadOnly ,
251- } ,
252- {
253- type : 'icon-button' ,
254- id : 'remove' ,
255- iconName : 'remove' ,
256- text : 'Remove' ,
257- disabled : isDisabled || isReadOnly ,
258- } ,
259- ] }
260- variant = "icon"
261- />
262- </ Box >
263- ) : undefined
264- }
265- secondaryContent = {
266- hasSecondaryContent && files . length > 0 ? (
267- < FileTokenGroup
268- items = { files . map ( file => ( {
269- file,
270- } ) ) }
271- showFileThumbnail = { true }
272- onDismiss = { onDismiss }
273- i18nStrings = { i18nStrings }
274- alignment = "horizontal"
275- />
276- ) : undefined
277- }
278- />
279- </ ScreenshotArea >
252+ </ Box >
253+ ) : undefined
254+ }
255+ secondaryContent = {
256+ hasSecondaryContent && files . length > 0 ? (
257+ < FileTokenGroup
258+ items = { files . map ( file => ( {
259+ file,
260+ } ) ) }
261+ showFileThumbnail = { true }
262+ onDismiss = { onDismiss }
263+ i18nStrings = { i18nStrings }
264+ alignment = "horizontal"
265+ />
266+ ) : undefined
267+ }
268+ />
280269 </ FormField >
281270 < div />
282271 </ ColumnLayout >
0 commit comments