N
N
Neuro2019-05-02 13:03:36
JavaScript
Neuro, 2019-05-02 13:03:36

How to implement hint when hovering over a block?

There is a react component like this:

<CM.UI.Flexbox.Box className='message-wrapper' column>
           <CM.UI.Flexbox.Item flex='0 1 auto'>
             {model.get('message')}
           </CM.UI.Flexbox.Item>
           <CM.UI.Flexbox.Item flex='0 1 auto' style={{opacity: '0.7'}}>
             {modelSensor ? `${CM.gettext('Name')}: ${modelSensor.get('description')}` : null}
           </CM.UI.Flexbox.Item>
           <CM.UI.Flexbox.Item flex='0 1 auto' style={{opacity: '0.7'}}>
             {modelSensor && modelSensor.get('location') ? `${CM.gettext('Address')}: ${modelSensor.get('location')}` : null}
           </CM.UI.Flexbox.Item>
           <CM.UI.Flexbox.Item flex='0 1 auto' style={{opacity: '0.5'}}>
             {timeFromNow}
           </CM.UI.Flexbox.Item>
</CM.UI.Flexbox.Box>

Which looks like this: 5cac03aa8e40898737639.png
How to make it so that when you hover over this block, a tooltip in the form of a name and address pops up?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-05-02
@Riveran

import React, { useState, useCallback } from 'react';
import { Icon, Hint } from '../some-place';

const Example = () => {
  const [shouldShowHint, setShouldShowHint] = useState(false);

  const onMouseEnter = () => useCallback({
    setShouldShowHint(true);
  }, []);
  
  const onMouseLeave = useCallback(() => {
    setShouldShowHint(false);
  }, []);

  return (
    <div
      onMouseEnter={onMouseEnter}
      onMouseLeave={onMouseLeave}
    >
      <Icon />
      {shouldShowHint && <Hint />}
    </div>
  );
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question