Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-path-tooltip

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-path-tooltip

A tooltip for SVG paths in React

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.6K
decreased by-32.75%
Maintainers
1
Weekly downloads
 
Created
Source

React Path Tooltop

A simple yet beautiful react tooltip component for SVG-Paths. The component detects the SVG and Path locations/sizes. The component also detects the display text width of the tooltip. Based on that information a calculation is done so that the rendering of the tooltip will be optimized and correctly oriented.

Note: When generating SVG with multiple paths, make sure to add the tooltips at the bottom of the SVG element, after all the paths are already displays.

Install

In order to install, run the following command:

$ npm install react-path-tooltip --save

Usage

A very simple `App.tsx' example:

import React from "react"
import "./App.css"
import { PathTooltip } from "ReactPathTooltip" // import the package

function App() {

  const svgRef = React.createRef<SVGSVGElement>()
  const pathRef = React.createRef<SVGCircleElement>()

  return (
    < div className="App" >
      < div className="Main">
        <svg width="400" height="400" ref={svgRef}>
          <circle cx={50} cy={50} r={50} fill="red" ref={pathRef} />
          <PathTooltip svgRef={svgRef} pathRef={pathRef} tip="Hello World!" />
        </svg>
      </div>
    </div>
  )
}

export default App

Customization

The following parameters are passed to the tooltip component:

PropTypeDescription
tipstringMandatory. The text to be displayed inside the tooltip
svgRefReact.RefObjectMandatory. A React reference object to the SVG element
pathRefReact.RefObjectMandatory. A React reference object to the path element bounded to the tooltip
bgColorstringOptional. Background color. Default: "black"
textColorstringOptional. Text color. Default: "white"
fontFamilystringOptional. The font family. Default: san-serif
fontSizenumberOptional. The font size. Default 12

Notes:

  • tip must include simple text. No new lines, or html decoration.
  • pathRef must be a valid reference to a path element. There are a number of such types such as SVGRectElement, SVGCircleElement, etc.
  • The SVG rendering should be such that all the tooltip elelments are at the bottom of the SVG definition, and specifically, after the path elements. Otherwise, there is a risk of paths overlaping tooltips.

License

MIT

Keywords

FAQs

Package last updated on 24 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc