Code Monkey home page Code Monkey logo

aurelia-plugins-tabs's Introduction

aurelia-plugins-tabs

A tabs plugin for Aurelia.

Installation

Webpack/Aurelia CLI

npm install aurelia-plugins-tabs --save

JSPM

jspm install aurelia-plugins-tabs

Bower

bower install aurelia-plugins-tabs

Configuration

Inside of your main.js or main.ts file simply load the plugin inside of the configure method using .plugin().

export async function configure(aurelia) {
  aurelia.use
    .standardConfiguration()
    .developmentLogging();

  aurelia.use
    .plugin('aurelia-plugins-tabs');

    await aurelia.start();
    aurelia.setRoot('app');
}

Usage

This plugin is comprised of multiple components to be used together.

Tabs

The tabs component is where your clickable tabs are generated. It has a required bindable attribute tabs and a optional attribute class.

  • The tabs attribute expects an array of one or more objects which contains at least an id property and a label property. The id property is used to identify which pane this tab will open. The label property is the value displayed. A third optional property active allows us to specify if this tab is the default active tab.
  • The class attribute is copied from the custom element to the inner UL element. Useful if you want to use something else than tabs, like pills or inline. For more info see the Bootstrap documentation.
<aup-tabs class="nav-tabs" tabs.bind="myTabs"></aup-tabs>
export class App {
  constructor() {
    this.myTabs = [
      { id: 'tab1', label: 'Tab 1', active: true },
      { id: 'tab2', label: 'Tab 2' },
      { id: 'tab3', label: 'Tab 3' }
    ];
  }
}

When a tab is clicked, the event aurelia-plugins:tabs:tab-clicked:{tab-id} will be published, where {tab-id} is the corresponding id as defined in the tabs array. The payload is the click event.

Tab Content

Once you have your tabs setup, you will want to create your tab content which wraps tab panes.

<aup-tab-content></aup-tab-content>

Tab Pane

Inside the tab content, create a tab pane for each defined tab. A tab pane has a required value tab which matches the id of a tab in the tabs array.

<aup-tab-pane tab="tab1">
  <h1>Tab 1</h1>
  <p>Lorem ipsum...</p>
</aup-tab-pane>

Composition

A tab pane can dynamically render a ViewModel by placing the compose element inside it.

<aup-tab-pane tab="tab1"><compose view="./helloWorld.html"></compose></aup-tab-pane>

Full Example

<aup-tabs tabs.bind="myTabs"></aup-tabs>
<aup-tab-content>
  <aup-tab-pane tab="tab1">
    <h1>Tab 1</h1>
    <p>Lorem ipsum...</p>
  </aup-tab-pane>
  <aup-tab-pane tab="tab2"><compose view="./helloWorld.html"></compose></aup-tab-pane>
  <aup-tab-pane tab="tab3"><compose view-model="./helloWorld" model.bind="myModel"></compose></aup-tab-pane>
</aup-tab-content>
export class App {
  constructor() {
    this.myModel = { target: 'Hello World' };
    this.myTabs = [
      { id: 'tab1', label: 'Tab 1', active: true },
      { id: 'tab2', label: 'Tab 2' },
      { id: 'tab3', label: 'Tab 3' }
    ];
  }
}

aurelia-plugins-tabs's People

Contributors

trydis avatar

Watchers

Alyce Bills 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.