Giter Club home page Giter Club logo

bc-tabs's Introduction

Bigcommerce Tabs UI Module

Create a tabbed UI element

TODO

  • Update _toggleClasses to allow for accordion layout.
  • Add responsive setting that allows tabbed UI to break down into accordion at smaller screen sizes

Installation

npm install --save github:pixelunion/bc-tabs

Options

All options are optional.

tabScope

The jQuery object of the tab nav container. defaults to $('[data-tabs]').

tabToggle

The jQuery object of the tab link. defaults to $('[data-tab-title]').

tabContent

The jQuery object of the tab content. defaults to $('[data-tab-content]').

toggleTab

Override for the tab toggle function.

keepTabsOpen

Override for keepTabsOpen function. Needs to return boolean

activeClass

Class given to both the nav element and content container for the currently active tab.

defaultTab

E.G. #search-content-listing

afterSetup

Callback function called once the tabs have been initialized. Gets passed the id of the currently active tab.

afterChange

Callback function called when a tab is clicked. Gets passed the id of the clicked tab.

tabHistory

Leverage the history API for tab chages. Defaults to false.

Some sample markup

Tabs

<ul class="tabs" data-tabs>
  <li class="tab-title"><a href="#featured-products">Featured Products</a></li>
  <li class="tab-title"><a href="#best-sellers">Best Sellers</a></li>
</ul>
<div class="tabs-content">
  <div class="tabs-content-panel" id="featured-products">
    Tab panel content
  </div>
  <div class="tabs-content-panel" id="best-sellers">
    Tab panel content
  </div>
</div>

Accordion

<section data-tabs>
  <h2 class="tab-title"><a href="#hello">tab</a></h2>
  <div class="tabs-content-panel" id="hello">
   content with an anchor
   <a href="http://google.com">google</a>
  </div>
  <h2 class="tab-title"><a href="#goodbye">tab2</a></h2>
  <div class="tabs-content-panel" id="goodbye">
   other content
  </div>
</section>

Javascript

// Constructor:
this.tabs = new Tabs({
  afterSetup: (tabId) => {
    alert(`The tabs are ready! the current tab is ${tabId}`);
  },
  afterChange: () => {
    alert(`A tab has been changed! the new tab is ${tabId}`);
  }
});

// _bind:
this.tabs.displayTabContent('#leave-review');

SCSS

// Style the tab themselves.
.tab-title {
  font-weight: normal;

  &.active {
    font-weight: bold;
  }
}

.tab-content-panel {
  display: none;

  &.active {
    display: block;
  }
}

Further Development

For debugging or improvements you can run a standalone test version of the module using a very basic webpack development server:

$ npm install
$ npm run demo

This will allow you to make changes to the JS and HTML while working with a live demo in your browser.

bc-tabs's People

Contributors

pixelmargaret avatar essmahr avatar nboliver 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.