/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/components/src/range-control/tooltip.tsx
65 строк
1 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import clsx from 'clsx'; import { useCallback, useEffect, useState } from '@wordpress/element'; import { Tooltip } from './styles/range-control-styles'; import type { TooltipProps } from './types'; import type { WordPressComponentProps } from '../context'; export default function SimpleTooltip( props: WordPressComponentProps< TooltipProps, 'span' > ) { const { className, inputRef, tooltipPlacement, show = false, style = {}, value = 0, renderTooltipContent = ( v ) => v, zIndex = 100, ...restProps } = props; const placement = useTooltipPlacement( { inputRef, tooltipPlacement } ); const classes = clsx( 'components-simple-tooltip', className ); const styles = { ...style, zIndex, }; return ( <Tooltip { ...restProps } aria-hidden="false" className={ classes } placement={ placement } show={ show } role="tooltip" style={ styles } > { renderTooltipContent( value ) } </Tooltip> ); } function useTooltipPlacement( { inputRef, tooltipPlacement }: TooltipProps ) { const [ placement, setPlacement ] = useState< string >(); const setTooltipPlacement = useCallback( () => { if ( inputRef && inputRef.current ) { setPlacement( tooltipPlacement ); } }, [ tooltipPlacement, inputRef ] ); useEffect( () => { setTooltipPlacement(); }, [ setTooltipPlacement ] ); useEffect( () => { window.addEventListener( 'resize', setTooltipPlacement ); return () => { window.removeEventListener( 'resize', setTooltipPlacement ); }; } ); return placement; }