Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="react-root"></div>
              
            
!

CSS

              
                #react-root {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 10px;
}

section {
  margin-bottom: 50px;
}

a {
  display: inline-block;
}

.target {
  text-decoration: underline;
  cursor: pointer;
}

.target .react-tooltip-lite {
  cursor: default;
}

.flex-spread {
  display: flex;
  justify-content: space-between;
}

.tip-heading {
  margin: 0 0 10px;
}

.tip-list {
  margin: 0;
  padding: 0 0 0 15px;
}

.tip-list li {
  margin: 5px 0;
  padding: 0;
}

/* tooltip styles */
.react-tooltip-lite {
  background: #333;
  color: white;
}

.react-tooltip-lite a {
  color: #86b0f4;
  text-decoration: none;
}

.react-tooltip-lite a:hover {
  color: #4286f4;
}

.react-tooltip-lite-arrow {
  border-color: #333;
}

/* overrides with a custom class */
.customTip .react-tooltip-lite {
  border: 1px solid #888;
  background: #ccc;
  color: black;
}

.customTip .react-tooltip-lite-arrow {
  border-color:  #444;
  position: relative;
}

.customTip .react-tooltip-lite-arrow::before {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
  z-index: 99;
  display: block;
}

.customTip .react-tooltip-lite-up-arrow::before {
  border-top: 10px solid #ccc;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  left: -10px;
  top: -11px;
}

.customTip .react-tooltip-lite-down-arrow::before {
  border-bottom: 10px solid #ccc;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  left: -10px;
  bottom: -11px;
}

.customTip .react-tooltip-lite-right-arrow::before {
  border-right: 10px solid #ccc;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  right: -11px;
  top: -10px;
}

.customTip .react-tooltip-lite-left-arrow::before {
  border-left: 10px solid #ccc;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  left: -11px;
  top: -10px;
}

.imageWrapper {
  margin: 50px 0 0;
  position: relative;
}

.imageWrapper img {
  width: 500px;
  height: 500px;
}

.controlled-example {
  max-width: 250px;
}

.controlled-example_header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 15px;
  padding-bottom: 5px;
  border-bottom: 1px solid #fff;
}

.controlled-example_close-button {
  cursor: pointer;
  background: none;
  border: none;
  color: white;
  font-size: 16px;
  padding: 0;
}

.controlled-example_close-button:hover {
  color: grey;
}

.internal-scroll-container {
  height: 200px;
  overflow: auto;
}

.internal-scroll-container > div {
  padding-top: 100px;
  height: 400px;
}

.arrow-content-tooltip .react-tooltip-lite {
  box-sizing: border-box;
  border: 1px solid gray;
  border-radius: 8px;
  box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.2);
}

.arrow-content-tooltip .react-tooltip-lite-down-arrow svg {
  transform: translateY(1px);
}

.arrow-content-tooltip .react-tooltip-lite-right-arrow svg {
  transform: rotate(270deg) translateY(-4px) translateX(-4px);
}
.arrow-content-tooltip .react-tooltip-lite-up-arrow svg {
  transform: rotate(180deg) translateY(1px);
}
.arrow-content-tooltip .react-tooltip-lite-left-arrow svg {
  transform: rotate(90deg) translateY(5px) translateX(4px);
}

              
            
!

JS

              
                const Tooltip = ReactToolTipLite.default;

class App extends React.Component {
  constructor(props) {
    super(props);

    this.state = { tipOpen: false };

    this.toggleTip = this.toggleTip.bind(this);
    this.bodyClick = this.bodyClick.bind(this);
  }

  componentDidMount() {
    document.addEventListener('mousedown', this.bodyClick);
  }

  componentWillUnmount() {
    document.removeEventListener('mousedown', this.bodyClick);
  }

  tipContentRef;

  buttonRef;

  toggleTip() {
    this.setState(prevState => ({ tipOpen: !prevState.tipOpen }));
  }

