|
| 1 | +import React, { useState } from 'react'; |
| 2 | +import { IconButton, Popover } from '../../base'; |
| 3 | +import { InfoCircleIcon } from '../../icons'; |
| 4 | +import { WHITE } from '../../theme'; |
| 5 | +import { RenderMarkdownTooltip } from '../Markdown'; |
| 6 | + |
| 7 | +type HelperTextPopoverProps = { |
| 8 | + content: string | React.ReactNode | JSX.Element; |
| 9 | + fontSize?: string; |
| 10 | + fontWeight?: number; |
| 11 | + variant?: 'standard' | 'small'; |
| 12 | + bgColor?: string; |
| 13 | + icon?: React.ReactNode; |
| 14 | +}; |
| 15 | + |
| 16 | +function HelperTextPopover({ |
| 17 | + content, |
| 18 | + fontSize, |
| 19 | + fontWeight = 400, |
| 20 | + variant = 'standard', |
| 21 | + bgColor = '#141414', |
| 22 | + icon = <InfoCircleIcon fontSize="small" />, |
| 23 | + ...props |
| 24 | +}: HelperTextPopoverProps): JSX.Element { |
| 25 | + const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null); |
| 26 | + const open = Boolean(anchorEl); |
| 27 | + |
| 28 | + const handleOpen = (event: React.MouseEvent<HTMLElement>) => { |
| 29 | + setAnchorEl(event.currentTarget); |
| 30 | + }; |
| 31 | + |
| 32 | + const handleClose = () => { |
| 33 | + setAnchorEl(null); |
| 34 | + }; |
| 35 | + |
| 36 | + return ( |
| 37 | + <> |
| 38 | + <IconButton |
| 39 | + size="small" |
| 40 | + onClick={handleOpen} |
| 41 | + sx={{ color: 'inherit', padding: '2px', verticalAlign: 'middle' }} |
| 42 | + > |
| 43 | + {icon} |
| 44 | + </IconButton> |
| 45 | + <Popover |
| 46 | + open={open} |
| 47 | + anchorEl={anchorEl} |
| 48 | + onClose={handleClose} |
| 49 | + disablePortal |
| 50 | + container={anchorEl?.ownerDocument?.body} |
| 51 | + anchorOrigin={{ |
| 52 | + vertical: 'top', |
| 53 | + horizontal: 'center' |
| 54 | + }} |
| 55 | + transformOrigin={{ |
| 56 | + vertical: 'bottom', |
| 57 | + horizontal: 'center' |
| 58 | + }} |
| 59 | + PaperProps={{ |
| 60 | + sx: { |
| 61 | + background: bgColor, |
| 62 | + zIndex: 1501, |
| 63 | + opacity: '1', |
| 64 | + color: WHITE, |
| 65 | + maxWidth: '500px', |
| 66 | + fontSize: fontSize || (variant === 'standard' ? '1rem' : '0.75rem'), |
| 67 | + fontWeight: fontWeight, |
| 68 | + borderRadius: '0.5rem', |
| 69 | + padding: variant === 'standard' ? '0.9rem' : '0.5rem 0.75rem', |
| 70 | + boxShadow: 'rgba(0, 0, 0, 0.6) 0px 4px 10px, rgba(0, 0, 0, 0.5) 0px 2px 4px' |
| 71 | + } |
| 72 | + }} |
| 73 | + {...props} |
| 74 | + > |
| 75 | + {typeof content === 'string' ? <RenderMarkdownTooltip content={content} /> : content} |
| 76 | + </Popover> |
| 77 | + </> |
| 78 | + ); |
| 79 | +} |
| 80 | + |
| 81 | +export default HelperTextPopover; |
| 82 | +export type { HelperTextPopoverProps }; |
0 commit comments