GithubHelp home page GithubHelp logo

salahatwa / ng2-fittext Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thisloke/ng2-fittext

0.0 1.0 0.0 850 KB

An Angular2+ directive that autoscale the font size of an element until it fit the upper level container dimension.

License: MIT License

TypeScript 100.00%

ng2-fittext's Introduction

ng2-fittext

An Angular2 directive written in pure typescript (and without jquery!), for autoscale the font size of an element to fit an upper level container.

How many times your font doesn't scale automatically to fit the size of the container? Always, if you don't say it to do that! How you can say it? ng2-fittext!

Demo

http://plnkr.co/edit/v0TQaYepV4E2Heur02j5?p=preview

Installation

Install the library

$ npm install --save ng2-fittext

Usage

Import it in your Angular2 project like a module

  1. Declare it in your module

    import {Ng2FittextModule} from "ng2-fittext";
    @NgModule({
      imports: [
        Ng2FittextModule
      ]
    })
    
  2. Use it in your components

    Fit with specified container (can be the parent or a deeper ancestor)

    import {Component} from '@angular/core';
    
    @Component({
      selector: 'label',
      template: `<div #container>
                    <div [fittext]="true" [activateOnResize]="true" [container]="container">Bla bla bla...</div>
                </div>`
    })
    
    export class LabelComponent {}

    Fit with the parent element (this works if you have a variable number of element between element and parent)

    import {Component} from '@angular/core';
    
    @Component({
      selector: 'label',
      template: `<div>
                    <div [fittext]="true" [activateOnResize]="true">Bla bla bla...</div>
                </div>`
    })
    
    export class LabelComponent {}

    NEW! Support for autoresize input box!

    import {Component} from '@angular/core';
    
    @Component({
      selector: 'inputbox',
      template: `<div #container>
                    <input [fittext]="true" [activateOnResize]="true" [container]="container" [activateOnInputEvents]="true">`,
                </div>`
    })
    
    export class InputBoxComponent {}

    NEW! Support for maxFontSize!

    import {Component} from '@angular/core';
    
    @Component({
      selector: 'inputbox',
      template: `<div>
                    <input [fittext]="true" [activateOnResize]="true" [activateOnInputEvents]="true" [minFontSize]="40" [maxFontSize]="100">`,
                </div>`
    })
    
    export class InputBoxComponent {}

    Input Parameters:

Parameter Description Values
fittext is the selector of the directive true/false
container the container to fit (if not present it fit default to parent container) ElementRef
activateOnResize enable/disable the autofit in case of window resize true or false (default false)
activateOnInputEvents enbale/disable the autofit in case of input box events (keydown, keyup etc..) true or false (default false)
maxFontSize maximal font size number, default is 1000
!deprecated! useMaxFontSize use max font size if is true deprecated!
minFontSize minimal font size number, default is 7
modelToWatch pass model to watch, when this model changes -> font size is automatically recalculated any type of model

Output Parameters:

Parameter Description Values
fontSizeChanged current font size string

Development

Want to contribute? Great! Simply, clone the repository!

I created this library because I always spended too much time for solve this problem and because i didn't find nothing on the web (13/03/2017) that do this without jquery and easily integrable in angular2. For sure is not a good implementation, maybe is not the best way to do it, but, it do the job.

Todos

  • Write tests
  • Find a better algorithm to find the font-size who fits better the container

License

MIT

Lorenzo I.

ng2-fittext's People

Contributors

davidstellini avatar dependabot[bot] avatar kiwikern avatar ljupcospeci avatar martinduris avatar nischi avatar thisloke avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.