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-text-vice

v1.2.2

Published

Fit text to container using SVG

Downloads

12

Readme

react-text-vice

Fit text to container using SVG

NPM JavaScript Style Guide

Image of a vice / vise

A component that will place any text in an SVG <text> element and adjust the SVG viewBox so that the text fits in it perfectly.

The SVG can then be styled like any regular SVG to fit its containers width / height, scale, crop etc, allowing the text to be fitted to a container as if it was an image, while still retaining its accessibility.

This is supposed to be an alternative to various text-fit / fit-text libraries that did not work for me.

👉 Live Demo

Install

npm install --save react-text-vice

Usage

import React, {Component} from 'react'

import TextVice from 'react-text-vice'

class Example extends Component {
  render() {
    return (
      <TextVice
        font="sans-serif"
      >
        This text will fit its container
      </TextVice>
    )
  }
}

Apply styles to the text using the props below, keep in mind that it's an SVG text element, so you will have to use fill instead of color etc.

Props

children

Add text content directly as a child of the component, changing the text will trigger a re-fit.

font (String)

Shortcut to set the fontFamily of the text, this can be used instead of textStyle / textClassName if all you want to change is the font family.

textStyle (Object)

Styles to apply to the inner <text> Element, you can use this to set the font, text color etc.

svgStyle (Object)

Styles to apply to the outer <svg> element.

textClassName (String)

Class to apply to the inner <text> element, use this if you wish to set the font styling from a CSS file.

svgClassName (String)

Class to apply to the outer <svg> element

width, height, preserveAspectRatio (String)

Standard SVG props to apply to the outer <svg> element, use this to control scaling etc as you would with any other SVG.

onFit(viewBox) (Function)

Function to be called when text has been fit, will be passed the viewBox string calculated for the outer <svg>

cropTop, cropBot (Number)

Factor relative to the calculated height to crop from the top and bottom.

License

MIT © JonasGruenwald