@@ -258,12 +258,48 @@ export const OptionTextElement = () => (
258258 </ Wrapper >
259259) ;
260260
261- const choicesForCreationSupport = [
262- { id : 1 , name : 'Leo Tolstoy' } ,
263- { id : 2 , name : 'Victor Hugo' } ,
264- { id : 3 , name : 'William Shakespeare' } ,
265- { id : 4 , name : 'Charles Baudelaire' } ,
266- { id : 5 , name : 'Marcel Proust' } ,
261+ const choicesForCreationSupport : Partial < {
262+ id : number ;
263+ name : string ;
264+ full_name : string ;
265+ first_name : string ;
266+ last_name : string ;
267+ } > [ ] = [
268+ {
269+ id : 1 ,
270+ name : 'Leo Tolstoy' ,
271+ full_name : 'Leo Tolstoy' ,
272+ first_name : 'Leo' ,
273+ last_name : 'Tolstoy' ,
274+ } ,
275+ {
276+ id : 2 ,
277+ name : 'Victor Hugo' ,
278+ full_name : 'Victor Hugo' ,
279+ first_name : 'Victor' ,
280+ last_name : 'Hugo' ,
281+ } ,
282+ {
283+ id : 3 ,
284+ name : 'William Shakespeare' ,
285+ full_name : 'William Shakespeare' ,
286+ first_name : 'William' ,
287+ last_name : 'Shakespeare' ,
288+ } ,
289+ {
290+ id : 4 ,
291+ name : 'Charles Baudelaire' ,
292+ full_name : 'Charles Baudelaire' ,
293+ first_name : 'Charles' ,
294+ last_name : 'Baudelaire' ,
295+ } ,
296+ {
297+ id : 5 ,
298+ name : 'Marcel Proust' ,
299+ full_name : 'Marcel Proust' ,
300+ first_name : 'Marcel' ,
301+ last_name : 'Proust' ,
302+ } ,
267303] ;
268304
269305const OnCreateInput = ( ) => {
@@ -450,7 +486,7 @@ export const CreateDialog = () => (
450486 </ Wrapper >
451487) ;
452488
453- const CreateLabelInput = ( ) => {
489+ const CreateLabelInput = ( { optionText } ) => {
454490 const [ choices , setChoices ] = useState ( choicesForCreationSupport ) ;
455491 return (
456492 < AutocompleteInput
@@ -459,25 +495,53 @@ const CreateLabelInput = () => {
459495 onCreate = { async filter => {
460496 if ( ! filter ) return ;
461497
462- const newOption = {
498+ const newOption : Partial < {
499+ id : number ;
500+ name : string ;
501+ full_name : string ;
502+ first_name : string ;
503+ last_name : string ;
504+ } > = {
463505 id : choices . length + 1 ,
464- name : filter ,
465506 } ;
507+ if ( optionText == null ) {
508+ newOption . name = filter ;
509+ } else if ( typeof optionText === 'string' ) {
510+ newOption [ optionText ] = filter ;
511+ } else {
512+ newOption . first_name = filter ;
513+ newOption . last_name = filter ;
514+ }
466515 setChoices ( options => [ ...options , newOption ] ) ;
467516 // Wait until next tick to give some time for React to update the state
468517 await new Promise ( resolve => setTimeout ( resolve ) ) ;
469518 return newOption ;
470519 } }
471520 createLabel = "Start typing to create a new item"
521+ optionText = { optionText }
472522 />
473523 ) ;
474524} ;
475525
476- export const CreateLabel = ( ) => (
526+ export const CreateLabel = ( { optionText } : any ) => (
477527 < Wrapper >
478- < CreateLabelInput />
528+ < CreateLabelInput optionText = { optionText } />
479529 </ Wrapper >
480530) ;
531+ CreateLabel . args = {
532+ optionText : undefined ,
533+ } ;
534+ CreateLabel . argTypes = {
535+ optionText : {
536+ options : [ 'default' , 'string' , 'function' ] ,
537+ mapping : {
538+ default : undefined ,
539+ string : 'full_name' ,
540+ function : choice => `${ choice . first_name } ${ choice . last_name } ` ,
541+ } ,
542+ control : { type : 'inline-radio' } ,
543+ } ,
544+ } ;
481545
482546const CreateItemLabelInput = ( ) => {
483547 const [ choices , setChoices ] = useState ( choicesForCreationSupport ) ;
0 commit comments