# fitr-svg-text

> Fits text of any number of characters into provided dimensions and position within svg.

Latest version **1.0.6** (published 2021-06-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install fitr-svg-text
pnpm add fitr-svg-text
yarn add fitr-svg-text
bun add fitr-svg-text
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2021-06-07 |
| First published | 2018-05-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 4 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Ivan Maksimovic |
| Maintainers | ivnmaksimovic |
| Keywords | react-component, fittext, textsize, svgtext, svg, react |

## Links

- npm: https://www.npmjs.com/package/fitr-svg-text
- Repository: https://github.com/ivnmaksimovic/fitr-svg-text
- Homepage: https://github.com/ivnmaksimovic/fitr-svg-text#readme
- Issues: https://github.com/ivnmaksimovic/fitr-svg-text/issues
- npm.io page: https://npm.io/package/fitr-svg-text

## Dependencies (1)

- [prop-types](https://npm.io/package/prop-types.md) ^15.7.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.6 (latest) — 2021-06-07
- 1.0.5 — 2020-08-20
- 1.0.3 — 2019-09-02
- 1.0.2 — 2019-09-02
- 1.0.1 — 2019-08-29
- 1.0.0 — 2018-10-17
- 0.0.6 — 2018-10-17
- 0.0.5 — 2018-05-20
- 0.0.4 — 2018-05-20
- 0.0.3 — 2018-05-20
- 0.0.2 — 2018-05-20
- 0.0.1 — 2018-05-20

## README

# fitr-svg-text

React text component that fits the text within svg to specified dimensions and position.

## Install

```bash
npm install --save fitr-svg-text
```

## Usage

````js
import React from 'react';
import ReactDOM from 'react-dom';
import FitrSvgText from 'fitr-svg-text';

ReactDOM.render(
  <svg id="some-svg-container" viewBox="0 0 400 200" >
    <FitrSvgText
      text='This should fit in 200px'
      width={200}
      maxHeight={80}
      x={200}
      y={100}
      textAnchor='middle'
    />
  </svg>,
  document.getElementById('root')
);
`````

## API

| Name         | Type    | Default | Description |
| ------------ | ------- | ------- | ----------- |
| text | string | - | Text to render |
| width | number | - | Width to fit text to |
| maxHeight | number | - | Limit height so text can not grow to much if there is for example only 2 characters but width is 400px |
| x | number | - | x position of text relative to parent svg. It respects the text-achor property |
| y | number | - | y position of text baseline relative to parent svg |
| textAnchor | string | 'start' | native text-anchor accepting one of 'start', 'middle' or 'end' [https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/text-anchor](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/text-anchor) |

## Develop

1. run `npm install`
2. run `npm start`
3. go to [http://localhost:9001/](http://localhost:9001/)

## Generate static doc

run `npm run static-docs` to generate docs in `docs` folder

## License

`fitr-svg-text` is released under the MIT license.

---
_Source: https://npm.io/package/fitr-svg-text · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
