3.2.0 • Published 3 months ago

adaptable-text v3.2.0

Weekly downloads
4
License
MIT
Repository
github
Last release
3 months ago

adaptable-text

npm version stability-stable npm minzipped size dependencies types Conventional Commits styled with prettier linted with eslint license

Adapt font size to a specified width using either binary search or linear steps.

Linear steps works best for small adjustments (eg. on resize) while binary search is most efficient when the expected font-size change is big.

paypal coinbase twitter

Installation

npm install adaptable-text

Usage

import AdaptableText from "adaptable-text";

const textToAdapt = new AdaptableText(document.querySelector(".TextToAdapt"), {
  step: 0.1,
  minFontSize: 10,
  width: null,
});
textToAdapt.init();

// Adapt
const adapt = () => {
  textToAdapt.setWidth();
  textToAdapt.adapt();
};

// Listen for a resize event
window.addEventListener("resize", adapt);

// Kick off
adapt(true);

API

Classes

Typedefs

AdaptableText

Kind: global class

new AdaptableText(element, options)

Creates an instance of AdaptableText.

ParamType
elementHTMLElement
optionsOptions

adaptableText.init()

Initialise the adaptor.

Kind: instance method of AdaptableText

adaptableText.setWidth()

Set the desired width for adaptation from options.width or getBoundingClientRect().width

Kind: instance method of AdaptableText

adaptableText.adapt(useBinarySearch)

Adapt font size to a specified width.

Kind: instance method of AdaptableText

ParamType
useBinarySearchboolean

Options : object

Kind: global typedef Properties

NameTypeDefaultDescription
stepnumber0.5The step used by the generator to calculate the width of the element.
minFontSizenumber0A minimum font size for the element (max would be the size defined in a stylesheet retrieved by window.getComputedStyle(this.element)).
widthnumber"null"A maximum width for the container.

License

MIT. See license file.

3.2.0

3 months ago

3.1.0

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.1

7 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago