Giter Site home page Giter Site logo

knockout-accordion's Introduction

Knockout Accordion

Accordion Knockout Component based on Bootstrap.

It's using the latest knockout features that allow communication between components.

Demo

Install

Download and insert to the page the knockout-accordion.min.js script file.

<script src="knockout-accordion.min.js"></script>

Dependencies:

  • Knockout 3.3.0 and above
  • jQuery
  • Bootstrap CSS (Optional)

Usage

Case 1 - Static list of items

A simple example of accordion with specified items count.

<ko-accordion>
  <ko-accordion-item params="{ heading: 'Item 1' }">
    Content
  </ko-accordion-item>
  <ko-accordion-item params="{ heading: 'Item 2' }">
    Content
  </ko-accordion-item>
</ko-accordion>

Case 2 - Dynamic list of items

An example of accordion which items can be changed dynamically.

<ko-accordion>
  <!-- ko foreach: $root.items -->
  <ko-accordion-item params="{ heading: $data.name }">
    <div data-bind="text: $parent.content"></div>
  </ko-accordion-item>
  <!-- /ko -->
</ko-accordion>
var viewModel = {
  items: ko.observableArray([
    { name: 'Item 1', content: 'Content' },
    { name: 'Item 2', content: 'Content' }
  ])
};
ko.applyBindings(viewModel);

Components

The following components are included in this library:

Accordion

Parent component to contains the accordion items.

Selector: ko-accordion

Options:

Name Type Description
selectedIndex number | KnockoutObservable<number> Defines the expanded item

Options are available through the params binding.

Accordion Item

Collapsible panel with header and content.

Selector: ko-accordion-item

Options:

Name Type Description
heading string | KnockoutObservable<string> Sets the text in the header

Options are available through the params binding.

knockout-accordion's People

Contributors

tsvetomirnik 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.