Skip to content

Commit

Permalink
Add handler for tooltips on mobile, update Chains description
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytrotkk committed Sep 25, 2024
1 parent bfd8bae commit a87f912
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
40 changes: 35 additions & 5 deletions src/components/SkIconBth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<SvgIconProps>
Expand All @@ -48,27 +50,55 @@ const SkIconBtn: React.FC<SkIconBtnProps> = ({
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<HTMLButtonElement>) => {
if (isMobile) {
handleTooltipToggle()
}
if (onClick) {
onClick(event)
}
},
[isMobile, onClick, handleTooltipToggle]
)

const button = (
<IconButton
onClick={onClick}
onClick={handleClick}
className={cls(styles.paperGrey, 'sk-icon-btn', `sk-icon-btn-${size}`, className)}
size={size}
{...props}
>
<Icon
className={cls(
iconClassName,
[cmn.pPrim, primary],
[cmn.pSec, !primary],
'sk-icon-btn-img',
iconClassName
'sk-icon-btn-img'
)}
/>
</IconButton>
)

if (tooltipTitle) {
return (
<Tooltip title={tooltipTitle} {...tooltipProps} arrow>
<Tooltip
title={tooltipTitle}
{...tooltipProps}
open={isMobile ? tooltipOpen : undefined}
onClose={handleTooltipToggle}
onOpen={handleTooltipToggle}
>
{button}
</Tooltip>
)
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Chains.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default function Chains(props: {
Connect, get block explorer links and endpoints
</p>
</div>
<SkPageInfoIcon meta_tag={META_TAGS.onramp} />
<SkPageInfoIcon meta_tag={META_TAGS.chains} />
</div>
<ChainsSection
name="SKALE Hubs"
Expand Down

0 comments on commit a87f912

Please sign in to comment.