// @flow import React, { useState, useCallback } from 'react'; import * as ICONS from 'constants/icons'; import Button from 'component/button'; // the maximum length of history to show per button const MAX_HISTORY_SIZE = 12; type Props = { isBackward: boolean, history: { entries: Array<{ key: string, title: string, pathname: string }>, go: number => void, goBack: () => void, goForward: () => void, index: number, length: number, location: { pathname: string }, push: string => void, }, }; // determines which slice of entries should make up the back or forward button drop-downs (isBackward vs !isBackward respectively) const sliceEntries = (currentIndex, entries, historyLength, isBackward, maxSize) => { let l = isBackward ? 0 : currentIndex + 1; let r = isBackward ? currentIndex : historyLength; const exceedsMax = maxSize < r - l; if (!exceedsMax) { return entries.slice(l, r); } else if (isBackward) { l = r - maxSize; } else { r = l + maxSize; } return entries.slice(l, r); }; const NavigationButton = (props: Props) => { const { isBackward, history } = props; const { entries, go } = history; const currentIndex = history.index; const historyLength = history.length; const [showHistory, setShowHistory] = useState(false); // creates an
  • intended for the button's