msyavuz commented on code in PR #33256: URL: https://github.com/apache/superset/pull/33256#discussion_r2068505229
########## superset-frontend/packages/superset-ui-chart-controls/src/components/InfoTooltipWithTrigger.tsx: ########## @@ -16,65 +16,101 @@ * specific language governing permissions and limitations * under the License. */ -import { CSSProperties } from 'react'; +import { KeyboardEvent, useMemo } from 'react'; +import { SerializedStyles, CSSObject } from '@emotion/react'; import { kebabCase } from 'lodash'; -import { t } from '@superset-ui/core'; +import { css, t, useTheme, themeObject } from '@superset-ui/core'; +import { + CloseCircleOutlined, + InfoCircleOutlined, + WarningOutlined, + ThunderboltOutlined, + QuestionCircleOutlined, +} from '@ant-design/icons'; import { Tooltip, TooltipProps, TooltipPlacement } from './Tooltip'; export interface InfoTooltipWithTriggerProps { label?: string; tooltip?: TooltipProps['title']; - icon?: string; onClick?: () => void; placement?: TooltipPlacement; - bsStyle?: string; className?: string; - iconsStyle?: CSSProperties; + iconStyle?: CSSObject | SerializedStyles; + type?: 'info' | 'warning' | 'notice' | 'error' | 'question'; + iconSize?: 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl'; } -export function InfoTooltipWithTrigger({ +export const InfoTooltipWithTrigger = ({ + type, + iconSize = 's', label, tooltip, - bsStyle, onClick, - icon = 'info-circle', className = 'text-muted', placement = 'right', - iconsStyle = {}, -}: InfoTooltipWithTriggerProps) { - const iconClass = `fa fa-${icon} ${className} ${ - bsStyle ? `text-${bsStyle}` : '' - }`; + iconStyle, +}: InfoTooltipWithTriggerProps) => { + const theme = useTheme(); + + const infoTooltipWithTriggerVariants = useMemo( + () => ({ + info: { color: theme.colorIcon, icon: <InfoCircleOutlined /> }, + question: { color: theme.colorIcon, icon: <QuestionCircleOutlined /> }, + warning: { color: theme.colorWarning, icon: <WarningOutlined /> }, + notice: { color: theme.colorWarning, icon: <ThunderboltOutlined /> }, + error: { color: theme.colorError, icon: <CloseCircleOutlined /> }, + }), + [theme], + ); + + const variant = type ? infoTooltipWithTriggerVariants[type] : null; + + const iconCss = css` + color: ${variant?.color ?? theme.colorIcon}; + font-size: ${themeObject.getFontSize(iconSize)}; + `; + + const handleKeyDown = (event: KeyboardEvent<HTMLSpanElement>) => { + if (onClick && (event.key === 'Enter' || event.key === ' ')) { + onClick(); + } + }; + const iconEl = ( - <i + <span role="button" aria-label={t('Show info tooltip')} tabIndex={0} - className={iconClass} - style={{ cursor: onClick ? 'pointer' : undefined, ...iconsStyle }} + className={className} + css={[ + css` + display: inline-flex; + align-items: center; + line-height: 0; + vertical-align: middle; + ${onClick ? 'cursor: pointer;' : ''} + `, + iconCss, + iconStyle, + ]} onClick={onClick} - onKeyPress={ - onClick && - (event => { - if (event.key === 'Enter' || event.key === ' ') { - onClick(); - } - }) - } - /> + onKeyDown={handleKeyDown} + > + {variant?.icon} + </span> ); + if (!tooltip) { return iconEl; } + return ( <Tooltip - id={`${kebabCase(label)}-tooltip`} + id={`${kebabCase(label) || Math.floor(Math.random() * 10000)}-tooltip`} Review Comment: I think we should still look to avoid doing this. Is this necessary? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org