PagerView
View Source
Allows paging between views. Use with the useRovingIndex
hook to control the activeViewIndex.
1
2
3
4
Copy
Edit
const views = [['blue-5', 18],['seagreen', 24],['rebeccapurple', 32],['hotpink', 20],]render(() => {const {activeIndex,moveActiveIndex,moveBackwardDisabled,moveForwardDisabled,} = hooks.useRovingIndex({maxIndex: views.length - 1,})return (<StackView spacing={1}><PagerViewactiveViewIndex={activeIndex}width={40}backgroundColor="backgroundTertiary">{views.map(([color, height], index) => (<PagerView.Viewkey={color}minHeight={height}alignment="center"distribution="center"paddingHorizontal={4}fontSize={0}color="light-5"backgroundColor={color}>{index + 1}</PagerView.View>))}</PagerView><StackView axis="horizontal" distribution="center" spacing={1}><Buttontitle="Prev"icon={{ name: 'caret-left' }}radius="circle"disabled={moveBackwardDisabled}onClick={() => moveActiveIndex(-1)}/><Buttontitle="Next"icon={{ name: 'caret-right' }}radius="circle"disabled={moveForwardDisabled}onClick={() => moveActiveIndex(1)}/></StackView></StackView>)})
Arrangement
A
Ab
B
C
C#
D
Db
E
Eb
F
F#
G
Arrangement
A
Ab
B
C
C#
D
Db
E
Eb
F
F#
G
Copy
Edit
function View({ children }) {return (<PagerView.View><Card minHeight={24} padding={2}>{children}</Card></PagerView.View>)}function Arrangement({ expanded, expandOrShrink }) {return (<View><Toolbartitle="Arrangement"helpContent="These files are only available in plans that use the Default Arrangement, no matter what key is chosen."actions={<Buttontitle={expanded ? 'show single-view' : 'show multi-view'}icon={{ name: expanded ? 'caret-shrink' : 'caret-grow' }}variant="naked"onClick={expandOrShrink}/>}/></View>)}function Key({ name, expanded, expandOrShrink }) {return (<View><Toolbartitle={name}actions={[<Button title="edit" icon={{ name: 'pencil' }} variant="naked" />,<Buttontitle={expanded ? 'show single-view' : 'show multi-view'}icon={{ name: expanded ? 'caret-shrink' : 'caret-grow' }}variant="naked"onClick={expandOrShrink}/>,]}/></View>)}const keys = ['A', 'Ab', 'B', 'C', 'C#', 'D', 'Db', 'E', 'Eb', 'F', 'F#', 'G']render(() => {const [expanded, setExpanded] = React.useState(false)const {activeIndex,moveActiveIndex,setActiveIndex,moveBackwardDisabled,moveForwardDisabled,} = hooks.useRovingIndex({maxIndex: keys.length - 1,})const viewsToShow = expanded ? 1 : 3const expandOrShrink = (nextIndex) => {setActiveIndex(nextIndex)setExpanded((bool) => !bool)}const isActiveIndex = (index) => {return index >= activeIndex && index < activeIndex + viewsToShow}return (<StackView width="100%" maxWidth={104} spacing={2}><PagerViewwidth="100%"activeViewIndex={activeIndex}viewsToShow={viewsToShow}spacing={2}><Arrangementexpanded={expanded && activeIndex === 0}expandOrShrink={() => expandOrShrink(0)}/>{keys.map((key, index) => (<Keykey={key}name={key}expanded={expanded && activeIndex === index + 1}expandOrShrink={() => expandOrShrink(index + 1)}/>))}</PagerView><GridView columns="auto 1fr auto" spacing={1}><Buttontitle="Prev"icon={{ name: 'caret-left' }}radius="circle"disabled={moveBackwardDisabled}onClick={() => moveActiveIndex(-1)}/><StackViewaxis="horizontal"maxWidth="100%"marginHorizontal="auto"overflow="scroll">{['Arrangement', ...keys].map((key, index) => {const buttonProps = {key,title: key,variant: 'naked',onClick: () => setActiveIndex(index),}if (isActiveIndex(index)) {buttonProps.theme = falsebuttonProps.radius = 0buttonProps.borderBottomWidth = 2buttonProps.borderBottomColor = 'primary'buttonProps.color = 'primary'}return <Button {...buttonProps} />})}</StackView><Buttontitle="Next"icon={{ name: 'caret-right' }}radius="circle"disabled={moveForwardDisabled}onClick={() => moveActiveIndex(1)}/></GridView></StackView>)})
Props
axis
'horizontal' | 'vertical'
Which axis the track moves on. Defaults to horizontal
.
activeViewIndex
number
Controls the active view by index.
viewsToShow
number
The number of views visible in the frame at one time. Defaults to 1.
viewsToMove
number
The number of views to move upon using prev and next methods. Defaults to 1.
spacing
number
The amount of space between views. Uses 8-point grid multiplier.
autoFocus
boolean
Auto focus the first focusable element in the active view.