1.1.0 • Published 6 years ago

ngx-height-toggle v1.1.0

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

ngx-height-toggle - Angular(2+) directive to change the height of html elements to their content's height on toggle and on content change.

npm version

Table of Contents

Demo

Check out the demo at https://stackblitz.com/edit/ngx-height-toggle-demo

Dependencies

  • @angular/common: ^5.1.0
  • @angular/core: ^5.1.0
  • rxjs: ^6.3.3

Installation

Install ngx-height-toggle via npm:

npm install --save ngx-height-toggle

or with yarn:

yarn add ngx-height-toggle

Once installed you need to import NgxHeightToggleModule in your module where you'd like to use the directive:

import { NgxHeightToggleModule } from 'ngx-height-toggle';

@NgModule({
  declarations: [MyComponent, ...],
  imports: [NgxHeightToggleModule, ...],
})
export class MyModule { }

Usage

Default Height change

You have to add the directive ngxHeightToggle to the element you want to toggle, and pass a variable telling it whether it should be expanded or collapsed.

<div class="collapsible" ngxHeightToggle [open]="open">
    <p>some text</p>
</div>

When you want to toggle the height, change the variable.

export class MyComponent {

    public open = false;

    public toggle(): void {
        this.open = !this.open;
    }

}

The directive will automatically adjust the height when the content height changes.

Collapsible in another collapsible

In case you want to include a collapsible inside another collapsible, you need to disable change detection for the wrapper collapsible directive.

Directive inputs

Input nameTypeDefault valueNote
openbooleanrequiredDepending on the value the directive will close or open.
closedHeightnumber0Specifies the height of closed state in pixels.
transitionDurationnumber500Standard css property for translation-duration. Specify in ms.
transitionPropertystring'height'Standard css property for transition-property. Other than 'height', only option that makes sense is using 'all', if needed.
transitionTimingFunctionstring'linear'Standard css property for transition-timing-function.
transitionDelaynumber0Standard css property for transition-delay. Specify in ms.
enableChangeDetectionbooleantrueUse this input to turn off change detection. Unless disabled the directive will check the content height in every AfterViewChecked lifecycle hook and change the directive's height to the height of its content.
1.1.0

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago

0.0.0

6 years ago