Giter Site home page Giter Site logo

ibhargav90 / ngx-tab-scroll Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rovico/ngx-tab-scroll

0.0 0.0 0.0 873 KB

Angular 7 clone of https://github.com/VersifitTechnologies/angular-ui-tab-scroll

License: MIT License

JavaScript 4.98% HTML 8.19% TypeScript 62.86% SCSS 23.97%

ngx-tab-scroll's Introduction

ngx-tab-scroll11

forked from rovico/ngx-tab-scroll to make it compitible with Angular 11, REMOVED ngbTabset as it was deprecated in newer version A scrollable tab plugin intended for scrolling UI Bootstrap tabset.

npm version npm downloads License

Installation

npm install [email protected]

or

yarn add [email protected]

Usage

  • Import preferred theme styles:

    /**
    ngx-tab-scroll
     */
    @import '~ngx-tab-scroll/tab-scroll-theme-flatten';
      

    OR

    /**
    ngx-tab-scroll
     */
    @import '~ngx-tab-scroll/tab-scroll-theme-bootstrap';
      

    And icons

    @import '~ngx-tab-scroll/tab-scroll-icons';
  • Import angular npm module:

    import { TabScrollModule } from 'ngx-tab-scroll';

    and in your @NgModule() decorator

    {
      ...,
      imports: [
        ...,
        TabScrollModule.forRoot({
          autoRecalculate: true,
          showDropDown: true,
          showTooltips: false,
          tooltipLeftPlacement: 'top',
          tooltipRightPlacement: 'top',
          scrollBy: 50,
          autoRecalculate: false,
          leftScrollAddition: 0
        }),
        ...
      ],
    }
  • Wrap your <ngb-tabset> inside of <ngx-tab-scroll>, like so:

<ngx-tab-scroll [showTooltips]="true">
	<ngb-tabset>
		<ngb-tab *ngFor="let x of tabs">...</ngb-tab>
	</ngb-tabset>
</scrollable-tabset>

Attributes

  • showDropDown - whether or not to show the drop-down for navigating the tabs, the drop-down reflects the selected tab and reflect if a tab is disabled. default is true.
  • showTooltips - whether or not to show tooltips on the scroll buttons. default is true.
  • tooltipLeftPlacement - which tooltip direction to use for the left button tooltip (bottom, top, left, right). default is right.
  • tooltipRightPlacement - which tooltip direction to use for the right button tooltip (bottom, top, left, right). default is left.
  • scrollBy - the amount of pixels to offset upon each scroll. default is 50.
  • autoRecalculate - whether or not to watch the tabs collection for changes to initiate a re-calculation. default is false. important! see warning below
  • dropDownHeaderTemplate - set custom header TemplateRef inside the drop-down. default is empty.

And additional attributes you can set on an individual tab:

  • data-tabScrollIgnore - if there is 'data-tabScrollIgnore="true"' on a tab than it will not be shown in the drop-down.
  • data-tabScrollHeading - put this on a tab and the value of it will be the text for this tab's tooltip and drop-down item.

Attributes can be directly set on each directive as DOM attributes

Example:

<ngx-tab-scroll [showTooltips]="true"
	              tooltipLeftPlacement="bottom"
	              [scrollBy]="150">
	<ngb-tabset>
		<ngb-tab *ngFor="let x of tabs">...</ngb-tab>
	</ngb-tabset>
</ngx-tab-scroll>

Or, they can be configured globally for all your ngx-tab-scroll components, by using the TabScrollConfigInterface, in the forRoot/forChild parameter. This way, you can keep the directive usage simple and consistent across all your html.

Important Notes:

  • Use autoRecalculate with caution! - when set to true a watcher is added to the collection of tabs, and watcher are costly on performance! it is better to call doRecalculate() when needed. use this option only on small applications.
  • When an option is both defined at directive level and at config level, the value specified in the DOM takes precedence over the one from the config!.

Api

there is an exposed api, with it you can call:

  • doRecalculate() - force a re-calculation of the scroll, this will calculate if the scroll buttons are needed and which to enable\disable. usually needed after a tabs are added or removed.
  • scrollTabIntoView() - scroll the selected tab into center of view. or if you want to scroll to a specific tab index:
  • scrollTabIntoView(number) - scroll the tab index into center of view.

Example:

export class AppComponent {

  @ViewChild(forwardRef(() => TabScrollComponent)) tabScroll: TabScrollComponent;

  tabs: {heading: string, content: string}[] = [];

  reCalcScroll() {
    this.tabScroll.api.doRecalculate();
  }

  scrollIntoView(n?: number) {
    this.tabScroll.api.scrollTabIntoView(n);
  }
}

Styling

you can use the default style by referencing tab-scroll-theme-bootstrap.css, or you can chose to use the alternative customized flat style by referencing the supplied tab-scroll-theme-flatten.css. both files are the result of a transpiled scss, which are also included in this package.

if you intend to have your own design i highly recommend you start with tab-scroll-theme-flatten.scss with it you can unleash the power of scss&css.

to change the icons on the buttons you simply need to override the relevant button's css with your own css

Example:

i[class^=ts-icon] {
  display: inline-block;
  width: 100%;
  margin-top: 10px;
  margin-left: 6px;
}
.ts-icon {
  &-chevron-left:before {
    content: url(data:image/svg+xml);
  }
  &-chevron-right:before {
    content: url(data:image/svg+xml);
  }
  &-chevron-down:before {
    content: url(data:image/svg+xml);
  }
  &-check:before {
    content: url(data:image/svg+xml);
  }
}

the drop-down can be given a class by using the dropDownClass property.

the drop-down menu can be given a class by using the dropDownMenuClass property.

the drop-down menu header can be given a class by using the dropDownHeaderClass property.

Dependencies

  • Angular7
  • Ngx Bootstrap
  • Bootstrap CSS

ngx-tab-scroll's People

Contributors

pavelaverkiev avatar ibhargav90 avatar rovico avatar falkzilm-nuclos 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.