mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* Contract tab: finding matching bytecode states Fixes #2678 * handle case when there is only one sub-tab on contract tab * tests * prevent calling the smart contract resource twice when opening the tab * [wip] add debug logs * change api host for op sepolia * rollback debug and update screenshots
85 lines
2.4 KiB
TypeScript
85 lines
2.4 KiB
TypeScript
import React from 'react';
|
|
|
|
import type { TabsProps } from '../../chakra/tabs';
|
|
import { TabsContent, TabsRoot } from '../../chakra/tabs';
|
|
import { useViewportSize } from '../../hooks/useViewportSize';
|
|
import AdaptiveTabsList, { type BaseProps as AdaptiveTabsListProps } from './AdaptiveTabsList';
|
|
import { getTabValue } from './utils';
|
|
|
|
export interface Props extends TabsProps, AdaptiveTabsListProps { }
|
|
|
|
const AdaptiveTabs = (props: Props) => {
|
|
const {
|
|
tabs,
|
|
onValueChange,
|
|
defaultValue,
|
|
isLoading,
|
|
listProps,
|
|
rightSlot,
|
|
rightSlotProps,
|
|
leftSlot,
|
|
leftSlotProps,
|
|
stickyEnabled,
|
|
size,
|
|
variant,
|
|
...rest
|
|
} = props;
|
|
|
|
const [ activeTab, setActiveTab ] = React.useState<string>(defaultValue || getTabValue(tabs[0]));
|
|
|
|
const handleTabChange = React.useCallback(({ value }: { value: string }) => {
|
|
if (isLoading) {
|
|
return;
|
|
}
|
|
onValueChange ? onValueChange({ value }) : setActiveTab(value);
|
|
}, [ isLoading, onValueChange ]);
|
|
|
|
const viewportSize = useViewportSize();
|
|
|
|
React.useEffect(() => {
|
|
if (defaultValue) {
|
|
setActiveTab(defaultValue);
|
|
}
|
|
}, [ defaultValue ]);
|
|
|
|
return (
|
|
<TabsRoot
|
|
position="relative"
|
|
value={ activeTab }
|
|
onValueChange={ handleTabChange }
|
|
size={ size }
|
|
variant={ variant }
|
|
{ ...rest }
|
|
>
|
|
<AdaptiveTabsList
|
|
// the easiest and most readable way to achieve correct tab's cut recalculation when
|
|
// - screen is resized or
|
|
// - tabs list is changed when API data is loaded
|
|
// is to do full re-render of the tabs list
|
|
// so we use screenWidth + tabIds as a key for the TabsList component
|
|
key={ isLoading + '_' + viewportSize.width + '_' + tabs.map((tab) => tab.id).join(':') }
|
|
tabs={ tabs }
|
|
listProps={ listProps }
|
|
leftSlot={ leftSlot }
|
|
leftSlotProps={ leftSlotProps }
|
|
rightSlot={ rightSlot }
|
|
rightSlotProps={ rightSlotProps }
|
|
stickyEnabled={ stickyEnabled }
|
|
activeTab={ activeTab }
|
|
isLoading={ isLoading }
|
|
variant={ variant }
|
|
/>
|
|
{ tabs.map((tab) => {
|
|
const value = getTabValue(tab);
|
|
return (
|
|
<TabsContent padding={ 0 } key={ value } value={ value }>
|
|
{ tab.component }
|
|
</TabsContent>
|
|
);
|
|
}) }
|
|
</TabsRoot>
|
|
);
|
|
};
|
|
|
|
export default React.memo(AdaptiveTabs);
|