  bodyClick(e) {
    if ((this.tipContentRef && this.tipContentRef.contains(e.target)) || this.buttonRef.contains(e.target)) {
      return;
    }

    this.setState({ tipOpen: false });
  }
  
  render() {
    const { tipOpen } = this.state;
    return (
      <div className="wrapper">
        <h1>React tooltip-lite examples</h1>

        <section>
          <h3>Basic:</h3>

          <div className="flex-spread">
            <Tooltip padding={20} content="By default the text is above the element" className="target" tipContentClassName="foo">
              Target
            </Tooltip>

            <Tooltip content="It'll center if it has room" className="target" tipContentClassName="">
              Target
            </Tooltip>

            <Tooltip content="you can specify 'direction' (up, down, left, right) too" direction="down" className="target" tipContentClassName="">
              t
            </Tooltip>

            <Tooltip onToggle={(isOpen) => { console.log(`Is tooltip open ? \n Answer : ${isOpen ? 'Yes' : 'No'}`); }} content="alert shown" className="target" tipContentClassName="">
              Hover Me
            </Tooltip>
          </div>
        </section>

        <section>
          <h3>In a paragraph</h3>
          <p>
            For&nbsp;
            <Tooltip content="Go to google" direction="right" tagName="span">
              <a href="http://google.com" target="_blank" rel="noopener noreferrer">inline text</a>
            </Tooltip>
            , a right or left tip works nicely. The tip will try to go the desired way and flip if there is not
            enough&nbsp;
            <Tooltip content="Go to google" direction="right" tagName="span" distance={20}>
              <a href="http://google.com" target="_blank" rel="noopener noreferrer">space</a>
            </Tooltip>
            . Shrink the window and see how the tip behaves when close to the&nbsp;
            <Tooltip content="Go to google" direction="right" tagName="span">
              <a href="http://google.com" target="_blank" rel="noopener noreferrer">edge</a>
            </Tooltip>
            . You can also force the direction of the tip and it will allow itself&nbsp;
            <Tooltip className="target" tipContentClassName="" content="this direction is forced" direction="right" tagName="span" forceDirection>to go off screen</Tooltip>
            .
          </p>
        </section>

        <section>
          <h3>Html Contents</h3>

          <p>
            You can also have a tooltip with&nbsp;
            <Tooltip
              content={(
                <div>
                  <h4 className="tip-heading">An unordered list to demo some html content</h4>
                  <ul className="tip-list">
                    <li>One</li>
                    <li>Two</li>
                    <li>Three</li>
                    <li>Four</li>
                    <li>Five</li>
                  </ul>
                </div>
              )}
              direction="down"
              tagName="span"
              className="target"
              tipContentClassName=""
            >
              Html content
            </Tooltip>
            .
          </p>

          <p>
            By specifying the prop &quot;tipContentHover&quot; as true, you can persist hover state when cursor is over the tip.  This allows for links
            in your tip, copying contents and other behaviors.  Here&apos;s an&nbsp;
            <Tooltip
              content={(
                <div>
                  You can copy this text, or click this&nbsp;
                  <a href="https://www.npmjs.com/package/react-tooltip-lite" target="_blank" rel="noopener noreferrer">link</a>
                </div>
              )}
              tagName="span"
              direction="right"
              className="target"
              tipContentClassName=""
              tipContentHover
            >
              example
            </Tooltip>
            .
          </p>
        </section>

        <section>
          <h3>Colors</h3>

          You can pass&nbsp;
          <Tooltip
            tagName="span"
            className="target"
            tipContentClassName=""
            color="blue"
            background="red"
            content="The color for this is defined by props"
          >
            color options as props
          </Tooltip>
          &nbsp;
          or use a&nbsp;
          <Tooltip
            tagName="span"
            className="target customTip"
            direction="right"
            content="The color for this tip is defined by examples/index.css"
          >
            css stylesheet.
          </Tooltip>
          &nbsp;
          With the arrowContent prop you have&nbsp;
          <Tooltip
            content="Event more customizations possible via the arrowContent prop"
            className="target"
            background="white"
            color="black"
            tipContentClassName="arrow-content-tooltip"
            spacing={0}
            tagName="span"
            arrowContent={(
              <svg style={{ display: 'block' }} viewBox="0 0 21 11" width="20px" height="10px">
                <path
                  d="M0,11 L9.43630703,1.0733987 L9.43630703,1.0733987 C10.1266203,0.3284971 11.2459708,0 11.936284,1.0733987 L20,11"
                  style={{ stroke: 'gray', fill: 'white' }}
                />
              </svg>
            )}
          >
            even more control.
          </Tooltip>
        </section>

        <section>
          <h3>Wrap anything as a target</h3>
          <Tooltip content="this is lorem ipsum">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut tincidunt egestas sapien quis lacinia. Praesent ut sem leo.
            Curabitur vel dolor eu nulla ultrices efficitur a ut mauris. Nulla non odio non nibh venenatis commodo non vitae magna.
            Nunc porttitor, dolor nec sodales commodo, velit elit auctor arcu, sed dapibus nibh lacus sit amet nunc.
            Phasellus enim dui, blandit sed faucibus sit amet, feugiat vel urna. Vivamus ut lacus sollicitudin, dignissim risus vel,
            iaculis leo. Donec lobortis, turpis nec pulvinar venenatis, orci nunc semper sem, nec ornare nisl nisi ut ligula. Integer
            ut tempus elit. Cras luctus, tellus id vestibulum accumsan, purus velit mattis erat, euismod tempor mauris elit eget metus.
            Vivamus interdum ex sed egestas tincidunt.
          </Tooltip>

        </section>

        <section>
          <h3>Custom events</h3>
          <p>
            <Tooltip content="this uses hover but also closes on click" className="target" tipContentClassName="" tagName="span" eventOff="onClick">
              Close on click
            </Tooltip>
          </p>

          <p>
            <Tooltip
              content="opens on a click and closes on mouse out"
              className="target"
              tipContentClassName=""
              tagName="span"
              eventOn="onClick"
              eventOff="onMouseOut"
              useHover={false}
            >
              Open on click
            </Tooltip>
          </p>

          <p>
            <Tooltip content="this uses hover but also closes on click" className="target" tipContentClassName="" tagName="span" eventToggle="onClick">
              Toggle on click
            </Tooltip>
          </p>
        </section>
        <section>
          <h3>Default styles</h3>
          <p>
            pass the
            {'"defaultStyles"'}
            prop as true to get up and running quick and easy
          </p>
          <p>
            <Tooltip content="styled with defaults" className="target" tipContentClassName="" useDefaultStyles tagName="span">
              See default styles
            </Tooltip>
          </p>
        </section>
        <section>
          <h3>Controlled by props</h3>

          <button
            type="button"
            ref={(el) => { this.buttonRef = el; }}
            onClick={this.toggleTip}
          >
            {tipOpen ? 'close' : 'open'}
          </button>
          <br />
          <br />
          <Tooltip
            content={(
              <div ref={(el) => { this.tipContentRef = el; }} className="controlled-example">
                <div className="controlled-example_header">
                  Hello
                  <button type="button" className="controlled-example_close-button" onClick={this.toggleTip}>&times;</button>
                </div>
                This tip is controlled by the button, you can also click outside the tip or on the&nbsp;
                {'"x"'}
                &nbsp;to close it
              </div>
            )}
            isOpen={tipOpen}
            tagName="span"
            direction="down"
            forceDirection
          >
            click the button
          </Tooltip>
        </section>

        <section>
          <h3>Distance and arrow size</h3>

          <div className="flex-spread">
            <Tooltip content="This has an arrowSize of 20, where the default is 10" className="target" tipContentClassName="" arrowSize={20}>Larger arrowSize</Tooltip>
            <Tooltip content="This has an arrowSize of 5, where the default is 10" className="target" tipContentClassName="" arrowSize={5}>Smaller arrowSize</Tooltip>
            <Tooltip content="This has a distance prop of 20, where the default is arrowSize" className="target" tipContentClassName="" distance={20}>Increase distance</Tooltip>
            <Tooltip content="This has a distance prop of 0, where the default is the arrowSize" className="target" tipContentClassName="" distance={0}>Decrease distance</Tooltip>
          </div>
        </section>

        <section>
          <h3>Compound Alignment</h3>

          <div className="flex-spread">
            <Tooltip content="you can have compound alignments" direction="right-start" className="target" tipContentClassName="" arrow={false}>
              right-start
            </Tooltip>

            <Tooltip content="you can have compound alignments" direction="right-end" className="target" tipContentClassName="" arrow={false}>
              right-end
            </Tooltip>

            <Tooltip content="you can have compound alignments" direction="left-start" className="target" tipContentClassName="" arrow={false}>
              left-start
            </Tooltip>

            <Tooltip content="you can have compound alignments" direction="left-end" className="target" tipContentClassName="" arrow={false}>
              left-end
            </Tooltip>

            <Tooltip content="you can have compound alignments" direction="up-start" className="target" tipContentClassName="" arrow={false}>
              top-start
            </Tooltip>

            <Tooltip content="you can have compound alignments" direction="up-end" className="target" tipContentClassName="" arrow={false}>
              top-end
            </Tooltip>

            <Tooltip content="you can have compound alignments" direction="down-start" className="target" tipContentClassName="" arrow={false}>
              down-start
            </Tooltip>

            <Tooltip content="you can have compound alignments" direction="down-end" className="target" tipContentClassName="" arrow={false}>
              down-end
            </Tooltip>
          </div>
          <br />
          <br />
          <div className="flex-spread">
            <Tooltip content="you can have compound alignments" direction="right-start" className="target" tipContentClassName="">
              right-start with arrow
            </Tooltip>

            <Tooltip content="you can have compound alignments" direction="right-end" className="target" tipContentClassName="">
              right-end with arrow
            </Tooltip>

            <Tooltip content="you can have compound alignments" direction="left-start" className="target" tipContentClassName="">
              left-start with arrow
            </Tooltip>

            <Tooltip content="you can have compound alignments" direction="left-end" className="target" tipContentClassName="">
              left-end with arrow
            </Tooltip>

            <Tooltip content="you can have compound alignments" direction="down-start" className="target" tipContentClassName="">
              down-start with arrow
            </Tooltip>

            <Tooltip content="you can have compound alignments" direction="down-end" className="target" tipContentClassName="">
              down-end with arrow
            </Tooltip>

            <Tooltip content="you can have compound alignments" direction="up-start" className="target" tipContentClassName="">
              up-start with arrow
            </Tooltip>

            <Tooltip content="you can have compound alignments" direction="up-end" className="target" tipContentClassName="">
              up-end with arrow
            </Tooltip>
          </div>
        </section>
        <section>
          <Tooltip tagName="span" content="check the console log" onToggle={isVisible => console.log(`is visible: ${isVisible}`)}>
            On toggle example
          </Tooltip>
          &nbsp; &nbsp;
          <Tooltip tagName="span" content="This has a z-index of 5000" zIndex={5000} eventToggle="onClick">
            z-index example
          </Tooltip>
        </section>
        <section>
          <h3>Internal scrollbars</h3>
          <div className="internal-scroll-container">
            <div>
              <Tooltip content="hello" tagName="span">
                  Scroll on mobile tapping here
              </Tooltip>
            </div>
          </div>
        </section>
      </div>
    );
  }
}

ReactDOM.render(<App />, document.getElementById('react-root'));
              
            
!
999px

Console