npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-svg-text

v0.1.2

Published

## Features - Word-wrapping (when `width` prop is defined) - Vertical alignment (`verticalAnchor` prop) - Rotation (`angle` prop) - Scale-to-fit text (`scaleToFit` prop)

Downloads

2,269

Readme

Better SVG text component for React

Features

  • Word-wrapping (when width prop is defined)
  • Vertical alignment (verticalAnchor prop)
  • Rotation (angle prop)
  • Scale-to-fit text (scaleToFit prop)

Example

Simple demo to show off a useful feature. Since svg <text> itself does not support verticalAnchor, normally text rendered at 0,0 would be outside the viewport and not visible. By using <Text> with verticalAnchor="start" prop, the text will now be visible as you'd expect.

import React from 'react';
import { render } from 'react-dom';
import Text from 'react-svg-text';

const App = () => (
  <svg>
    <Text verticalAnchor="start">Hello world</Text>
  </svg>
);

render(<App />, document.getElementById('root'));

See demo to see additional props and how they work

Props

Property | Type | Default | Description -------- | ---- | ------- | ----------- x | number | | x coordinate to use as a basis for positioning the text element y | number | | y coordinate to use as a basis for positioning the text element dx | number | | Horizontal shift from the x coordinate dy | number | | Vertical shift from the y coordinate width | number | | Width of text container. Used to implement word wrapping and for context when scaleToFit is true scaleToFit | bool | false | Resize text to fit container width angle | number | | Rotate text around origin (defined by textAnchor and verticalAnchor) textAnchor | string | start | How the text is horizontally positioned relative to the given x and y coordinates. Options are start, middle, end, and inherit. verticalAnchor | string | end | How text is vertically positioned relative to the given x and y coordinates. Options are start, middle, end lineHeight | string | 1em | How much space a single line of text should take up capHeight | string | 0.71em (Magic number from d3) | Defines a text metric for the font being used: the expected height of capital letters. This is necessary because of SVG, which (a) positions the bottom of the text at y, and (b) has no notion of line height. This prop should be given as a number of ems additional props | | | Additional props are passed down to underlying <text> component, including style and className

TODO

  • Fix tests (jsdom does not support getComputedTextLength() or getBoundingClientRect()) and setup CI