Giter Site home page Giter Site logo

react-collapsible-mixin's Introduction

Build Status

React Collapsible mixin

Bootstrap like Collapsible mixin which work with a predefined toggling behaviour.

Usage

Usage via npm and browserify is recommended at this stage.

Install

npm install --save react-collapsible-mixin

Use

  • Each collapsible content element must have unique ref that has collapsible prefix
  • Each collapser (trigger) element must have href set referencing '#' + ref
  • Each collapser (trigger) element must pass ref of the content its responsible for toggling
var CollapsibleMixin = require('react-collapsible-mixin');

var MyComponent = React.createClass({
	mixins: [CollapsibleMixin],

	render: function () {
		var c1_ref = 'collapsible-content-1';
		var c2_ref = 'collapsible-content-2';

		return (
			<div className="row">
				<div className="col-xs-12">
					<a
						href={'#' + c1_ref}
						className={this.getCollapserClassSet(c1_ref)}
						onClick={this._onToggleCollapsible}>
						Toggle
					</a>
					<a
						href={'#' + c2_ref}
						className={this.getCollapserClassSet(c2_ref)}
						onClick={this._onToggleCollapsible}>
						Toggle
					</a>
				</div>
				<div
					ref={c1_ref}
					className={this.getCollapsibleClassSet(c1_ref)}>
					<p>Here are some random content</p>
					<p>That will toggle</p>
				</div>
				<div
					ref={c2_ref}
					className={this.getCollapsibleClassSet(c2_ref)}>
					<p>Here are some random content</p>
					<p>That will toggle</p>
				</div>
			</div>
		);
	}
});

API

When you include CollapsibleMixin in your component you will get the following states and functions added to your component:

State

this.state.expanded: contains key values pairs that map each ref to its current expanded state. State is obtained initial after component has been mounted by inspecting collapsible content element for existing in className.

getCollapserClassSet(ref, defaults)

Helper function to grab class names for the collapser element. You can optionally pass in defaults object to set extra class names.

getCollapsibleClassSet(ref, defaults)

Helper function to grab class names for the collapsible element. You can optionally pass in defaults object to set extra class names.

_onToggleCollapsible

Event handler which you can attach to collapsers.

Remembering state

Use it with existing LocalStorageMixin to remember the state of the collapsible element.

Recent changes

13th Feb 2015

  • Add support for multiple collapsible elements

react-collapsible-mixin's People

Contributors

hongymagic avatar dwendo avatar

Stargazers

Richard avatar

Watchers

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