@@ -3,11 +3,14 @@ import { IconNames } from '@blueprintjs/icons';
33import { clamp } from 'lodash' ;
44import React from 'react' ;
55
6- type MultiItemDisplayProps = {
6+ export type MultiItemDisplayProps = {
77 elements : React . JSX . Element [ ]
88} ;
99
10- const MultiItemDisplay = ( { elements } : MultiItemDisplayProps ) => {
10+ /**
11+ * React Component for displaying multiple items
12+ */
13+ const MultiItemDisplay = ( props : MultiItemDisplayProps ) => {
1114 // The actual index of the currently selected element
1215 const [ currentStep , setCurrentStep ] = React . useState ( 0 ) ;
1316
@@ -16,7 +19,7 @@ const MultiItemDisplay = ({ elements }: MultiItemDisplayProps) => {
1619 const [ stepEditorFocused , setStepEditorFocused ] = React . useState ( false ) ;
1720
1821 const resetStepEditor = ( ) => setStepEditorValue ( ( currentStep + 1 ) . toString ( ) ) ;
19- const elementsDigitCount = Math . floor ( Math . log10 ( Math . max ( 1 , elements . length ) ) ) + 1 ;
22+ const elementsDigitCount = Math . floor ( Math . log10 ( Math . max ( 1 , props . elements . length ) ) ) + 1 ;
2023
2124 return (
2225 < div
@@ -68,7 +71,7 @@ const MultiItemDisplay = ({ elements }: MultiItemDisplayProps) => {
6871 < div style = { { width : `${ stepEditorFocused ? elementsDigitCount + 2 : elementsDigitCount } ch` } } >
6972 < EditableText
7073 value = { stepEditorValue }
71- disabled = { elements . length === 1 }
74+ disabled = { props . elements . length === 1 }
7275 placeholder = { undefined }
7376 type = "number"
7477 onChange = { ( newValue ) => {
@@ -82,7 +85,7 @@ const MultiItemDisplay = ({ elements }: MultiItemDisplayProps) => {
8285 onConfirm = { ( value ) => {
8386 if ( value ) {
8487 const newStep = parseInt ( value ) ;
85- const clampedStep = clamp ( newStep , 1 , elements . length ) ;
88+ const clampedStep = clamp ( newStep , 1 , props . elements . length ) ;
8689 setCurrentStep ( clampedStep - 1 ) ;
8790 setStepEditorFocused ( false ) ;
8891 setStepEditorValue ( clampedStep . toString ( ) ) ;
@@ -103,7 +106,7 @@ const MultiItemDisplay = ({ elements }: MultiItemDisplayProps) => {
103106 onEdit = { ( ) => setStepEditorFocused ( true ) }
104107 />
105108 </ div >
106- { stepEditorFocused && < > </ > } /{ elements . length }
109+ { stepEditorFocused && < > </ > } /{ props . elements . length }
107110 </ div >
108111 </ h3 >
109112 < Button
@@ -118,7 +121,7 @@ const MultiItemDisplay = ({ elements }: MultiItemDisplayProps) => {
118121 setCurrentStep ( currentStep + 1 ) ;
119122 setStepEditorValue ( ( currentStep + 2 ) . toString ( ) ) ;
120123 } }
121- disabled = { currentStep === elements . length - 1 }
124+ disabled = { currentStep === props . elements . length - 1 }
122125 >
123126 Next
124127 </ Button >
@@ -133,7 +136,7 @@ const MultiItemDisplay = ({ elements }: MultiItemDisplayProps) => {
133136 justifyContent : 'center'
134137 } }
135138 >
136- { elements [ currentStep ] }
139+ { props . elements [ currentStep ] }
137140 </ div >
138141 </ div >
139142 ) ;
0 commit comments