1313import { action } from '@storybook/addon-actions' ;
1414import { Collection , DropIndicator , GridLayout , Header , ListBox , ListBoxItem , ListBoxProps , ListBoxSection , ListLayout , Separator , Text , useDragAndDrop , Virtualizer , WaterfallLayout } from 'react-aria-components' ;
1515import { ListBoxLoadMoreItem } from '../src/ListBox' ;
16- import { LoadingSpinner , MyListBoxItem } from './utils' ;
16+ import { LoadingSpinner , MyHeader , MyListBoxItem } from './utils' ;
1717import React from 'react' ;
1818import { Size } from '@react-stately/virtualizer' ;
1919import styles from '../example/index.css' ;
@@ -394,6 +394,8 @@ function generateRandomString(minLength: number, maxLength: number): string {
394394}
395395
396396export function VirtualizedListBox ( args ) {
397+ let heightProperty = args . orientation === 'horizontal' ? 'width' : 'height' ;
398+ let widthProperty = args . orientation === 'horizontal' ? 'height' : 'width' ;
397399 let sections : { id : string , name : string , children : { id : string , name : string } [ ] } [ ] = [ ] ;
398400 for ( let s = 0 ; s < 10 ; s ++ ) {
399401 let items : { id : string , name : string } [ ] = [ ] ;
@@ -407,15 +409,16 @@ export function VirtualizedListBox(args) {
407409 return (
408410 < Virtualizer
409411 layout = { new ListLayout ( {
412+ orientation : args . orientation ,
410413 estimatedRowHeight : 25 ,
411414 estimatedHeadingHeight : 26 ,
412415 loaderHeight : 30
413416 } ) } >
414- < ListBox className = { styles . menu } style = { { height : 400 } } aria-label = "virtualized listbox" >
417+ < ListBox orientation = { args . orientation } className = { styles . menu } style = { { [ heightProperty ] : 400 , [ widthProperty ] : 200 } } aria-label = "virtualized listbox" >
415418 < Collection items = { sections } >
416419 { section => (
417420 < ListBoxSection className = { styles . group } >
418- < Header style = { { fontSize : '1.2em' } } > { section . name } </ Header >
421+ < MyHeader style = { { fontSize : '1.2em' } } > { section . name } </ MyHeader >
419422 < Collection items = { section . children } >
420423 { item => < MyListBoxItem > { item . name } </ MyListBoxItem > }
421424 </ Collection >
@@ -430,8 +433,15 @@ export function VirtualizedListBox(args) {
430433
431434VirtualizedListBox . story = {
432435 args : {
436+ orientation : 'vertical' ,
433437 variableHeight : false ,
434438 isLoading : false
439+ } ,
440+ argTypes : {
441+ orientation : {
442+ control : 'radio' ,
443+ options : [ 'vertical' , 'horizontal' ]
444+ }
435445 }
436446} ;
437447
@@ -450,7 +460,7 @@ export function VirtualizedListBoxEmpty() {
450460 ) ;
451461}
452462
453- export function VirtualizedListBoxDnd ( ) {
463+ export function VirtualizedListBoxDnd ( args ) {
454464 let items : { id : number , name : string } [ ] = [ ] ;
455465 for ( let i = 0 ; i < 10000 ; i ++ ) {
456466 items . push ( { id : i , name : `Item ${ i } ` } ) ;
@@ -481,13 +491,15 @@ export function VirtualizedListBoxDnd() {
481491 < Virtualizer
482492 layout = { ListLayout }
483493 layoutOptions = { {
484- rowHeight : 25 ,
494+ orientation : args . orientation ,
495+ rowHeight : args . orientation === 'horizontal' ? 45 : 25 ,
485496 gap : 8
486497 } } >
487498 < ListBox
488499 className = { styles . menu }
489500 selectionMode = "multiple"
490501 selectionBehavior = "replace"
502+ orientation = { args . orientation }
491503 style = { { width : '100%' , height : '100%' } }
492504 aria-label = "virtualized listbox"
493505 items = { list . items }
@@ -499,6 +511,18 @@ export function VirtualizedListBoxDnd() {
499511 ) ;
500512}
501513
514+ VirtualizedListBoxDnd . story = {
515+ args : {
516+ orientation : 'vertical'
517+ } ,
518+ argTypes : {
519+ orientation : {
520+ control : 'radio' ,
521+ options : [ 'vertical' , 'horizontal' ]
522+ }
523+ }
524+ } ;
525+
502526function VirtualizedListBoxGridExample ( { minSize = 80 , maxSize = 100 , preserveAspectRatio = false } ) {
503527 let items : { id : number , name : string } [ ] = [ ] ;
504528 for ( let i = 0 ; i < 10000 ; i ++ ) {
0 commit comments