UNPKG

@shopify/polaris

Version:

Shopify’s product component library

36 lines (30 loc) 969 B
function getVisibleAndHiddenTabIndices(tabs, selected, disclosureWidth, tabWidths, containerWidth) { var sumTabWidths = tabWidths.reduce((sum, width) => sum + width, 0); var arrayOfTabIndices = tabs.map((_, index) => { return index; }); var visibleTabs = []; var hiddenTabs = []; if (containerWidth > sumTabWidths) { visibleTabs.push(...arrayOfTabIndices); } else { visibleTabs.push(selected); var tabListWidth = tabWidths[selected]; arrayOfTabIndices.forEach(currentTabIndex => { if (currentTabIndex !== selected) { var currentTabWidth = tabWidths[currentTabIndex]; if (tabListWidth + currentTabWidth > containerWidth - disclosureWidth) { hiddenTabs.push(currentTabIndex); return; } visibleTabs.push(currentTabIndex); tabListWidth += currentTabWidth; } }); } return { visibleTabs, hiddenTabs }; } export { getVisibleAndHiddenTabIndices };