Commit dde2cfc5 authored by tom's avatar tom

skeleton for tabs

parent d07b3303
...@@ -173,14 +173,16 @@ const TokenPageContent = () => { ...@@ -173,14 +173,16 @@ const TokenPageContent = () => {
{ /* should stay before tabs to scroll up with pagination */ } { /* should stay before tabs to scroll up with pagination */ }
<Box ref={ scrollRef }></Box> <Box ref={ scrollRef }></Box>
{ tokenQuery.isLoading || contractQuery.isLoading ? <SkeletonTabs/> : ( { tokenQuery.isPlaceholderData || contractQuery.isPlaceholderData ?
<RoutedTabs <SkeletonTabs tabs={ tabs }/> :
tabs={ tabs } (
tabListProps={ tabListProps } <RoutedTabs
rightSlot={ !isMobile && hasPagination ? <Pagination { ...(pagination as PaginationProps) }/> : null } tabs={ tabs }
stickyEnabled={ !isMobile } tabListProps={ tabListProps }
/> rightSlot={ !isMobile && hasPagination ? <Pagination { ...(pagination as PaginationProps) }/> : null }
) } stickyEnabled={ !isMobile }
/>
) }
{ !tokenQuery.isLoading && !tokenQuery.isError && <Box h={{ base: 0, lg: '40vh' }}/> } { !tokenQuery.isLoading && !tokenQuery.isError && <Box h={{ base: 0, lg: '40vh' }}/> }
</> </>
......
...@@ -175,6 +175,7 @@ const RoutedTabs = ({ tabs, tabListProps, rightSlot, stickyEnabled, className, . ...@@ -175,6 +175,7 @@ const RoutedTabs = ({ tabs, tabListProps, rightSlot, stickyEnabled, className, .
} }
onItemClick={ handleTabChange } onItemClick={ handleTabChange }
buttonRef={ tabsRefs[index] } buttonRef={ tabsRefs[index] }
size={ themeProps.size || 'md' }
/> />
); );
} }
......
import type {
ButtonProps } from '@chakra-ui/react';
import { Popover, import { Popover,
PopoverTrigger, PopoverTrigger,
PopoverContent, PopoverContent,
...@@ -20,9 +22,10 @@ interface Props { ...@@ -20,9 +22,10 @@ interface Props {
styles?: StyleProps; styles?: StyleProps;
onItemClick: (index: number) => void; onItemClick: (index: number) => void;
buttonRef: React.RefObject<HTMLButtonElement>; buttonRef: React.RefObject<HTMLButtonElement>;
size: ButtonProps['size'];
} }
const RoutedTabsMenu = ({ tabs, tabsCut, isActive, styles, onItemClick, buttonRef, activeTab }: Props) => { const RoutedTabsMenu = ({ tabs, tabsCut, isActive, styles, onItemClick, buttonRef, activeTab, size }: Props) => {
const { isOpen, onClose, onOpen } = useDisclosure(); const { isOpen, onClose, onOpen } = useDisclosure();
const handleItemClick = React.useCallback((event: React.MouseEvent<HTMLButtonElement>) => { const handleItemClick = React.useCallback((event: React.MouseEvent<HTMLButtonElement>) => {
...@@ -40,6 +43,7 @@ const RoutedTabsMenu = ({ tabs, tabsCut, isActive, styles, onItemClick, buttonRe ...@@ -40,6 +43,7 @@ const RoutedTabsMenu = ({ tabs, tabsCut, isActive, styles, onItemClick, buttonRe
variant="ghost" variant="ghost"
isActive={ isOpen || isActive } isActive={ isOpen || isActive }
ref={ buttonRef } ref={ buttonRef }
size={ size }
{ ...styles } { ...styles }
> >
{ menuButton.title } { menuButton.title }
......
import { Flex, Skeleton, chakra } from '@chakra-ui/react'; import { Flex, Skeleton, chakra } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import type { RoutedTab } from '../RoutedTabs/types';
interface Props { interface Props {
className?: string; className?: string;
tabs?: Array<RoutedTab>;
size?: 'sm' | 'md';
} }
const SkeletonTabs = ({ className }: Props) => { const SkeletonTabs = ({ className, tabs, size = 'md' }: Props) => {
if (tabs) {
if (tabs.length === 1) {
return null;
}
const paddingHor = size === 'sm' ? 3 : 4;
const paddingVert = size === 'sm' ? 1 : 2;
return (
<Flex className={ className } my={ 8 } alignItems="center">
{ tabs.map(({ title, id }, index) => (
<Skeleton
key={ id }
py={ index === 0 ? paddingVert : 0 }
px={ index === 0 ? paddingHor : 0 }
mx={ index === 0 ? 0 : paddingHor }
borderRadius="base"
fontWeight={ 600 }
borderWidth={ size === 'sm' ? '2px' : 0 }
>
{ typeof title === 'string' ? title : title() }
</Skeleton>
)) }
</Flex>
);
}
return ( return (
<Flex my={ 8 } className={ className }> <Flex my={ 8 } className={ className }>
<Skeleton h={ 6 } my={ 2 } mx={ 4 } w="100px"/> <Skeleton h={ 6 } my={ 2 } mx={ 4 } w="100px"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment