Skip to content

Commit

Permalink
Optionally show navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheu committed Oct 25, 2023
1 parent 3a6454f commit 197c2a4
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/components/InnerBlockSlider/inner-block-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ const InnerBlockSlider = ( {
slideLimit,
currentItemIndex,
setCurrentItemIndex,
showNavigation ,
showNavigation,
} ) => {
const innerBlockTemplate = template || [ [ allowedBlock ] ];

const slideBlocks = useSelect(
( select ) =>
select( 'core/block-editor' ).getBlock( parentBlockId ).innerBlocks
);
const slideBlocks = useSelect( ( select ) => select( 'core/block-editor' ).getBlock( parentBlockId ).innerBlocks );

// Track state in a ref, to allow us to determine if slides are added or removed.
const slideCount = useRef( slideBlocks.length );
Expand Down Expand Up @@ -80,15 +77,16 @@ const InnerBlockSlider = ( {
template={ innerBlockTemplate }
/>

<Navigation
addSlide={ addSlide }
addSlideEnabled={ slideBlocks.length < slideLimit }
currentPage={ currentItemIndex + 1 }
nextEnabled={ currentItemIndex + 1 < slideBlocks.length }
prevEnabled={ currentItemIndex + 1 > 1 }
setCurrentPage={ ( page ) => setCurrentItemIndex( page - 1 ) }
totalPages={ slideBlocks.length }
/>
{ showNavigation && (
<Navigation
addSlide={ addSlide }
addSlideEnabled={ slideBlocks.length < slideLimit }
currentPage={ currentItemIndex + 1 }
nextEnabled={ currentItemIndex + 1 < slideBlocks.length }
prevEnabled={ currentItemIndex + 1 > 1 }
setCurrentPage={ ( page ) => setCurrentItemIndex( page - 1 ) }
totalPages={ slideBlocks.length }
/> ) }
</div>
);
};
Expand All @@ -105,7 +103,7 @@ InnerBlockSlider.propTypes = {
template: PropTypes.array,
showNavigation: PropTypes.bool,
currentItemIndex: PropTypes.number.isRequired,
setCurrentItemIndex: PropTypes.function.isRequired,
setCurrentItemIndex: PropTypes.func.isRequired,
};

export default InnerBlockSlider;

0 comments on commit 197c2a4

Please sign in to comment.