How to use @reach/tooltip - 5 common examples

To help you get started, we’ve selected a few @reach/tooltip examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vanilla / vanilla / library / src / scripts / toolTip / ToolTip.tsx View on Github external
function TriangleTooltip(props: { children: React.ReactNode; label: React.ReactNode; ariaLabel?: React.ReactNode }) {
    const globalVars = globalVariables();
    const { children, label, ariaLabel } = props;

    // get the props from useTooltip
    const [trigger, tooltip] = useTooltip();

    // destructure off what we need to position the triangle
    const { isVisible, triggerRect } = tooltip;

    const [hasOverflow, setHasOverflow] = useState(false);
    const classes = toolTipClasses();
    const toolTipVars = tooltipVariables();
    const borderOffset = globalVars.border.width * 2;

    const toolBoxPosition = (triggerRect, tooltipRect) => {
        const triangleHeight = toolTipVars.nub.width / 2;
        const triggerCenter = triggerRect.left + triggerRect.width / 2;
        const left = triggerCenter - tooltipRect.width / 2;
        const maxLeft = window.innerWidth - tooltipRect.width - 2;
        const hasOverflow = triggerRect.bottom + tooltipRect.height + triangleHeight > window.innerHeight;
github reach / reach-ui / packages / tooltip / examples / triangle.example.js View on Github external
function ExampleTriangle({ children, ...rest }) {
  // get the props from useTooltip
  const [trigger, tooltip] = useTooltip();

  // destructure off what we need to position the triangle
  const { isVisible, triggerRect } = tooltip;

  return (
    
      {cloneElement(children, trigger)}

      {isVisible && (
        // the Triangle, we position it relative to the trigger, not the popup
        // so that collisions don't have a triangle pointing off to nowhere
github reach / reach-ui / packages / slider / examples / with-tooltip.example.js View on Github external
export function Example() {
  const handleRef = useRef();
  const [trigger, tooltip] = useTooltip();
  const centered = (triggerRect, tooltipRect) => {
    const triggerCenter = triggerRect.left + triggerRect.width / 2;
    const left = triggerCenter - tooltipRect.width / 2;
    const maxLeft = window.innerWidth - tooltipRect.width - 2;
    return {
      left: Math.min(Math.max(2, left), maxLeft) + window.pageXOffset,
      top: triggerRect.bottom + 8 + window.pageYOffset
    };
  };

  // We want to show the tooltip whenever the handle is focused, regardless
  // of what happens with mouse events.
  const preventDefaultWhenFocused = useCallback(event => {
    if (document.activeElement === event.currentTarget) {
      event.preventDefault();
    }
github lbryio / lbry-desktop / src / ui / component / channelTooltip / view.jsx View on Github external
function TriangleTooltip(props: TriangleTooltipProps) {
  const { label, children, ariaLabel } = props;

  // get the props from useTooltip
  const [trigger, tooltip] = useTooltip();

  // Tooltip direction
  const [direction, setDirection] = React.useState('bottom');

  // destructure off what we need to position the triangle
  const { isVisible, triggerRect } = tooltip;

  let arrowTop;

  // Top
  if (direction === 'top') {
    arrowTop = triggerRect && triggerRect.bottom - (triggerRect.height + ARROW_SIZE) + window.scrollY;
  }

  // Bottom
  if (direction === 'bottom') {
github reach / reach-ui / packages / tooltip / examples / animated.example.js View on Github external
function ExampleAnimatedTooltip({ children, ...rest }) {
  const [trigger, tooltip, isVisible] = useTooltip();

  const transitions = useTransition(isVisible ? tooltip : false, null, {
    from: { opacity: 0 },
    enter: { opacity: 1 },
    leave: { opacity: 0 },
    config: { mass: 1, tension: 500, friction: 40 }
  });

  return (
    
      {cloneElement(children, trigger)}

      {transitions.map(
        ({ item: tooltip, props: styles, key }) =>
          tooltip && (

@reach/tooltip

Accessible tooltips

MIT
Latest version published 2 years ago

Package Health Score

68 / 100
Full package analysis

Popular @reach/tooltip functions

Similar packages