-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #383 from skalenetwork/add-pages-tooltips
Add tooltips to the main pages
- Loading branch information
Showing
14 changed files
with
276 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/** | ||
* @license | ||
* SKALE portal | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* @file SkIconBth.tsx | ||
* @copyright SKALE Labs 2024-Present | ||
*/ | ||
|
||
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> | ||
|
||
interface SkIconBtnProps extends Omit<IconButtonProps, 'children'> { | ||
icon: IconType | ||
iconClassName?: string | ||
tooltipTitle?: React.ReactNode | ||
tooltipProps?: Partial<TooltipProps> | ||
primary?: boolean | ||
} | ||
|
||
const SkIconBtn: React.FC<SkIconBtnProps> = ({ | ||
icon: Icon, | ||
onClick, | ||
className, | ||
iconClassName, | ||
size = 'medium', | ||
tooltipTitle, | ||
tooltipProps, | ||
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={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' | ||
)} | ||
/> | ||
</IconButton> | ||
) | ||
|
||
if (tooltipTitle) { | ||
return ( | ||
<Tooltip | ||
title={tooltipTitle} | ||
{...tooltipProps} | ||
open={isMobile ? tooltipOpen : undefined} | ||
onClose={handleTooltipToggle} | ||
onOpen={handleTooltipToggle} | ||
> | ||
{button} | ||
</Tooltip> | ||
) | ||
} | ||
|
||
return button | ||
} | ||
|
||
export default SkIconBtn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @license | ||
* SKALE portal | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* @file SkPageInfoIcon.tsx | ||
* @copyright SKALE Labs 2024-Present | ||
*/ | ||
|
||
import React from 'react' | ||
import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined' | ||
import SkIconBtn from './SkIconBth' | ||
|
||
interface SkPageInfoIconProps { | ||
meta_tag: any | ||
} | ||
|
||
const SkPageInfoIcon: React.FC<SkPageInfoIconProps> = ({ meta_tag }) => { | ||
return ( | ||
<SkIconBtn | ||
primary={false} | ||
icon={InfoOutlinedIcon} | ||
size="small" | ||
tooltipTitle={meta_tag.help || meta_tag.description} | ||
/> | ||
) | ||
} | ||
|
||
export default SkPageInfoIcon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.