From a87f9120e956e564510e46c8fa703a7b464029ab Mon Sep 17 00:00:00 2001 From: Dmytro Date: Wed, 25 Sep 2024 12:40:44 +0100 Subject: [PATCH] Add handler for tooltips on mobile, update Chains description --- src/components/SkIconBth.tsx | 40 +++++++++++++++++++++++++++++++----- src/pages/Chains.tsx | 2 +- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/components/SkIconBth.tsx b/src/components/SkIconBth.tsx index c506add..8d6429b 100644 --- a/src/components/SkIconBth.tsx +++ b/src/components/SkIconBth.tsx @@ -21,10 +21,12 @@ * @copyright SKALE Labs 2024-Present */ -import React from 'react' +import React, { useState, useCallback } from 'react' import IconButton, { IconButtonProps } from '@mui/material/IconButton' import Tooltip, { TooltipProps } from '@mui/material/Tooltip' import { SvgIconProps } from '@mui/material/SvgIcon' +import { useTheme } from '@mui/material/styles' +import useMediaQuery from '@mui/material/useMediaQuery' import { cls, styles, cmn } from '@skalenetwork/metaport' type IconType = React.ComponentType @@ -48,19 +50,41 @@ const SkIconBtn: React.FC = ({ primary = true, ...props }) => { + const [tooltipOpen, setTooltipOpen] = useState(false) + const theme = useTheme() + const isMobile = useMediaQuery(theme.breakpoints.down('sm')) + + const handleTooltipToggle = useCallback(() => { + if (isMobile) { + setTooltipOpen((prevOpen) => !prevOpen) + } + }, [isMobile]) + + const handleClick = useCallback( + (event: React.MouseEvent) => { + if (isMobile) { + handleTooltipToggle() + } + if (onClick) { + onClick(event) + } + }, + [isMobile, onClick, handleTooltipToggle] + ) + const button = ( @@ -68,7 +92,13 @@ const SkIconBtn: React.FC = ({ if (tooltipTitle) { return ( - + {button} ) diff --git a/src/pages/Chains.tsx b/src/pages/Chains.tsx index d12a6cd..0a32382 100644 --- a/src/pages/Chains.tsx +++ b/src/pages/Chains.tsx @@ -100,7 +100,7 @@ export default function Chains(props: { Connect, get block explorer links and endpoints

- +